mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 00:24:12 +00:00
expr.c:
fix a braino that caused only sizeof expr to work linker.c: print an error message if unable to open the lib qc-parse.y: revamp expression parsing so casting is done via (type)expr rather than type(expr) make it so pointers to pointers don't need ()s
This commit is contained in:
parent
b3671874bf
commit
7af99f422f
3 changed files with 55 additions and 34 deletions
|
@ -2402,7 +2402,7 @@ message_expr (expr_t *receiver, keywordarg_t *message)
|
||||||
expr_t *
|
expr_t *
|
||||||
sizeof_expr (expr_t *expr, struct type_s *type)
|
sizeof_expr (expr_t *expr, struct type_s *type)
|
||||||
{
|
{
|
||||||
if (!((!expr) ^ (!expr))) {
|
if (!((!expr) ^ (!type))) {
|
||||||
error (0, "internal error");
|
error (0, "internal error");
|
||||||
abort ();
|
abort ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ static const char rcsid[] =
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "QF/dstring.h"
|
#include "QF/dstring.h"
|
||||||
#include "QF/hash.h"
|
#include "QF/hash.h"
|
||||||
|
@ -643,8 +644,11 @@ linker_add_lib (const char *libname)
|
||||||
int i, j;
|
int i, j;
|
||||||
int did_something;
|
int did_something;
|
||||||
|
|
||||||
if (!pack)
|
if (!pack) {
|
||||||
|
if (errno)
|
||||||
|
perror (libname);
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
did_something = 0;
|
did_something = 0;
|
||||||
for (i = 0; i < pack->numfiles; i++) {
|
for (i = 0; i < pack->numfiles; i++) {
|
||||||
|
|
|
@ -119,8 +119,8 @@ expr_t *argv_expr (void);
|
||||||
%left SHL SHR %left '+' '-'
|
%left SHL SHR %left '+' '-'
|
||||||
%left '*' '/' '&' '|' '^' '%'
|
%left '*' '/' '&' '|' '^' '%'
|
||||||
%right <op> UNARY INCOP
|
%right <op> UNARY INCOP
|
||||||
%right '(' '['
|
%left HYPERUNARY
|
||||||
%left '.'
|
%left '.' '(' '['
|
||||||
|
|
||||||
%token <string_val> CLASS_NAME NAME STRING_VAL
|
%token <string_val> CLASS_NAME NAME STRING_VAL
|
||||||
%token <integer_val> INT_VAL
|
%token <integer_val> INT_VAL
|
||||||
|
@ -142,10 +142,11 @@ expr_t *argv_expr (void);
|
||||||
%type <param> param param_list
|
%type <param> param param_list
|
||||||
%type <def> def_name
|
%type <def> def_name
|
||||||
%type <def> def_item def_list
|
%type <def> def_item def_list
|
||||||
%type <expr> const opt_expr expr arg_list element_list element_list1 element
|
%type <expr> const opt_expr expr element_list element_list1 element
|
||||||
%type <expr> string_val opt_state_expr array_decl
|
%type <expr> string_val opt_state_expr array_decl
|
||||||
%type <expr> statement statements statement_block
|
%type <expr> statement statements statement_block
|
||||||
%type <expr> break_label continue_label enum_list enum
|
%type <expr> break_label continue_label enum_list enum
|
||||||
|
%type <expr> unary_expr primary cast_expr opt_arg_list arg_list
|
||||||
%type <function> begin_function
|
%type <function> begin_function
|
||||||
%type <def_list> save_inits
|
%type <def_list> save_inits
|
||||||
%type <switch_block> switch_block
|
%type <switch_block> switch_block
|
||||||
|
@ -163,7 +164,7 @@ expr_t *argv_expr (void);
|
||||||
%type <methodlist> methodprotolist methodprotolist2
|
%type <methodlist> methodprotolist methodprotolist2
|
||||||
%type <type> ivar_decl_list
|
%type <type> ivar_decl_list
|
||||||
|
|
||||||
%expect 3 // statement : if | if else, class_name : maybe_class | category_name : maybe_class '(' maybe_class ')', type_name : TYPE | expr : TYPE '(' expr ')'
|
%expect 3
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
|
@ -284,6 +285,10 @@ type
|
||||||
current_params = $2;
|
current_params = $2;
|
||||||
$$ = parse_params ($1, $2);
|
$$ = parse_params ($1, $2);
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
non_field_type
|
||||||
|
: '(' type ')' { $$ = $2; }
|
||||||
| non_field_type array_decl
|
| non_field_type array_decl
|
||||||
{
|
{
|
||||||
if ($2)
|
if ($2)
|
||||||
|
@ -291,10 +296,6 @@ type
|
||||||
else
|
else
|
||||||
$$ = pointer_type ($1);
|
$$ = pointer_type ($1);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
non_field_type
|
|
||||||
: '(' type ')' { $$ = $2; }
|
|
||||||
| type_name { $$ = $1; }
|
| type_name { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -790,8 +791,42 @@ opt_expr
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
unary_expr
|
||||||
|
: primary
|
||||||
|
| '+' cast_expr %prec UNARY { $$ = $2; }
|
||||||
|
| '-' cast_expr %prec UNARY { $$ = unary_expr ('-', $2); }
|
||||||
|
| '!' cast_expr %prec UNARY { $$ = unary_expr ('!', $2); }
|
||||||
|
| '~' cast_expr %prec UNARY { $$ = unary_expr ('~', $2); }
|
||||||
|
| '&' cast_expr %prec UNARY { $$ = address_expr ($2, 0, 0); }
|
||||||
|
| SIZEOF unary_expr %prec UNARY { $$ = sizeof_expr ($2, 0); }
|
||||||
|
| SIZEOF '(' non_field_type ')' %prec HYPERUNARY { $$ = sizeof_expr (0, $3); }
|
||||||
|
;
|
||||||
|
|
||||||
|
primary
|
||||||
|
: NAME { $$ = new_name_expr ($1); }
|
||||||
|
| ARGS { $$ = new_name_expr (".args"); }
|
||||||
|
| ARGC { $$ = argc_expr (); }
|
||||||
|
| ARGV { $$ = argv_expr (); }
|
||||||
|
| SELF { $$ = new_self_expr (); }
|
||||||
|
| THIS { $$ = new_this_expr (); }
|
||||||
|
| const { $$ = $1; }
|
||||||
|
| '(' expr ')' { $$ = $2; $$->paren = 1; }
|
||||||
|
| primary '(' opt_arg_list ')' { $$ = function_expr ($1, $3); }
|
||||||
|
| primary '[' expr ']' { $$ = array_expr ($1, $3); }
|
||||||
|
| primary '.' primary { $$ = binary_expr ('.', $1, $3); }
|
||||||
|
| INCOP primary { $$ = incop_expr ($1, $2, 0); }
|
||||||
|
| primary INCOP { $$ = incop_expr ($2, $1, 1); }
|
||||||
|
| obj_expr { $$ = $1; }
|
||||||
|
;
|
||||||
|
|
||||||
|
cast_expr
|
||||||
|
: unary_expr
|
||||||
|
| '(' non_field_type ')' cast_expr %prec UNARY { $$ = cast_expr ($2, $4); }
|
||||||
|
;
|
||||||
|
|
||||||
expr
|
expr
|
||||||
: expr '=' expr { $$ = assign_expr ($1, $3); }
|
: cast_expr
|
||||||
|
| expr '=' expr { $$ = assign_expr ($1, $3); }
|
||||||
| expr ASX expr { $$ = asx_expr ($2, $1, $3); }
|
| expr ASX expr { $$ = asx_expr ($2, $1, $3); }
|
||||||
| expr '?' expr ':' expr { $$ = conditional_expr ($1, $3, $5); }
|
| expr '?' expr ':' expr { $$ = conditional_expr ($1, $3, $5); }
|
||||||
| expr AND expr { $$ = binary_expr (AND, $1, $3); }
|
| expr AND expr { $$ = binary_expr (AND, $1, $3); }
|
||||||
|
@ -812,29 +847,11 @@ expr
|
||||||
| expr '|' expr { $$ = binary_expr ('|', $1, $3); }
|
| expr '|' expr { $$ = binary_expr ('|', $1, $3); }
|
||||||
| expr '^' expr { $$ = binary_expr ('^', $1, $3); }
|
| expr '^' expr { $$ = binary_expr ('^', $1, $3); }
|
||||||
| expr '%' expr { $$ = binary_expr ('%', $1, $3); }
|
| expr '%' expr { $$ = binary_expr ('%', $1, $3); }
|
||||||
| expr '(' arg_list ')' { $$ = function_expr ($1, $3); }
|
;
|
||||||
| expr '(' ')' { $$ = function_expr ($1, 0); }
|
|
||||||
| TYPE '(' expr ')' { $$ = cast_expr ($1, $3); }
|
opt_arg_list
|
||||||
| expr '[' expr ']' { $$ = array_expr ($1, $3); }
|
: /* emtpy */ { $$ = 0; }
|
||||||
| expr '.' expr { $$ = binary_expr ('.', $1, $3); }
|
| arg_list { $$ = $1; }
|
||||||
| '+' expr %prec UNARY { $$ = $2; }
|
|
||||||
| '-' expr %prec UNARY { $$ = unary_expr ('-', $2); }
|
|
||||||
| '!' expr %prec UNARY { $$ = unary_expr ('!', $2); }
|
|
||||||
| '~' expr %prec UNARY { $$ = unary_expr ('~', $2); }
|
|
||||||
| '&' expr %prec UNARY { $$ = address_expr ($2, 0, 0); }
|
|
||||||
| INCOP expr { $$ = incop_expr ($1, $2, 0); }
|
|
||||||
| expr INCOP { $$ = incop_expr ($2, $1, 1); }
|
|
||||||
| obj_expr { $$ = $1; }
|
|
||||||
| NAME { $$ = new_name_expr ($1); }
|
|
||||||
| ARGS { $$ = new_name_expr (".args"); }
|
|
||||||
| ARGC { $$ = argc_expr (); }
|
|
||||||
| ARGV { $$ = argv_expr (); }
|
|
||||||
| SELF { $$ = new_self_expr (); }
|
|
||||||
| THIS { $$ = new_this_expr (); }
|
|
||||||
| SIZEOF '(' expr ')' { $$ = sizeof_expr ($3, 0); }
|
|
||||||
| SIZEOF '(' type ')' { $$ = sizeof_expr (0, $3); }
|
|
||||||
| const { $$ = $1; }
|
|
||||||
| '(' expr ')' { $$ = $2; $$->paren = 1; }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
arg_list
|
arg_list
|
||||||
|
|
Loading…
Reference in a new issue