From cd7c53d223bf08fda704ef52b46efed0f3f7996b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 18 Dec 2012 12:49:43 +0900 Subject: [PATCH] Parse id and classname . This is needed to allow compile-time protocol conformance checks, though nothing along those lines has been implemented yet. id has been changed from TYPE to OBJECT, required to allow id to be parsed. OBJECT uses symbol, allowing id to be redefined once suitable work has been done on the parser. --- tools/qfcc/source/class.c | 2 ++ tools/qfcc/source/qc-lex.l | 5 ++++- tools/qfcc/source/qc-parse.y | 10 ++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index 4526f4f7a..430ecd6a4 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -1375,6 +1375,8 @@ init_objective_structs (void) chain_type (&type_obj_super); chain_type (&type_SuperPtr); chain_type (&type_supermsg); + + symtab_addsymbol (current_symtab, new_symbol ("id")); } static void diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index bcbd9a174..2acdd3818 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -281,7 +281,7 @@ static keyword_t keywords[] = { {"int", TYPE, &type_integer, 0, PROG_VERSION, 0}, {"unsigned", TYPE, &type_integer, 0, PROG_VERSION, 0},//FIXME {"function", TYPE, &type_function, 0, PROG_VERSION, 0}, - {"id", TYPE, &type_id, 0, PROG_VERSION, 1}, + {"id", OBJECT, &type_id, 0, PROG_VERSION, 1}, {"Class", TYPE, &type_Class, 0, PROG_VERSION, 1}, // {"Protocol", TYPE, &type_Protocol, 0, PROG_VERSION, 0}, {"Method", TYPE, &type_obj_method, 0, PROG_VERSION, 1}, @@ -363,6 +363,9 @@ keyword_or_id (char *token) if (keyword->value) { if (keyword->value == STRUCT) { qc_yylval.op = token[0]; + } else if (keyword->value == OBJECT) { + sym = symtab_lookup (current_symtab, token); + qc_yylval.symbol = sym; } else { qc_yylval.type = 0; qc_yylval.type = keyword->type; diff --git a/tools/qfcc/source/qc-parse.y b/tools/qfcc/source/qc-parse.y index fd423ae5c..f2f6cd886 100644 --- a/tools/qfcc/source/qc-parse.y +++ b/tools/qfcc/source/qc-parse.y @@ -148,7 +148,7 @@ int yylex (void); %token ARGS EXTERN STATIC SYSTEM SIZEOF OVERLOAD %token STRUCT %token TYPE -%token TYPE_NAME +%token OBJECT TYPE_NAME %token CLASS DEFS ENCODE END IMPLEMENTATION INTERFACE PRIVATE %token PROTECTED PROTOCOL PUBLIC SELECTOR REFERENCE SELF THIS @@ -462,7 +462,11 @@ type_specifier { $$ = make_spec ($1->type, 0, 0, 0); } - | CLASS_NAME + | OBJECT protocolrefs + { + $$ = make_spec (&type_id, 0, 0, 0); + } + | CLASS_NAME protocolrefs { $$ = make_spec ($1->type, 0, 0, 0); } @@ -1271,6 +1275,7 @@ identifier if (!($$ = symtab_lookup (current_symtab, "break"))) $$ = new_symbol ("break"); } + | OBJECT | CLASS_NAME | TYPE_NAME ; @@ -1710,6 +1715,7 @@ keywordselector selector : NAME { $$ = $1; } | CLASS_NAME { $$ = $1; } + | OBJECT { $$ = new_symbol (qc_yytext); } | TYPE { $$ = new_symbol (qc_yytext); } | TYPE_NAME { $$ = $1; } | reserved_word