2001-06-12 19:44:26 +00:00
|
|
|
%{
|
2001-09-28 07:09:38 +00:00
|
|
|
/*
|
2002-11-06 16:32:28 +00:00
|
|
|
qc-parse.y
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
parser for quakec
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-11-06 16:32:28 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/06/12
|
2001-09-28 07:09:38 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-14 20:18:29 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-10-24 22:50:06 +00:00
|
|
|
#include <QF/hash.h>
|
|
|
|
#include <QF/sys.h>
|
2001-06-15 19:38:43 +00:00
|
|
|
|
2002-06-21 20:46:56 +00:00
|
|
|
#include "class.h"
|
2002-06-04 21:23:39 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "def.h"
|
2002-07-08 20:31:59 +00:00
|
|
|
#include "emit.h"
|
2002-06-01 05:30:16 +00:00
|
|
|
#include "expr.h"
|
2002-05-08 05:15:19 +00:00
|
|
|
#include "function.h"
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "immediate.h"
|
2002-05-08 21:24:24 +00:00
|
|
|
#include "method.h"
|
2002-06-04 18:44:03 +00:00
|
|
|
#include "options.h"
|
2002-06-21 20:46:56 +00:00
|
|
|
#include "qfcc.h"
|
|
|
|
#include "reloc.h"
|
2001-12-08 08:19:48 +00:00
|
|
|
#include "struct.h"
|
2001-10-25 06:41:52 +00:00
|
|
|
#include "switch.h"
|
2002-01-17 16:59:00 +00:00
|
|
|
#include "type.h"
|
2001-10-25 06:41:52 +00:00
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
#define YYDEBUG 1
|
|
|
|
#define YYERROR_VERBOSE 1
|
2003-02-25 07:48:12 +00:00
|
|
|
#undef YYERROR_VERBOSE
|
2001-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
extern char *yytext;
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-06-18 22:51:49 +00:00
|
|
|
yyerror (const char *s)
|
2001-06-12 20:24:02 +00:00
|
|
|
{
|
2003-02-25 07:48:12 +00:00
|
|
|
#ifdef YYERROR_VERBOSE
|
2001-07-03 20:53:49 +00:00
|
|
|
error (0, "%s %s\n", yytext, s);
|
2003-02-25 07:48:12 +00:00
|
|
|
#else
|
|
|
|
error (0, "%s before %s", s, yytext);
|
|
|
|
#endif
|
2001-06-12 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-05-15 19:10:23 +00:00
|
|
|
parse_error (void)
|
|
|
|
{
|
|
|
|
error (0, "parse error before %s", yytext);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PARSE_ERROR do { parse_error (); YYERROR; } while (0)
|
|
|
|
|
2001-06-12 20:24:02 +00:00
|
|
|
int yylex (void);
|
2001-06-21 07:08:34 +00:00
|
|
|
|
2002-06-09 03:57:20 +00:00
|
|
|
hashtab_t *save_local_inits (scope_t *scope);
|
2001-10-19 03:22:04 +00:00
|
|
|
hashtab_t *merge_local_inits (hashtab_t *dl_1, hashtab_t *dl_2);
|
2001-10-19 00:45:56 +00:00
|
|
|
void restore_local_inits (hashtab_t *def_list);
|
2001-10-19 03:22:04 +00:00
|
|
|
void free_local_inits (hashtab_t *def_list);
|
2001-10-18 23:06:39 +00:00
|
|
|
|
2002-10-16 02:28:08 +00:00
|
|
|
expr_t *argc_expr (void);
|
|
|
|
expr_t *argv_expr (void);
|
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%}
|
|
|
|
|
2001-06-12 20:24:02 +00:00
|
|
|
%union {
|
2001-10-19 00:45:56 +00:00
|
|
|
int op;
|
2002-06-04 21:23:39 +00:00
|
|
|
struct def_s *def;
|
2004-01-25 08:55:03 +00:00
|
|
|
struct hashtab_s *def_list;
|
|
|
|
struct type_s *type;
|
2004-11-02 07:02:00 +00:00
|
|
|
struct typedef_s *typename;
|
2004-01-25 08:55:03 +00:00
|
|
|
struct expr_s *expr;
|
2001-10-19 00:45:56 +00:00
|
|
|
int integer_val;
|
|
|
|
float float_val;
|
2002-06-27 22:48:28 +00:00
|
|
|
const char *string_val;
|
2001-10-19 00:45:56 +00:00
|
|
|
float vector_val[3];
|
|
|
|
float quaternion_val[4];
|
2002-06-04 18:44:03 +00:00
|
|
|
struct function_s *function;
|
2004-01-25 08:55:03 +00:00
|
|
|
struct switch_block_s *switch_block;
|
2002-05-08 05:15:19 +00:00
|
|
|
struct param_s *param;
|
2002-05-08 21:24:24 +00:00
|
|
|
struct method_s *method;
|
2002-05-10 00:00:23 +00:00
|
|
|
struct class_s *class;
|
2002-11-14 18:17:43 +00:00
|
|
|
struct category_s *category;
|
|
|
|
struct class_type_s *class_type;
|
2002-05-08 21:24:24 +00:00
|
|
|
struct protocol_s *protocol;
|
2004-11-11 00:34:00 +00:00
|
|
|
struct protocollist_s *protocol_list;
|
2002-05-08 23:12:49 +00:00
|
|
|
struct keywordarg_s *keywordarg;
|
2002-05-10 00:00:23 +00:00
|
|
|
struct methodlist_s *methodlist;
|
2003-07-30 04:11:45 +00:00
|
|
|
struct struct_s *strct;
|
2001-06-12 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
2007-04-28 08:49:07 +00:00
|
|
|
%nonassoc IFX
|
|
|
|
%nonassoc ELSE
|
|
|
|
%nonassoc BREAK_PRIMARY
|
|
|
|
%nonassoc ';'
|
|
|
|
%nonassoc CLASS_NOT_CATEGORY
|
|
|
|
|
2007-05-07 23:44:45 +00:00
|
|
|
%nonassoc STORAGEX
|
|
|
|
|
2001-12-12 08:39:47 +00:00
|
|
|
%right <op> '=' ASX PAS /* pointer assign */
|
2001-08-11 21:15:24 +00:00
|
|
|
%right '?' ':'
|
2003-09-19 20:50:05 +00:00
|
|
|
%left OR
|
|
|
|
%left AND
|
|
|
|
%left '|'
|
|
|
|
%left '^'
|
|
|
|
%left '&'
|
|
|
|
%left EQ NE
|
|
|
|
%left LE GE LT GT
|
|
|
|
%left SHL SHR
|
|
|
|
%left '+' '-'
|
|
|
|
%left '*' '/' '%'
|
2001-08-20 06:22:28 +00:00
|
|
|
%right <op> UNARY INCOP
|
2002-10-31 22:58:59 +00:00
|
|
|
%left HYPERUNARY
|
|
|
|
%left '.' '(' '['
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2002-08-18 04:08:02 +00:00
|
|
|
%token <string_val> CLASS_NAME NAME STRING_VAL
|
2001-07-23 01:31:22 +00:00
|
|
|
%token <integer_val> INT_VAL
|
2001-06-15 07:16:18 +00:00
|
|
|
%token <float_val> FLOAT_VAL
|
|
|
|
%token <vector_val> VECTOR_VAL
|
|
|
|
%token <quaternion_val> QUATERNION_VAL
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2002-05-08 05:15:19 +00:00
|
|
|
%token LOCAL RETURN WHILE DO IF ELSE FOR BREAK CONTINUE ELLIPSIS NIL
|
pr_comp.h:
o add ev_uniteger to the types enum
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
progs.h:
o add uinteger accessors
pr_exec.c:
o implement ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
pr_opcode.c:
o add opcodes for ifbe, ifb, ifae, ifa, jump, lt.ui, gt.ui, le.ui, ge.ui
expr.h:
o prototype inc_users
qfcc.h:
o add externs for op_ifbe, op_ifb, op_ifae and op_ifa
emit.c:
o don't bother emiting an assignment to a temp def that's only used once
(ie, it's never read, only written to)
o support the new if* instructions
expr.c:
o support the new if* insructions
o dectect expression loops in append_expr
o support unsigned integers
o re-work temp def usage counting
pr_def.c
o debugging for temp def usage counts
pr_opcode.c:
o support the new if* instructions
qc-parse.y:
o provide defines for IFBE IFB IFAE IFA
switch.c:
o do binary searches for strings, floats and ints if there are more than
8 cases in a switch. Strings need more testing.
2001-11-09 00:58:16 +00:00
|
|
|
%token IFBE IFB IFAE IFA
|
2002-06-20 20:28:01 +00:00
|
|
|
%token SWITCH CASE DEFAULT STRUCT UNION ENUM TYPEDEF SUPER SELF THIS
|
2004-11-13 11:50:00 +00:00
|
|
|
%token ARGS ARGC ARGV EXTERN STATIC SYSTEM SIZEOF OVERLOAD
|
2001-06-14 21:49:47 +00:00
|
|
|
%token <type> TYPE
|
2004-11-02 07:02:00 +00:00
|
|
|
%token <typename> TYPE_NAME
|
2002-05-07 16:55:54 +00:00
|
|
|
%token CLASS DEFS ENCODE END IMPLEMENTATION INTERFACE PRIVATE PROTECTED
|
|
|
|
%token PROTOCOL PUBLIC SELECTOR
|
|
|
|
|
2002-11-04 17:54:31 +00:00
|
|
|
%type <type> type non_field_type type_name def simple_def struct_def
|
|
|
|
%type <type> struct_def_item ivar_decl ivar_declarator def_item def_list
|
2004-02-10 23:20:44 +00:00
|
|
|
%type <type> struct_def_list ivars func_type non_func_type
|
2004-11-13 11:50:00 +00:00
|
|
|
%type <type> non_code_func code_func func_init func_defs func_def_list
|
|
|
|
%type <def> fdef_name cfunction_def func_def
|
2002-05-08 05:15:19 +00:00
|
|
|
%type <param> function_decl
|
|
|
|
%type <param> param param_list
|
2002-11-04 17:54:31 +00:00
|
|
|
%type <def> def_name opt_initializer methoddef var_initializer
|
2004-01-25 21:36:44 +00:00
|
|
|
%type <expr> const opt_expr fexpr expr element_list element_list1 element
|
2004-02-11 08:09:10 +00:00
|
|
|
%type <expr> string_val opt_state_expr think opt_step array_decl
|
2001-06-25 20:52:04 +00:00
|
|
|
%type <expr> statement statements statement_block
|
2003-10-22 08:05:17 +00:00
|
|
|
%type <expr> label break_label continue_label enum_list enum
|
2002-10-31 22:58:59 +00:00
|
|
|
%type <expr> unary_expr primary cast_expr opt_arg_list arg_list
|
2007-04-09 06:16:34 +00:00
|
|
|
%type <function> begin_function builtin_function
|
2001-10-18 23:06:39 +00:00
|
|
|
%type <def_list> save_inits
|
2001-10-25 06:41:52 +00:00
|
|
|
%type <switch_block> switch_block
|
2004-11-02 07:02:00 +00:00
|
|
|
%type <string_val> identifier
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2004-11-02 07:02:00 +00:00
|
|
|
%type <string_val> selector reserved_word
|
2002-05-08 21:24:24 +00:00
|
|
|
%type <param> optparmlist unaryselector keyworddecl keywordselector
|
|
|
|
%type <method> methodproto methoddecl
|
2002-05-08 23:12:49 +00:00
|
|
|
%type <expr> obj_expr identifier_list obj_messageexpr obj_string receiver
|
2004-11-11 00:34:00 +00:00
|
|
|
%type <protocol_list> protocolrefs protocol_list
|
2002-05-08 23:12:49 +00:00
|
|
|
%type <keywordarg> messageargs keywordarg keywordarglist selectorarg
|
|
|
|
%type <keywordarg> keywordnamelist keywordname
|
2002-11-14 18:17:43 +00:00
|
|
|
%type <class> class_name new_class_name class_with_super new_class_with_super
|
|
|
|
%type <class> classdef
|
|
|
|
%type <category> category_name new_category_name
|
2002-05-10 00:00:23 +00:00
|
|
|
%type <protocol> protocol_name
|
|
|
|
%type <methodlist> methodprotolist methodprotolist2
|
2003-07-30 04:11:45 +00:00
|
|
|
%type <strct> ivar_decl_list
|
2004-02-09 07:35:19 +00:00
|
|
|
%type <op> ci
|
2002-05-08 05:15:19 +00:00
|
|
|
|
2001-06-15 07:16:18 +00:00
|
|
|
%{
|
|
|
|
|
2001-06-25 22:11:20 +00:00
|
|
|
function_t *current_func;
|
2002-05-08 05:15:19 +00:00
|
|
|
param_t *current_params;
|
2002-05-08 21:24:24 +00:00
|
|
|
expr_t *current_init;
|
2002-11-14 18:17:43 +00:00
|
|
|
class_type_t *current_class;
|
2001-07-15 01:51:01 +00:00
|
|
|
expr_t *local_expr;
|
2001-10-24 18:57:29 +00:00
|
|
|
expr_t *break_label;
|
|
|
|
expr_t *continue_label;
|
2001-10-25 06:41:52 +00:00
|
|
|
switch_block_t *switch_block;
|
2003-07-30 04:11:45 +00:00
|
|
|
struct_t *current_struct;
|
|
|
|
visibility_type current_visibility;
|
|
|
|
struct_t *current_ivars;
|
2002-06-09 03:57:20 +00:00
|
|
|
scope_t *current_scope;
|
2004-02-08 23:46:40 +00:00
|
|
|
storage_class_t current_storage = st_global;
|
2001-06-15 07:16:18 +00:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
2007-04-28 08:49:07 +00:00
|
|
|
%expect 2
|
2004-02-08 23:46:40 +00:00
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
defs
|
|
|
|
: /* empty */
|
2004-02-08 23:46:40 +00:00
|
|
|
| defs {if (current_class) PARSE_ERROR;} def
|
2002-05-08 21:24:24 +00:00
|
|
|
| defs obj_def
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
def
|
2004-11-02 07:02:00 +00:00
|
|
|
: simple_def { }
|
|
|
|
| storage_class simple_def { current_storage = st_global; }
|
2004-02-08 23:46:40 +00:00
|
|
|
| storage_class '{' simple_defs '}' ';'
|
|
|
|
{ current_storage = st_global; }
|
2004-11-02 07:02:00 +00:00
|
|
|
| STRUCT identifier
|
|
|
|
{ current_struct = new_struct ($2); } opt_eq '{' struct_defs '}' ';' { }
|
|
|
|
| UNION identifier
|
|
|
|
{ current_struct = new_union ($2); } opt_eq '{' struct_defs '}' ';' { }
|
|
|
|
| STRUCT identifier ';' { decl_struct ($2); }
|
|
|
|
| UNION identifier ';' { decl_union ($2); }
|
2004-02-08 23:46:40 +00:00
|
|
|
| ENUM '{' enum_list opt_comma '}' ';'
|
2002-01-21 19:03:29 +00:00
|
|
|
{ process_enum ($3); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| TYPEDEF type identifier ';'
|
2002-01-23 20:50:25 +00:00
|
|
|
{ new_typedef ($3, $2); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| TYPEDEF ENUM '{' enum_list opt_comma '}' identifier ';'
|
2002-01-23 20:50:25 +00:00
|
|
|
{
|
|
|
|
process_enum ($4);
|
|
|
|
new_typedef ($7, &type_integer);
|
|
|
|
}
|
2002-01-21 19:09:23 +00:00
|
|
|
;
|
|
|
|
|
2004-11-13 11:50:00 +00:00
|
|
|
opt_eq
|
2005-03-31 08:23:11 +00:00
|
|
|
: /* empty */ { }
|
|
|
|
| '=' { }
|
2004-11-13 11:50:00 +00:00
|
|
|
;
|
|
|
|
|
2004-02-10 23:20:44 +00:00
|
|
|
opt_semi
|
|
|
|
: /* empty */
|
|
|
|
| ';'
|
|
|
|
;
|
|
|
|
|
2002-09-12 17:13:19 +00:00
|
|
|
simple_defs
|
|
|
|
: /* empty */
|
2004-02-08 23:46:40 +00:00
|
|
|
| simple_defs simple_def
|
2002-09-12 17:13:19 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
simple_def
|
2004-02-10 23:20:44 +00:00
|
|
|
: non_func_type def_list ';' { }
|
2004-11-02 07:08:00 +00:00
|
|
|
| func_type func_defs { }
|
|
|
|
| cfunction { }
|
2004-02-11 00:36:34 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
cfunction
|
2004-11-13 11:50:00 +00:00
|
|
|
: cfunction_def ';'
|
2004-02-11 00:36:34 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-09 06:16:34 +00:00
|
|
|
| cfunction_def '=' '#' fexpr
|
|
|
|
{ $<def>$ = $1; }
|
|
|
|
{ $<expr>$ = constant_expr ($4); }
|
|
|
|
builtin_function ';'
|
2004-02-11 00:36:34 +00:00
|
|
|
{
|
2007-04-09 06:16:34 +00:00
|
|
|
(void) ($<def>5);
|
|
|
|
(void) ($<expr>6);
|
2004-02-11 00:36:34 +00:00
|
|
|
}
|
2004-11-13 11:50:00 +00:00
|
|
|
| cfunction_def opt_state_expr
|
2004-02-11 00:36:34 +00:00
|
|
|
{ $<op>$ = current_storage; }
|
2004-11-13 11:50:00 +00:00
|
|
|
{ $<def>$ = $1; }
|
|
|
|
begin_function statement_block { $<op>$ = $<op>3; } end_function
|
2004-02-11 00:36:34 +00:00
|
|
|
{
|
2004-11-13 11:50:00 +00:00
|
|
|
build_code_function ($5, $2, $6);
|
2004-02-13 04:57:15 +00:00
|
|
|
current_func = 0;
|
2006-12-01 08:17:55 +00:00
|
|
|
(void) ($<def>4);
|
|
|
|
(void) ($<op>7);
|
2004-02-11 00:36:34 +00:00
|
|
|
}
|
2002-09-12 17:13:19 +00:00
|
|
|
;
|
|
|
|
|
2004-11-13 11:50:00 +00:00
|
|
|
cfunction_def
|
|
|
|
: OVERLOAD non_func_type identifier function_decl
|
|
|
|
{
|
|
|
|
type_t *type = parse_params ($2, current_params = $4);
|
|
|
|
$$ = get_function_def ($3, type, current_scope,
|
|
|
|
current_storage, 1, 1);
|
|
|
|
}
|
|
|
|
| non_func_type identifier function_decl
|
|
|
|
{
|
|
|
|
type_t *type = parse_params ($1, current_params = $3);
|
|
|
|
$$ = get_function_def ($2, type, current_scope,
|
|
|
|
current_storage, 0, 1);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2002-06-28 17:59:32 +00:00
|
|
|
storage_class
|
2004-11-02 07:08:00 +00:00
|
|
|
: EXTERN { current_storage = st_extern; }
|
|
|
|
| STATIC { current_storage = st_static; }
|
|
|
|
| SYSTEM { current_storage = st_system; }
|
2002-06-28 17:59:32 +00:00
|
|
|
;
|
|
|
|
|
2006-12-11 09:26:07 +00:00
|
|
|
local_storage_class
|
|
|
|
: LOCAL { current_storage = st_local; }
|
2007-04-28 08:49:07 +00:00
|
|
|
| %prec STORAGEX { current_storage = st_local; }
|
2006-12-11 09:26:07 +00:00
|
|
|
| STATIC { current_storage = st_static; }
|
|
|
|
;
|
|
|
|
|
2001-12-08 08:19:48 +00:00
|
|
|
struct_defs
|
|
|
|
: /* empty */
|
|
|
|
| struct_defs struct_def ';'
|
2004-11-02 07:02:00 +00:00
|
|
|
| DEFS '(' identifier ')'
|
2002-05-10 00:00:23 +00:00
|
|
|
{
|
|
|
|
class_t *class = get_class ($3, 0);
|
|
|
|
|
|
|
|
if (class) {
|
2003-08-20 19:58:41 +00:00
|
|
|
class_to_struct (class, current_struct);
|
2002-05-10 00:00:23 +00:00
|
|
|
} else {
|
|
|
|
error (0, "undefined symbol `%s'", $3);
|
|
|
|
}
|
|
|
|
}
|
2001-12-08 08:19:48 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
struct_def
|
2006-12-01 08:17:55 +00:00
|
|
|
: type { $$ = $1; } struct_def_list { $$ = $<type>2; }
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
2006-12-02 06:49:55 +00:00
|
|
|
struct_def_list
|
|
|
|
: struct_def_list ',' { $$ = $<type>0; } struct_def_item
|
|
|
|
{ (void) ($<type>3); }
|
|
|
|
| struct_def_item
|
|
|
|
;
|
|
|
|
|
|
|
|
struct_def_item
|
|
|
|
: identifier
|
|
|
|
{
|
|
|
|
new_struct_field (current_struct, $<type>0, $1, vis_public);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2002-01-21 19:03:29 +00:00
|
|
|
enum_list
|
|
|
|
: enum
|
|
|
|
| enum_list ',' enum
|
|
|
|
{
|
|
|
|
if ($3) {
|
|
|
|
$3->next = $1;
|
|
|
|
$$ = $3;
|
|
|
|
} else {
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
enum
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier { $$ = new_name_expr ($1); }
|
|
|
|
| identifier '=' fexpr
|
2002-01-21 19:03:29 +00:00
|
|
|
{
|
|
|
|
$$ = 0;
|
2004-01-25 08:55:03 +00:00
|
|
|
$3 = constant_expr ($3);
|
2002-01-21 19:03:29 +00:00
|
|
|
if ($3->type < ex_string) {
|
|
|
|
error ($3, "non-constant initializer");
|
|
|
|
} else if ($3->type != ex_integer) {
|
|
|
|
error ($3, "invalid initializer type");
|
|
|
|
} else {
|
|
|
|
$$ = new_binary_expr ('=', new_name_expr ($1), $3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
type
|
2004-02-08 23:46:40 +00:00
|
|
|
: non_func_type
|
|
|
|
| func_type
|
|
|
|
;
|
|
|
|
|
|
|
|
non_func_type
|
2004-11-02 07:02:00 +00:00
|
|
|
: '.' type { $$ = field_type ($2); }
|
|
|
|
| non_field_type { $$ = $1; }
|
2004-02-08 23:46:40 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
func_type
|
|
|
|
: non_field_type function_decl
|
2002-05-01 21:35:39 +00:00
|
|
|
{
|
2002-05-08 05:15:19 +00:00
|
|
|
current_params = $2;
|
2002-05-31 16:58:42 +00:00
|
|
|
$$ = parse_params ($1, $2);
|
2002-05-01 21:35:39 +00:00
|
|
|
}
|
2002-10-31 22:58:59 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
non_field_type
|
2004-11-02 07:02:00 +00:00
|
|
|
: '(' type ')' { $$ = $2; }
|
2002-05-22 17:13:52 +00:00
|
|
|
| non_field_type array_decl
|
|
|
|
{
|
2002-06-13 04:40:09 +00:00
|
|
|
if ($2)
|
|
|
|
$$ = array_type ($1, $2->e.integer_val);
|
|
|
|
else
|
|
|
|
$$ = pointer_type ($1);
|
2002-05-22 17:13:52 +00:00
|
|
|
}
|
2004-11-02 07:02:00 +00:00
|
|
|
| type_name { $$ = $1; }
|
2001-11-14 07:16:58 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
type_name
|
2004-11-02 07:02:00 +00:00
|
|
|
: TYPE { $$ = $1; }
|
|
|
|
| TYPE_NAME { $$ = $1->type; }
|
2002-08-18 04:08:02 +00:00
|
|
|
| CLASS_NAME
|
|
|
|
{
|
|
|
|
class_t *class = get_class ($1, 0);
|
|
|
|
if (!class) {
|
|
|
|
error (0, "undefined symbol `%s'", $1);
|
|
|
|
class = get_class (0, 1);
|
|
|
|
}
|
|
|
|
$$ = class->type;
|
|
|
|
}
|
2004-11-02 07:02:00 +00:00
|
|
|
| STRUCT identifier { $$ = decl_struct ($2)->type; }
|
|
|
|
| UNION identifier { $$ = decl_union ($2)->type; }
|
2002-05-01 21:35:39 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
function_decl
|
2004-11-02 07:08:00 +00:00
|
|
|
: '(' param_list ')' { $$ = reverse_params ($2); }
|
2002-05-10 00:00:23 +00:00
|
|
|
| '(' param_list ',' ELLIPSIS ')'
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2002-05-08 05:15:19 +00:00
|
|
|
$$ = new_param (0, 0, 0);
|
2002-05-10 00:00:23 +00:00
|
|
|
$$->next = $2;
|
2002-05-08 17:33:28 +00:00
|
|
|
$$ = reverse_params ($$);
|
2001-06-15 20:38:57 +00:00
|
|
|
}
|
2004-11-02 07:08:00 +00:00
|
|
|
| '(' ELLIPSIS ')' { $$ = new_param (0, 0, 0); }
|
2003-02-28 23:36:56 +00:00
|
|
|
| '(' TYPE ')'
|
2001-06-19 23:35:09 +00:00
|
|
|
{
|
2003-02-28 23:36:56 +00:00
|
|
|
if ($2 != &type_void)
|
|
|
|
PARSE_ERROR;
|
2002-05-08 05:15:19 +00:00
|
|
|
$$ = 0;
|
2001-06-15 20:38:57 +00:00
|
|
|
}
|
2004-11-02 07:08:00 +00:00
|
|
|
| '(' ')' { $$ = 0; }
|
2002-05-01 21:35:39 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
param_list
|
|
|
|
: param
|
|
|
|
| param_list ',' param
|
2001-06-19 23:35:09 +00:00
|
|
|
{
|
2002-05-08 05:15:19 +00:00
|
|
|
$3->next = $1;
|
|
|
|
$$ = $3;
|
2002-05-01 21:35:39 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
param
|
2004-11-02 07:02:00 +00:00
|
|
|
: type identifier { $$ = new_param (0, $1, $2); }
|
2001-06-20 23:32:13 +00:00
|
|
|
;
|
|
|
|
|
2001-11-15 00:46:36 +00:00
|
|
|
array_decl
|
|
|
|
: '[' const ']'
|
|
|
|
{
|
2002-05-01 21:35:39 +00:00
|
|
|
if ($2->type != ex_integer || $2->e.integer_val < 1) {
|
2001-11-15 00:46:36 +00:00
|
|
|
error (0, "invalid array size");
|
2002-05-01 21:35:39 +00:00
|
|
|
$$ = 0;
|
|
|
|
} else {
|
2002-06-13 04:40:09 +00:00
|
|
|
$$ = $2;
|
2002-05-01 21:35:39 +00:00
|
|
|
}
|
2001-11-15 00:46:36 +00:00
|
|
|
}
|
2004-11-02 07:08:00 +00:00
|
|
|
| '[' ']' { $$ = 0; }
|
2001-11-15 00:46:36 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
def_list
|
2006-12-01 08:17:55 +00:00
|
|
|
: def_list ',' { $$ = $<type>0; } def_item { (void) ($<type>3); }
|
2002-05-01 21:35:39 +00:00
|
|
|
| def_item
|
2001-06-20 23:32:13 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
def_item
|
|
|
|
: def_name opt_initializer
|
2001-11-14 22:31:57 +00:00
|
|
|
{
|
2002-11-04 17:54:31 +00:00
|
|
|
if ($1 && !$1->local
|
|
|
|
&& $1->type->type != ev_func)
|
|
|
|
def_initialized ($1);
|
2001-11-14 22:31:57 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-02-10 23:20:44 +00:00
|
|
|
func_defs
|
|
|
|
: func_def_list ',' fdef_name func_term
|
2004-11-13 11:50:00 +00:00
|
|
|
| func_def func_term {}
|
2004-02-10 23:20:44 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
func_term
|
2004-11-02 07:08:00 +00:00
|
|
|
: non_code_func ';' {}
|
|
|
|
| code_func opt_semi {}
|
2004-02-10 23:20:44 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
func_def_list
|
2004-11-13 11:50:00 +00:00
|
|
|
: func_def_list ',' fdef_name func_init
|
|
|
|
| func_def func_init { $$ = $<type>0; }
|
2004-02-10 23:20:44 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
fdef_name
|
2006-12-01 08:17:55 +00:00
|
|
|
: { $<type>$ = $<type>-1; } func_def { $$ = $2; (void) ($<type>1); }
|
2004-02-10 23:20:44 +00:00
|
|
|
;
|
|
|
|
|
2004-02-10 03:25:24 +00:00
|
|
|
func_def
|
2004-11-13 11:50:00 +00:00
|
|
|
: identifier
|
|
|
|
{
|
|
|
|
$$ = get_function_def ($1, $<type>0, current_scope,
|
|
|
|
current_storage, 0, 1);
|
|
|
|
}
|
|
|
|
| OVERLOAD identifier
|
|
|
|
{
|
|
|
|
$$ = get_function_def ($2, $<type>0, current_scope,
|
|
|
|
current_storage, 1, 1);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
func_init
|
2004-02-10 23:20:44 +00:00
|
|
|
: non_code_func
|
|
|
|
| code_func
|
|
|
|
;
|
|
|
|
|
2007-04-09 06:16:34 +00:00
|
|
|
builtin_function
|
|
|
|
: /* emtpy */
|
|
|
|
{
|
|
|
|
$$ = build_builtin_function ($<def>-1, $<expr>0);
|
|
|
|
build_scope ($$, $$->def, current_params);
|
|
|
|
flush_scope ($$->scope, 1);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-02-10 23:20:44 +00:00
|
|
|
non_code_func
|
|
|
|
: '=' '#' fexpr
|
2007-04-09 06:16:34 +00:00
|
|
|
{ $<def>$ = $<def>0; }
|
|
|
|
{ $<expr>$ = constant_expr ($3); }
|
|
|
|
builtin_function
|
2004-02-10 23:20:44 +00:00
|
|
|
{
|
2007-04-09 06:16:34 +00:00
|
|
|
(void) ($<def>4);
|
|
|
|
(void) ($<expr>5);
|
2004-02-10 23:20:44 +00:00
|
|
|
}
|
|
|
|
| /* emtpy */
|
2004-02-10 03:25:24 +00:00
|
|
|
{
|
|
|
|
}
|
2004-02-10 23:20:44 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
code_func
|
|
|
|
: '=' opt_state_expr
|
2004-02-10 03:25:24 +00:00
|
|
|
{ $<op>$ = current_storage; }
|
2004-02-10 23:20:44 +00:00
|
|
|
{ $<def>$ = $<def>0; }
|
|
|
|
begin_function statement_block { $<op>$ = $<op>3; } end_function
|
2004-02-10 03:25:24 +00:00
|
|
|
{
|
2004-02-11 00:36:34 +00:00
|
|
|
build_code_function ($5, $2, $6);
|
2004-02-13 04:57:15 +00:00
|
|
|
current_func = 0;
|
2006-12-01 08:17:55 +00:00
|
|
|
(void) ($<def>4);
|
|
|
|
(void) ($<op>7);
|
2004-02-10 03:25:24 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
def_name
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier
|
2001-06-15 07:16:18 +00:00
|
|
|
{
|
2007-04-12 09:39:42 +00:00
|
|
|
scope_type st = current_scope->type;
|
|
|
|
// traditional functions have only the one scope
|
|
|
|
//FIXME should the scope be set to local when the params scope
|
|
|
|
//is created in traditional mode?
|
|
|
|
if (options.traditional && st == sc_params)
|
|
|
|
st = sc_local;
|
|
|
|
if (st == sc_local) {
|
2002-06-28 17:59:32 +00:00
|
|
|
def_t *def = get_def (0, $1, current_scope, st_none);
|
2002-06-09 05:19:13 +00:00
|
|
|
if (def) {
|
2007-04-12 09:39:42 +00:00
|
|
|
if (def->scope->type == sc_params
|
|
|
|
&& current_scope->parent->type == sc_params) {
|
|
|
|
warning (0, "local %s shadows param %s", $1,
|
|
|
|
def->name);
|
|
|
|
}
|
|
|
|
if (def->scope == current_scope) {
|
|
|
|
expr_t e;
|
|
|
|
warning (0, "local %s redeclared", $1);
|
|
|
|
e.file = def->file;
|
|
|
|
e.line = def->line;
|
|
|
|
warning (&e, "previously declared here");
|
|
|
|
}
|
2002-02-19 00:16:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-04 17:54:31 +00:00
|
|
|
$$ = get_def ($<type>0, $1, current_scope, current_storage);
|
2001-06-15 07:16:18 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
opt_initializer
|
2004-11-02 07:02:00 +00:00
|
|
|
: /*empty*/ { }
|
2004-02-10 03:25:24 +00:00
|
|
|
| { $$ = $<def>0; }
|
2006-12-01 08:17:55 +00:00
|
|
|
var_initializer { (void) ($<def>1); }
|
2001-11-14 22:31:57 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
var_initializer
|
2004-01-25 22:08:08 +00:00
|
|
|
: '=' expr // don't bother folding twice
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2007-05-07 15:04:06 +00:00
|
|
|
if (current_scope->type == sc_local
|
|
|
|
|| current_scope->type == sc_params) {
|
2004-01-25 22:08:08 +00:00
|
|
|
expr_t *expr = assign_expr (new_def_expr ($<def>0), $2);
|
|
|
|
expr = fold_constants (expr);
|
|
|
|
append_expr (local_expr, expr);
|
2002-11-04 17:54:31 +00:00
|
|
|
def_initialized ($<def>0);
|
2001-06-26 22:43:28 +00:00
|
|
|
} else {
|
2004-01-25 08:55:03 +00:00
|
|
|
$2 = constant_expr ($2);
|
2001-10-18 20:05:26 +00:00
|
|
|
if ($2->type >= ex_string) {
|
2003-01-29 22:29:37 +00:00
|
|
|
if ($<def>0->constant) {
|
|
|
|
error ($2, "%s re-initialized", $<def>0->name);
|
2002-08-20 02:09:34 +00:00
|
|
|
} else {
|
2003-01-29 22:29:37 +00:00
|
|
|
if ($<def>0->type->type == ev_func) {
|
|
|
|
PARSE_ERROR;
|
|
|
|
} else {
|
|
|
|
ReuseConstant ($2, $<def>0);
|
|
|
|
}
|
2002-08-20 02:09:34 +00:00
|
|
|
}
|
2001-10-18 20:05:26 +00:00
|
|
|
} else {
|
2001-07-27 20:55:14 +00:00
|
|
|
error ($2, "non-constant expression used for initializer");
|
2001-10-18 20:05:26 +00:00
|
|
|
}
|
2001-06-26 22:43:28 +00:00
|
|
|
}
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2004-02-10 03:25:24 +00:00
|
|
|
| '=' '{' { current_init = new_block_expr (); } element_list '}'
|
2002-01-18 08:26:37 +00:00
|
|
|
{
|
2002-11-04 17:54:31 +00:00
|
|
|
init_elements ($<def>0, $4);
|
2002-01-18 08:26:37 +00:00
|
|
|
current_init = 0;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
opt_state_expr
|
|
|
|
: /* emtpy */
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2002-05-07 16:55:54 +00:00
|
|
|
$$ = 0;
|
2001-07-14 01:15:40 +00:00
|
|
|
}
|
2004-02-11 08:09:10 +00:00
|
|
|
| '[' fexpr ',' think opt_step ']'
|
2001-07-14 01:15:40 +00:00
|
|
|
{
|
2002-05-07 16:55:54 +00:00
|
|
|
if ($2->type == ex_integer)
|
|
|
|
convert_int ($2);
|
2003-08-01 21:20:04 +00:00
|
|
|
else if ($2->type == ex_uinteger)
|
|
|
|
convert_uint ($2);
|
2004-02-11 04:00:11 +00:00
|
|
|
if (!type_assignable (&type_float, get_type ($2)))
|
2002-05-07 16:55:54 +00:00
|
|
|
error ($2, "invalid type for frame number");
|
2004-02-11 04:00:11 +00:00
|
|
|
$2 = cast_expr (&type_float, $2);
|
2004-02-11 08:09:10 +00:00
|
|
|
if (extract_type ($4) != ev_func)
|
2002-05-07 16:55:54 +00:00
|
|
|
error ($2, "invalid type for think");
|
2004-02-11 08:09:10 +00:00
|
|
|
if ($5) {
|
|
|
|
if ($5->type == ex_integer)
|
|
|
|
convert_int ($5);
|
|
|
|
else if ($5->type == ex_uinteger)
|
|
|
|
convert_uint ($5);
|
|
|
|
if (!type_assignable (&type_float, get_type ($5)))
|
|
|
|
error ($5, "invalid type for time step");
|
2004-02-11 04:00:11 +00:00
|
|
|
}
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2004-02-11 08:09:10 +00:00
|
|
|
$$ = new_state_expr ($2, $4, $5);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
think
|
|
|
|
: { $<type>$ = &type_function; } def_name
|
|
|
|
{
|
|
|
|
$$ = new_def_expr ($2);
|
2006-12-01 08:17:55 +00:00
|
|
|
(void) ($<type>1);
|
2004-02-11 08:09:10 +00:00
|
|
|
}
|
|
|
|
| '(' fexpr ')'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
;
|
|
|
|
|
2004-02-11 01:43:33 +00:00
|
|
|
opt_step
|
|
|
|
: ',' fexpr { $$ = $2; }
|
|
|
|
| /* empty */ { $$ = 0; }
|
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
element_list
|
|
|
|
: /* empty */
|
|
|
|
{
|
|
|
|
$$ = new_block_expr ();
|
|
|
|
}
|
|
|
|
| element_list1 opt_comma
|
|
|
|
{
|
|
|
|
$$ = current_init;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
element_list1
|
|
|
|
: element
|
|
|
|
{
|
|
|
|
append_expr (current_init, $1);
|
|
|
|
}
|
|
|
|
| element_list1 ',' element
|
|
|
|
{
|
|
|
|
append_expr (current_init, $3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
element
|
|
|
|
: '{'
|
|
|
|
{
|
|
|
|
$$ = current_init;
|
|
|
|
current_init = new_block_expr ();
|
|
|
|
}
|
|
|
|
element_list
|
|
|
|
{
|
|
|
|
current_init = $<expr>2;
|
|
|
|
}
|
|
|
|
'}'
|
|
|
|
{
|
|
|
|
$$ = $3;
|
|
|
|
}
|
2004-01-25 21:36:44 +00:00
|
|
|
| fexpr
|
2002-05-01 21:35:39 +00:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_comma
|
|
|
|
: /* empty */
|
|
|
|
| ','
|
|
|
|
;
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
begin_function
|
|
|
|
: /*empty*/
|
|
|
|
{
|
2004-02-11 01:53:17 +00:00
|
|
|
if ($<def>0->constant)
|
|
|
|
error (0, "%s redefined", $<def>0->name);
|
2002-11-04 17:54:31 +00:00
|
|
|
$$ = current_func = new_function ($<def>0->name);
|
|
|
|
$$->def = $<def>0;
|
2007-04-10 07:40:03 +00:00
|
|
|
if (!$$->def->external)
|
|
|
|
reloc_def_func ($$, $$->def->ofs);
|
2002-07-08 20:31:59 +00:00
|
|
|
$$->code = pr.code->size;
|
2001-10-26 06:43:56 +00:00
|
|
|
if (options.code.debug) {
|
2001-07-14 01:15:40 +00:00
|
|
|
pr_lineno_t *lineno = new_lineno ();
|
2002-07-17 14:39:54 +00:00
|
|
|
$$->aux->source_line = $$->def->line;
|
2002-07-17 14:19:30 +00:00
|
|
|
$$->aux->line_info = lineno - pr.linenos;
|
|
|
|
$$->aux->local_defs = pr.num_locals;
|
2001-07-14 01:15:40 +00:00
|
|
|
|
2002-07-17 14:19:30 +00:00
|
|
|
lineno->fa.func = $$->aux - pr.auxfunctions;
|
2001-07-14 01:15:40 +00:00
|
|
|
}
|
2002-11-04 17:54:31 +00:00
|
|
|
build_scope ($$, $<def>0, current_params);
|
2002-06-09 03:57:20 +00:00
|
|
|
current_scope = $$->scope;
|
2004-02-08 23:46:40 +00:00
|
|
|
current_storage = st_local;
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
end_function
|
|
|
|
: /*empty*/
|
|
|
|
{
|
2002-06-09 03:57:20 +00:00
|
|
|
current_scope = current_scope->parent;
|
2004-02-08 23:46:40 +00:00
|
|
|
current_storage = $<op>0;
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statement_block
|
2001-10-24 06:39:49 +00:00
|
|
|
: '{'
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2003-09-23 17:59:46 +00:00
|
|
|
if (!options.traditional) {
|
|
|
|
scope_t *scope = new_scope (sc_local, current_scope->space,
|
|
|
|
current_scope);
|
|
|
|
current_scope = scope;
|
|
|
|
}
|
2001-10-24 06:39:49 +00:00
|
|
|
}
|
|
|
|
statements '}'
|
|
|
|
{
|
2003-09-23 17:59:46 +00:00
|
|
|
if (!options.traditional) {
|
|
|
|
def_t *defs = current_scope->head;
|
|
|
|
int num_defs = current_scope->num_defs;
|
2001-10-24 06:39:49 +00:00
|
|
|
|
2003-09-23 17:59:46 +00:00
|
|
|
flush_scope (current_scope, 1);
|
2001-10-24 06:39:49 +00:00
|
|
|
|
2003-09-23 17:59:46 +00:00
|
|
|
current_scope = current_scope->parent;
|
|
|
|
current_scope->num_defs += num_defs;
|
|
|
|
*current_scope->tail = defs;
|
|
|
|
while (*current_scope->tail) {
|
2004-04-09 03:47:41 +00:00
|
|
|
(*current_scope->tail)->scope = current_scope;
|
2003-09-23 17:59:46 +00:00
|
|
|
current_scope->tail = &(*current_scope->tail)->def_next;
|
|
|
|
}
|
2002-06-09 03:57:20 +00:00
|
|
|
}
|
2001-10-24 06:39:49 +00:00
|
|
|
$$ = $3;
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statements
|
|
|
|
: /*empty*/
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
| statements statement
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = append_expr ($1, $2);
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
statement
|
2004-11-02 07:02:00 +00:00
|
|
|
: ';' { $$ = 0; }
|
|
|
|
| statement_block { $$ = $1; }
|
2004-01-25 21:36:44 +00:00
|
|
|
| RETURN fexpr ';'
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2001-07-23 02:27:46 +00:00
|
|
|
$$ = return_expr (current_func, $2);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| RETURN ';'
|
|
|
|
{
|
2001-07-23 02:27:46 +00:00
|
|
|
$$ = return_expr (current_func, 0);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2001-10-24 18:57:29 +00:00
|
|
|
| BREAK ';'
|
|
|
|
{
|
2001-10-25 06:41:52 +00:00
|
|
|
$$ = 0;
|
2001-10-24 18:57:29 +00:00
|
|
|
if (break_label)
|
|
|
|
$$ = new_unary_expr ('g', break_label);
|
|
|
|
else
|
2001-10-25 06:41:52 +00:00
|
|
|
error (0, "break outside of loop or switch");
|
2001-10-24 18:57:29 +00:00
|
|
|
}
|
|
|
|
| CONTINUE ';'
|
|
|
|
{
|
2001-10-25 06:41:52 +00:00
|
|
|
$$ = 0;
|
2001-10-24 18:57:29 +00:00
|
|
|
if (continue_label)
|
|
|
|
$$ = new_unary_expr ('g', continue_label);
|
|
|
|
else
|
2001-10-25 06:41:52 +00:00
|
|
|
error (0, "continue outside of loop");
|
|
|
|
}
|
2004-01-25 21:36:44 +00:00
|
|
|
| CASE fexpr ':'
|
2001-10-25 06:41:52 +00:00
|
|
|
{
|
|
|
|
$$ = case_label_expr (switch_block, $2);
|
|
|
|
}
|
|
|
|
| DEFAULT ':'
|
|
|
|
{
|
|
|
|
$$ = case_label_expr (switch_block, 0);
|
|
|
|
}
|
2004-01-25 21:36:44 +00:00
|
|
|
| SWITCH break_label switch_block '(' fexpr ')'
|
2001-10-25 06:41:52 +00:00
|
|
|
{
|
|
|
|
switch_block->test = $5;
|
|
|
|
}
|
|
|
|
save_inits statement_block
|
|
|
|
{
|
|
|
|
restore_local_inits ($8);
|
|
|
|
free_local_inits ($8);
|
|
|
|
$$ = switch_expr (switch_block, break_label, $9);
|
|
|
|
switch_block = $3;
|
|
|
|
break_label = $2;
|
2001-10-24 18:57:29 +00:00
|
|
|
}
|
2004-01-25 21:36:44 +00:00
|
|
|
| WHILE break_label continue_label '(' fexpr ')' save_inits statement
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
2001-10-24 18:57:29 +00:00
|
|
|
expr_t *l2 = break_label;
|
2003-10-22 09:14:53 +00:00
|
|
|
int line = pr.source_line;
|
|
|
|
string_t file = pr.source_file;
|
|
|
|
|
|
|
|
pr.source_line = $5->line;
|
|
|
|
pr.source_file = $5->file;
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-10-24 18:57:29 +00:00
|
|
|
restore_local_inits ($7);
|
|
|
|
free_local_inits ($7);
|
2001-10-19 05:16:24 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2003-10-22 08:05:17 +00:00
|
|
|
append_expr ($$, new_unary_expr ('g', continue_label));
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l1);
|
2001-10-24 18:57:29 +00:00
|
|
|
append_expr ($$, $8);
|
|
|
|
append_expr ($$, continue_label);
|
2003-10-22 08:05:17 +00:00
|
|
|
|
|
|
|
$5 = convert_bool ($5, 1);
|
2003-10-24 22:23:56 +00:00
|
|
|
if ($5->type != ex_error) {
|
|
|
|
backpatch ($5->e.bool.true_list, l1);
|
|
|
|
backpatch ($5->e.bool.false_list, l2);
|
|
|
|
append_expr ($5->e.bool.e, l2);
|
|
|
|
append_expr ($$, $5);
|
|
|
|
}
|
2003-10-22 08:05:17 +00:00
|
|
|
|
2001-10-24 18:57:29 +00:00
|
|
|
break_label = $2;
|
|
|
|
continue_label = $3;
|
2003-10-22 09:14:53 +00:00
|
|
|
|
|
|
|
pr.source_line = line;
|
|
|
|
pr.source_file = file;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2004-01-25 21:36:44 +00:00
|
|
|
| DO break_label continue_label statement WHILE '(' fexpr ')' ';'
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
2003-10-22 09:14:53 +00:00
|
|
|
int line = pr.source_line;
|
|
|
|
string_t file = pr.source_file;
|
|
|
|
|
|
|
|
pr.source_line = $7->line;
|
|
|
|
pr.source_file = $7->file;
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l1);
|
2001-10-24 18:57:29 +00:00
|
|
|
append_expr ($$, $4);
|
|
|
|
append_expr ($$, continue_label);
|
2003-10-22 08:05:17 +00:00
|
|
|
|
|
|
|
$7 = convert_bool ($7, 1);
|
2003-10-24 22:23:56 +00:00
|
|
|
if ($7->type != ex_error) {
|
|
|
|
backpatch ($7->e.bool.true_list, l1);
|
|
|
|
backpatch ($7->e.bool.false_list, break_label);
|
|
|
|
append_expr ($7->e.bool.e, break_label);
|
|
|
|
append_expr ($$, $7);
|
|
|
|
}
|
2003-10-22 08:05:17 +00:00
|
|
|
|
2001-10-24 18:57:29 +00:00
|
|
|
break_label = $2;
|
|
|
|
continue_label = $3;
|
2003-10-22 09:14:53 +00:00
|
|
|
|
|
|
|
pr.source_line = line;
|
|
|
|
pr.source_file = file;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2006-12-11 09:26:07 +00:00
|
|
|
| local_storage_class type
|
2001-06-20 21:18:04 +00:00
|
|
|
{
|
2002-11-04 17:54:31 +00:00
|
|
|
$<type>$ = $2;
|
2001-07-15 01:51:01 +00:00
|
|
|
local_expr = new_block_expr ();
|
|
|
|
}
|
2002-05-01 21:35:39 +00:00
|
|
|
def_list ';'
|
2001-07-15 01:51:01 +00:00
|
|
|
{
|
|
|
|
$$ = local_expr;
|
|
|
|
local_expr = 0;
|
2006-12-01 08:17:55 +00:00
|
|
|
(void) ($<type>3);
|
2006-12-11 09:26:07 +00:00
|
|
|
current_storage = st_local;
|
2001-06-20 21:18:04 +00:00
|
|
|
}
|
2007-04-28 08:49:07 +00:00
|
|
|
| IF '(' fexpr ')' save_inits statement %prec IFX
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2003-10-22 08:05:17 +00:00
|
|
|
expr_t *tl = new_label_expr ();
|
|
|
|
expr_t *fl = new_label_expr ();
|
2003-10-22 09:14:53 +00:00
|
|
|
int line = pr.source_line;
|
|
|
|
string_t file = pr.source_file;
|
|
|
|
|
|
|
|
pr.source_line = $3->line;
|
|
|
|
pr.source_file = $3->file;
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-10-19 05:16:24 +00:00
|
|
|
restore_local_inits ($5);
|
|
|
|
free_local_inits ($5);
|
|
|
|
|
2003-10-22 08:05:17 +00:00
|
|
|
$3 = convert_bool ($3, 1);
|
2003-10-24 22:23:56 +00:00
|
|
|
if ($3->type != ex_error) {
|
|
|
|
backpatch ($3->e.bool.true_list, tl);
|
|
|
|
backpatch ($3->e.bool.false_list, fl);
|
|
|
|
append_expr ($3->e.bool.e, tl);
|
|
|
|
append_expr ($$, $3);
|
|
|
|
}
|
2003-10-22 08:05:17 +00:00
|
|
|
|
2001-10-18 23:06:39 +00:00
|
|
|
append_expr ($$, $6);
|
2003-10-22 08:05:17 +00:00
|
|
|
append_expr ($$, fl);
|
2003-10-22 09:14:53 +00:00
|
|
|
|
|
|
|
pr.source_line = line;
|
|
|
|
pr.source_file = file;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2004-01-25 21:36:44 +00:00
|
|
|
| IF '(' fexpr ')' save_inits statement ELSE
|
2001-10-18 23:06:39 +00:00
|
|
|
{
|
2002-06-09 03:57:20 +00:00
|
|
|
$<def_list>$ = save_local_inits (current_scope);
|
2001-10-18 23:06:39 +00:00
|
|
|
restore_local_inits ($5);
|
|
|
|
}
|
|
|
|
statement
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2003-10-22 08:05:17 +00:00
|
|
|
expr_t *tl = new_label_expr ();
|
|
|
|
expr_t *fl = new_label_expr ();
|
|
|
|
expr_t *nl = new_label_expr ();
|
2001-10-19 03:22:04 +00:00
|
|
|
expr_t *e;
|
|
|
|
hashtab_t *merged;
|
|
|
|
hashtab_t *else_ini;
|
2003-10-22 09:14:53 +00:00
|
|
|
int line = pr.source_line;
|
|
|
|
string_t file = pr.source_file;
|
|
|
|
|
|
|
|
pr.source_line = $3->line;
|
|
|
|
pr.source_file = $3->file;
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2002-06-09 03:57:20 +00:00
|
|
|
else_ini = save_local_inits (current_scope);
|
2001-10-19 05:16:24 +00:00
|
|
|
|
|
|
|
restore_local_inits ($5);
|
|
|
|
free_local_inits ($5);
|
|
|
|
|
2003-10-22 08:05:17 +00:00
|
|
|
$3 = convert_bool ($3, 1);
|
2003-10-24 22:23:56 +00:00
|
|
|
if ($3->type != ex_error) {
|
|
|
|
backpatch ($3->e.bool.true_list, tl);
|
|
|
|
backpatch ($3->e.bool.false_list, fl);
|
|
|
|
append_expr ($3->e.bool.e, tl);
|
|
|
|
append_expr ($$, $3);
|
|
|
|
}
|
2001-07-15 01:51:01 +00:00
|
|
|
|
2001-10-18 23:06:39 +00:00
|
|
|
append_expr ($$, $6);
|
2001-07-15 01:51:01 +00:00
|
|
|
|
2003-10-22 08:05:17 +00:00
|
|
|
e = new_unary_expr ('g', nl);
|
2001-07-15 01:51:01 +00:00
|
|
|
append_expr ($$, e);
|
|
|
|
|
2003-10-22 08:05:17 +00:00
|
|
|
append_expr ($$, fl);
|
2001-10-18 23:06:39 +00:00
|
|
|
append_expr ($$, $9);
|
2003-10-22 08:05:17 +00:00
|
|
|
append_expr ($$, nl);
|
|
|
|
|
2001-10-19 03:22:04 +00:00
|
|
|
merged = merge_local_inits ($<def_list>8, else_ini);
|
|
|
|
restore_local_inits (merged);
|
|
|
|
free_local_inits (merged);
|
|
|
|
free_local_inits (else_ini);
|
|
|
|
free_local_inits ($<def_list>8);
|
2003-10-22 09:14:53 +00:00
|
|
|
|
|
|
|
pr.source_line = line;
|
|
|
|
pr.source_file = file;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2001-10-25 06:41:52 +00:00
|
|
|
| FOR break_label continue_label
|
|
|
|
'(' opt_expr ';' opt_expr ';' opt_expr ')' save_inits statement
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2003-10-22 08:05:17 +00:00
|
|
|
expr_t *tl = new_label_expr ();
|
|
|
|
expr_t *fl = break_label;
|
|
|
|
expr_t *l1 = 0;
|
2004-03-30 02:31:02 +00:00
|
|
|
expr_t *t;
|
2003-10-22 08:05:17 +00:00
|
|
|
int line = pr.source_line;
|
|
|
|
string_t file = pr.source_file;
|
|
|
|
|
2004-03-30 02:31:02 +00:00
|
|
|
if ($9)
|
|
|
|
t = $9;
|
|
|
|
else if ($7)
|
|
|
|
t = $7;
|
|
|
|
else if ($5)
|
|
|
|
t = $5;
|
|
|
|
else
|
|
|
|
t = continue_label;
|
|
|
|
pr.source_line = t->line;
|
|
|
|
pr.source_file = t->file;
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-10-24 18:57:29 +00:00
|
|
|
restore_local_inits ($11);
|
|
|
|
free_local_inits ($11);
|
2001-10-19 05:16:24 +00:00
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
$$ = new_block_expr ();
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2001-10-24 18:57:29 +00:00
|
|
|
append_expr ($$, $5);
|
2003-10-22 08:05:17 +00:00
|
|
|
if ($7) {
|
|
|
|
l1 = new_label_expr ();
|
|
|
|
append_expr ($$, new_unary_expr ('g', l1));
|
|
|
|
}
|
|
|
|
append_expr ($$, tl);
|
2001-10-24 18:57:29 +00:00
|
|
|
append_expr ($$, $12);
|
|
|
|
append_expr ($$, continue_label);
|
|
|
|
append_expr ($$, $9);
|
2003-10-22 08:05:17 +00:00
|
|
|
if ($7) {
|
|
|
|
append_expr ($$, l1);
|
|
|
|
$7 = convert_bool ($7, 1);
|
2003-10-24 22:23:56 +00:00
|
|
|
if ($7->type != ex_error) {
|
|
|
|
backpatch ($7->e.bool.true_list, tl);
|
|
|
|
backpatch ($7->e.bool.false_list, fl);
|
|
|
|
append_expr ($7->e.bool.e, fl);
|
|
|
|
append_expr ($$, $7);
|
|
|
|
}
|
2003-10-22 08:05:17 +00:00
|
|
|
} else {
|
2004-03-30 02:31:02 +00:00
|
|
|
append_expr ($$, new_unary_expr ('g', tl));
|
2003-10-22 08:05:17 +00:00
|
|
|
append_expr ($$, fl);
|
|
|
|
}
|
2001-10-24 18:57:29 +00:00
|
|
|
break_label = $2;
|
|
|
|
continue_label = $3;
|
2003-10-22 08:05:17 +00:00
|
|
|
|
|
|
|
pr.source_line = line;
|
|
|
|
pr.source_file = file;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2004-01-25 21:36:44 +00:00
|
|
|
| fexpr ';'
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
2003-10-22 08:05:17 +00:00
|
|
|
label
|
|
|
|
: /* empty */
|
|
|
|
{
|
|
|
|
$$ = new_label_expr ();
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2001-10-24 18:57:29 +00:00
|
|
|
break_label
|
|
|
|
: /* empty */
|
|
|
|
{
|
|
|
|
$$ = break_label;
|
|
|
|
break_label = new_label_expr ();
|
|
|
|
}
|
2002-04-27 02:51:00 +00:00
|
|
|
;
|
2001-10-24 18:57:29 +00:00
|
|
|
|
|
|
|
continue_label
|
|
|
|
: /* empty */
|
|
|
|
{
|
|
|
|
$$ = continue_label;
|
|
|
|
continue_label = new_label_expr ();
|
2001-10-25 06:41:52 +00:00
|
|
|
}
|
2002-04-27 02:51:00 +00:00
|
|
|
;
|
2001-10-25 06:41:52 +00:00
|
|
|
|
|
|
|
switch_block
|
|
|
|
: /* empty */
|
|
|
|
{
|
|
|
|
$$ = switch_block;
|
|
|
|
switch_block = new_switch_block ();
|
2001-10-24 18:57:29 +00:00
|
|
|
}
|
2002-04-27 02:51:00 +00:00
|
|
|
;
|
2001-10-24 18:57:29 +00:00
|
|
|
|
2001-10-18 23:06:39 +00:00
|
|
|
save_inits
|
|
|
|
: /* empty */
|
|
|
|
{
|
2002-06-09 03:57:20 +00:00
|
|
|
$$ = save_local_inits (current_scope);
|
2001-10-18 23:06:39 +00:00
|
|
|
}
|
2002-04-27 02:51:00 +00:00
|
|
|
;
|
2001-10-18 23:06:39 +00:00
|
|
|
|
2001-08-01 06:29:09 +00:00
|
|
|
opt_expr
|
2004-01-25 21:36:44 +00:00
|
|
|
: fexpr
|
2001-08-01 06:29:09 +00:00
|
|
|
| /* empty */
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
}
|
2002-04-27 02:51:00 +00:00
|
|
|
;
|
2001-08-01 06:29:09 +00:00
|
|
|
|
2002-10-31 22:58:59 +00:00
|
|
|
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); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| SIZEOF unary_expr %prec UNARY { $$ = sizeof_expr ($2, 0); }
|
2003-03-10 21:23:05 +00:00
|
|
|
| SIZEOF '(' type ')' %prec HYPERUNARY { $$ = sizeof_expr (0, $3); }
|
2002-10-31 22:58:59 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
primary
|
2004-11-02 07:02:00 +00:00
|
|
|
: NAME { $$ = new_name_expr ($1); }
|
2007-04-28 08:49:07 +00:00
|
|
|
| BREAK %prec BREAK_PRIMARY { $$ = new_name_expr (save_string ("break")); }
|
2002-10-31 22:58:59 +00:00
|
|
|
| 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
|
2003-03-10 21:23:05 +00:00
|
|
|
| '(' type ')' cast_expr %prec UNARY { $$ = cast_expr ($2, $4); }
|
2002-10-31 22:58:59 +00:00
|
|
|
;
|
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
expr
|
2002-10-31 22:58:59 +00:00
|
|
|
: cast_expr
|
|
|
|
| expr '=' expr { $$ = assign_expr ($1, $3); }
|
2001-08-20 06:22:28 +00:00
|
|
|
| expr ASX expr { $$ = asx_expr ($2, $1, $3); }
|
2001-08-11 21:15:24 +00:00
|
|
|
| expr '?' expr ':' expr { $$ = conditional_expr ($1, $3, $5); }
|
2003-10-22 08:05:17 +00:00
|
|
|
| expr AND label expr { $$ = bool_expr (AND, $3, $1, $4); }
|
|
|
|
| expr OR label expr { $$ = bool_expr (OR, $3, $1, $4); }
|
2001-08-11 21:15:24 +00:00
|
|
|
| expr EQ expr { $$ = binary_expr (EQ, $1, $3); }
|
|
|
|
| expr NE expr { $$ = binary_expr (NE, $1, $3); }
|
|
|
|
| expr LE expr { $$ = binary_expr (LE, $1, $3); }
|
|
|
|
| expr GE expr { $$ = binary_expr (GE, $1, $3); }
|
|
|
|
| expr LT expr { $$ = binary_expr (LT, $1, $3); }
|
|
|
|
| expr GT expr { $$ = binary_expr (GT, $1, $3); }
|
|
|
|
| expr SHL expr { $$ = binary_expr (SHL, $1, $3); }
|
|
|
|
| expr SHR expr { $$ = binary_expr (SHR, $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 '|' expr { $$ = binary_expr ('|', $1, $3); }
|
|
|
|
| expr '^' expr { $$ = binary_expr ('^', $1, $3); }
|
|
|
|
| expr '%' expr { $$ = binary_expr ('%', $1, $3); }
|
2002-10-31 22:58:59 +00:00
|
|
|
;
|
|
|
|
|
2004-01-25 21:36:44 +00:00
|
|
|
fexpr
|
|
|
|
: expr { $$ = fold_constants ($1); }
|
2004-01-27 04:41:20 +00:00
|
|
|
;
|
2004-01-25 21:36:44 +00:00
|
|
|
|
2002-10-31 22:58:59 +00:00
|
|
|
opt_arg_list
|
|
|
|
: /* emtpy */ { $$ = 0; }
|
|
|
|
| arg_list { $$ = $1; }
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
arg_list
|
2004-01-25 21:36:44 +00:00
|
|
|
: fexpr
|
|
|
|
| arg_list ',' fexpr
|
2001-06-20 21:18:04 +00:00
|
|
|
{
|
|
|
|
$3->next = $1;
|
|
|
|
$$ = $3;
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
2001-06-13 07:16:39 +00:00
|
|
|
const
|
2002-09-11 16:21:26 +00:00
|
|
|
: FLOAT_VAL { $$ = new_float_expr ($1); }
|
|
|
|
| string_val { $$ = $1; }
|
|
|
|
| VECTOR_VAL { $$ = new_vector_expr ($1); }
|
|
|
|
| QUATERNION_VAL { $$ = new_quaternion_expr ($1); }
|
|
|
|
| INT_VAL { $$ = new_integer_expr ($1); }
|
|
|
|
| NIL { $$ = new_nil_expr (); }
|
2001-06-13 07:16:39 +00:00
|
|
|
;
|
|
|
|
|
2002-04-26 21:42:50 +00:00
|
|
|
string_val
|
2002-09-11 16:21:26 +00:00
|
|
|
: STRING_VAL { $$ = new_string_expr ($1); }
|
2002-04-26 21:42:50 +00:00
|
|
|
| string_val STRING_VAL
|
|
|
|
{
|
2002-09-11 16:21:26 +00:00
|
|
|
$$ = binary_expr ('+', $1, new_string_expr ($2));
|
2002-04-26 21:42:50 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2004-11-02 07:02:00 +00:00
|
|
|
identifier
|
|
|
|
: NAME
|
2007-04-06 11:46:21 +00:00
|
|
|
| BREAK { $$ = save_string ("break"); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| CLASS_NAME
|
|
|
|
| TYPE_NAME { $$ = $1->name; }
|
|
|
|
;
|
|
|
|
|
|
|
|
// Objective-QC stuff
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
obj_def
|
2002-11-15 17:12:16 +00:00
|
|
|
: classdef { }
|
2002-05-07 16:55:54 +00:00
|
|
|
| classdecl
|
|
|
|
| protocoldef
|
2002-05-15 19:10:23 +00:00
|
|
|
| { if (!current_class) PARSE_ERROR; } methoddef
|
2002-05-07 16:55:54 +00:00
|
|
|
| END
|
2002-05-15 19:10:23 +00:00
|
|
|
{
|
|
|
|
if (!current_class)
|
|
|
|
PARSE_ERROR;
|
2002-05-15 23:24:19 +00:00
|
|
|
else
|
|
|
|
class_finish (current_class);
|
2002-05-15 19:10:23 +00:00
|
|
|
current_class = 0;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
identifier_list
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
$$ = new_block_expr ();
|
|
|
|
append_expr ($$, new_name_expr ($1));
|
|
|
|
}
|
2004-11-02 07:02:00 +00:00
|
|
|
| identifier_list ',' identifier
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
append_expr ($1, new_name_expr ($3));
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
classdecl
|
2002-08-20 21:13:18 +00:00
|
|
|
: CLASS identifier_list ';'
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
expr_t *e;
|
|
|
|
for (e = $2->e.block.head; e; e = e->next)
|
2002-05-10 00:00:23 +00:00
|
|
|
get_class (e->e.string_val, 1);
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-08-18 04:08:02 +00:00
|
|
|
class_name
|
2007-04-28 08:49:07 +00:00
|
|
|
: identifier %prec CLASS_NOT_CATEGORY
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
2002-05-10 00:00:23 +00:00
|
|
|
$$ = get_class ($1, 0);
|
|
|
|
if (!$$) {
|
|
|
|
error (0, "undefined symbol `%s'", $1);
|
|
|
|
$$ = get_class (0, 1);
|
|
|
|
}
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-10 00:00:23 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
new_class_name
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
2002-05-10 00:00:23 +00:00
|
|
|
$$ = get_class ($1, 1);
|
|
|
|
if ($$->defined) {
|
|
|
|
error (0, "redefinition of `%s'", $1);
|
|
|
|
$$ = get_class (0, 1);
|
|
|
|
}
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-30 21:18:58 +00:00
|
|
|
;
|
2002-05-10 00:00:23 +00:00
|
|
|
|
2002-05-15 19:10:23 +00:00
|
|
|
class_with_super
|
|
|
|
: class_name ':' class_name
|
|
|
|
{
|
|
|
|
if ($1->super_class != $3)
|
2002-11-12 19:52:43 +00:00
|
|
|
error (0, "%s is not a super class of %s", $3->name, $1->name);
|
2002-05-15 19:10:23 +00:00
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
new_class_with_super
|
|
|
|
: new_class_name ':' class_name
|
|
|
|
{
|
|
|
|
$1->super_class = $3;
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
category_name
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier '(' identifier ')'
|
2002-05-15 19:10:23 +00:00
|
|
|
{
|
|
|
|
$$ = get_category ($1, $3, 0);
|
|
|
|
if (!$$) {
|
|
|
|
error (0, "undefined category `%s (%s)'", $1, $3);
|
|
|
|
$$ = get_category (0, 0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
new_category_name
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier '(' identifier ')'
|
2002-05-15 19:10:23 +00:00
|
|
|
{
|
|
|
|
$$ = get_category ($1, $3, 1);
|
|
|
|
if ($$->defined) {
|
|
|
|
error (0, "redefinition of category `%s (%s)'", $1, $3);
|
|
|
|
$$ = get_category (0, 0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
protocol_name
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
2002-05-15 19:10:23 +00:00
|
|
|
$$ = get_protocol ($1, 0);
|
|
|
|
if ($$) {
|
2002-05-10 00:00:23 +00:00
|
|
|
error (0, "redefinition of %s", $1);
|
|
|
|
$$ = get_protocol (0, 1);
|
2002-05-15 19:10:23 +00:00
|
|
|
} else {
|
|
|
|
$$ = get_protocol ($1, 1);
|
2002-05-10 00:00:23 +00:00
|
|
|
}
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-30 21:18:58 +00:00
|
|
|
;
|
2002-05-10 00:00:23 +00:00
|
|
|
|
2002-05-15 19:10:23 +00:00
|
|
|
classdef
|
2002-05-22 17:13:52 +00:00
|
|
|
: INTERFACE new_class_name
|
2006-12-01 08:17:55 +00:00
|
|
|
protocolrefs { class_add_protocols ($2, $3); }
|
2002-11-14 18:17:43 +00:00
|
|
|
'{' { $$ = $2; }
|
|
|
|
ivar_decl_list '}' { class_add_ivars ($2, $7); $$ = $2; }
|
|
|
|
methodprotolist { class_add_methods ($2, $10); }
|
2006-12-01 08:17:55 +00:00
|
|
|
END
|
|
|
|
{
|
|
|
|
current_class = 0;
|
|
|
|
(void) ($<class>6);
|
|
|
|
(void) ($<class>9);
|
|
|
|
}
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_class_name
|
2004-11-11 00:34:00 +00:00
|
|
|
protocolrefs { class_add_protocols ($2, $3); }
|
2003-08-01 02:43:11 +00:00
|
|
|
{ class_add_ivars ($2, class_new_ivars ($2)); $$ = $2; }
|
2003-07-30 04:11:45 +00:00
|
|
|
methodprotolist { class_add_methods ($2, $6); }
|
2006-12-01 08:17:55 +00:00
|
|
|
END
|
|
|
|
{
|
|
|
|
current_class = 0;
|
|
|
|
(void) ($<class>5);
|
|
|
|
}
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_class_with_super
|
2004-11-11 00:34:00 +00:00
|
|
|
protocolrefs { class_add_protocols ($2, $3);}
|
2002-11-14 18:17:43 +00:00
|
|
|
'{' { $$ = $2; }
|
|
|
|
ivar_decl_list '}' { class_add_ivars ($2, $7); $$ = $2; }
|
|
|
|
methodprotolist { class_add_methods ($2, $10); }
|
2006-12-01 08:17:55 +00:00
|
|
|
END
|
|
|
|
{
|
|
|
|
current_class = 0;
|
|
|
|
(void) ($<class>6);
|
|
|
|
(void) ($<class>9);
|
|
|
|
}
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_class_with_super
|
2004-11-11 00:34:00 +00:00
|
|
|
protocolrefs { class_add_protocols ($2, $3); }
|
2003-08-01 02:43:11 +00:00
|
|
|
{ class_add_ivars ($2, class_new_ivars ($2)); $$ = $2; }
|
2003-07-30 04:11:45 +00:00
|
|
|
methodprotolist { class_add_methods ($2, $6); }
|
2006-12-01 08:17:55 +00:00
|
|
|
END
|
|
|
|
{
|
|
|
|
current_class = 0;
|
|
|
|
(void) ($<class>5);
|
|
|
|
}
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_category_name
|
2004-11-11 00:34:00 +00:00
|
|
|
protocolrefs { category_add_protocols ($2, $3); $$ = $2->class;}
|
2002-11-14 18:17:43 +00:00
|
|
|
methodprotolist { category_add_methods ($2, $5); }
|
2006-12-01 08:17:55 +00:00
|
|
|
END
|
|
|
|
{
|
|
|
|
current_class = 0;
|
|
|
|
(void) ($<class>4);
|
|
|
|
}
|
2002-11-14 18:17:43 +00:00
|
|
|
| IMPLEMENTATION class_name { class_begin (&$2->class_type); }
|
|
|
|
'{' { $$ = $2; }
|
2006-12-01 08:17:55 +00:00
|
|
|
ivar_decl_list '}'
|
|
|
|
{
|
|
|
|
class_check_ivars ($2, $6);
|
|
|
|
(void) ($<class>5);
|
|
|
|
}
|
2002-11-14 18:17:43 +00:00
|
|
|
| IMPLEMENTATION class_name { class_begin (&$2->class_type); }
|
|
|
|
| IMPLEMENTATION class_with_super { class_begin (&$2->class_type); }
|
|
|
|
'{' { $$ = $2; }
|
2006-12-01 08:17:55 +00:00
|
|
|
ivar_decl_list '}'
|
|
|
|
{
|
|
|
|
class_check_ivars ($2, $6);
|
|
|
|
(void) ($<class>5);
|
|
|
|
}
|
2002-11-14 18:17:43 +00:00
|
|
|
| IMPLEMENTATION class_with_super { class_begin (&$2->class_type); }
|
|
|
|
| IMPLEMENTATION category_name { class_begin (&$2->class_type); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
protocoldef
|
|
|
|
: PROTOCOL protocol_name
|
2004-11-11 00:34:00 +00:00
|
|
|
protocolrefs { protocol_add_protocols ($2, $3); $<class>$ = 0; }
|
2002-05-10 00:00:23 +00:00
|
|
|
methodprotolist { protocol_add_methods ($2, $5); }
|
2006-12-01 08:17:55 +00:00
|
|
|
END { (void) ($<class>4); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
protocolrefs
|
|
|
|
: /* emtpy */ { $$ = 0; }
|
2004-11-11 00:34:00 +00:00
|
|
|
| LT { $$ = new_protocol_list (); }
|
2006-12-01 08:17:55 +00:00
|
|
|
protocol_list GT { $$ = $3; (void) ($<protocol_list>2); }
|
2003-07-25 20:34:24 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
protocol_list
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier
|
2003-07-25 20:34:24 +00:00
|
|
|
{
|
2004-11-02 07:02:00 +00:00
|
|
|
$$ = add_protocol ($<protocol_list>0, $1);
|
2003-07-25 20:34:24 +00:00
|
|
|
}
|
2004-11-02 07:02:00 +00:00
|
|
|
| protocol_list ',' identifier
|
2003-07-25 20:34:24 +00:00
|
|
|
{
|
2004-11-11 00:34:00 +00:00
|
|
|
$$ = add_protocol ($1, $3);
|
2003-07-25 20:34:24 +00:00
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
ivar_decl_list
|
2002-05-17 06:20:27 +00:00
|
|
|
: /* */
|
|
|
|
{
|
2002-05-17 17:58:57 +00:00
|
|
|
current_visibility = vis_protected;
|
2003-07-30 04:11:45 +00:00
|
|
|
current_ivars = class_new_ivars ($<class>0);
|
2002-05-17 06:20:27 +00:00
|
|
|
}
|
|
|
|
ivar_decl_list_2
|
2002-05-15 19:10:23 +00:00
|
|
|
{
|
|
|
|
$$ = current_ivars;
|
|
|
|
current_ivars = 0;
|
2006-12-01 08:17:55 +00:00
|
|
|
(void) ($<class>1);
|
2002-05-15 19:10:23 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
ivar_decl_list_2
|
|
|
|
: ivar_decl_list_2 visibility_spec ivar_decls
|
2002-05-07 16:55:54 +00:00
|
|
|
| ivar_decls
|
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
visibility_spec
|
|
|
|
: PRIVATE { current_visibility = vis_private; }
|
|
|
|
| PROTECTED { current_visibility = vis_protected; }
|
|
|
|
| PUBLIC { current_visibility = vis_public; }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
ivar_decls
|
2002-05-07 16:55:54 +00:00
|
|
|
: /* empty */
|
|
|
|
| ivar_decls ivar_decl ';'
|
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
ivar_decl
|
2006-12-01 08:17:55 +00:00
|
|
|
: type { $$ = $1; } ivars { (void) ($<type>2); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
ivars
|
2002-05-07 16:55:54 +00:00
|
|
|
: ivar_declarator
|
2006-12-01 08:17:55 +00:00
|
|
|
| ivars ',' { $$ = $<type>0; } ivar_declarator { (void) ($<type>3); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
ivar_declarator
|
2004-11-02 07:02:00 +00:00
|
|
|
: identifier
|
2002-05-10 00:00:23 +00:00
|
|
|
{
|
2002-11-04 17:54:31 +00:00
|
|
|
new_struct_field (current_ivars, $<type>0, $1, current_visibility);
|
2002-05-10 00:00:23 +00:00
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
methoddef
|
2004-02-09 07:35:19 +00:00
|
|
|
: ci methoddecl
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
2004-02-09 07:35:19 +00:00
|
|
|
$2->instance = $1;
|
2002-05-15 23:24:19 +00:00
|
|
|
$2 = class_find_method (current_class, $2);
|
|
|
|
}
|
|
|
|
opt_state_expr
|
2004-02-09 07:17:44 +00:00
|
|
|
{ $<op>$ = current_storage; }
|
2002-05-15 23:24:19 +00:00
|
|
|
{
|
2002-11-04 17:54:31 +00:00
|
|
|
$$ = $2->def = method_def (current_class, $2);
|
2002-05-08 21:24:24 +00:00
|
|
|
current_params = $2->params;
|
|
|
|
}
|
2004-02-09 07:17:44 +00:00
|
|
|
begin_function statement_block { $<op>$ = $<op>5; } end_function
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
2004-02-11 00:36:34 +00:00
|
|
|
$2->func = build_code_function ($7, $4, $8);
|
2004-02-13 04:57:15 +00:00
|
|
|
current_func = 0;
|
2006-12-01 08:17:55 +00:00
|
|
|
(void) ($<method>6);
|
|
|
|
(void) ($<op>9);
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2007-04-09 06:16:34 +00:00
|
|
|
| ci methoddecl
|
2002-05-17 18:35:54 +00:00
|
|
|
{
|
2004-02-09 07:35:19 +00:00
|
|
|
$2->instance = $1;
|
2002-05-17 18:35:54 +00:00
|
|
|
$2 = class_find_method (current_class, $2);
|
2007-04-09 06:16:34 +00:00
|
|
|
}
|
|
|
|
'=' '#' const
|
|
|
|
{ $<def>$ = $2->def = method_def (current_class, $2); }
|
|
|
|
{ $<expr>$ = $6; }
|
|
|
|
builtin_function ';'
|
|
|
|
{
|
|
|
|
$2->func = $9;
|
2002-05-17 18:35:54 +00:00
|
|
|
|
2007-04-09 06:16:34 +00:00
|
|
|
(void) ($<def>7);
|
|
|
|
(void) ($<expr>8);
|
2002-05-17 18:35:54 +00:00
|
|
|
}
|
2004-02-09 07:35:19 +00:00
|
|
|
;
|
2002-05-17 18:35:54 +00:00
|
|
|
|
2004-02-09 07:35:19 +00:00
|
|
|
ci
|
|
|
|
: '+' { $$ = 0; }
|
|
|
|
| '-' { $$ = 1; }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
methodprotolist
|
2002-05-10 00:00:23 +00:00
|
|
|
: /* emtpy */ { $$ = 0; }
|
2002-05-07 16:55:54 +00:00
|
|
|
| methodprotolist2
|
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
methodprotolist2
|
2002-11-14 18:17:43 +00:00
|
|
|
: { } methodproto
|
2002-05-10 00:00:23 +00:00
|
|
|
{
|
|
|
|
$$ = new_methodlist ();
|
2002-11-14 18:17:43 +00:00
|
|
|
add_method ($$, $2);
|
2002-05-10 00:00:23 +00:00
|
|
|
}
|
|
|
|
| methodprotolist2 methodproto
|
|
|
|
{
|
|
|
|
add_method ($1, $2);
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
methodproto
|
2002-05-07 16:55:54 +00:00
|
|
|
: '+' methoddecl ';'
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
$2->instance = 0;
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
| '-' methoddecl ';'
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
$2->instance = 1;
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
methoddecl
|
2002-05-07 16:55:54 +00:00
|
|
|
: '(' type ')' unaryselector
|
2002-05-08 21:24:24 +00:00
|
|
|
{ $$ = new_method ($2, $4, 0); }
|
2002-05-07 16:55:54 +00:00
|
|
|
| unaryselector
|
2002-05-08 21:24:24 +00:00
|
|
|
{ $$ = new_method (&type_id, $1, 0); }
|
|
|
|
| '(' type ')' keywordselector optparmlist
|
|
|
|
{ $$ = new_method ($2, $4, $5); }
|
|
|
|
| keywordselector optparmlist
|
|
|
|
{ $$ = new_method (&type_id, $1, $2); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
optparmlist
|
2002-05-10 00:00:23 +00:00
|
|
|
: /* empty */ { $$ = 0; }
|
|
|
|
| ',' ELLIPSIS { $$ = new_param (0, 0, 0); }
|
|
|
|
| ',' param_list { $$ = $2; }
|
2002-05-08 23:12:49 +00:00
|
|
|
| ',' param_list ',' ELLIPSIS
|
|
|
|
{
|
|
|
|
$$ = new_param (0, 0, 0);
|
|
|
|
$$->next = $2;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
unaryselector
|
2002-05-10 00:00:23 +00:00
|
|
|
: selector { $$ = new_param ($1, 0, 0); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
keywordselector
|
|
|
|
: keyworddecl
|
2002-05-08 05:55:57 +00:00
|
|
|
| keywordselector keyworddecl { $2->next = $1; $$ = $2; }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
selector
|
2004-11-02 07:02:00 +00:00
|
|
|
: NAME { $$ = save_string ($1); }
|
|
|
|
| CLASS_NAME { $$ = save_string ($1); }
|
2002-06-27 22:48:28 +00:00
|
|
|
| TYPE { $$ = save_string (yytext); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| TYPE_NAME { $$ = save_string ($1->name); }
|
2002-05-08 23:12:49 +00:00
|
|
|
| reserved_word
|
|
|
|
;
|
|
|
|
|
|
|
|
reserved_word
|
2002-06-27 22:48:28 +00:00
|
|
|
: LOCAL { $$ = save_string (yytext); }
|
|
|
|
| RETURN { $$ = save_string (yytext); }
|
|
|
|
| WHILE { $$ = save_string (yytext); }
|
|
|
|
| DO { $$ = save_string (yytext); }
|
|
|
|
| IF { $$ = save_string (yytext); }
|
|
|
|
| ELSE { $$ = save_string (yytext); }
|
|
|
|
| FOR { $$ = save_string (yytext); }
|
|
|
|
| BREAK { $$ = save_string (yytext); }
|
|
|
|
| CONTINUE { $$ = save_string (yytext); }
|
|
|
|
| SWITCH { $$ = save_string (yytext); }
|
|
|
|
| CASE { $$ = save_string (yytext); }
|
|
|
|
| DEFAULT { $$ = save_string (yytext); }
|
|
|
|
| NIL { $$ = save_string (yytext); }
|
|
|
|
| STRUCT { $$ = save_string (yytext); }
|
|
|
|
| UNION { $$ = save_string (yytext); }
|
|
|
|
| ENUM { $$ = save_string (yytext); }
|
|
|
|
| TYPEDEF { $$ = save_string (yytext); }
|
|
|
|
| SUPER { $$ = save_string (yytext); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
keyworddecl
|
2004-11-02 07:02:00 +00:00
|
|
|
: selector ':' '(' type ')' identifier
|
2002-05-08 05:55:57 +00:00
|
|
|
{ $$ = new_param ($1, $4, $6); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| selector ':' identifier
|
2002-05-08 21:24:24 +00:00
|
|
|
{ $$ = new_param ($1, &type_id, $3); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| ':' '(' type ')' identifier
|
2002-05-08 21:24:24 +00:00
|
|
|
{ $$ = new_param ("", $3, $5); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| ':' identifier
|
2002-05-08 21:24:24 +00:00
|
|
|
{ $$ = new_param ("", &type_id, $2); }
|
2002-05-08 05:55:57 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
obj_expr
|
|
|
|
: obj_messageexpr
|
|
|
|
| SELECTOR '(' selectorarg ')' { $$ = selector_expr ($3); }
|
2004-11-02 07:02:00 +00:00
|
|
|
| PROTOCOL '(' identifier ')' { $$ = protocol_expr ($3); }
|
2002-05-08 23:12:49 +00:00
|
|
|
| ENCODE '(' type ')' { $$ = encode_expr ($3); }
|
|
|
|
| obj_string /* FIXME string object? */
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
obj_messageexpr
|
|
|
|
: '[' receiver messageargs ']' { $$ = message_expr ($2, $3); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
receiver
|
2004-01-25 21:36:44 +00:00
|
|
|
: fexpr
|
2002-09-11 16:21:26 +00:00
|
|
|
| CLASS_NAME { $$ = new_name_expr ($1); }
|
|
|
|
| SUPER { $$ = new_name_expr ("super"); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
messageargs
|
2002-09-11 16:21:26 +00:00
|
|
|
: selector { $$ = new_keywordarg ($1, 0); }
|
2002-05-08 23:12:49 +00:00
|
|
|
| keywordarglist
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
keywordarglist
|
|
|
|
: keywordarg
|
|
|
|
| keywordarglist keywordarg
|
|
|
|
{
|
|
|
|
$2->next = $1;
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
keywordarg
|
2002-09-11 16:21:26 +00:00
|
|
|
: selector ':' arg_list { $$ = new_keywordarg ($1, $3); }
|
|
|
|
| ':' arg_list { $$ = new_keywordarg ("", $2); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
selectorarg
|
2002-09-11 16:21:26 +00:00
|
|
|
: selector { $$ = new_keywordarg ($1, 0); }
|
2002-05-07 16:55:54 +00:00
|
|
|
| keywordnamelist
|
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
keywordnamelist
|
2002-05-07 16:55:54 +00:00
|
|
|
: keywordname
|
|
|
|
| keywordnamelist keywordname
|
2002-05-08 23:12:49 +00:00
|
|
|
{
|
|
|
|
$2->next = $1;
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
keywordname
|
2004-02-04 01:30:12 +00:00
|
|
|
: selector ':' { $$ = new_keywordarg ($1, new_nil_expr ()); }
|
|
|
|
| ':' { $$ = new_keywordarg ("", new_nil_expr ()); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
obj_string
|
2002-09-11 16:21:26 +00:00
|
|
|
: '@' STRING_VAL { $$ = new_string_expr ($2); }
|
2002-05-07 16:55:54 +00:00
|
|
|
| obj_string '@' STRING_VAL
|
2002-05-08 23:12:49 +00:00
|
|
|
{
|
2002-09-11 16:21:26 +00:00
|
|
|
$$ = binary_expr ('+', $1, new_string_expr ($3));
|
2002-05-08 23:12:49 +00:00
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%%
|
2001-06-18 22:51:49 +00:00
|
|
|
|
2002-06-05 21:13:29 +00:00
|
|
|
typedef struct def_state_s {
|
|
|
|
struct def_state_s *next;
|
2001-10-19 03:22:04 +00:00
|
|
|
def_t *def;
|
|
|
|
int state;
|
|
|
|
} def_state_t;
|
|
|
|
|
2002-06-05 21:13:29 +00:00
|
|
|
static def_state_t *free_def_states;
|
|
|
|
|
2001-10-19 03:22:04 +00:00
|
|
|
static const char *
|
2003-02-22 22:38:55 +00:00
|
|
|
ds_get_key (void *_d, void *unused)
|
2001-10-19 03:22:04 +00:00
|
|
|
{
|
|
|
|
return ((def_state_t *)_d)->def->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-22 22:38:55 +00:00
|
|
|
ds_free_key (void *_d, void *unused)
|
2001-10-19 03:22:04 +00:00
|
|
|
{
|
2002-06-05 21:13:29 +00:00
|
|
|
def_state_t *d = (def_state_t *)_d;
|
|
|
|
d->next = free_def_states;
|
|
|
|
free_def_states = d;
|
2001-10-19 03:22:04 +00:00
|
|
|
}
|
|
|
|
|
2001-10-24 15:21:21 +00:00
|
|
|
static void
|
2002-06-09 03:57:20 +00:00
|
|
|
scan_scope (hashtab_t *tab, scope_t *scope)
|
2001-10-18 23:06:39 +00:00
|
|
|
{
|
2001-10-19 03:22:04 +00:00
|
|
|
def_t *def;
|
2002-06-09 05:19:13 +00:00
|
|
|
if (scope->type == sc_local)
|
2002-06-09 03:57:20 +00:00
|
|
|
scan_scope (tab, scope->parent);
|
|
|
|
for (def = scope->head; def; def = def->def_next) {
|
2001-10-24 15:21:21 +00:00
|
|
|
if (def->name && !def->removed) {
|
2002-06-05 21:13:29 +00:00
|
|
|
def_state_t *ds;
|
|
|
|
ALLOC (1024, def_state_t, def_states, ds);
|
2001-10-19 03:22:04 +00:00
|
|
|
ds->def = def;
|
|
|
|
ds->state = def->initialized;
|
|
|
|
Hash_Add (tab, ds);
|
|
|
|
}
|
|
|
|
}
|
2001-10-24 15:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hashtab_t *
|
2002-06-09 03:57:20 +00:00
|
|
|
save_local_inits (scope_t *scope)
|
2001-10-24 15:21:21 +00:00
|
|
|
{
|
2003-02-22 22:38:55 +00:00
|
|
|
hashtab_t *tab = Hash_NewTable (61, ds_get_key, ds_free_key, 0);
|
2001-10-24 15:21:21 +00:00
|
|
|
scan_scope (tab, scope);
|
2001-10-19 03:22:04 +00:00
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
hashtab_t *
|
|
|
|
merge_local_inits (hashtab_t *dl_1, hashtab_t *dl_2)
|
|
|
|
{
|
2003-02-22 22:38:55 +00:00
|
|
|
hashtab_t *tab = Hash_NewTable (61, ds_get_key, ds_free_key, 0);
|
2001-10-19 03:22:04 +00:00
|
|
|
def_state_t **ds_list = (def_state_t **)Hash_GetList (dl_1);
|
|
|
|
def_state_t **ds;
|
|
|
|
def_state_t *d;
|
|
|
|
def_state_t *nds;
|
|
|
|
|
|
|
|
for (ds = ds_list; *ds; ds++) {
|
|
|
|
d = Hash_Find (dl_2, (*ds)->def->name);
|
|
|
|
(*ds)->def->initialized = (*ds)->state;
|
|
|
|
|
2002-06-05 21:13:29 +00:00
|
|
|
ALLOC (1024, def_state_t, def_states, nds);
|
2001-10-19 03:22:04 +00:00
|
|
|
nds->def = (*ds)->def;
|
|
|
|
nds->state = (*ds)->state && d->state;
|
|
|
|
Hash_Add (tab, nds);
|
|
|
|
}
|
|
|
|
free (ds_list);
|
|
|
|
return tab;
|
2001-10-18 23:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-19 00:45:56 +00:00
|
|
|
restore_local_inits (hashtab_t *def_list)
|
2001-10-18 23:06:39 +00:00
|
|
|
{
|
2001-10-19 03:22:04 +00:00
|
|
|
def_state_t **ds_list = (def_state_t **)Hash_GetList (def_list);
|
|
|
|
def_state_t **ds;
|
|
|
|
|
|
|
|
for (ds = ds_list; *ds; ds++)
|
|
|
|
(*ds)->def->initialized = (*ds)->state;
|
|
|
|
free (ds_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_local_inits (hashtab_t *def_list)
|
|
|
|
{
|
|
|
|
Hash_DelTable (def_list);
|
2001-10-18 23:06:39 +00:00
|
|
|
}
|
2002-10-16 02:28:08 +00:00
|
|
|
|
|
|
|
expr_t *
|
|
|
|
argc_expr (void)
|
|
|
|
{
|
|
|
|
warning (0, "@argc deprecated: use @args.count");
|
|
|
|
return binary_expr ('.', new_name_expr (".args"), new_name_expr ("count"));
|
|
|
|
}
|
|
|
|
|
|
|
|
expr_t *
|
|
|
|
argv_expr (void)
|
|
|
|
{
|
|
|
|
warning (0, "@argv deprecated: use @args.list");
|
|
|
|
return binary_expr ('.', new_name_expr (".args"), new_name_expr ("list"));
|
|
|
|
}
|