Changeset 159
- Timestamp:
- 04/11/07 04:17:09 (2 years ago)
- Files:
-
- trunk/gcc/gcc/algol60/Make-lang.in (modified) (3 diffs)
- trunk/gcc/gcc/algol60/a60_symtab.c (added)
- trunk/gcc/gcc/algol60/a60_symtab.h (added)
- trunk/gcc/gcc/algol60/a60_symtab.i (added)
- trunk/gcc/gcc/algol60/al60l-bind.c (modified) (5 diffs)
- trunk/gcc/gcc/algol60/desig-expr.c (modified) (3 diffs)
- trunk/gcc/gcc/algol60/expression.c (modified) (3 diffs)
- trunk/gcc/gcc/algol60/parser.y (modified) (10 diffs)
- trunk/gcc/gcc/algol60/statement.c (modified) (11 diffs)
- trunk/gcc/gcc/algol60/statement.h (modified) (3 diffs)
- trunk/gcc/gcc/algol60/symbol.c (modified) (7 diffs)
- trunk/gcc/gcc/algol60/symbol.h (modified) (2 diffs)
- trunk/gcc/gcc/algol60/type.c (modified) (5 diffs)
- trunk/gcc/gcc/algol60/type.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/gcc/gcc/algol60/Make-lang.in
r154 r159 32 32 algol60/symbol.o algol60/type.o \ 33 33 algol60/for-elmt.o algol60/desig-expr.o \ 34 algol60/statement.o algol60/expression.o 34 algol60/statement.o algol60/expression.o \ 35 algol60/a60_symtab.o 35 36 36 37 .PHONY: algol60 … … 144 145 algol60/symbol.o: algol60/symbol.c algol60/symbol.h algol60/symbol.i\ 145 146 algol60/label.i algol60/type.i algol60/statement.i algol60/estring.i\ 146 algol60/cursor.i \147 algol60/cursor.i algol60/logger.i\ 147 148 algol60/label.h algol60/type.h algol60/statement.h algol60/estring.h\ 148 algol60/cursor.h \149 algol60/cursor.h algol60/logger.h\ 149 150 algol60/visitor.i algol60/visitor.h algol60/visitor-impl.h\ 151 algol60/meta.h algol60/pd.h algol60/gcc-stuff 152 153 algol60/a60_symtab.o: algol60/a60_symtab.c algol60/a60_symtab.h algol60/a60_symtab.i\ 154 algol60/symbol.i algol60/label.i algol60/type.i algol60/statement.i\ 155 algol60/estring.i algol60/logger.i algol60/cursor.i algol60/visitor.i\ 156 algol60/slist.h algol60/symbol.h algol60/label.h algol60/type.h\ 157 algol60/logger.h algol60/estring.h\ 150 158 algol60/meta.h algol60/pd.h algol60/gcc-stuff 151 159 … … 163 171 algol60/cursor.i algol60/slist.i algol60/expression.i\ 164 172 algol60/logger.i algol60/symbol.i algol60/label.i algol60/type.i\ 165 algol60/estring.i \173 algol60/estring.i algol60/a60_symtab.i\ 166 174 algol60/cursor.h algol60/slist.h algol60/expression.h\ 167 175 algol60/logger.h algol60/symbol.h algol60/label.h algol60/type.h\ 168 176 algol60/estring.h algol60/boundspair.h algol60/for-elmt.h\ 177 algol60/a60_symtab.h\ 169 178 algol60/visitor-impl.h algol60/visitor.h algol60/visitor.i\ 170 179 algol60/meta.h algol60/pd.h algol60/gcc-stuff trunk/gcc/gcc/algol60/al60l-bind.c
r157 r159 40 40 #include "for-elmt.h" 41 41 #include "visitor.h" 42 #include "a60_symtab.h" 42 43 43 44 struct struct_al60l_bind_state_t … … 730 731 } 731 732 733 static void * 734 private_stmt_container_build_decl_for_symbol (symbol_t * sym, void * _state) 735 { 736 // This is called from stmt_container_build_generic for each symbol 737 // in symbol table. 738 al60l_bind_state_t * state = _state; 739 tree decl = symbol_decl_for_type (sym, symbol_type (sym), state); 740 symbol_set_extra (sym, decl); 741 bind_state_add_decl (state, decl); 742 return NULL; 743 } 744 745 static void * 746 private_stmt_container_build_init_for_symbol (symbol_t * sym, void * _state) 747 { 748 // This is called from stmt_container_build_generic for each symbol 749 // in symbol table. 750 al60l_bind_state_t * state = _state; 751 tree init = symbol_init_for_type (sym, symbol_type (sym), state); 752 bind_state_add_stmt (state, init); 753 return NULL; 754 } 755 732 756 void * 733 757 stmt_container_build_generic (container_t * self, void * _state) … … 740 764 bind_state_push_block (state); 741 765 742 it = slist_iter (container_symtab (self)); 743 for (; slist_it_has (it); slist_it_next (it)) 744 { 745 symbol_t * sym = slist_it_get (it); 746 tree decl = symbol_decl_for_type (sym, symbol_type (sym), _state); 747 symbol_set_extra (sym, decl); 748 749 bind_state_add_decl (state, decl); 750 } 751 752 slist_it_reset (it, container_symtab (self)); 753 754 for (; slist_it_has (it); slist_it_next (it)) 755 { 756 symbol_t * sym = slist_it_get (it); 757 tree init = symbol_init_for_type (sym, symbol_type (sym), _state); 758 bind_state_add_stmt (state, init); 759 } 760 761 slist_it_reset (it, container_stmts (self)); 762 766 a60_symtab_each (container_symtab (self), 767 a60_symbol_callback (private_stmt_container_build_decl_for_symbol), 768 _state); 769 770 a60_symtab_each (container_symtab (self), 771 a60_symbol_callback (private_stmt_container_build_init_for_symbol), 772 _state); 773 774 it = slist_iter (container_stmts (self)); 763 775 for (; slist_it_has (it); slist_it_next (it)) 764 776 { … … 782 794 } 783 795 796 static void * 797 private_stmt_toplev_build_decl_for_symbol (symbol_t * sym, void * _state) 798 { 799 // This is called from stmt_toplev_build_generic for each symbol 800 // in symbol table. 801 al60l_bind_state_t * state = _state; 802 symbol_set_extra (sym, builtin_decl_get_generic (sym, state)); 803 return NULL; 804 } 805 784 806 void * 785 807 stmt_toplev_build_generic (container_t * self, void * _state) 786 808 { 787 al60l_bind_state_t * state = _state;788 789 809 // Process builtins first. 790 slist_it_t * it = slist_iter (container_symtab (self)); 791 for (; slist_it_has (it); slist_it_next (it)) 792 { 793 symbol_t * sym = a60_as_symbol (slist_it_get (it)); 794 symbol_set_extra (sym, builtin_decl_get_generic (sym, state)); 795 } 796 delete_slist_it (it); 810 a60_symtab_each (container_symtab (self), 811 a60_symbol_callback (private_stmt_toplev_build_decl_for_symbol), 812 _state); 797 813 798 814 // The toplev block should contain only one node: the actual program … … 961 977 // typechecking, and subexpression resolving has already been done 962 978 // by this point. 963 symbol_t * sym = new_symbol (l);979 symbol_t * sym = new_symbol_var (l); 964 980 symbol_set_type (sym, types[typeidx]); // function type 965 981 symbol_set_hidden (sym, 1); trunk/gcc/gcc/algol60/desig-expr.c
r151 r159 228 228 assert (self != NULL); 229 229 assert (log != NULL); 230 a60_symtab_t * symtab = container_symtab (context); 230 231 231 232 switch (self->base.kind) … … 234 235 { 235 236 self->elbl.sym 236 = container_find_name_rec_add_undefined (context, self->elbl.lbl,237 = a60_symtab_find_name_rec_add_undefined (symtab, self->elbl.lbl, 237 238 type_label (), 238 239 log, self->cursor); … … 266 267 { 267 268 self->eswitch.sym 268 = container_find_name_rec_add_undefined (context, self->elbl.lbl,269 = a60_symtab_find_name_rec_add_undefined (symtab, self->elbl.lbl, 269 270 type_switch_any (), 270 271 log, self->cursor); trunk/gcc/gcc/algol60/expression.c
r151 r159 617 617 { 618 618 type_t * match_type = new_t_proc (type_any (), new_slist ()); 619 symbol_t * found = container_find_name_rec (block, self->idref.lbl, match_type); 619 a60_symtab_t * symtab = container_symtab (block); 620 symbol_t * found = a60_symtab_find_name_rec (symtab, self->idref.lbl, match_type); 620 621 if (found == NULL) 621 found = container_find_name_rec_add_undefined (block, self->idref.lbl, type_any (), 622 found = a60_symtab_find_name_rec_add_undefined (symtab, self->idref.lbl, 623 type_any (), 622 624 log, self->cursor); 623 625 self->idref.sym = found; … … 727 729 728 730 type_t * match_type = new_t_proc (type_any (), argtypes); 731 a60_symtab_t * symtab = container_symtab (block); 729 732 self->call.sym = 730 container_find_name_rec_add_undefined (block, self->call.lbl,733 a60_symtab_find_name_rec_add_undefined (symtab, self->call.lbl, 731 734 match_type, log, 732 735 self->cursor); … … 746 749 delete_slist_it (it); 747 750 751 a60_symtab_t * symtab = container_symtab (block); 748 752 self->subscript.sym = 749 container_find_name_rec_add_undefined (block, self->subscript.lbl,753 a60_symtab_find_name_rec_add_undefined (symtab, self->subscript.lbl, 750 754 type_array_any (), log, 751 755 self->cursor); trunk/gcc/gcc/algol60/parser.y
r154 r159 14 14 #include "desig-expr.h" 15 15 #include "for-elmt.h" 16 #include "a60_symtab.h"//! 16 17 #include "meta.h" 17 18 #include "visitor-impl.h" … … 196 197 //%type <sym> DeclaredIdentifier 197 198 %type <stmt> Block 199 %type <type> Specifier 200 %type <lst> SpecificationPart 201 %type <lst> ValuePart 202 %type <lst> FormalParameterList 203 %type <lst> FormalParameterPart 198 204 //%type <> BlockDeclarationsList 199 205 //%type <> BlockDeclarations 200 206 %type <type> Type 207 %type <type> OptType 201 208 %type <flag> OptOwn 202 209 %type <type> OptIntrinsicType … … 228 235 %type <lst> ForList 229 236 %type <lelm> ForListElmt 230 231 237 %% 232 238 … … 241 247 container_t * c = new_stmt_toplev (NULL); 242 248 container_set_parent (c, dummy); 243 stmt_toplev_define_internals (c); 249 a60_symtab_t * symtab = container_symtab (c); 250 a60_symtab_toplev_define_internals (symtab); 244 251 private_open_block (parser, c); 245 252 } … … 278 285 279 286 LabelIdentifier: 280 IDENTIFIER 281 { 282 log_printf (parser->log, ll_debug, "LabelIdentifier -> IDENTIFIER"); 283 estring_t * lit = $1; 284 $$ = new_label (lit); 285 label_set_cursor ($$, cr_csr (parser, &@1)); 286 } 287 Identifier 287 288 | 288 289 LITINTEGER … … 404 405 private_setup_and_add_symbol (parser, $2, t); 405 406 } 407 | 408 OptType KWPROCEDURE Identifier FormalParameterPart SEPSEMICOLON ValuePart SpecificationPart Statement 409 { 410 log_printf (parser->log, ll_debug, 411 "BlockDeclarations -> OptType KWPROCEDURE Identifier " 412 "FormalParameterPart SEPSEMICOLON ValuePart " 413 "SpecificationPart Statement"); 414 /* 415 slist_t * formal_params = $4; 416 slist_t * value_params = $6; 417 slist_t * param_types = $7; 418 slist_it_t * it = slist_iter (formal_params); 419 for (; slist_it_has (it); slist_it_next (it)) 420 { 421 //@TODO 422 } 423 delete_slist_it (it); 424 //type_t * t = new_t_switch ($4); 425 */ 426 } 427 428 FormalParameterPart: 429 /*epsilon*/ { $$ = new_slist (); } 430 | 431 SEPLPAREN FormalParameterList SEPRPAREN { $$ = $2; } 432 433 FormalParameterList: 434 Identifier 435 { 436 $$ = new_slist (); 437 slist_pushfront ($$, $1); 438 @$ = @1; 439 } 440 | 441 FormalParameterList ParameterDelimiter Identifier 442 { 443 slist_pushfront ($$, $3); 444 @$ = @1; 445 } 446 447 ValuePart: 448 /*epsilon*/ { $$ = new_slist (); } 449 | 450 KWVALUE IdentifierList SEPSEMICOLON { $$ = $2; } 451 452 SpecificationPart: 453 /*epsilon*/ 454 { $$ = new_slist (); } 455 | 456 SpecificationPart Specifier IdentifierList SEPSEMICOLON 457 { 458 slist_pushfront ($$, $3); 459 slist_pushfront ($$, $2); 460 @$ = @1; 461 } 462 463 Specifier: 464 IntrinsicType 465 | 466 IntrinsicType KWARRAY { $$ = new_t_array ($1); } 467 | 468 KWARRAY { $$ = type_array_real (); } 469 | 470 KWLABEL 471 { 472 log_printf (parser->log, ll_debug, "Specifier -> KWLABEL"); 473 $$ = type_label (); 474 @$ = @1; 475 } 476 | 477 KWSWITCH 478 { 479 log_printf (parser->log, ll_debug, "Specifier -> KWSWITCH"); 480 $$ = type_switch_any (); 481 @$ = @1; 482 } 483 | 484 OptIntrinsicType KWPROCEDURE 485 { 486 log_printf (parser->log, ll_debug, "Specifier -> OptType KWPROCEDURE"); 487 $$ = new_t_proc_stub ($1 ? $1 : type_any ()); 488 @$ = @1; 489 } 406 490 407 491 Type: … … 438 522 } 439 523 524 OptType: 525 /*epsilon*/ { $$ = 0; } 526 | 527 Type 528 440 529 OptOwn: 441 530 /*epsilon*/ { $$ = 0; } … … 1178 1267 1179 1268 while (context != parser->program_block 1180 && slist_empty (container_symtab (context)))1269 && a60_symtab_empty (container_symtab (context))) 1181 1270 context = container_parent (context); 1182 1271 … … 1185 1274 { 1186 1275 label_t * lbl = slist_it_get (it); 1187 symbol_t * sym = new_symbol (lbl); 1188 if (container_add_symbol (context, sym, sek_ordinary) != 0) 1276 symbol_t * sym = new_symbol_var (lbl); 1277 a60_symtab_t * symtab = container_symtab (context); 1278 if (a60_symtab_add_symbol (symtab, sym, sek_ordinary) != 0) 1189 1279 { 1190 1280 cursor_t * csr = stmt_cursor (target); … … 1207 1297 { 1208 1298 // Setup symbol and add to table. 1209 symbol_t * sym = new_symbol (lbl);1299 symbol_t * sym = new_symbol_var (lbl); 1210 1300 symbol_set_type (sym, qt); 1211 int conflict = container_add_symbol (parser->block, sym, sek_ordinary); 1301 a60_symtab_t * symtab = container_symtab (parser->block); 1302 int conflict = a60_symtab_add_symbol (symtab, sym, sek_ordinary); 1212 1303 if (conflict) 1213 1304 { trunk/gcc/gcc/algol60/statement.c
r154 r159 16 16 #include "for-elmt.h" 17 17 #include "meta.h" 18 #include "a60_symtab.h" 18 19 #include "visitor-impl.h" 19 20 … … 64 65 { 65 66 slist_t * statements; 66 slist_t * symtab;67 a60_symtab_t * symtab; 67 68 } 68 69 container_rep_t; … … 77 78 sk_goto, 78 79 sk_block, 79 sk_toplev 80 sk_toplev, 80 81 } 81 82 stmt_kind_t; … … 205 206 statement_t * ret = private_new_statement (kind, cursor, NULL); 206 207 ret->block.statements = new_slist_typed (adapt_test, a60_as_statement); 207 ret->block.symtab = new_slist_typed (adapt_test, a60_as_symbol);208 ret->block.symtab = a60_new_symtab (); 208 209 return (container_t *)ret; 209 210 } … … 219 220 { 220 221 return private_new_container (sk_toplev, cursor); 221 }222 223 statement_t *224 clone_statement (statement_t const * self)225 {226 assert (self != NULL);227 228 statement_t * ret = private_new_statement (self->base.kind, self->cursor, NULL);229 230 switch (self->base.kind)231 {232 case sk_dummy:233 break;234 235 case sk_assign:236 ret->assign.lhss = clone_slist (self->assign.lhss);237 slist_map (ret->assign.lhss, adapt_test, clone_expression);238 ret->assign.rhs = clone_expression (self->assign.rhs);239 break;240 241 case sk_call:242 ret->call.call = clone_expression (self->call.call);243 break;244 245 case sk_cond:246 ret->cond.cond = clone_expression (self->cond.cond);247 ret->cond.ifclause = clone_statement (self->cond.ifclause);248 ret->cond.elseclause249 = ret->cond.elseclause ? clone_statement (self->cond.elseclause) : NULL;250 break;251 252 case sk_for:253 ret->afor.variable = clone_expression (self->afor.variable);254 ret->afor.elmts = clone_slist (self->afor.elmts);255 slist_map (ret->afor.elmts, adapt_test, clone_for_elmt);256 ret->afor.body = clone_statement (self->afor.body);257 break;258 259 case sk_goto:260 ret->agoto.target = clone_desig_expr (self->agoto.target);261 break;262 263 case sk_block:264 case sk_toplev:265 {266 ret->block.symtab = clone_slist (self->block.symtab);267 slist_map (ret->block.symtab, adapt_test, clone_symbol);268 ret->block.statements = new_slist_typed (adapt_test, a60_as_statement);269 270 // extract labels from the list271 slist_t * labels = new_slist ();272 slist_it_t * jt = slist_iter (ret->block.symtab);273 for (; slist_it_has (jt); slist_it_next (jt))274 {275 symbol_t * sym = slist_it_get (jt);276 if (types_same (symbol_type (sym), type_label ()))277 slist_pushback (labels, sym);278 }279 280 // clone statement list and retarget labels in one pass281 slist_it_t * it = slist_iter (self->block.statements);282 for (; slist_it_has (it); slist_it_next (it))283 {284 statement_t * stmt = slist_it_get (it);285 statement_t * clone = clone_statement (stmt);286 container_add_stmt (a60_as_container (ret), clone);287 288 slist_it_reset (jt, labels);289 for (; slist_it_has (jt); slist_it_next (jt))290 {291 symbol_t * sym = slist_it_get (jt);292 statement_t * target = symbol_stmt (sym);293 if (target == stmt)294 {295 symbol_set_stmt (sym, clone);296 stmt_add_label (clone, sym);297 }298 }299 }300 301 delete_slist_it (jt);302 delete_slist_it (it);303 delete_slist (labels);304 }305 break;306 };307 308 return ret;309 }310 311 container_t *312 clone_container (container_t const * self)313 {314 return a60_as_container (clone_statement (a60_as_statement ((container_t *)self)));315 222 } 316 223 … … 353 260 354 261 static void 355 private_dump_container (statement_t const * self, estring_t * buf, int level) 356 { 262 private_dump_container (statement_t const * self ATTRIBUTE_UNUSED, 263 estring_t * buf ATTRIBUTE_UNUSED, 264 int level ATTRIBUTE_UNUSED) 265 { 266 /* 357 267 estring_t * buf0 = new_estring (); 358 268 … … 428 338 429 339 delete_estring (buf0); 340 */ 430 341 } 431 342 … … 605 516 { 606 517 assert (a60_as_container (self)); 607 slist_it_t * it; 608 609 it = slist_iter (self->block.symtab); 610 for (; slist_it_has (it); slist_it_next (it)) 611 { 612 symbol_t * sym = slist_it_get (it); 613 type_resolve_symbols (symbol_type (sym), a60_as_container (self), log); 614 } 615 616 slist_it_reset (it, self->block.statements); 617 518 a60_symtab_resolve_symbols (self->block.symtab, a60_as_container (self), log); 519 slist_it_t * it = slist_iter (self->block.statements); 618 520 for (; slist_it_has (it); slist_it_next (it)) 619 521 stmt_resolve_symbols (slist_it_get (it), log); … … 729 631 730 632 self->parent = parent; 633 a60_symtab_set_parent (self->block.symtab, ((statement_t*)parent)->block.symtab); 731 634 } 732 635 … … 838 741 } 839 742 840 slist_t *743 a60_symtab_t * 841 744 container_symtab (container_t const * _self) 842 745 { … … 854 757 assert (self->base.kind == sk_block || self->base.kind == sk_toplev); 855 758 return self->block.statements; 856 }857 858 static void859 private_container_find_it (statement_t * container, label_t const * lbl, type_t const * atype, slist_it_t ** ret_prev, slist_it_t ** ret_it)860 {861 slist_it_t * it = slist_iter (container->block.symtab);862 slist_it_t * prev = NULL;863 864 for (; slist_it_has (it); )865 {866 symbol_t * sym = slist_it_get (it);867 type_t * symtype = symbol_type (sym);868 if (label_eq (symbol_label (sym), lbl)869 && (symtype == NULL || types_match (symtype, atype)))870 break;871 872 slist_it_next (it);873 if (ret_prev)874 {875 if (prev)876 slist_it_next (prev);877 else878 prev = slist_iter (container->block.symtab);879 }880 }881 882 if (ret_it)883 *ret_it = it;884 else885 delete_slist_it (it);886 887 if (ret_prev)888 *ret_prev = prev;889 }890 891 int892 container_add_symbol (container_t * _self, symbol_t * sym,893 symtab_entry_kind_t internal)894 {895 assert (_self != NULL);896 assert (sym != NULL);897 A60_USER_TO_REP (statement, self, *);898 assert (a60_as_container (self));899 900 if (internal == sek_ordinary901 && container_find_name (_self, symbol_label (sym), type_any ()) != NULL)902 return -1;903 904 slist_pushback (self->block.symtab, sym);905 return 0;906 }907 908 symbol_t *909 container_erase_symbol (container_t * _self, symbol_t * sym)910 {911 assert (_self != NULL);912 assert (sym != NULL);913 A60_USER_TO_REP (statement, self, *);914 assert (a60_as_container (self));915 916 slist_it_t * pr, * it;917 symbol_t * ret;918 919 private_container_find_it (self, symbol_label (sym), symbol_type (sym), &pr, &it);920 921 if (pr == NULL && it != NULL)922 // found at the beginning923 {924 ret = slist_popfront (self->block.symtab);925 delete_slist_it (it);926 }927 else928 // found somewhere in the middle929 {930 assert (pr != NULL && it != NULL);931 ret = slist_it_erase_after (pr);932 delete_slist_it (pr);933 delete_slist_it (it);934 }935 936 return ret;937 }938 939 symbol_t *940 container_find_name (container_t * _self, label_t const * lbl, type_t const * atype)941 {942 assert (_self != NULL);943 assert (lbl != NULL);944 A60_USER_TO_REP (statement, self, *);945 assert (a60_as_container (self));946 947 slist_it_t * it;948 private_container_find_it (self, lbl, atype, NULL, &it);949 symbol_t * ret = slist_it_has (it) ? slist_it_get (it) : NULL;950 delete_slist_it (it);951 return ret;952 }953 954 symbol_t *955 container_find_name_rec (container_t * _self, label_t const * lbl, type_t const * atype)956 {957 assert (_self != NULL);958 assert (lbl != NULL);959 A60_USER_TO_REP (statement, self, *);960 assert (a60_as_container (self));961 962 symbol_t * sym = container_find_name (_self, lbl, atype);963 if (sym == NULL && self->parent != NULL)964 return container_find_name_rec (self->parent, lbl, atype);965 else966 return sym;967 }968 969 symbol_t *970 container_find_name_rec_add_undefined (container_t * self, label_t const * lbl,971 type_t * atype, logger_t * log,972 cursor_t * cursor)973 {974 assert (self != NULL);975 assert (lbl != NULL);976 assert (atype != NULL);977 assert (log != NULL);978 assert (a60_as_container (self));979 980 symbol_t * found = container_find_name_rec (self, lbl, atype);981 if (found == NULL)982 {983 if (types_same (atype, type_any ()))984 log_printfc (log, ll_error, cursor,985 "(1) unknown symbol named `%s'",986 estr_cstr (label_id (lbl)));987 else988 {989 // second chance: look up any symbol of that name990 found = container_find_name_rec (self, lbl, type_any ());991 if (found == NULL)992 {993 log_printfc (log, ll_error, cursor,994 "(2) unknown symbol named `%s'",995 estr_cstr (label_id (lbl)));996 }997 else998 {999 estring_t * t1s = type_to_str (atype, NULL);1000 estring_t * t2s = type_to_str (symbol_type (found), NULL);1001 estring_t * fmt =1002 new_estring_fmt ("type mismatch for symbol `%s': "1003 "requested type `%s', found type `%s'",1004 estr_cstr (label_id (lbl)),1005 estr_cstr (t1s), estr_cstr (t2s));1006 log_printfc (log, ll_error, cursor, "%s", estr_cstr (fmt));1007 delete_estring (fmt);1008 delete_estring (t2s);1009 delete_estring (t1s);1010 }1011 }1012 int was_there = container_add_symbol (self, new_symbol (lbl), sek_ordinary);1013 assert (!was_there);1014 found = container_find_name (self, lbl, atype);1015 // mark a type at new symbol, either fallback type_int, or1016 // atype, if it has suitable type1017 symbol_set_type (found, is_metatype (atype) ? type_int () : atype);1018 }1019 assert (found != NULL);1020 1021 return found;1022 }1023 1024 void1025 stmt_toplev_define_internals (container_t * _self)1026 {1027 assert (_self != NULL);1028 A60_USER_TO_REP (statement, self, *);1029 assert (a60_as_container (self));1030 assert (self->base.kind == sk_toplev);1031 1032 struct interfun {1033 char const* n;1034 type_t * t;1035 } builtins [] =1036 {1037 // Algol 60 intrinsics1038 {"abs", type_proc_real_real ()},1039 {"abs", type_proc_int_int ()},1040 {"sign", type_proc_int_real ()},1041 {"sign", type_proc_int_int ()},1042 {"sqrt", type_proc_real_real ()},1043 {"sin", type_proc_real_real ()},1044 {"cos", type_proc_real_real ()},1045 {"arctan", type_proc_real_real ()},1046 {"ln", type_proc_real_real ()},1047 {"exp", type_proc_real_real ()},1048 {"entier", type_proc_int_real ()},1049 {"entier", type_proc_real_int ()},1050 // Extensions1051 {"exit", type_proc_void_int ()},1052 {"puts", type_proc_int_string ()},1053 //1054 {NULL, NULL}1055 };1056 1057 struct interfun * ptr = builtins;1058 for (; ptr->n != NULL; ptr++)1059 {1060 symbol_t * s = new_symbol (new_label (new_estring_from (ptr->n)));1061 symbol_set_type (s, ptr->t);1062 symbol_set_hidden (s, 1);1063 int fail = container_add_symbol (_self, s, sek_internal);1064 assert (fail == 0);1065 }1066 759 } 1067 760 trunk/gcc/gcc/algol60/statement.h
r151 r159 23 23 #include "type.i" 24 24 #include "estring.i" 25 #include "a60_symtab.i" 25 26 #include "visitor.i" 26 27 #include "pd.h" … … 73 74 container_t * new_stmt_toplev (cursor_t * cursor) 74 75 ATTRIBUTE_MALLOC; 75 76 /// Create a copy of subtree starting at given statement.77 /// Cursor is shared, and parent is set to NULL, but other components78 /// are recursively cloned.79 statement_t * clone_statement (statement_t const * self)80 ATTRIBUTE_MALLOC81 ATTRIBUTE_NONNULL(1);82 83 /// The same as above, just with typing for containers.84 container_t * clone_container (container_t const * self)85 ATTRIBUTE_MALLOC86 ATTRIBUTE_NONNULL(1);87 76 88 77 /// Convert void* to statement, if it is statement, or abort. … … 187 176 188 177 /// Answer the symtab associated with the container. 189 slist_t * container_symtab (container_t const * self)178 a60_symtab_t * container_symtab (container_t const * self) 190 179 ATTRIBUTE_NONNULL(1); 191 180 192 181 /// Answer the statement list associated with the container. 193 182 slist_t * container_stmts (container_t const * self) 194 ATTRIBUTE_NONNULL(1);195 196 typedef enum enum_symtab_entry_kind_t197 {198 sek_internal,199 sek_ordinary200 } symtab_entry_kind_t;201 202 /// Add given symbol to the container and return 0. It there already203 /// is other symbol with the same name, do nothing and return -1.204 /// `internal' is sek_internal for internal symbols (internal symbols205 /// may be overloaded) and sek_ordinary for ordinary symbols (which206 /// may not).207 int container_add_symbol (container_t * self, symbol_t * sym, symtab_entry_kind_t internal)208 ATTRIBUTE_NONNULL(1)209 ATTRIBUTE_NONNULL(2);210 211 /// Remove the symbol from symtab. The symbol must be present in212 /// symtab.213 symbol_t * container_erase_symbol (container_t * self, symbol_t * sym)214 ATTRIBUTE_NONNULL(1)215 ATTRIBUTE_NONNULL(2);216 217 /// Look up given symbol in the container. Answer first symbol that218 /// matches restriction `atype', or first symbol with matching name,219 /// if its type is NULL (in that case type can't be checked). Return220 /// NULL if not found.221 symbol_t * container_find_name (container_t * self, label_t const * lbl, type_t const * atype)222 ATTRIBUTE_NONNULL(1)223 ATTRIBUTE_NONNULL(2);224 225 /// Lookup given symbol in the container, and if it fails, recursively226 /// in all parental containers. Answer first symbol that matches227 /// restriction `atype', or first symbol with matching name, if its228 /// type is NULL (in that case type can't be checked). Return NULL if229 /// not found.230 symbol_t * container_find_name_rec (container_t * self, label_t const * lbl, type_t const * atype)231 ATTRIBUTE_NONNULL(1)232 ATTRIBUTE_NONNULL(2);233 234 /// See if given symbol with requested matching type, is already235 /// defined somewhere in the scope. If it's not, create new236 /// definition in most enclosing scope. Answer either found, or newly237 /// created symbol.238 symbol_t * container_find_name_rec_add_undefined (container_t * self, label_t const * lbl, type_t * atype, logger_t * log, cursor_t * cursor)239 ATTRIBUTE_NONNULL(1)240 ATTRIBUTE_NONNULL(2)241 ATTRIBUTE_NONNULL(3)242 ATTRIBUTE_NONNULL(4);243 244 /// Populate given container with algol internal functions. The245 /// container must be `stmt_toplev`.246 void stmt_toplev_define_internals (container_t * self)247 183 ATTRIBUTE_NONNULL(1); 248 184 trunk/gcc/gcc/algol60/symbol.c
r151 r159 9 9 #include "estring.h" 10 10 #include "visitor.h" 11 #include "logger.h" 11 12 #include "visitor-impl.h" 12 13 13 14 static char const * private_symbol_signature = "symbol"; 15 16 typedef struct struct_sym_var_t 17 { 18 } 19 sym_var_t; 20 21 typedef struct struct_sym_func_t 22 { 23 /// List typed with a60_as_symbol, contains explicit parameters of 24 /// the function. 25 slist_t * params; 26 27 /// List typed with a60_as_symbol, contains symbols that are 28 /// unresolved in function body, and as such form implicit 29 /// parameters of the function. 30 slist_t * implied_params; 31 32 /// Body of this function. 33 statement_t * body; 34 } 35 sym_func_t; 36 37 typedef enum enum_symbol_kind_t 38 { 39 sk_var, 40 sk_func, 41 } 42 symbol_kind_t; 14 43 15 44 struct struct_symbol_t … … 21 50 int hidden; 22 51 void * extra; 52 53 union { 54 sym_var_t sym_var; 55 sym_func_t sym_func; 56 }; 23 57 }; 24 58 25 59 static symbol_t * 26 private_alloc_symbol (label_t const * label )60 private_alloc_symbol (label_t const * label, symbol_kind_t kind) 27 61 { 28 62 symbol_t * ret = malloc (sizeof (symbol_t)); … … 30 64 ret->base.signature = private_symbol_signature; 31 65 #endif 66 ret->base.kind = kind; 32 67 ret->label = label; 33 return ret;34 }35 36 symbol_t *37 new_symbol (label_t const * label)38 {39 assert (label != NULL);40 41 symbol_t * ret = private_alloc_symbol (label);42 68 ret->stmt = NULL; 43 69 ret->type = NULL; … … 48 74 49 75 symbol_t * 76 new_symbol_var (label_t const * label) 77 { 78 assert (label != NULL); 79 80 symbol_t * ret = private_alloc_symbol (label, sk_var); 81 return ret; 82 } 83 84 symbol_t * 85 new_symbol_func (label_t const * label) 86 { 87 assert (label != NULL); 88 89 symbol_t * ret = private_alloc_symbol (label, sk_func); 90 return ret; 91 } 92 93 symbol_t * 50 94 clone_symbol (symbol_t const * self) 51 95 { … … 59 103 assert (label != NULL); 60 104 61 symbol_t * ret = private_alloc_symbol (label );105 symbol_t * ret = private_alloc_symbol (label, self->base.kind); 62 106 ret->stmt = self->stmt; 63 107 ret->type = self->type; 64 108 ret->hidden = self->hidden; 65 109 ret->extra = self->extra; 110 111 switch (self->base.kind) 112 { 113 case sk_var: 114 break; 115 116 case sk_func: 117 break; 118 } 119 66 120 return ret; 67 121 } … … 70 124 delete_symbol (symbol_t * self) 71 125 { 72 free (self); 126 if (self != NULL) 127 { 128 free (self); 129 130 switch (self->base.kind) 131 { 132 case sk_var: 133 break; 134 135 case sk_func: 136 break; 137 } 138 } 73 139 } 74 140 … … 97 163 98 164 void 165 symbol_resolve_symbols (symbol_t * self, container_t * context, logger_t * log) 166 { 167 switch (self->base.kind) 168 { 169 case sk_var: 170 type_resolve_symbols (self->type, context, log); 171 return; 172 173 case sk_func: 174 // @TODO: Do the right thing :) 175 log_printf (log, ll_info, "note: skipping resolve of function symbol."); 176 return; 177 } 178 } 179 180 void 99 181 symbol_set_type (symbol_t * self, type_t * type) 100 182 { trunk/gcc/gcc/algol60/symbol.h
r151 r159 17 17 #include "estring.i" 18 18 #include "visitor.i" <19 #include "logger.i"
