2001-06-12 19:44:26 +00:00
|
|
|
%{
|
2001-09-28 07:09:38 +00:00
|
|
|
/*
|
|
|
|
#FILENAME#
|
|
|
|
|
|
|
|
#DESCRIPTION#
|
|
|
|
|
|
|
|
Copyright (C) 2001 #AUTHOR#
|
|
|
|
|
|
|
|
Author: #AUTHOR#
|
|
|
|
Date: #DATE#
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
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-05-08 21:24:24 +00:00
|
|
|
#include "qfcc.h"
|
2002-05-08 05:15:19 +00:00
|
|
|
#include "function.h"
|
2002-05-08 21:24:24 +00:00
|
|
|
#include "method.h"
|
|
|
|
#include "class.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
|
2001-06-18 22:51:49 +00:00
|
|
|
|
|
|
|
extern char *yytext;
|
2001-06-25 23:38:32 +00:00
|
|
|
extern int pr_source_line;
|
2001-06-18 22:51:49 +00:00
|
|
|
|
2001-06-12 20:24:02 +00:00
|
|
|
void
|
2001-06-18 22:51:49 +00:00
|
|
|
yyerror (const char *s)
|
2001-06-12 20:24:02 +00:00
|
|
|
{
|
2001-07-03 20:53:49 +00:00
|
|
|
error (0, "%s %s\n", yytext, s);
|
2001-06-12 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
2002-05-15 19:10:23 +00:00
|
|
|
void
|
|
|
|
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
|
|
|
|
2001-11-14 22:31:57 +00:00
|
|
|
type_t *build_type (int is_field, type_t *type);
|
2002-05-01 21:35:39 +00:00
|
|
|
type_t *build_array_type (type_t *type, int size);
|
2001-06-18 22:51:49 +00:00
|
|
|
|
2001-10-19 00:45:56 +00:00
|
|
|
hashtab_t *save_local_inits (def_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
|
|
|
|
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;
|
|
|
|
def_t *def;
|
|
|
|
struct hashtab_s *def_list;
|
|
|
|
type_t *type;
|
|
|
|
expr_t *expr;
|
|
|
|
int integer_val;
|
|
|
|
float float_val;
|
|
|
|
char *string_val;
|
|
|
|
float vector_val[3];
|
|
|
|
float quaternion_val[4];
|
2001-06-25 18:23:29 +00:00
|
|
|
function_t *function;
|
2001-10-25 06:41:52 +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-05-08 21:24:24 +00:00
|
|
|
struct protocol_s *protocol;
|
2002-05-08 23:12:49 +00:00
|
|
|
struct keywordarg_s *keywordarg;
|
2002-05-10 00:00:23 +00:00
|
|
|
struct methodlist_s *methodlist;
|
2001-06-12 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
2001-12-12 08:39:47 +00:00
|
|
|
%right <op> '=' ASX PAS /* pointer assign */
|
2001-08-11 21:15:24 +00:00
|
|
|
%right '?' ':'
|
2001-06-27 00:10:34 +00:00
|
|
|
%left OR AND
|
2001-06-12 20:24:02 +00:00
|
|
|
%left EQ NE LE GE LT GT
|
2002-05-07 16:55:54 +00:00
|
|
|
%left SHL SHR %left '+' '-'
|
2001-08-10 16:17:00 +00:00
|
|
|
%left '*' '/' '&' '|' '^' '%'
|
2001-08-20 06:22:28 +00:00
|
|
|
%right <op> UNARY INCOP
|
2001-11-15 00:46:36 +00:00
|
|
|
%right '(' '['
|
2001-06-25 17:15:56 +00:00
|
|
|
%left '.'
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2001-06-15 07:16:18 +00:00
|
|
|
%token <string_val> 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-05-17 20:25:46 +00:00
|
|
|
%token SWITCH CASE DEFAULT STRUCT ENUM TYPEDEF SUPER SELF
|
2002-05-01 21:35:39 +00:00
|
|
|
%token ELE_START
|
2001-06-14 21:49:47 +00:00
|
|
|
%token <type> TYPE
|
|
|
|
|
2002-05-07 16:55:54 +00:00
|
|
|
%token CLASS DEFS ENCODE END IMPLEMENTATION INTERFACE PRIVATE PROTECTED
|
|
|
|
%token PROTOCOL PUBLIC SELECTOR
|
|
|
|
|
2002-05-22 17:13:52 +00:00
|
|
|
%type <type> type non_field_type type_name
|
2002-05-08 05:15:19 +00:00
|
|
|
%type <param> function_decl
|
2002-05-01 21:35:39 +00:00
|
|
|
%type <integer_val> array_decl
|
2002-05-08 05:15:19 +00:00
|
|
|
%type <param> param param_list
|
|
|
|
%type <def> def_name
|
2002-05-01 21:35:39 +00:00
|
|
|
%type <def> def_item def_list
|
2002-01-18 08:26:37 +00:00
|
|
|
%type <expr> const opt_expr expr arg_list element_list element_list1 element
|
2002-05-08 23:12:49 +00:00
|
|
|
%type <expr> string_val opt_state_expr
|
2001-06-25 20:52:04 +00:00
|
|
|
%type <expr> statement statements statement_block
|
2002-01-21 19:03:29 +00:00
|
|
|
%type <expr> break_label continue_label enum_list enum
|
2001-06-25 18:23:29 +00:00
|
|
|
%type <function> begin_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
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2002-05-08 23:12:49 +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
|
2002-05-10 00:00:23 +00:00
|
|
|
%type <expr> protocolrefs
|
2002-05-08 23:12:49 +00:00
|
|
|
%type <keywordarg> messageargs keywordarg keywordarglist selectorarg
|
|
|
|
%type <keywordarg> keywordnamelist keywordname
|
2002-05-15 19:10:23 +00:00
|
|
|
%type <class> class_name new_class_name class_with_super new_class_with_super
|
|
|
|
%type <class> category_name new_category_name
|
2002-05-10 00:00:23 +00:00
|
|
|
%type <protocol> protocol_name
|
|
|
|
%type <methodlist> methodprotolist methodprotolist2
|
2002-05-15 19:10:23 +00:00
|
|
|
%type <type> ivar_decl_list
|
2002-05-08 05:15:19 +00:00
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
%expect 2 // statement : if | if else, defs : defs def ';' | defs obj_def
|
2001-06-12 19:44:26 +00:00
|
|
|
|
2001-06-15 07:16:18 +00:00
|
|
|
%{
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
type_t *current_type;
|
|
|
|
def_t *current_def;
|
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;
|
|
|
|
class_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;
|
2001-12-08 08:19:48 +00:00
|
|
|
type_t *struct_type;
|
2002-05-10 00:00:23 +00:00
|
|
|
visibility_t current_visibility;
|
2002-05-15 19:10:23 +00:00
|
|
|
type_t *current_ivars;
|
2001-06-15 07:16:18 +00:00
|
|
|
|
2001-09-15 20:31:17 +00:00
|
|
|
def_t *pr_scope; // the function being parsed, or NULL
|
|
|
|
string_t s_file; // filename for function definition
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
int element_flag;
|
|
|
|
|
2001-06-15 07:16:18 +00:00
|
|
|
%}
|
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
defs
|
|
|
|
: /* empty */
|
2002-05-15 19:10:23 +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
|
2002-05-01 21:42:29 +00:00
|
|
|
: type { current_type = $1; } def_list
|
2001-12-08 08:19:48 +00:00
|
|
|
| STRUCT NAME
|
|
|
|
{ struct_type = new_struct ($2); } '=' '{' struct_defs '}'
|
2002-01-23 20:50:25 +00:00
|
|
|
| ENUM '{' enum_list opt_comma '}'
|
2002-01-21 19:03:29 +00:00
|
|
|
{ process_enum ($3); }
|
2002-01-23 20:50:25 +00:00
|
|
|
| TYPEDEF type NAME
|
|
|
|
{ new_typedef ($3, $2); }
|
|
|
|
| TYPEDEF ENUM '{' enum_list opt_comma '}' NAME
|
|
|
|
{
|
|
|
|
process_enum ($4);
|
|
|
|
new_typedef ($7, &type_integer);
|
|
|
|
}
|
2002-01-21 19:09:23 +00:00
|
|
|
;
|
|
|
|
|
2001-12-08 08:19:48 +00:00
|
|
|
struct_defs
|
|
|
|
: /* empty */
|
|
|
|
| struct_defs struct_def ';'
|
2002-05-10 00:00:23 +00:00
|
|
|
| DEFS '(' NAME ')'
|
|
|
|
{
|
|
|
|
class_t *class = get_class ($3, 0);
|
|
|
|
|
|
|
|
if (class) {
|
|
|
|
copy_struct_fields (struct_type, class->ivars);
|
|
|
|
} else {
|
|
|
|
error (0, "undefined symbol `%s'", $3);
|
|
|
|
}
|
|
|
|
}
|
2001-12-08 08:19:48 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
struct_def
|
2002-05-01 21:35:39 +00:00
|
|
|
: type struct_def_list
|
|
|
|
{}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
2002-01-21 19:03:29 +00:00
|
|
|
enum_list
|
|
|
|
: enum
|
|
|
|
| enum_list ',' enum
|
|
|
|
{
|
|
|
|
if ($3) {
|
|
|
|
$3->next = $1;
|
|
|
|
$$ = $3;
|
|
|
|
} else {
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
enum
|
|
|
|
: NAME { $$ = new_name_expr ($1); }
|
|
|
|
| NAME '=' expr
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
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
|
|
|
|
: '.' type { $$ = build_type (1, $2); }
|
2002-05-22 17:13:52 +00:00
|
|
|
| non_field_type { $$ = $1; }
|
|
|
|
| non_field_type function_decl
|
2002-05-01 21:35:39 +00:00
|
|
|
{
|
2002-05-08 05:15:19 +00:00
|
|
|
current_params = $2;
|
|
|
|
$$ = build_type (0, parse_params ($1, $2));
|
2002-05-01 21:35:39 +00:00
|
|
|
}
|
2002-05-22 17:13:52 +00:00
|
|
|
| non_field_type array_decl
|
|
|
|
{
|
|
|
|
$$ = build_type (0, build_array_type ($1, $2));
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
non_field_type
|
|
|
|
: '(' type ')' { $$ = $2; }
|
|
|
|
| type_name { $$ = $1; }
|
2001-11-14 07:16:58 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
type_name
|
|
|
|
: TYPE { $$ = $1; }
|
2002-05-16 20:20:23 +00:00
|
|
|
| class_name { $$ = $1->type; }
|
2002-05-01 21:35:39 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
function_decl
|
2002-05-10 00:00:23 +00:00
|
|
|
: '(' param_list ')' { $$ = reverse_params ($2); }
|
|
|
|
| '(' 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
|
|
|
}
|
2002-05-10 00:00:23 +00:00
|
|
|
| '(' ELLIPSIS ')' { $$ = new_param (0, 0, 0); }
|
2002-05-01 21:35:39 +00:00
|
|
|
| '(' ')'
|
2001-06-19 23:35:09 +00:00
|
|
|
{
|
2002-05-08 05:15:19 +00:00
|
|
|
$$ = 0;
|
2001-06-15 20:38:57 +00:00
|
|
|
}
|
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
|
2002-05-08 05:15:19 +00:00
|
|
|
: type NAME { $$ = 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 {
|
|
|
|
$$ = $2->e.integer_val;
|
|
|
|
}
|
2001-11-15 00:46:36 +00:00
|
|
|
}
|
2002-05-01 21:35:39 +00:00
|
|
|
| '[' ']' { $$ = 0; }
|
2001-11-15 00:46:36 +00:00
|
|
|
;
|
|
|
|
|
2001-12-08 08:19:48 +00:00
|
|
|
struct_def_list
|
|
|
|
: struct_def_list ',' struct_def_item
|
|
|
|
| struct_def_item
|
|
|
|
;
|
|
|
|
|
|
|
|
struct_def_item
|
2002-05-10 00:00:23 +00:00
|
|
|
: NAME { new_struct_field (struct_type, current_type, $1, vis_public); }
|
2001-12-08 08:19:48 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
def_list
|
|
|
|
: def_list ',' def_item
|
|
|
|
| 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
|
|
|
{
|
|
|
|
$$ = $1;
|
2002-01-21 19:03:29 +00:00
|
|
|
if ($$ && !$$->scope && $$->type->type != ev_func)
|
2001-11-14 22:31:57 +00:00
|
|
|
PR_DefInitialized ($$);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
def_name
|
2001-06-15 07:16:18 +00:00
|
|
|
: NAME
|
|
|
|
{
|
2001-11-14 22:31:57 +00:00
|
|
|
int *alloc = &numpr_globals;
|
|
|
|
|
2002-02-19 00:16:56 +00:00
|
|
|
if (pr_scope) {
|
2001-11-14 22:31:57 +00:00
|
|
|
alloc = pr_scope->alloc;
|
2002-02-19 00:16:56 +00:00
|
|
|
if (pr_scope->scope && !pr_scope->scope->scope) {
|
|
|
|
def_t *def = PR_GetDef (0, $1, pr_scope->scope, 0);
|
|
|
|
if (def && def->scope && !def->scope->scope)
|
|
|
|
warning (0, "local %s shadows param %s", $1, def->name);
|
|
|
|
}
|
|
|
|
}
|
2001-11-14 22:31:57 +00:00
|
|
|
$$ = PR_GetDef (current_type, $1, pr_scope, alloc);
|
2001-06-15 19:38:43 +00:00
|
|
|
current_def = $$;
|
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
|
|
|
|
: /*empty*/
|
|
|
|
| { element_flag = current_type->type != ev_func; } var_initializer
|
|
|
|
{ element_flag = 0; }
|
2001-11-14 22:31:57 +00:00
|
|
|
;
|
|
|
|
|
2002-05-01 21:35:39 +00:00
|
|
|
var_initializer
|
|
|
|
: '=' expr
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2001-06-26 22:43:28 +00:00
|
|
|
if (pr_scope) {
|
2002-05-22 17:18:48 +00:00
|
|
|
append_expr (local_expr,
|
|
|
|
assign_expr (new_def_expr (current_def), $2));
|
2001-10-18 20:05:26 +00:00
|
|
|
PR_DefInitialized (current_def);
|
2001-06-26 22:43:28 +00:00
|
|
|
} else {
|
2001-10-18 20:05:26 +00:00
|
|
|
if ($2->type >= ex_string) {
|
2001-07-27 20:55:14 +00:00
|
|
|
current_def = PR_ReuseConstant ($2, current_def);
|
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
|
|
|
}
|
2002-05-01 21:35:39 +00:00
|
|
|
| '=' ELE_START { current_init = new_block_expr (); } element_list '}'
|
2002-01-18 08:26:37 +00:00
|
|
|
{
|
|
|
|
init_elements (current_def, $4);
|
|
|
|
current_init = 0;
|
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
| '=' '#' const
|
|
|
|
{
|
2002-05-17 18:35:54 +00:00
|
|
|
build_builtin_function (current_def, $3);
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
| '=' opt_state_expr begin_function statement_block end_function
|
2001-06-20 07:02:36 +00:00
|
|
|
{
|
2002-05-07 16:55:54 +00:00
|
|
|
build_function ($3);
|
|
|
|
if ($2) {
|
|
|
|
$2->next = $4;
|
|
|
|
emit_function ($3, $2);
|
|
|
|
} else {
|
|
|
|
emit_function ($3, $4);
|
|
|
|
}
|
|
|
|
finish_function ($3);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
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
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
| '[' const ',' { $<def>$ = current_def; }
|
2002-05-13 20:11:33 +00:00
|
|
|
def_name { current_def = $<def>4; } ']'
|
2001-07-14 01:15:40 +00:00
|
|
|
{
|
2002-05-07 16:55:54 +00:00
|
|
|
if ($2->type == ex_integer)
|
|
|
|
convert_int ($2);
|
|
|
|
if ($2->type != ex_float)
|
|
|
|
error ($2, "invalid type for frame number");
|
|
|
|
if ($5->type->type != ev_func)
|
|
|
|
error ($2, "invalid type for think");
|
2001-06-25 20:52:04 +00:00
|
|
|
|
2002-05-22 17:18:48 +00:00
|
|
|
$$ = new_binary_expr ('s', $2, new_def_expr ($5));
|
2001-06-20 07:02:36 +00:00
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
| expr
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_comma
|
|
|
|
: /* empty */
|
|
|
|
| ','
|
|
|
|
;
|
|
|
|
|
2001-06-15 19:38:43 +00:00
|
|
|
begin_function
|
|
|
|
: /*empty*/
|
|
|
|
{
|
2001-06-25 22:11:20 +00:00
|
|
|
$$ = current_func = new_function ();
|
2001-06-25 18:23:29 +00:00
|
|
|
$$->def = current_def;
|
|
|
|
$$->code = numstatements;
|
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 ();
|
|
|
|
$$->aux = new_auxfunction ();
|
|
|
|
$$->aux->source_line = pr_source_line;
|
|
|
|
$$->aux->line_info = lineno - linenos;
|
|
|
|
$$->aux->local_defs = num_locals;
|
|
|
|
|
|
|
|
lineno->fa.func = $$->aux - auxfunctions;
|
|
|
|
}
|
2001-06-15 19:38:43 +00:00
|
|
|
pr_scope = current_def;
|
2002-05-08 05:15:19 +00:00
|
|
|
build_scope ($$, current_def, current_params);
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
end_function
|
|
|
|
: /*empty*/
|
|
|
|
{
|
|
|
|
pr_scope = 0;
|
|
|
|
}
|
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
|
|
|
{
|
2001-10-24 06:39:49 +00:00
|
|
|
def_t *scope = PR_NewDef (&type_void, ".scope", pr_scope);
|
|
|
|
scope->alloc = pr_scope->alloc;
|
|
|
|
scope->used = 1;
|
|
|
|
pr_scope->scope_next = scope->scope_next;
|
|
|
|
scope->scope_next = 0;
|
|
|
|
pr_scope = scope;
|
|
|
|
}
|
|
|
|
statements '}'
|
|
|
|
{
|
|
|
|
def_t *scope = pr_scope;
|
|
|
|
|
|
|
|
PR_FlushScope (pr_scope, 1);
|
|
|
|
|
|
|
|
while (scope->scope_next)
|
|
|
|
scope = scope->scope_next;
|
|
|
|
|
|
|
|
scope->scope_next = pr_scope->scope->scope_next;
|
|
|
|
pr_scope->scope->scope_next = pr_scope;
|
|
|
|
pr_scope = pr_scope->scope;
|
|
|
|
$$ = $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
|
2001-06-25 20:52:04 +00:00
|
|
|
: ';' { $$ = 0; }
|
2001-06-20 07:02:36 +00:00
|
|
|
| statement_block { $$ = $1; }
|
2001-06-25 20:52:04 +00:00
|
|
|
| RETURN expr ';'
|
|
|
|
{
|
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");
|
|
|
|
}
|
|
|
|
| CASE expr ':'
|
|
|
|
{
|
|
|
|
$$ = case_label_expr (switch_block, $2);
|
|
|
|
}
|
|
|
|
| DEFAULT ':'
|
|
|
|
{
|
|
|
|
$$ = case_label_expr (switch_block, 0);
|
|
|
|
}
|
|
|
|
| SWITCH break_label switch_block '(' expr ')'
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
| WHILE break_label continue_label '(' expr ')' 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;
|
2001-07-15 01:51:01 +00:00
|
|
|
expr_t *e;
|
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
|
|
|
|
2001-10-24 18:57:29 +00:00
|
|
|
e = new_binary_expr ('n', test_expr ($5, 1), l2);
|
|
|
|
e->line = $5->line;
|
|
|
|
e->file = $5->file;
|
2001-07-15 01:51:01 +00:00
|
|
|
append_expr ($$, e);
|
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);
|
|
|
|
e = new_binary_expr ('i', test_expr ($5, 1), l1);
|
|
|
|
e->line = $5->line;
|
|
|
|
e->file = $5->file;
|
2001-07-15 01:51:01 +00:00
|
|
|
append_expr ($$, e);
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l2);
|
2001-10-24 18:57:29 +00:00
|
|
|
break_label = $2;
|
|
|
|
continue_label = $3;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2001-10-24 18:57:29 +00:00
|
|
|
| DO break_label continue_label statement WHILE '(' expr ')' ';'
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2001-06-26 02:46:02 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
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);
|
|
|
|
append_expr ($$, new_binary_expr ('i', test_expr ($7, 1), l1));
|
|
|
|
append_expr ($$, break_label);
|
|
|
|
break_label = $2;
|
|
|
|
continue_label = $3;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2001-06-20 21:18:04 +00:00
|
|
|
| LOCAL type
|
|
|
|
{
|
|
|
|
current_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;
|
2001-06-20 21:18:04 +00:00
|
|
|
}
|
2001-10-18 23:06:39 +00:00
|
|
|
| IF '(' expr ')' 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-07-15 01:51:01 +00:00
|
|
|
expr_t *e;
|
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);
|
|
|
|
|
2001-07-24 22:30:31 +00:00
|
|
|
e = new_binary_expr ('n', test_expr ($3, 1), l1);
|
2001-07-15 01:51:01 +00:00
|
|
|
e->line = $3->line;
|
|
|
|
e->file = $3->file;
|
|
|
|
append_expr ($$, e);
|
2001-10-18 23:06:39 +00:00
|
|
|
append_expr ($$, $6);
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l1);
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
2001-10-18 23:06:39 +00:00
|
|
|
| IF '(' expr ')' save_inits statement ELSE
|
|
|
|
{
|
|
|
|
$<def_list>$ = save_local_inits (pr_scope);
|
|
|
|
restore_local_inits ($5);
|
|
|
|
}
|
|
|
|
statement
|
2001-06-25 20:52:04 +00:00
|
|
|
{
|
2001-10-19 03:22:04 +00:00
|
|
|
expr_t *l1 = new_label_expr ();
|
|
|
|
expr_t *l2 = new_label_expr ();
|
|
|
|
expr_t *e;
|
|
|
|
hashtab_t *merged;
|
|
|
|
hashtab_t *else_ini;
|
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
|
|
|
else_ini = save_local_inits (pr_scope);
|
|
|
|
|
|
|
|
restore_local_inits ($5);
|
|
|
|
free_local_inits ($5);
|
|
|
|
|
2001-07-24 22:30:31 +00:00
|
|
|
e = new_binary_expr ('n', test_expr ($3, 1), l1);
|
2001-07-15 01:51:01 +00:00
|
|
|
e->line = $3->line;
|
|
|
|
e->file = $3->file;
|
|
|
|
append_expr ($$, e);
|
|
|
|
|
2001-10-18 23:06:39 +00:00
|
|
|
append_expr ($$, $6);
|
2001-07-15 01:51:01 +00:00
|
|
|
|
|
|
|
e = new_unary_expr ('g', l2);
|
|
|
|
append_expr ($$, e);
|
|
|
|
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l1);
|
2001-10-18 23:06:39 +00:00
|
|
|
append_expr ($$, $9);
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l2);
|
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);
|
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
|
|
|
{
|
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;
|
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);
|
|
|
|
if ($7)
|
|
|
|
append_expr ($$, new_binary_expr ('n', test_expr ($7, 1), l2));
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l1);
|
2001-10-24 18:57:29 +00:00
|
|
|
append_expr ($$, $12);
|
|
|
|
append_expr ($$, continue_label);
|
|
|
|
append_expr ($$, $9);
|
2001-08-01 06:29:09 +00:00
|
|
|
if ($5)
|
2001-10-24 18:57:29 +00:00
|
|
|
append_expr ($$, new_binary_expr ('i', test_expr ($7, 1), l1));
|
2001-06-26 03:33:01 +00:00
|
|
|
append_expr ($$, l2);
|
2001-10-24 18:57:29 +00:00
|
|
|
break_label = $2;
|
|
|
|
continue_label = $3;
|
2001-06-25 20:52:04 +00:00
|
|
|
}
|
|
|
|
| expr ';'
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
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 */
|
|
|
|
{
|
|
|
|
$$ = save_local_inits (pr_scope);
|
|
|
|
}
|
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
|
|
|
|
: expr
|
|
|
|
| /* empty */
|
|
|
|
{
|
|
|
|
$$ = 0;
|
|
|
|
}
|
2002-04-27 02:51:00 +00:00
|
|
|
;
|
2001-08-01 06:29:09 +00:00
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
expr
|
2001-12-12 08:39:47 +00:00
|
|
|
: 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); }
|
|
|
|
| expr AND expr { $$ = binary_expr (AND, $1, $3); }
|
|
|
|
| expr OR expr { $$ = binary_expr (OR, $1, $3); }
|
|
|
|
| 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); }
|
|
|
|
| expr '(' arg_list ')' { $$ = function_expr ($1, $3); }
|
|
|
|
| expr '(' ')' { $$ = function_expr ($1, 0); }
|
2002-01-17 19:32:04 +00:00
|
|
|
| TYPE '(' expr ')' { $$ = cast_expr ($1, $3); }
|
2001-11-15 00:46:36 +00:00
|
|
|
| expr '[' expr ']' { $$ = array_expr ($1, $3); }
|
2001-08-11 21:15:24 +00:00
|
|
|
| expr '.' expr { $$ = binary_expr ('.', $1, $3); }
|
2001-08-20 06:22:28 +00:00
|
|
|
| '+' expr %prec UNARY { $$ = $2; }
|
|
|
|
| '-' expr %prec UNARY { $$ = unary_expr ('-', $2); }
|
|
|
|
| '!' expr %prec UNARY { $$ = unary_expr ('!', $2); }
|
|
|
|
| '~' expr %prec UNARY { $$ = unary_expr ('~', $2); }
|
2001-12-12 08:39:47 +00:00
|
|
|
| '&' expr %prec UNARY { $$ = address_expr ($2, 0, 0); }
|
2001-08-20 06:22:28 +00:00
|
|
|
| INCOP expr { $$ = incop_expr ($1, $2, 0); }
|
|
|
|
| expr INCOP { $$ = incop_expr ($2, $1, 1); }
|
2002-05-08 05:55:57 +00:00
|
|
|
| obj_expr { $$ = $1; }
|
2002-01-21 19:03:29 +00:00
|
|
|
| NAME { $$ = new_name_expr ($1); }
|
2002-05-18 00:30:14 +00:00
|
|
|
| SELF { $$ = new_self_expr (); }
|
2001-08-11 21:15:24 +00:00
|
|
|
| const { $$ = $1; }
|
|
|
|
| '(' expr ')' { $$ = $2; $$->paren = 1; }
|
2001-06-12 19:44:26 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
arg_list
|
2001-06-13 07:16:39 +00:00
|
|
|
: expr
|
2001-06-12 19:44:26 +00:00
|
|
|
| arg_list ',' expr
|
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
|
2001-06-15 19:38:43 +00:00
|
|
|
: FLOAT_VAL
|
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_float;
|
|
|
|
$$->e.float_val = $1;
|
|
|
|
}
|
2002-04-26 21:42:50 +00:00
|
|
|
| string_val
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
2002-04-26 21:42:50 +00:00
|
|
|
$$ = $1;
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
2001-06-27 19:40:43 +00:00
|
|
|
| VECTOR_VAL
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_vector;
|
|
|
|
memcpy ($$->e.vector_val, $1, sizeof ($$->e.vector_val));
|
|
|
|
}
|
2001-06-27 19:40:43 +00:00
|
|
|
| QUATERNION_VAL
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_quaternion;
|
|
|
|
memcpy ($$->e.quaternion_val, $1, sizeof ($$->e.quaternion_val));
|
|
|
|
}
|
2001-06-27 19:40:43 +00:00
|
|
|
| INT_VAL
|
2001-06-15 19:38:43 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
2001-07-22 06:59:12 +00:00
|
|
|
$$->type = ex_integer;
|
2001-07-23 01:31:22 +00:00
|
|
|
$$->e.integer_val = $1;
|
2001-06-15 19:38:43 +00:00
|
|
|
}
|
2001-10-17 07:45:37 +00:00
|
|
|
| NIL
|
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_nil;
|
|
|
|
}
|
2001-06-13 07:16:39 +00:00
|
|
|
;
|
|
|
|
|
2002-04-26 21:42:50 +00:00
|
|
|
string_val
|
|
|
|
: STRING_VAL
|
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_string;
|
|
|
|
$$->e.string_val = $1;
|
|
|
|
}
|
|
|
|
| string_val STRING_VAL
|
|
|
|
{
|
|
|
|
expr_t *e = new_expr ();
|
|
|
|
e->type = ex_string;
|
|
|
|
e->e.string_val = $2;
|
|
|
|
$$ = binary_expr ('+', $1, e);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
obj_def
|
2002-05-07 16:55:54 +00:00
|
|
|
: classdef
|
|
|
|
| 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
|
|
|
|
: NAME
|
|
|
|
{
|
|
|
|
$$ = new_block_expr ();
|
|
|
|
append_expr ($$, new_name_expr ($1));
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
| identifier_list ',' NAME
|
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-05-07 16:55:54 +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-05-10 00:00:23 +00:00
|
|
|
class_name
|
|
|
|
: NAME
|
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
|
|
|
|
: NAME
|
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-22 17:13:52 +00:00
|
|
|
current_class = $$;
|
2002-05-08 21:24:24 +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)
|
|
|
|
error (0, "%s is not a super class of %s",
|
|
|
|
$3->class_name, $1->class_name);
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
new_class_with_super
|
|
|
|
: new_class_name ':' class_name
|
|
|
|
{
|
|
|
|
$1->super_class = $3;
|
|
|
|
$$ = $1;
|
2002-05-22 17:13:52 +00:00
|
|
|
current_class = $$;
|
2002-05-15 19:10:23 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
category_name
|
|
|
|
: NAME '(' NAME ')'
|
|
|
|
{
|
|
|
|
$$ = get_category ($1, $3, 0);
|
|
|
|
if (!$$) {
|
|
|
|
error (0, "undefined category `%s (%s)'", $1, $3);
|
|
|
|
$$ = get_category (0, 0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
new_category_name
|
|
|
|
: NAME '(' NAME ')'
|
|
|
|
{
|
|
|
|
$$ = get_category ($1, $3, 1);
|
|
|
|
if ($$->defined) {
|
|
|
|
error (0, "redefinition of category `%s (%s)'", $1, $3);
|
|
|
|
$$ = get_category (0, 0, 1);
|
|
|
|
}
|
2002-05-22 17:13:52 +00:00
|
|
|
current_class = $$;
|
2002-05-15 19:10:23 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
protocol_name
|
|
|
|
: NAME
|
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-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
|
|
|
|
protocolrefs { class_add_protocol_methods ($2, $3);}
|
|
|
|
'{' ivar_decl_list '}' { class_add_ivars ($2, $6); }
|
|
|
|
methodprotolist { class_add_methods ($2, $9); }
|
2002-05-16 22:33:11 +00:00
|
|
|
END { current_class = 0; }
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_class_name
|
|
|
|
protocolrefs { class_add_protocol_methods ($2, $3);}
|
|
|
|
methodprotolist { class_add_methods ($2, $5); }
|
2002-05-16 22:33:11 +00:00
|
|
|
END { current_class = 0; }
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_class_with_super
|
|
|
|
protocolrefs { class_add_protocol_methods ($2, $3);}
|
|
|
|
'{' ivar_decl_list '}' { class_add_ivars ($2, $6); }
|
|
|
|
methodprotolist { class_add_methods ($2, $9); }
|
2002-05-16 22:33:11 +00:00
|
|
|
END { current_class = 0; }
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_class_with_super
|
|
|
|
protocolrefs { class_add_protocol_methods ($2, $3);}
|
|
|
|
methodprotolist { class_add_methods ($2, $5); }
|
2002-05-16 22:33:11 +00:00
|
|
|
END { current_class = 0; }
|
2002-05-22 17:13:52 +00:00
|
|
|
| INTERFACE new_category_name
|
|
|
|
protocolrefs { class_add_protocol_methods ($2, $3);}
|
|
|
|
methodprotolist { class_add_methods ($2, $5); }
|
2002-05-16 22:33:11 +00:00
|
|
|
END { current_class = 0; }
|
|
|
|
| IMPLEMENTATION class_name { class_begin ($2); }
|
|
|
|
'{' ivar_decl_list '}' { class_check_ivars ($2, $5); }
|
|
|
|
| IMPLEMENTATION class_name { class_begin ($2); }
|
|
|
|
| IMPLEMENTATION class_with_super { class_begin ($2); }
|
|
|
|
'{' ivar_decl_list '}' { class_check_ivars ($2, $5); }
|
|
|
|
| IMPLEMENTATION class_with_super { class_begin ($2); }
|
|
|
|
| IMPLEMENTATION category_name { class_begin ($2); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
protocoldef
|
|
|
|
: PROTOCOL protocol_name
|
|
|
|
protocolrefs { protocol_add_protocol_methods ($2, $3); }
|
|
|
|
methodprotolist { protocol_add_methods ($2, $5); }
|
|
|
|
END
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
protocolrefs
|
|
|
|
: /* emtpy */ { $$ = 0; }
|
|
|
|
| LT identifier_list GT { $$ = $2->e.block.head; }
|
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;
|
2002-05-17 06:20:27 +00:00
|
|
|
current_ivars = new_struct (0);
|
|
|
|
if (current_class->super_class)
|
|
|
|
new_struct_field (current_ivars,
|
|
|
|
current_class->super_class->ivars, 0,
|
|
|
|
vis_private);
|
|
|
|
}
|
|
|
|
ivar_decl_list_2
|
2002-05-15 19:10:23 +00:00
|
|
|
{
|
|
|
|
$$ = current_ivars;
|
|
|
|
current_ivars = 0;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
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
|
2002-05-15 19:10:23 +00:00
|
|
|
: type { current_type = $1; } ivars
|
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
|
|
|
|
| ivars ',' ivar_declarator
|
|
|
|
;
|
|
|
|
|
2002-05-10 00:00:23 +00:00
|
|
|
ivar_declarator
|
|
|
|
: NAME
|
|
|
|
{
|
2002-05-15 19:10:23 +00:00
|
|
|
new_struct_field (current_ivars, current_type,
|
2002-05-10 00:00:23 +00:00
|
|
|
$1, current_visibility);
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 21:24:24 +00:00
|
|
|
methoddef
|
2002-05-15 23:24:19 +00:00
|
|
|
: '+' methoddecl
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
$2->instance = 0;
|
2002-05-15 23:24:19 +00:00
|
|
|
$2 = class_find_method (current_class, $2);
|
|
|
|
}
|
|
|
|
opt_state_expr
|
|
|
|
{
|
2002-05-15 19:10:23 +00:00
|
|
|
current_def = $2->def = method_def (current_class, $2);
|
2002-05-08 21:24:24 +00:00
|
|
|
current_params = $2->params;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
begin_function statement_block end_function
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
2002-05-15 23:24:19 +00:00
|
|
|
build_function ($6);
|
|
|
|
if ($4) {
|
|
|
|
$4->next = $7;
|
|
|
|
emit_function ($6, $4);
|
2002-05-08 21:24:24 +00:00
|
|
|
} else {
|
2002-05-15 23:24:19 +00:00
|
|
|
emit_function ($6, $7);
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-15 23:24:19 +00:00
|
|
|
finish_function ($6);
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-17 18:35:54 +00:00
|
|
|
| '+' methoddecl '=' '#' const ';'
|
|
|
|
{
|
|
|
|
$2->instance = 0;
|
|
|
|
$2 = class_find_method (current_class, $2);
|
|
|
|
$2->def = method_def (current_class, $2);
|
|
|
|
|
|
|
|
build_builtin_function ($2->def, $5);
|
|
|
|
}
|
2002-05-15 23:24:19 +00:00
|
|
|
| '-' methoddecl
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
$2->instance = 1;
|
2002-05-15 23:24:19 +00:00
|
|
|
$2 = class_find_method (current_class, $2);
|
|
|
|
}
|
|
|
|
opt_state_expr
|
|
|
|
{
|
2002-05-15 19:10:23 +00:00
|
|
|
current_def = $2->def = method_def (current_class, $2);
|
2002-05-08 21:24:24 +00:00
|
|
|
current_params = $2->params;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
begin_function statement_block end_function
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
2002-05-15 23:24:19 +00:00
|
|
|
build_function ($6);
|
|
|
|
if ($4) {
|
|
|
|
$4->next = $7;
|
|
|
|
emit_function ($6, $4);
|
2002-05-08 21:24:24 +00:00
|
|
|
} else {
|
2002-05-15 23:24:19 +00:00
|
|
|
emit_function ($6, $7);
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-15 23:24:19 +00:00
|
|
|
finish_function ($6);
|
2002-05-08 21:24:24 +00:00
|
|
|
}
|
2002-05-17 18:35:54 +00:00
|
|
|
| '-' methoddecl '=' '#' const ';'
|
|
|
|
{
|
2002-05-21 22:51:46 +00:00
|
|
|
$2->instance = 1;
|
2002-05-17 18:35:54 +00:00
|
|
|
$2 = class_find_method (current_class, $2);
|
|
|
|
$2->def = method_def (current_class, $2);
|
|
|
|
|
|
|
|
build_builtin_function ($2->def, $5);
|
|
|
|
}
|
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-05-10 00:00:23 +00:00
|
|
|
: methodproto
|
|
|
|
{
|
|
|
|
$$ = new_methodlist ();
|
|
|
|
add_method ($$, $1);
|
|
|
|
}
|
|
|
|
| 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;
|
2002-05-17 06:20:27 +00:00
|
|
|
$2->params->type = &type_Class;
|
2002-05-08 21:24:24 +00:00
|
|
|
$$ = $2;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
| '-' methoddecl ';'
|
2002-05-08 21:24:24 +00:00
|
|
|
{
|
|
|
|
$2->instance = 1;
|
2002-05-17 06:20:27 +00:00
|
|
|
$2->params->type = current_class->type;
|
2002-05-08 21:24:24 +00:00
|
|
|
$$ = $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
|
2002-05-08 05:15:19 +00:00
|
|
|
: NAME
|
2002-05-10 00:00:23 +00:00
|
|
|
| TYPE { $$ = strdup (yytext); }
|
2002-05-08 23:12:49 +00:00
|
|
|
| reserved_word
|
|
|
|
;
|
|
|
|
|
|
|
|
reserved_word
|
2002-05-10 00:00:23 +00:00
|
|
|
: LOCAL { $$ = strdup (yytext); }
|
|
|
|
| RETURN { $$ = strdup (yytext); }
|
|
|
|
| WHILE { $$ = strdup (yytext); }
|
|
|
|
| DO { $$ = strdup (yytext); }
|
|
|
|
| IF { $$ = strdup (yytext); }
|
|
|
|
| ELSE { $$ = strdup (yytext); }
|
|
|
|
| FOR { $$ = strdup (yytext); }
|
|
|
|
| BREAK { $$ = strdup (yytext); }
|
|
|
|
| CONTINUE { $$ = strdup (yytext); }
|
|
|
|
| SWITCH { $$ = strdup (yytext); }
|
|
|
|
| CASE { $$ = strdup (yytext); }
|
|
|
|
| DEFAULT { $$ = strdup (yytext); }
|
|
|
|
| NIL { $$ = strdup (yytext); }
|
|
|
|
| STRUCT { $$ = strdup (yytext); }
|
|
|
|
| ENUM { $$ = strdup (yytext); }
|
|
|
|
| TYPEDEF { $$ = strdup (yytext); }
|
2002-05-17 19:47:15 +00:00
|
|
|
| SUPER { $$ = strdup (yytext); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
keyworddecl
|
2002-05-08 05:55:57 +00:00
|
|
|
: selector ':' '(' type ')' NAME
|
|
|
|
{ $$ = new_param ($1, $4, $6); }
|
|
|
|
| selector ':' NAME
|
2002-05-08 21:24:24 +00:00
|
|
|
{ $$ = new_param ($1, &type_id, $3); }
|
2002-05-08 05:55:57 +00:00
|
|
|
| ':' '(' type ')' NAME
|
2002-05-08 21:24:24 +00:00
|
|
|
{ $$ = new_param ("", $3, $5); }
|
2002-05-08 05:55:57 +00:00
|
|
|
| ':' NAME
|
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); }
|
|
|
|
| PROTOCOL '(' NAME ')' { $$ = protocol_expr ($3); }
|
|
|
|
| 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
|
|
|
|
: expr
|
2002-05-17 19:47:15 +00:00
|
|
|
| SUPER { $$ = new_name_expr ("super"); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
messageargs
|
|
|
|
: selector { $$ = new_keywordarg ($1, 0); }
|
|
|
|
| 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-05-22 05:03:36 +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
|
|
|
|
: 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
|
|
|
|
: selector ':' { $$ = new_keywordarg ($1, 0); }
|
|
|
|
| ':' { $$ = new_keywordarg ("", 0); }
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2002-05-08 23:12:49 +00:00
|
|
|
obj_string
|
2002-05-07 16:55:54 +00:00
|
|
|
: '@' STRING_VAL
|
2002-05-08 23:12:49 +00:00
|
|
|
{
|
|
|
|
$$ = new_expr ();
|
|
|
|
$$->type = ex_string;
|
|
|
|
$$->e.string_val = $2;
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
| obj_string '@' STRING_VAL
|
2002-05-08 23:12:49 +00:00
|
|
|
{
|
|
|
|
expr_t *e = new_expr ();
|
|
|
|
e->type = ex_string;
|
|
|
|
e->e.string_val = $3;
|
|
|
|
$$ = binary_expr ('+', $1, e);
|
|
|
|
}
|
2002-05-07 16:55:54 +00:00
|
|
|
;
|
|
|
|
|
2001-06-12 19:44:26 +00:00
|
|
|
%%
|
2001-06-18 22:51:49 +00:00
|
|
|
|
2001-11-14 22:31:57 +00:00
|
|
|
type_t *
|
|
|
|
build_type (int is_field, type_t *type)
|
|
|
|
{
|
|
|
|
if (is_field) {
|
|
|
|
type_t new;
|
|
|
|
memset (&new, 0, sizeof (new));
|
|
|
|
new.type = ev_field;
|
|
|
|
new.aux_type = type;
|
2002-05-09 06:34:48 +00:00
|
|
|
return find_type (&new);
|
2001-11-14 22:31:57 +00:00
|
|
|
} else {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-15 00:46:36 +00:00
|
|
|
type_t *
|
2002-05-01 21:35:39 +00:00
|
|
|
build_array_type (type_t *type, int size)
|
2001-11-15 00:46:36 +00:00
|
|
|
{
|
|
|
|
type_t new;
|
|
|
|
|
|
|
|
memset (&new, 0, sizeof (new));
|
|
|
|
new.type = ev_pointer;
|
2002-05-01 21:35:39 +00:00
|
|
|
new.aux_type = type;
|
2001-11-15 00:46:36 +00:00
|
|
|
new.num_parms = size;
|
2002-05-09 06:34:48 +00:00
|
|
|
return find_type (&new);
|
2001-11-15 00:46:36 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 03:22:04 +00:00
|
|
|
typedef struct {
|
|
|
|
def_t *def;
|
|
|
|
int state;
|
|
|
|
} def_state_t;
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
get_key (void *_d, void *unused)
|
|
|
|
{
|
|
|
|
return ((def_state_t *)_d)->def->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_key (void *_d, void *unused)
|
|
|
|
{
|
|
|
|
free (_d);
|
|
|
|
}
|
|
|
|
|
2001-10-24 15:21:21 +00:00
|
|
|
static void
|
|
|
|
scan_scope (hashtab_t *tab, def_t *scope)
|
2001-10-18 23:06:39 +00:00
|
|
|
{
|
2001-10-19 03:22:04 +00:00
|
|
|
def_t *def;
|
2001-10-24 15:21:21 +00:00
|
|
|
if (scope->scope)
|
|
|
|
scan_scope (tab, scope->scope);
|
2001-10-19 03:22:04 +00:00
|
|
|
for (def = scope->scope_next; def; def = def->scope_next) {
|
2001-10-24 15:21:21 +00:00
|
|
|
if (def->name && !def->removed) {
|
2001-10-19 03:22:04 +00:00
|
|
|
def_state_t *ds = malloc (sizeof (def_state_t));
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (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 *
|
|
|
|
save_local_inits (def_t *scope)
|
|
|
|
{
|
|
|
|
hashtab_t *tab = Hash_NewTable (61, get_key, free_key, 0);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
hashtab_t *tab = Hash_NewTable (61, get_key, free_key, 0);
|
|
|
|
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;
|
|
|
|
|
|
|
|
nds = malloc (sizeof (def_state_t));
|
2002-05-14 06:37:28 +00:00
|
|
|
SYS_CHECKMEM (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
|
|
|
}
|