Changes in src/Parser/parser.yy [cc22003:5fcba14]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (95 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rcc22003 r5fcba14 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 8 17:50:07 201813 // Update Count : 399812 // Last Modified On : Mon Nov 27 17:23:35 2017 13 // Update Count : 2992 14 14 // 15 15 … … 115 115 } // distExt 116 116 117 void distInl( DeclarationNode * declaration ) {118 // distribute EXTENSION across all declarations119 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {120 iter->set_inLine( true );121 } // for122 } // distInl123 124 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) {125 // distribute qualifiers across all non-variable declarations in a distribution statemement126 for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {127 // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since128 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To129 // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to130 // be copied to add to front), the appropriate forall pointers are interchanged before calling addQualifiers.131 DeclarationNode * clone = qualifiers->clone();132 if ( qualifiers->type ) { // forall clause ? (handles SC)133 if ( iter->type->kind == TypeData::Aggregate ) { // struct/union ?134 swap( clone->type->forall, iter->type->aggregate.params );135 iter->addQualifiers( clone );136 } else if ( iter->type->kind == TypeData::AggregateInst && iter->type->aggInst.aggregate->aggregate.body ) { // struct/union ?137 // Create temporary node to hold aggregate, call addQualifiers as above, then put nodes back together.138 DeclarationNode newnode;139 swap( newnode.type, iter->type->aggInst.aggregate );140 swap( clone->type->forall, newnode.type->aggregate.params );141 newnode.addQualifiers( clone );142 swap( newnode.type, iter->type->aggInst.aggregate );143 } else if ( iter->type->kind == TypeData::Function ) { // routines ?144 swap( clone->type->forall, iter->type->forall );145 iter->addQualifiers( clone );146 } // if147 } else { // just SC qualifiers148 iter->addQualifiers( clone );149 } // if150 } // for151 delete qualifiers;152 } // distQual153 154 117 // There is an ambiguity for inline generic-routine return-types and generic routines. 155 118 // forall( otype T ) struct S { int i; } bar( T ) {} 156 119 // Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding. 157 120 // forall( otype T ) struct S { int T; } forall( otype W ) bar( W ) {} 158 // Currently, the forall is associated with the routine, and the generic type has to be separately defined:159 // forall( otype T ) struct S { int T; };160 // forall( otype W ) bar( W ) {}161 121 162 122 void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) { 163 if ( declSpec->type->kind == TypeData::Aggregate ) { // ignoreaggregate definition123 if ( declSpec->type->kind == TypeData::Aggregate ) { // return is aggregate definition 164 124 funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type 165 125 declSpec->type->aggregate.params = nullptr; … … 167 127 } // rebindForall 168 128 169 NameExpr * build_postfix_name( const string * name ) { 170 NameExpr * new_name = build_varref( new string( "?`" + *name ) ); 171 delete name; 172 return new_name; 173 } // build_postfix_name 174 175 DeclarationNode * fieldDecl( DeclarationNode * typeSpec, DeclarationNode * fieldList ) { 176 if ( ! fieldList ) { // field declarator ? 177 if ( ! ( typeSpec->type && typeSpec->type->kind == TypeData::Aggregate ) ) { 178 stringstream ss; 179 typeSpec->type->print( ss ); 180 SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() ); 181 return nullptr; 182 } // if 183 fieldList = DeclarationNode::newName( nullptr ); 184 } // if 185 return distAttr( typeSpec, fieldList ); // mark all fields in list 186 } // fieldDecl 187 188 ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 189 return new ForCtrl( 190 distAttr( DeclarationNode::newTypeof( type ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ), 191 new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ), 192 new ExpressionNode( build_binary_val( OperKinds::PlusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) ); 193 } // forCtrl 194 195 196 bool forall = false, yyy = false; // aggregate have one or more forall qualifiers ? 129 bool forall = false; // aggregate have one or more forall qualifiers ? 197 130 198 131 // https://www.gnu.org/software/bison/manual/bison.html#Location-Type … … 225 158 WaitForStmt * wfs; 226 159 Expression * constant; 227 IfCtrl * ifctl; 228 ForCtrl * fctl; 229 enum OperKinds compop; 160 IfCtl * ifctl; 161 ForCtl * fctl; 230 162 LabelNode * label; 231 163 InitializerNode * in; … … 234 166 bool flag; 235 167 CatchStmt::Kind catch_kind; 236 GenericExpr * genexpr;237 168 } 238 169 … … 256 187 %token TYPEOF LABEL // GCC 257 188 %token ENUM STRUCT UNION 258 %token EXCEPTION // CFA259 189 %token COROUTINE MONITOR THREAD // CFA 260 190 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA … … 271 201 %token<tok> ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname 272 202 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 273 %token<tok> DIRECTIVE274 203 // Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and 275 204 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically … … 290 219 %token ANDassign ERassign ORassign // &= ^= |= 291 220 292 %token Erange // ~=293 221 %token ATassign // @= 294 222 … … 313 241 %type<ifctl> if_control_expression 314 242 %type<fctl> for_control_expression 315 %type<compop> inclexcl316 243 %type<en> subrange 317 244 %type<decl> asm_name_opt … … 321 248 %type<flag> asm_volatile_opt 322 249 %type<en> handler_predicate_opt 323 %type<genexpr> generic_association generic_assoc_list324 250 325 251 // statements 326 252 %type<sn> statement labeled_statement compound_statement 327 253 %type<sn> statement_decl statement_decl_list statement_list_nodecl 328 %type<sn> selection_statement if_statement329 %type<sn> switch_clause_list_opt switch_clause_list 254 %type<sn> selection_statement 255 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list 330 256 %type<en> case_value 331 257 %type<sn> case_clause case_value_list case_label case_label_list 258 %type<sn> fall_through fall_through_opt 332 259 %type<sn> iteration_statement jump_statement 333 260 %type<sn> expression_statement asm_statement 334 %type<sn> with_statement 335 %type<en> with_clause_opt 261 %type<sn> with_statement with_clause_opt 336 262 %type<sn> exception_statement handler_clause finally_clause 337 263 %type<catch_kind> handler_key … … 349 275 %type<decl> aggregate_type aggregate_type_nobody 350 276 351 %type<decl> assertion assertion_list assertion_list_opt277 %type<decl> assertion assertion_list_opt 352 278 353 279 %type<en> bit_subrange_size_opt bit_subrange_size … … 365 291 %type<en> enumerator_value_opt 366 292 367 %type<decl> external_definition external_definition_list external_definition_list_opt 368 369 %type<decl> exception_declaration 370 371 %type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract 372 %type<en> field field_name_list field_name fraction_constants_opt 293 %type<decl> exception_declaration external_definition external_definition_list external_definition_list_opt 294 295 %type<decl> field_declaration field_declaration_list field_declarator field_declaring_list 296 %type<en> field field_list field_name fraction_constants 373 297 374 298 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 383 307 %type<decl> cfa_array_parameter_1st_dimension 384 308 385 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list309 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list 386 310 %type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier 387 311 … … 389 313 %type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr 390 314 391 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ ellipsis_list_opt315 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_type_list cfa_parameter_type_list_opt 392 316 393 317 %type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier 394 318 395 %type<decl> c_declaration static_assert319 %type<decl> c_declaration 396 320 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 397 %type<decl> KR_parameter_list KR_parameter_list_opt 398 399 %type<decl> parameter_declaration parameter_list parameter_type_list_opt 321 %type<decl> KR_declaration_list KR_declaration_list_opt 322 323 %type<decl> parameter_declaration parameter_list parameter_type_list 324 %type<decl> parameter_type_list_opt 400 325 401 326 %type<decl> paren_identifier paren_type … … 418 343 %type<decl> type_parameter type_parameter_list type_initializer_opt 419 344 420 %type<en> type_ parameters_opt type_list345 %type<en> type_list 421 346 422 347 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 429 354 430 355 // initializers 431 %type<in> initializer initializer_list _optinitializer_opt356 %type<in> initializer initializer_list initializer_opt 432 357 433 358 // designators … … 453 378 // Foo ( *fp )( int ); 454 379 // `---' matches start of TYPEGENname '(' 455 // must be:380 // Must be: 456 381 // Foo( int ) ( *fp )( int ); 457 // The same problem occurs here:458 // forall( otype T ) struct Foo { T v; } ( *fp )( int );459 // must be:460 // forall( otype T ) struct Foo { T v; } ( int ) ( *fp )( int );461 382 462 383 // Order of these lines matters (low-to-high precedence). 463 384 %precedence TYPEGENname 464 %precedence '}'465 385 %precedence '(' 466 386 467 %locations // support location tracking for error messages387 %locations // support location tracking for error messages 468 388 469 389 %start translation_unit // parse-tree root … … 472 392 //************************* Namespace Management ******************************** 473 393 474 // The C grammar is not context free because it relies on the distinct terminal symbols "identifier" and "TYPEDEFname",475 // which are lexically identical.476 // 477 // typedef int foo; // identifier foo must now be scanned as TYPEDEFname478 // foo f; // to allow it to appear in this context479 // 480 // While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship481 // between syntactic and semantic constructs. Cforall compounds this problem by introducing type names local to the482 // scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type483 // generators" -- parameterized types. This latter type name creates a third class of identifiers, "TYPEGENname", which484 // must be distinguished by the lexical scanner.485 // 486 // Since the scanner cannot distinguish among the different classes of identifiers without some context information,487 // there is a type table (typedefTable), which holds type names and identifiers that override type names, for each named488 // scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For489 // each context that introduces a name scope, a new level is created in the type table and that level is popped on490 // exiting the scope. Since type names can be local to a particular declaration, each declaration is itself a scope.491 // This requires distinguishing between type names that are local to the current declaration scope and those that492 // persist past the end of the declaration (i.e., names defined in "typedef" or "otype" declarations).493 // 494 // The non-terminals "push" and "pop" denote the opening and closing of named scopes. Every push has a matching pop in495 // the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push496 // around the list separator.497 // 498 // int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) );499 // push pop push pop394 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols 395 // "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical. While it is possible to write a purely 396 // context-free grammar, such a grammar would obscure the relationship between syntactic and semantic constructs. 397 // Hence, this grammar uses the ANSI style. 398 // 399 // Cforall compounds this problem by introducing type names local to the scope of a declaration (for instance, those 400 // introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types. This latter 401 // type name creates a third class of identifiers that must be distinguished by the scanner. 402 // 403 // Since the scanner cannot distinguish among the different classes of identifiers without some context information, it 404 // accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read. Semantic 405 // actions during the parser update this data structure when the class of identifiers change. 406 // 407 // Because the Cforall language is block-scoped, there is the possibility that an identifier can change its class in a 408 // local scope; it must revert to its original class at the end of the block. Since type names can be local to a 409 // particular declaration, each declaration is itself a scope. This requires distinguishing between type names that are 410 // local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in 411 // "typedef" or "otype" declarations). 412 // 413 // The non-terminals "push" and "pop" derive the empty string; their only use is to denote the opening and closing of 414 // scopes. Every push must have a matching pop, although it is regrettable the matching pairs do not always occur 415 // within the same rule. These non-terminals may appear in more contexts than strictly necessary from a semantic point 416 // of view. Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have 417 // enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra 418 // rules is to open a new scope unconditionally. As the grammar evolves, it may be neccesary to add or move around 419 // "push" and "pop" nonterminals to resolve conflicts of this sort. 500 420 501 421 push: … … 523 443 ; 524 444 445 identifier: 446 IDENTIFIER 447 | ATTR_IDENTIFIER // CFA 448 | quasi_keyword 449 ; 450 525 451 no_attr_identifier: 526 452 IDENTIFIER 527 453 | quasi_keyword 528 | '@' // CFA529 { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }530 ;531 532 identifier:533 no_attr_identifier534 | ATTR_IDENTIFIER // CFA535 454 ; 536 455 … … 561 480 | '(' compound_statement ')' // GCC, lambda expression 562 481 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); } 563 | constant '`' IDENTIFIER // CFA, postfix call564 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }565 | string_literal '`' IDENTIFIER // CFA, postfix call566 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }567 | IDENTIFIER '`' IDENTIFIER // CFA, postfix call568 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); }569 | tuple '`' IDENTIFIER // CFA, postfix call570 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }571 | '(' comma_expression ')' '`' IDENTIFIER // CFA, postfix call572 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }573 482 | type_name '.' no_attr_identifier // CFA, nested type 574 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 575 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 576 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 577 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 578 { 579 // add the missing control expression to the GenericExpr and return it 580 $5->control = maybeMoveBuild<Expression>( $3 ); 581 $$ = new ExpressionNode( $5 ); 582 } 583 ; 584 585 generic_assoc_list: // C11 586 generic_association 587 | generic_assoc_list ',' generic_association 588 { 589 // steal the association node from the singleton and delete the wrapper 590 $1->associations.splice($1->associations.end(), $3->associations); 591 delete $3; 592 $$ = $1; 593 } 594 ; 595 596 generic_association: // C11 597 type_no_function ':' assignment_expression 598 { 599 // create a GenericExpr wrapper with one association pair 600 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } ); 601 } 602 | DEFAULT ':' assignment_expression 603 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); } 483 { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; } // FIX ME 484 | type_name '.' '[' push field_list pop ']' // CFA, nested type / tuple field selector 485 { throw SemanticError("Qualified names are currently unimplemented."); $$ = nullptr; } // FIX ME 604 486 ; 605 487 606 488 postfix_expression: 607 489 primary_expression 608 | postfix_expression '[' assignment_expression']'490 | postfix_expression '[' push assignment_expression pop ']' 609 491 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a 610 492 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 611 493 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 612 494 // equivalent to the old x[i,j]. 613 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $ 3) ); }495 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $4 ) ); } 614 496 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call 615 497 { … … 622 504 | postfix_expression '.' no_attr_identifier 623 505 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } 624 | postfix_expression '.' INTEGERconstant // CFA, tuple index625 { $$ = new ExpressionNode( build_fieldSel( $1, build_ constantInteger( *$3) ) ); }506 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector 507 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); } 626 508 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 627 509 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 628 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector629 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }630 510 | postfix_expression ARROW no_attr_identifier 631 511 { 632 512 $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) ); 633 513 } 514 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector 515 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); } 634 516 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 635 517 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); } 636 | postfix_expression ARROW '[' field_name_list ']' // CFA, tuple field selector637 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); }638 518 | postfix_expression ICR 639 519 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); } 640 520 | postfix_expression DECR 641 521 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } 642 | '(' type_no_function ')' '{' initializer_list _optcomma_opt '}' // C99, compound-literal522 | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal 643 523 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 644 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal645 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }646 524 | '^' primary_expression '{' argument_expression_list '}' // CFA 647 525 { … … 661 539 // empty 662 540 { $$ = nullptr; } 663 | '?' // CFA, default parameter 664 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; } 665 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 541 // | '@' // use default argument 542 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 666 543 | assignment_expression 667 544 ; 668 545 669 field_ name_list:// CFA, tuple field selector546 field_list: // CFA, tuple field selector 670 547 field 671 | field_ name_list ',' field{ $$ = (ExpressionNode *)$1->set_last( $3 ); }548 | field_list ',' field { $$ = (ExpressionNode *)$1->set_last( $3 ); } 672 549 ; 673 550 … … 676 553 | FLOATING_DECIMALconstant field 677 554 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 678 | FLOATING_DECIMALconstant '[' field_name_list']'679 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $ 3) ) ); }555 | FLOATING_DECIMALconstant '[' push field_list pop ']' 556 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $4 ) ) ); } 680 557 | field_name '.' field 681 558 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 682 | field_name '.' '[' field_name_list']'683 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $ 4) ) ); }559 | field_name '.' '[' push field_list pop ']' 560 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $5 ) ) ); } 684 561 | field_name ARROW field 685 562 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 686 | field_name ARROW '[' field_name_list']'687 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $ 4) ) ); }563 | field_name ARROW '[' push field_list pop ']' 564 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); } 688 565 ; 689 566 690 567 field_name: 691 INTEGERconstant fraction_constants _opt568 INTEGERconstant fraction_constants 692 569 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger( *$1 ), $2 ) ); } 693 | FLOATINGconstant fraction_constants _opt570 | FLOATINGconstant fraction_constants 694 571 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); } 695 | no_attr_identifier fraction_constants _opt572 | no_attr_identifier fraction_constants 696 573 { 697 574 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) ); … … 699 576 ; 700 577 701 fraction_constants _opt:578 fraction_constants: 702 579 // empty 703 580 { $$ = nullptr; } 704 | fraction_constants _optFLOATING_FRACTIONconstant581 | fraction_constants FLOATING_FRACTIONconstant 705 582 { 706 583 Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 ); … … 714 591 // semantics checks, e.g., ++3, 3--, *3, &&3 715 592 | constant 593 { $$ = $1; } 716 594 | string_literal 717 595 { $$ = new ExpressionNode( $1 ); } … … 779 657 | '(' type_no_function ')' cast_expression 780 658 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 781 | '(' COROUTINE '&' ')' cast_expression // CFA782 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); }783 | '(' THREAD '&' ')' cast_expression // CFA784 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); }785 | '(' MONITOR '&' ')' cast_expression // CFA786 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); }787 659 // VIRTUAL cannot be opt because of look ahead issues 788 | '(' VIRTUAL ')' cast_expression // CFA660 | '(' VIRTUAL ')' cast_expression 789 661 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); } 790 | '(' VIRTUAL type_no_function ')' cast_expression // CFA662 | '(' VIRTUAL type_no_function ')' cast_expression 791 663 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); } 792 664 // | '(' type_no_function ')' tuple … … 880 752 | logical_OR_expression '?' comma_expression ':' conditional_expression 881 753 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); } 882 // FIX ME: computes $1 twice754 // FIX ME: this hack computes $1 twice 883 755 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 884 756 { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); } … … 894 766 | unary_expression assignment_operator assignment_expression 895 767 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 896 | unary_expression '=' '{' initializer_list_opt comma_opt '}'897 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; }898 768 ; 899 769 … … 925 795 // '[' ']' 926 796 // { $$ = new ExpressionNode( build_tuple() ); } 927 // |'[' push assignment_expression pop ']'797 // '[' push assignment_expression pop ']' 928 798 // { $$ = new ExpressionNode( build_tuple( $3 ) ); } 929 '[' ',' tuple_expression_list']'930 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $ 3) ) ); }931 | '[' push assignment_expression pop ',' tuple_expression_list']'932 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $ 6) ) ); }799 '[' push ',' tuple_expression_list pop ']' 800 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $4 ) ) ); } 801 | '[' push assignment_expression ',' tuple_expression_list pop ']' 802 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $5 ) ) ); } 933 803 ; 934 804 … … 956 826 labeled_statement 957 827 | compound_statement 958 | expression_statement 828 | expression_statement { $$ = $1; } 959 829 | selection_statement 960 830 | iteration_statement … … 964 834 | waitfor_statement 965 835 | exception_statement 966 | enable_disable_statement967 { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; }968 836 | asm_statement 969 | DIRECTIVE970 { $$ = new StatementNode( build_directive( $1 ) ); }971 ;972 837 973 838 labeled_statement: … … 982 847 '{' '}' 983 848 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 984 | '{' push 849 | '{' 850 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also 851 // requires its own scope. 852 push push 985 853 local_label_declaration_opt // GCC, local labels 986 854 statement_decl_list // C99, intermix declarations and statements 987 855 pop '}' 988 { $$ = new StatementNode( build_compound( $ 4) ); }856 { $$ = new StatementNode( build_compound( $5 ) ); } 989 857 ; 990 858 991 859 statement_decl_list: // C99 992 860 statement_decl 993 | statement_decl_list statement_decl994 { if ( $1 != 0 ) { $1->set_last( $ 2); $$ = $1; } }861 | statement_decl_list push statement_decl 862 { if ( $1 != 0 ) { $1->set_last( $3 ); $$ = $1; } } 995 863 ; 996 864 … … 1010 878 $$ = new StatementNode( $2 ); 1011 879 } 1012 | statement 880 | statement pop 1013 881 ; 1014 882 … … 1025 893 1026 894 selection_statement: 1027 // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving 1028 // the inherent S/R conflict with THEN/ELSE. 1029 push if_statement pop 1030 { $$ = $2; } 895 IF '(' push if_control_expression ')' statement %prec THEN 896 // explicitly deal with the shift/reduce conflict on if/else 897 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); } 898 | IF '(' push if_control_expression ')' statement ELSE statement 899 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); } 1031 900 | SWITCH '(' comma_expression ')' case_clause 1032 { $$ = new StatementNode( build_switch( true,$3, $5 ) ); }1033 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop'}' // CFA1034 { 1035 StatementNode *sw = new StatementNode( build_switch( true,$3, $8 ) );901 { $$ = new StatementNode( build_switch( $3, $5 ) ); } 902 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA 903 { 904 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) ); 1036 905 // The semantics of the declaration list is changed to include associated initialization, which is performed 1037 906 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound … … 1042 911 } 1043 912 | CHOOSE '(' comma_expression ')' case_clause // CFA 1044 { $$ = new StatementNode( build_switch( false,$3, $5 ) ); }1045 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop'}' // CFA1046 { 1047 StatementNode *sw = new StatementNode( build_switch( false,$3, $8 ) );913 { $$ = new StatementNode( build_switch( $3, $5 ) ); } 914 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt '}' // CFA 915 { 916 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) ); 1048 917 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1049 918 } 1050 919 ; 1051 920 1052 if_statement:1053 IF '(' if_control_expression ')' statement %prec THEN1054 // explicitly deal with the shift/reduce conflict on if/else1055 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }1056 | IF '(' if_control_expression ')' statement ELSE statement1057 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }1058 ;1059 1060 921 if_control_expression: 1061 comma_expression 1062 { $$ = new IfCt rl( nullptr, $1 ); }1063 | c_declaration // no semi-colon1064 { $$ = new IfCt rl( $1, nullptr ); }1065 | cfa_declaration // no semi-colon1066 { $$ = new IfCt rl( $1, nullptr ); }922 comma_expression pop 923 { $$ = new IfCtl( nullptr, $1 ); } 924 | c_declaration pop // no semi-colon 925 { $$ = new IfCtl( $1, nullptr ); } 926 | cfa_declaration pop // no semi-colon 927 { $$ = new IfCtl( $1, nullptr ); } 1067 928 | declaration comma_expression // semi-colon separated 1068 { $$ = new IfCt rl( $1, $2 ); }929 { $$ = new IfCtl( $1, $2 ); } 1069 930 ; 1070 931 … … 1091 952 ; 1092 953 1093 //label_list_opt:1094 // // empty1095 // | identifier_or_type_name ':'1096 // | label_list_opt identifier_or_type_name ':'1097 // ;1098 1099 954 case_label_list: // CFA 1100 955 case_label … … 1119 974 ; 1120 975 976 choose_clause_list_opt: // CFA 977 // empty 978 { $$ = nullptr; } 979 | choose_clause_list 980 ; 981 982 choose_clause_list: // CFA 983 case_label_list fall_through 984 { $$ = $1->append_last_case( $2 ); } 985 | case_label_list statement_list_nodecl fall_through_opt 986 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); } 987 | choose_clause_list case_label_list fall_through 988 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); } 989 | choose_clause_list case_label_list statement_list_nodecl fall_through_opt 990 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); } 991 ; 992 993 fall_through_opt: // CFA 994 // empty 995 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break 996 | fall_through 997 ; 998 999 fall_through_name: // CFA 1000 FALLTHRU 1001 | FALLTHROUGH 1002 ; 1003 1004 fall_through: // CFA 1005 fall_through_name 1006 { $$ = nullptr; } 1007 | fall_through_name ';' 1008 { $$ = nullptr; } 1009 ; 1010 1121 1011 iteration_statement: 1122 WHILE '(' push if_control_expression ')' statement pop 1123 { $$ = new StatementNode( build_while( $4, $6 ) ); } 1124 | WHILE '(' ')' statement // CFA => while ( 1 ) 1125 { $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), $4 ) ); } 1012 WHILE '(' comma_expression ')' statement 1013 { $$ = new StatementNode( build_while( $3, $5 ) ); } 1126 1014 | DO statement WHILE '(' comma_expression ')' ';' 1127 { $$ = new StatementNode( build_do_while( $5, $2 ) ); } 1128 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1129 { $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), $2 ) ); } 1130 | FOR '(' push for_control_expression ')' statement pop 1015 { $$ = new StatementNode( build_while( $5, $2, true ) ); } 1016 | FOR '(' push for_control_expression ')' statement 1131 1017 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1132 1018 ; 1133 1019 1134 1020 for_control_expression: 1135 comma_expression_opt // CFA 1136 { 1137 if ( ! $1 ) { // => for ( ;; ) 1138 $$ = new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ); 1139 } else { 1140 $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), OperKinds::LThan, $1->clone(), 1141 new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); 1142 } // if 1143 } 1144 | constant_expression inclexcl constant_expression // CFA 1145 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1146 | constant_expression inclexcl constant_expression '~' constant_expression // CFA 1147 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, $5 ); } 1148 | comma_expression_opt ';' comma_expression // CFA 1149 { 1150 if ( ! $1 ) { 1151 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr; 1152 } else if ( ! $3 ) { 1153 SemanticError( yylloc, "Missing loop range." ); $$ = nullptr; 1154 } else { 1155 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) { 1156 $$ = forCtrl( $3, new string( identifier->name ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), OperKinds::LThan, $3->clone(), 1157 new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); 1158 } else { 1159 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr; 1160 } // if 1161 } // if 1162 } 1163 | comma_expression_opt ';' constant_expression inclexcl constant_expression // CFA 1164 { 1165 if ( ! $1 ) { 1166 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr; 1167 } else { 1168 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) { 1169 $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); 1170 } else { 1171 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr; 1172 } // if 1173 } // if 1174 } 1175 | comma_expression_opt ';' constant_expression inclexcl constant_expression '~' constant_expression // CFA 1176 { 1177 if ( ! $1 ) { 1178 SemanticError( yylloc, "Missing loop index." ); $$ = nullptr; 1179 } else { 1180 if ( NameExpr *identifier = dynamic_cast<NameExpr *>($1->get_expr()) ) { 1181 $$ = forCtrl( $3, new string( identifier->name ), $3->clone(), $4, $5, $7 ); 1182 } else { 1183 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed" ); $$ = nullptr; 1184 } // if 1185 } // if 1186 } 1187 | comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1188 { $$ = new ForCtrl( $1, $3, $5 ); } 1189 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1190 { $$ = new ForCtrl( $1, $2, $4 ); } 1191 ; 1192 1193 inclexcl: 1194 '~' 1195 { $$ = OperKinds::LThan; } 1196 | Erange 1197 { $$ = OperKinds::LEThan; } 1021 comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt 1022 { $$ = new ForCtl( $1, $4, $6 ); } 1023 | declaration comma_expression_opt ';' comma_expression_opt // C99 1024 { $$ = new ForCtl( $1, $2, $4 ); } 1198 1025 ; 1199 1026 … … 1205 1032 // whereas normal operator precedence yields goto (*i)+3; 1206 1033 { $$ = new StatementNode( build_computedgoto( $3 ) ); } 1207 // A semantic check is required to ensure fallthru appears only in the body of a choose statement.1208 | fall_through_name ';' // CFA1209 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); }1210 | fall_through_name identifier_or_type_name ';' // CFA1211 { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); }1212 | fall_through_name DEFAULT ';' // CFA1213 { $$ = new StatementNode( build_branch( BranchStmt::FallThroughDefault ) ); }1214 1034 | CONTINUE ';' 1215 1035 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. … … 1228 1048 | RETURN comma_expression_opt ';' 1229 1049 { $$ = new StatementNode( build_return( $2 ) ); } 1230 | RETURN '{' initializer_list_opt comma_opt '}'1231 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; }1232 1050 | THROW assignment_expression_opt ';' // handles rethrow 1233 1051 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1238 1056 ; 1239 1057 1240 fall_through_name: // CFA1241 FALLTHRU1242 | FALLTHROUGH1243 ;1244 1245 1058 with_statement: 1246 1059 WITH '(' tuple_expression_list ')' statement … … 1253 1066 mutex_statement: 1254 1067 MUTEX '(' argument_expression_list ')' statement 1255 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; }1068 { throw SemanticError("Mutex statement is currently unimplemented."); $$ = nullptr; } // FIX ME 1256 1069 ; 1257 1070 1258 1071 when_clause: 1259 WHEN '(' comma_expression ')' { $$ = $3; } 1072 WHEN '(' comma_expression ')' 1073 { $$ = $3; } 1260 1074 ; 1261 1075 … … 1267 1081 1268 1082 waitfor: 1269 WAITFOR '(' cast_expression ')' 1270 { $$ = $3; } 1271 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1272 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1083 WAITFOR '(' identifier ')' 1084 { 1085 $$ = new ExpressionNode( new NameExpr( *$3 ) ); 1086 delete $3; 1087 } 1088 | WAITFOR '(' identifier ',' argument_expression_list ')' 1089 { 1090 $$ = new ExpressionNode( new NameExpr( *$3 ) ); 1091 $$->set_last( $5 ); 1092 delete $3; 1093 } 1273 1094 ; 1274 1095 1275 1096 timeout: 1276 TIMEOUT '(' comma_expression ')' { $$ = $3; } 1097 TIMEOUT '(' comma_expression ')' 1098 { $$ = $3; } 1277 1099 ; 1278 1100 … … 1287 1109 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); } 1288 1110 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1289 | when_clause_opt timeout statement WOR ELSE statement1290 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }1291 1111 | when_clause_opt timeout statement WOR when_clause ELSE statement 1292 1112 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); } … … 1310 1130 1311 1131 handler_clause: 1312 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop1313 { $$ = new StatementNode( build_catch( $1, $ 4, $6, $8) ); }1314 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop1315 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $ 5, $7, $9) ) ); }1132 handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1133 { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); } 1134 | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1135 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); } 1316 1136 ; 1317 1137 1318 1138 handler_predicate_opt: 1319 // empty1139 //empty 1320 1140 { $$ = nullptr; } 1321 | ';' conditional_expression { $$ = $2; } 1141 | ';' conditional_expression 1142 { $$ = $2; } 1322 1143 ; 1323 1144 1324 1145 handler_key: 1325 CATCH { $$ = CatchStmt::Terminate; } 1326 | CATCHRESUME { $$ = CatchStmt::Resume; } 1146 CATCH 1147 { $$ = CatchStmt::Terminate; } 1148 | CATCHRESUME 1149 { $$ = CatchStmt::Resume; } 1327 1150 ; 1328 1151 1329 1152 finally_clause: 1330 FINALLY compound_statement { $$ = new StatementNode( build_finally( $2 ) ); } 1153 FINALLY compound_statement 1154 { 1155 $$ = new StatementNode( build_finally( $2 ) ); 1156 } 1331 1157 ; 1332 1158 … … 1335 1161 type_specifier_nobody 1336 1162 | type_specifier_nobody declarator 1337 { $$ = $2->addType( $1 ); } 1163 { 1164 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1165 $$ = $2->addType( $1 ); 1166 } 1338 1167 | type_specifier_nobody variable_abstract_declarator 1339 1168 { $$ = $2->addType( $1 ); } 1340 1169 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 1341 { $$ = $1->addName( $2 ); } 1170 { 1171 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1172 $$ = $1->addName( $2 ); 1173 } 1342 1174 | cfa_abstract_declarator_tuple // CFA 1343 ;1344 1345 enable_disable_statement:1346 enable_disable_key identifier_list compound_statement1347 ;1348 1349 enable_disable_key:1350 ENABLE1351 | DISABLE1352 1175 ; 1353 1176 1354 1177 asm_statement: 1355 1178 ASM asm_volatile_opt '(' string_literal ')' ';' 1356 { $$ = new StatementNode( build_asm ( $2, $4, 0 ) ); }1179 { $$ = new StatementNode( build_asmstmt( $2, $4, 0 ) ); } 1357 1180 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC 1358 { $$ = new StatementNode( build_asm ( $2, $4, $6 ) ); }1181 { $$ = new StatementNode( build_asmstmt( $2, $4, $6 ) ); } 1359 1182 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';' 1360 { $$ = new StatementNode( build_asm ( $2, $4, $6, $8 ) ); }1183 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8 ) ); } 1361 1184 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 1362 { $$ = new StatementNode( build_asm ( $2, $4, $6, $8, $10 ) ); }1185 { $$ = new StatementNode( build_asmstmt( $2, $4, $6, $8, $10 ) ); } 1363 1186 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 1364 { $$ = new StatementNode( build_asm ( $2, $5, 0, $8, $10, $12 ) ); }1187 { $$ = new StatementNode( build_asmstmt( $2, $5, 0, $8, $10, $12 ) ); } 1365 1188 ; 1366 1189 … … 1417 1240 1418 1241 declaration_list_opt: // used at beginning of switch statement 1242 pop 1243 { $$ = nullptr; } 1244 | declaration_list 1245 ; 1246 1247 declaration_list: 1248 declaration 1249 | declaration_list push declaration 1250 { $$ = $1->appendList( $3 ); } 1251 ; 1252 1253 KR_declaration_list_opt: // used to declare parameter types in K&R style functions 1419 1254 // empty 1420 1255 { $$ = nullptr; } 1421 | declaration_list 1422 ; 1423 1424 declaration_list: 1425 declaration 1426 | declaration_list declaration 1427 { $$ = $1->appendList( $2 ); } 1428 ; 1429 1430 KR_parameter_list_opt: // used to declare parameter types in K&R style functions 1431 // empty 1432 { $$ = nullptr; } 1433 | KR_parameter_list 1434 ; 1435 1436 KR_parameter_list: 1256 | KR_declaration_list 1257 ; 1258 1259 KR_declaration_list: 1437 1260 push c_declaration pop ';' 1438 1261 { $$ = $2; } 1439 | KR_ parameter_list push c_declaration pop ';'1262 | KR_declaration_list push c_declaration pop ';' 1440 1263 { $$ = $1->appendList( $3 ); } 1441 1264 ; … … 1452 1275 1453 1276 local_label_list: // GCC, local label 1454 no_attr_identifier_or_type_name 1455 | local_label_list ',' no_attr_identifier_or_type_name 1277 no_attr_identifier_or_type_name {} 1278 | local_label_list ',' no_attr_identifier_or_type_name {} 1456 1279 ; 1457 1280 1458 1281 declaration: // old & new style declarations 1459 c_declaration ';' 1460 | cfa_declaration ';' // CFA 1461 | static_assert // C11 1462 ; 1463 1464 static_assert: 1465 STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11 1466 { $$ = DeclarationNode::newStaticAssert( $3, $5 ); } 1467 | STATICASSERT '(' constant_expression ')' ';' // CFA 1468 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( *new string( "\"\"" ) ) ); } 1282 c_declaration pop ';' 1283 | cfa_declaration pop ';' // CFA 1284 | STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11 1285 { throw SemanticError("Static assert is currently unimplemented."); $$ = nullptr; } // FIX ME 1286 ; 1469 1287 1470 1288 // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function … … 1489 1307 cfa_variable_declaration: // CFA 1490 1308 cfa_variable_specifier initializer_opt 1491 { $$ = $1->addInitializer( $2 ); } 1309 { 1310 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1311 $$ = $1->addInitializer( $2 ); 1312 } 1492 1313 | declaration_qualifier_list cfa_variable_specifier initializer_opt 1493 1314 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude 1494 1315 // them as a type_qualifier cannot appear in that context. 1495 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); } 1316 { 1317 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1318 $$ = $2->addQualifiers( $1 )->addInitializer( $3 );; 1319 } 1496 1320 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1497 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); } 1321 { 1322 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); 1323 $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); 1324 } 1498 1325 ; 1499 1326 … … 1502 1329 // storage-class 1503 1330 cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt 1504 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1331 { 1332 typedefTable.setNextIdentifier( *$2 ); 1333 $$ = $1->addName( $2 )->addAsmName( $3 ); 1334 } 1505 1335 | cfa_abstract_tuple identifier_or_type_name asm_name_opt 1506 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1336 { 1337 typedefTable.setNextIdentifier( *$2 ); 1338 $$ = $1->addName( $2 )->addAsmName( $3 ); 1339 } 1507 1340 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt 1508 { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); } 1341 { 1342 typedefTable.setNextIdentifier( *$3 ); 1343 $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); 1344 } 1509 1345 ; 1510 1346 1511 1347 cfa_function_declaration: // CFA 1512 1348 cfa_function_specifier 1349 { 1350 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1351 $$ = $1; 1352 } 1513 1353 | type_qualifier_list cfa_function_specifier 1514 { $$ = $2->addQualifiers( $1 ); } 1354 { 1355 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1356 $$ = $2->addQualifiers( $1 ); 1357 } 1515 1358 | declaration_qualifier_list cfa_function_specifier 1516 { $$ = $2->addQualifiers( $1 ); } 1359 { 1360 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1361 $$ = $2->addQualifiers( $1 ); 1362 } 1517 1363 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 1518 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); } 1519 | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1364 { 1365 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1366 $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); 1367 } 1368 | cfa_function_declaration pop ',' push identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1520 1369 { 1521 1370 // Append the return type at the start (left-hand-side) to each identifier in the list. 1522 1371 DeclarationNode * ret = new DeclarationNode; 1523 1372 ret->type = maybeClone( $1->type->base ); 1524 $$ = $1->appendList( DeclarationNode::newFunction( $ 3, ret, $6, nullptr) );1373 $$ = $1->appendList( DeclarationNode::newFunction( $5, ret, $8, nullptr, true ) ); 1525 1374 } 1526 1375 ; 1527 1376 1528 1377 cfa_function_specifier: // CFA 1529 // '[' ']' identifier_or_type_name '(' push cfa_parameter_ ellipsis_list_opt pop ')' // S/R conflict1378 // '[' ']' identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' // S/R conflict 1530 1379 // { 1531 1380 // $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true ); 1532 1381 // } 1533 // '[' ']' identifier '(' push cfa_parameter_ ellipsis_list_opt pop ')'1382 // '[' ']' identifier '(' push cfa_parameter_type_list_opt pop ')' 1534 1383 // { 1535 1384 // typedefTable.setNextIdentifier( *$5 ); 1536 1385 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1537 1386 // } 1538 // | '[' ']' TYPEDEFname '(' push cfa_parameter_ ellipsis_list_opt pop ')'1387 // | '[' ']' TYPEDEFname '(' push cfa_parameter_type_list_opt pop ')' 1539 1388 // { 1540 1389 // typedefTable.setNextIdentifier( *$5 ); … … 1544 1393 // identifier_or_type_name must be broken apart because of the sequence: 1545 1394 // 1546 // '[' ']' identifier_or_type_name '(' cfa_parameter_ ellipsis_list_opt ')'1395 // '[' ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')' 1547 1396 // '[' ']' type_specifier 1548 1397 // 1549 1398 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1550 1399 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1551 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ ellipsis_list_opt pop ')'1400 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1552 1401 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1553 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1554 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1555 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1402 { 1403 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); 1404 } 1405 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_type_list_opt pop ')' 1406 { 1407 $$ = DeclarationNode::newFunction( $2, $1, $5, 0, true ); 1408 } 1556 1409 ; 1557 1410 … … 1560 1413 { $$ = DeclarationNode::newTuple( $3 ); } 1561 1414 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 1562 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 1415 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the 1416 // ']'. 1563 1417 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1564 1418 ; … … 1567 1421 TYPEDEF cfa_variable_specifier 1568 1422 { 1569 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "1");1423 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1570 1424 $$ = $2->addTypedef(); 1571 1425 } 1572 1426 | TYPEDEF cfa_function_specifier 1573 1427 { 1574 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "2");1428 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1575 1429 $$ = $2->addTypedef(); 1576 1430 } 1577 1431 | cfa_typedef_declaration pop ',' push no_attr_identifier 1578 1432 { 1579 typedefTable.addToEnclosingScope( *$5, T YPEDEFname, "3");1433 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); 1580 1434 $$ = $1->appendList( $1->cloneType( $5 ) ); 1581 1435 } … … 1588 1442 TYPEDEF type_specifier declarator 1589 1443 { 1590 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4");1444 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1591 1445 $$ = $3->addType( $2 )->addTypedef(); 1592 1446 } 1593 1447 | typedef_declaration pop ',' push declarator 1594 1448 { 1595 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "5");1449 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1596 1450 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1597 1451 } 1598 1452 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1599 1453 { 1600 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6");1454 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1601 1455 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1602 1456 } 1603 1457 | type_specifier TYPEDEF declarator 1604 1458 { 1605 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7");1459 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1606 1460 $$ = $3->addType( $1 )->addTypedef(); 1607 1461 } 1608 1462 | type_specifier TYPEDEF type_qualifier_list declarator 1609 1463 { 1610 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8");1464 typedefTable.addToEnclosingScope( TypedefTable::TD ); 1611 1465 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1612 1466 } … … 1617 1471 TYPEDEF no_attr_identifier '=' assignment_expression 1618 1472 { 1619 // $$ = DeclarationNode::newName( 0 ); // unimplemented1620 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;1473 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); 1474 $$ = DeclarationNode::newName( 0 ); // unimplemented 1621 1475 } 1622 1476 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1623 1477 { 1624 // $$ = DeclarationNode::newName( 0 ); // unimplemented1625 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr;1478 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD ); 1479 $$ = DeclarationNode::newName( 0 ); // unimplemented 1626 1480 } 1627 1481 ; … … 1639 1493 // declarator asm_name_opt initializer_opt 1640 1494 // { 1641 // typedefTable.addToEnclosingScope( IDENTIFIER);1495 // typedefTable.addToEnclosingScope( TypedefTable::ID ); 1642 1496 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1643 1497 // } 1644 1498 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1645 1499 // { 1646 // typedefTable.addToEnclosingScope( IDENTIFIER);1500 // typedefTable.addToEnclosingScope( TypedefTable::ID ); 1647 1501 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1648 1502 // } … … 1651 1505 c_declaration: 1652 1506 declaration_specifier declaring_list 1653 { $$ = distAttr( $1, $2 ); } 1507 { 1508 $$ = distAttr( $1, $2 ); 1509 } 1654 1510 | typedef_declaration 1655 1511 | typedef_expression // GCC, naming expression type … … 1661 1517 // storage-class 1662 1518 declarator asm_name_opt initializer_opt 1663 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); } 1519 { 1520 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1521 $$ = $1->addAsmName( $2 )->addInitializer( $3 ); 1522 } 1664 1523 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1665 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 1524 { 1525 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1526 $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); 1527 } 1666 1528 ; 1667 1529 … … 1735 1597 1736 1598 forall: 1737 FORALL '(' type_parameter_list ')' // CFA 1738 { $$ = DeclarationNode::newForall( $3 ); } 1599 FORALL '(' 1600 { 1601 typedefTable.enterScope(); 1602 } 1603 type_parameter_list ')' // CFA 1604 { 1605 typedefTable.leaveScope(); 1606 $$ = DeclarationNode::newForall( $4 ); 1607 } 1739 1608 ; 1740 1609 … … 1809 1678 | LONG 1810 1679 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); } 1680 | ZERO_T 1681 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); } 1682 | ONE_T 1683 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); } 1811 1684 | VALIST // GCC, __builtin_va_list 1812 1685 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); } … … 1828 1701 basic_type_specifier: 1829 1702 direct_type 1830 // Cannot have type modifiers, e.g., short, long, etc.1831 1703 | type_qualifier_list_opt indirect_type type_qualifier_list_opt 1832 1704 { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); } … … 1834 1706 1835 1707 direct_type: 1708 // A semantic check is necessary for conflicting type qualifiers. 1836 1709 basic_type_name 1837 1710 | type_qualifier_list basic_type_name … … 1852 1725 | ATTR_TYPEGENname '(' comma_expression ')' // CFA: e.g., @type(a+b) y; 1853 1726 { $$ = DeclarationNode::newAttr( $1, $3 ); } 1854 | ZERO_T // CFA1855 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }1856 | ONE_T // CFA1857 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }1858 1727 ; 1859 1728 … … 1875 1744 { $$ = $3->addQualifiers( $1 ); } 1876 1745 | sue_type_specifier type_qualifier 1877 { 1878 if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type 1879 $$ = $1->addQualifiers( $2 ); 1880 } 1746 { $$ = $1->addQualifiers( $2 ); } 1881 1747 ; 1882 1748 … … 1921 1787 { $$ = DeclarationNode::newFromTypedef( $1 ); } 1922 1788 | '.' TYPEDEFname 1923 { $$ = DeclarationNode::new QualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); }1789 { $$ = DeclarationNode::newFromTypedef( $2 ); } // FIX ME 1924 1790 | type_name '.' TYPEDEFname 1925 { $$ = DeclarationNode::new QualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); }1791 { $$ = DeclarationNode::newFromTypedef( $3 ); } // FIX ME 1926 1792 | typegen_name 1927 1793 | '.' typegen_name 1928 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); }1794 { $$ = $2; } // FIX ME 1929 1795 | type_name '.' typegen_name 1930 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); }1796 { $$ = $3; } // FIX ME 1931 1797 ; 1932 1798 … … 1950 1816 ; 1951 1817 1952 fred:1953 // empty1954 { yyy = false; }1955 ;1956 1957 1818 aggregate_type: // struct, union 1958 aggregate_key attribute_list_opt 1959 { forall = false; } // reset 1960 '{' field_declaration_list_opt '}' type_parameters_opt 1961 { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ); } 1962 | aggregate_key attribute_list_opt no_attr_identifier fred 1963 { 1964 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 1819 aggregate_key attribute_list_opt '{' field_declaration_list '}' 1820 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); } 1821 | aggregate_key attribute_list_opt no_attr_identifier_or_type_name 1822 { 1823 typedefTable.makeTypedef( *$3 ); // create typedef 1824 if ( forall ) typedefTable.changeKind( *$3, TypedefTable::TG ); // possibly update 1965 1825 forall = false; // reset 1966 1826 } 1967 '{' field_declaration_list_opt '}' type_parameters_opt 1968 { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); } 1969 | aggregate_key attribute_list_opt type_name fred 1970 { 1971 // for type_name can be a qualified type name S.T, in which case only the last name in the chain needs a typedef (other names in the chain should already have one) 1972 typedefTable.makeTypedef( *$3->type->leafName(), forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); // create typedef 1973 forall = false; // reset 1974 } 1975 '{' field_declaration_list_opt '}' type_parameters_opt 1976 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); } 1827 '{' field_declaration_list '}' 1828 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $6, true )->addQualifiers( $2 ); } 1829 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list '}' // CFA 1830 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } 1977 1831 | aggregate_type_nobody 1978 1832 ; 1979 1833 1980 type_parameters_opt:1981 // empty1982 { $$ = nullptr; } %prec '}'1983 | '(' type_list ')'1984 { $$ = $2; }1985 ;1986 1987 1834 aggregate_type_nobody: // struct, union - {...} 1988 aggregate_key attribute_list_opt no_attr_identifier fred 1989 { 1990 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); 1991 forall = false; // reset 1835 aggregate_key attribute_list_opt no_attr_identifier 1836 { 1837 typedefTable.makeTypedef( *$3 ); 1992 1838 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1993 1839 } 1994 | aggregate_key attribute_list_opt type_name fred 1995 { 1996 forall = false; // reset 1840 | aggregate_key attribute_list_opt TYPEDEFname 1841 { 1842 typedefTable.makeTypedef( *$3 ); 1843 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1844 } 1845 | aggregate_key attribute_list_opt typegen_name // CFA 1846 { 1997 1847 // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is 1998 1848 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and … … 2007 1857 aggregate_key: 2008 1858 STRUCT 2009 { yyy = true;$$ = DeclarationNode::Struct; }1859 { $$ = DeclarationNode::Struct; } 2010 1860 | UNION 2011 { yyy = true; $$ = DeclarationNode::Union; } 2012 | EXCEPTION 2013 { yyy = true; $$ = DeclarationNode::Exception; } 1861 { $$ = DeclarationNode::Union; } 2014 1862 | COROUTINE 2015 { yyy = true;$$ = DeclarationNode::Coroutine; }1863 { $$ = DeclarationNode::Coroutine; } 2016 1864 | MONITOR 2017 { yyy = true;$$ = DeclarationNode::Monitor; }1865 { $$ = DeclarationNode::Monitor; } 2018 1866 | THREAD 2019 { yyy = true;$$ = DeclarationNode::Thread; }2020 ; 2021 2022 field_declaration_list _opt:1867 { $$ = DeclarationNode::Thread; } 1868 ; 1869 1870 field_declaration_list: 2023 1871 // empty 2024 1872 { $$ = nullptr; } 2025 | field_declaration_list _optfield_declaration1873 | field_declaration_list field_declaration 2026 1874 { $$ = $1 ? $1->appendList( $2 ) : $2; } 2027 1875 ; 2028 1876 2029 1877 field_declaration: 2030 type_specifier field_declaring_list_opt ';' 2031 { $$ = fieldDecl( $1, $2 ); } 2032 | EXTENSION type_specifier field_declaring_list_opt ';' // GCC 2033 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } 2034 | INLINE type_specifier field_abstract_list_opt ';' // CFA 2035 { 2036 if ( ! $3 ) { // field declarator ? 2037 $3 = DeclarationNode::newName( nullptr ); 2038 } // if 2039 $3->inLine = true; 2040 $$ = distAttr( $2, $3 ); // mark all fields in list 2041 distInl( $3 ); 2042 } 2043 | typedef_declaration ';' // CFA 2044 | cfa_field_declaring_list ';' // CFA, new style field declaration 1878 cfa_field_declaring_list ';' // CFA, new style field declaration 2045 1879 | EXTENSION cfa_field_declaring_list ';' // GCC 2046 { distExt( $2 ); $$ = $2; } // mark all fields in list 2047 | INLINE cfa_field_abstract_list ';' // CFA, new style field declaration 2048 { $$ = $2; } // mark all fields in list 2049 | cfa_typedef_declaration ';' // CFA 2050 | static_assert // C11 2051 ; 2052 2053 field_declaring_list_opt: 2054 // empty 2055 { $$ = nullptr; } 2056 | field_declarator 2057 | field_declaring_list_opt ',' attribute_list_opt field_declarator 2058 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 2059 ; 2060 2061 field_declarator: 2062 bit_subrange_size // C special case, no field name 2063 { $$ = DeclarationNode::newBitfield( $1 ); } 2064 | variable_declarator bit_subrange_size_opt 2065 // A semantic check is required to ensure bit_subrange only appears on integral types. 2066 { $$ = $1->addBitfield( $2 ); } 2067 | variable_type_redeclarator bit_subrange_size_opt 2068 // A semantic check is required to ensure bit_subrange only appears on integral types. 2069 { $$ = $1->addBitfield( $2 ); } 2070 ; 2071 2072 field_abstract_list_opt: 2073 // empty 2074 { $$ = nullptr; } 2075 | field_abstract 2076 | field_abstract_list_opt ',' attribute_list_opt field_abstract 2077 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 2078 ; 2079 2080 field_abstract: 2081 // no bit fields 2082 variable_abstract_declarator 1880 { 1881 distExt( $2 ); // mark all fields in list 1882 $$ = $2; 1883 } 1884 | type_specifier field_declaring_list ';' 1885 { 1886 $$ = distAttr( $1, $2 ); } 1887 | EXTENSION type_specifier field_declaring_list ';' // GCC 1888 { 1889 distExt( $3 ); // mark all fields in list 1890 $$ = distAttr( $2, $3 ); 1891 } 2083 1892 ; 2084 1893 2085 1894 cfa_field_declaring_list: // CFA, new style field declaration 2086 // bit-fields are handled by C declarations2087 cfa_abstract_declarator_tuple no_attr_identifier_or_type_name1895 cfa_abstract_declarator_tuple // CFA, no field name 1896 | cfa_abstract_declarator_tuple no_attr_identifier_or_type_name 2088 1897 { $$ = $1->addName( $2 ); } 2089 1898 | cfa_field_declaring_list ',' no_attr_identifier_or_type_name 2090 1899 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 2091 ; 2092 2093 cfa_field_abstract_list: // CFA, new style field declaration 2094 // bit-fields are handled by C declarations 2095 cfa_abstract_declarator_tuple 2096 | cfa_field_abstract_list ',' 1900 | cfa_field_declaring_list ',' // CFA, no field name 2097 1901 { $$ = $1->appendList( $1->cloneType( 0 ) ); } 1902 ; 1903 1904 field_declaring_list: 1905 field_declarator 1906 | field_declaring_list ',' attribute_list_opt field_declarator 1907 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 1908 ; 1909 1910 field_declarator: 1911 // empty 1912 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name 1913 // '@' 1914 // { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name 1915 | bit_subrange_size // no field name 1916 { $$ = DeclarationNode::newBitfield( $1 ); } 1917 | variable_declarator bit_subrange_size_opt 1918 // A semantic check is required to ensure bit_subrange only appears on base type int. 1919 { $$ = $1->addBitfield( $2 ); } 1920 | variable_type_redeclarator bit_subrange_size_opt 1921 // A semantic check is required to ensure bit_subrange only appears on base type int. 1922 { $$ = $1->addBitfield( $2 ); } 1923 | variable_abstract_declarator // CFA, no field name 2098 1924 ; 2099 1925 … … 2102 1928 { $$ = nullptr; } 2103 1929 | bit_subrange_size 1930 { $$ = $1; } 2104 1931 ; 2105 1932 … … 2111 1938 enum_type: // enum 2112 1939 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2113 { $$ = DeclarationNode::newEnum( n ullptr, $4, true )->addQualifiers( $2 ); }2114 | ENUM attribute_list_opt no_attr_identifier 1940 { $$ = DeclarationNode::newEnum( new string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); } 1941 | ENUM attribute_list_opt no_attr_identifier_or_type_name 2115 1942 { typedefTable.makeTypedef( *$3 ); } 2116 1943 '{' enumerator_list comma_opt '}' 2117 1944 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2118 | ENUM attribute_list_opt type_name2119 '{' enumerator_list comma_opt '}'2120 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); }2121 1945 | enum_type_nobody 2122 1946 ; 2123 1947 2124 1948 enum_type_nobody: // enum - {...} 2125 ENUM attribute_list_opt no_attr_identifier 1949 ENUM attribute_list_opt no_attr_identifier_or_type_name 2126 1950 { 2127 1951 typedefTable.makeTypedef( *$3 ); 2128 1952 $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); 2129 }2130 | ENUM attribute_list_opt type_name2131 {2132 typedefTable.makeTypedef( *$3->type->symbolic.name );2133 $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 );2134 1953 } 2135 1954 ; … … 2149 1968 ; 2150 1969 2151 cfa_parameter_ellipsis_list_opt: // CFA, abstract + real 1970 // Minimum of one parameter after which ellipsis is allowed only at the end. 1971 1972 cfa_parameter_type_list_opt: // CFA 2152 1973 // empty 2153 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }2154 | ELLIPSIS2155 1974 { $$ = nullptr; } 2156 | cfa_abstract_parameter_list 1975 | cfa_parameter_type_list 1976 ; 1977 1978 cfa_parameter_type_list: // CFA, abstract + real 1979 cfa_abstract_parameter_list 2157 1980 | cfa_parameter_list 2158 1981 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list … … 2185 2008 // empty 2186 2009 { $$ = nullptr; } 2187 | ELLIPSIS 2188 { $$ = nullptr; } 2189 | parameter_list 2010 | parameter_type_list 2011 ; 2012 2013 parameter_type_list: 2014 parameter_list 2190 2015 | parameter_list pop ',' push ELLIPSIS 2191 2016 { $$ = $1->addVarArgs(); } … … 2229 2054 // No SUE declaration in parameter list. 2230 2055 declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt 2231 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2056 { 2057 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2058 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2059 } 2232 2060 | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt 2233 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2061 { 2062 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2063 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2064 } 2234 2065 ; 2235 2066 … … 2282 2113 { $$ = $2; } 2283 2114 | '=' VOID 2284 { $$ = n ew InitializerNode( true ); }2115 { $$ = nullptr; } 2285 2116 | ATassign initializer 2286 2117 { $$ = $2->set_maybeConstructed( false ); } … … 2289 2120 initializer: 2290 2121 assignment_expression { $$ = new InitializerNode( $1 ); } 2291 | '{' initializer_list _opt comma_opt '}'{ $$ = new InitializerNode( $2, true ); }2292 ; 2293 2294 initializer_list _opt:2122 | '{' initializer_list comma_opt '}' { $$ = new InitializerNode( $2, true ); } 2123 ; 2124 2125 initializer_list: 2295 2126 // empty 2296 2127 { $$ = nullptr; } 2297 2128 | initializer 2298 2129 | designation initializer { $$ = $2->set_designators( $1 ); } 2299 | initializer_list _opt ',' initializer{ $$ = (InitializerNode *)( $1->set_last( $3 ) ); }2300 | initializer_list _opt',' designation initializer2130 | initializer_list ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2131 | initializer_list ',' designation initializer 2301 2132 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 2302 2133 ; … … 2335 2166 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2336 2167 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); } 2337 | '.' '[' push field_ name_list pop ']'// CFA, tuple field selector2168 | '.' '[' push field_list pop ']' // CFA, tuple field selector 2338 2169 { $$ = $4; } 2339 2170 ; … … 2359 2190 type_parameter_list: // CFA 2360 2191 type_parameter 2192 { $$ = $1; } 2361 2193 | type_parameter_list ',' type_parameter 2362 2194 { $$ = $1->appendList( $3 ); } … … 2372 2204 type_parameter: // CFA 2373 2205 type_class no_attr_identifier_or_type_name 2374 { typedefTable.addTo Scope( *$2, TYPEDEFname, "9"); }2206 { typedefTable.addToEnclosingScope( *$2, TypedefTable::TD ); } 2375 2207 type_initializer_opt assertion_list_opt 2376 2208 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2377 2209 | type_specifier identifier_parameter_declarator 2378 | assertion_list2379 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }2380 2210 ; 2381 2211 … … 2394 2224 // empty 2395 2225 { $$ = nullptr; } 2396 | assertion_list 2397 ; 2398 2399 assertion_list: // CFA 2400 assertion 2401 | assertion_list assertion 2226 | assertion_list_opt assertion 2402 2227 { $$ = $1 ? $1->appendList( $2 ) : $2; } 2403 2228 ; … … 2405 2230 assertion: // CFA 2406 2231 '|' no_attr_identifier_or_type_name '(' type_list ')' 2407 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2408 | '|' '{' push trait_declaration_list pop '}' 2232 { 2233 typedefTable.openTrait( *$2 ); 2234 $$ = DeclarationNode::newTraitUse( $2, $4 ); 2235 } 2236 | '|' '{' push trait_declaration_list '}' 2409 2237 { $$ = $4; } 2410 // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop'}' '(' type_list ')'2411 // { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." );$$ = nullptr; }2238 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list '}' '(' type_list ')' 2239 { $$ = nullptr; } 2412 2240 ; 2413 2241 … … 2416 2244 { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); } 2417 2245 | assignment_expression 2418 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; }2419 2246 | type_list ',' type 2420 2247 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); } 2421 2248 | type_list ',' assignment_expression 2422 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } 2423 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2249 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2424 2250 ; 2425 2251 … … 2443 2269 no_attr_identifier_or_type_name 2444 2270 { 2445 typedefTable.addToEnclosingScope( *$1, T YPEDEFname, "10");2271 typedefTable.addToEnclosingScope( *$1, TypedefTable::TD ); 2446 2272 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2447 2273 } 2448 | no_attr_identifier_or_type_name '(' type_parameter_list')'2449 { 2450 typedefTable.addToEnclosingScope( *$1, T YPEGENname, "11");2451 $$ = DeclarationNode::newTypeDecl( $1, $ 3);2274 | no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' 2275 { 2276 typedefTable.addToEnclosingScope( *$1, TypedefTable::TG ); 2277 $$ = DeclarationNode::newTypeDecl( $1, $4 ); 2452 2278 } 2453 2279 ; 2454 2280 2455 2281 trait_specifier: // CFA 2456 TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2457 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); } 2458 | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2459 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); } 2282 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}' 2283 { 2284 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 2285 $$ = DeclarationNode::newTrait( $2, $5, 0 ); 2286 } 2287 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' 2288 { 2289 typedefTable.enterTrait( *$2 ); 2290 typedefTable.enterScope(); 2291 } 2292 trait_declaration_list '}' 2293 { 2294 typedefTable.leaveTrait(); 2295 typedefTable.addToEnclosingScope( *$2, TypedefTable::ID ); 2296 $$ = DeclarationNode::newTrait( $2, $5, $10 ); 2297 } 2460 2298 ; 2461 2299 2462 2300 trait_declaration_list: // CFA 2463 2301 trait_declaration 2464 | trait_declaration_list p op push trait_declaration2465 { $$ = $1->appendList( $ 4); }2302 | trait_declaration_list push trait_declaration 2303 { $$ = $1->appendList( $3 ); } 2466 2304 ; 2467 2305 2468 2306 trait_declaration: // CFA 2469 cfa_trait_declaring_list ';'2470 | trait_declaring_list ';'2307 cfa_trait_declaring_list pop ';' 2308 | trait_declaring_list pop ';' 2471 2309 ; 2472 2310 2473 2311 cfa_trait_declaring_list: // CFA 2474 2312 cfa_variable_specifier 2313 { 2314 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2315 $$ = $1; 2316 } 2475 2317 | cfa_function_specifier 2318 { 2319 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2320 $$ = $1; 2321 } 2476 2322 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 2477 { $$ = $1->appendList( $1->cloneType( $5 ) ); } 2323 { 2324 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); 2325 $$ = $1->appendList( $1->cloneType( $5 ) ); 2326 } 2478 2327 ; 2479 2328 2480 2329 trait_declaring_list: // CFA 2481 2330 type_specifier declarator 2482 { $$ = $2->addType( $1 ); } 2331 { 2332 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2333 $$ = $2->addType( $1 ); 2334 } 2483 2335 | trait_declaring_list pop ',' push declarator 2484 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); } 2336 { 2337 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2338 $$ = $1->appendList( $1->cloneBaseType( $5 ) ); 2339 } 2485 2340 ; 2486 2341 … … 2488 2343 2489 2344 translation_unit: 2490 // empty, input file 2345 // empty 2346 {} // empty input file 2491 2347 | external_definition_list 2492 2348 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1; } … … 2494 2350 2495 2351 external_definition_list: 2496 push external_definition pop 2497 { $$ = $2; } 2498 | external_definition_list push external_definition pop 2352 external_definition 2353 | external_definition_list push external_definition 2499 2354 { $$ = $1 ? $1->appendList( $3 ) : $3; } 2500 2355 ; … … 2506 2361 ; 2507 2362 2508 up:2509 { typedefTable.up( forall ); forall = false; }2510 ;2511 2512 down:2513 { typedefTable.down(); }2514 ;2515 2516 2363 external_definition: 2517 2364 declaration 2518 2365 | external_function_definition 2366 | ASM '(' string_literal ')' ';' // GCC, global assembler statement 2367 { 2368 $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asmstmt( false, $3, 0 ) ) ); 2369 } 2370 | EXTERN STRINGliteral // C++-style linkage specifier 2371 { 2372 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2373 linkage = LinkageSpec::linkageUpdate( linkage, $2 ); 2374 } 2375 '{' external_definition_list_opt '}' 2376 { 2377 linkage = linkageStack.top(); 2378 linkageStack.pop(); 2379 $$ = $5; 2380 } 2519 2381 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown 2520 2382 { … … 2522 2384 $$ = $2; 2523 2385 } 2524 | ASM '(' string_literal ')' ';' // GCC, global assembler statement 2525 { 2526 $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) ); 2527 } 2528 | EXTERN STRINGliteral // C++-style linkage specifier 2529 { 2530 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2531 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2532 } 2533 '{' up external_definition_list_opt down '}' 2534 { 2535 linkage = linkageStack.top(); 2536 linkageStack.pop(); 2537 $$ = $6; 2538 } 2539 | type_qualifier_list 2540 { 2541 if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2542 if ( $1->type->forall ) forall = true; // remember generic type 2543 } 2544 '{' up external_definition_list_opt down '}' // CFA, namespace 2545 { 2546 distQual( $5, $1 ); 2547 forall = false; 2548 $$ = $5; 2549 } 2550 | declaration_qualifier_list 2551 { 2552 if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2553 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 2554 } 2555 '{' up external_definition_list_opt down '}' // CFA, namespace 2556 { 2557 distQual( $5, $1 ); 2558 forall = false; 2559 $$ = $5; 2560 } 2561 | declaration_qualifier_list type_qualifier_list 2562 { 2563 if ( ($1->type && $1->type->qualifiers.val) || $2->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 2564 if ( ($1->type && $1->type->forall) || $2->type->forall ) forall = true; // remember generic type 2565 } 2566 '{' up external_definition_list_opt down '}' // CFA, namespace 2567 { 2568 distQual( $6, $1->addQualifiers( $2 ) ); 2569 forall = false; 2570 $$ = $6; 2571 } 2386 | forall '{' external_definition_list '}' // CFA, namespace 2572 2387 ; 2573 2388 … … 2580 2395 // declaration must still have a type_specifier. OBSOLESCENT (see 1) 2581 2396 | function_declarator compound_statement 2582 { $$ = $1->addFunctionBody( $2 ); } 2583 | KR_function_declarator KR_parameter_list_opt compound_statement 2584 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2397 { 2398 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2399 typedefTable.leaveScope(); 2400 $$ = $1->addFunctionBody( $2 ); 2401 } 2402 | KR_function_declarator KR_declaration_list_opt compound_statement 2403 { 2404 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2405 typedefTable.leaveScope(); 2406 $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); 2407 } 2585 2408 ; 2586 2409 2587 2410 with_clause_opt: 2588 2411 // empty 2589 { $$ = nullptr; forall = false;}2412 { $$ = nullptr; } 2590 2413 | WITH '(' tuple_expression_list ')' 2591 { $$ = $3; forall = false; }2414 { $$ = new StatementNode( build_with( $3, nullptr ) ); } 2592 2415 ; 2593 2416 … … 2595 2418 cfa_function_declaration with_clause_opt compound_statement // CFA 2596 2419 { 2420 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2421 typedefTable.leaveScope(); 2597 2422 // Add the function body to the last identifier in the function definition list, i.e., foo3: 2598 2423 // [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; } … … 2603 2428 { 2604 2429 rebindForall( $1, $2 ); 2605 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2606 } 2607 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement 2608 { 2609 rebindForall( $1, $2 ); 2430 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2431 typedefTable.leaveScope(); 2610 2432 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2611 2433 } 2612 2434 // handles default int return type, OBSOLESCENT (see 1) 2613 2435 | type_qualifier_list function_declarator with_clause_opt compound_statement 2614 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2436 { 2437 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2438 typedefTable.leaveScope(); 2439 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2440 } 2615 2441 // handles default int return type, OBSOLESCENT (see 1) 2616 2442 | declaration_qualifier_list function_declarator with_clause_opt compound_statement 2617 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2443 { 2444 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2445 typedefTable.leaveScope(); 2446 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2447 } 2618 2448 // handles default int return type, OBSOLESCENT (see 1) 2619 2449 | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement 2620 { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2450 { 2451 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2452 typedefTable.leaveScope(); 2453 $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); 2454 } 2621 2455 2622 2456 // Old-style K&R function definition, OBSOLESCENT (see 4) 2623 | declaration_specifier KR_function_declarator KR_ parameter_list_opt with_clause_opt compound_statement2457 | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2624 2458 { 2625 2459 rebindForall( $1, $2 ); 2460 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2461 typedefTable.leaveScope(); 2626 2462 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 ); 2627 2463 } 2628 2464 // handles default int return type, OBSOLESCENT (see 1) 2629 | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2630 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2465 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2466 { 2467 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2468 typedefTable.leaveScope(); 2469 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2470 } 2631 2471 // handles default int return type, OBSOLESCENT (see 1) 2632 | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2633 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2472 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2473 { 2474 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2475 typedefTable.leaveScope(); 2476 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2477 } 2634 2478 // handles default int return type, OBSOLESCENT (see 1) 2635 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2636 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2479 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2480 { 2481 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2482 typedefTable.leaveScope(); 2483 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); 2484 } 2637 2485 ; 2638 2486 … … 2744 2592 paren_identifier: 2745 2593 identifier 2746 { $$ = DeclarationNode::newName( $1 ); } 2594 { 2595 typedefTable.setNextIdentifier( *$1 ); 2596 $$ = DeclarationNode::newName( $1 ); 2597 } 2747 2598 | '(' paren_identifier ')' // redundant parenthesis 2748 2599 { $$ = $2; } … … 2877 2728 paren_type: 2878 2729 typedef 2879 // hide type name in enclosing scope by variable name2880 {2881 // if ( ! typedefTable.existsCurr( *$1->name ) ) {2882 typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER, "ID" );2883 // } else {2884 // SemanticError( yylloc, string("'") + *$1->name + "' redeclared as different kind of symbol." ); $$ = nullptr;2885 // } // if2886 }2887 2730 | '(' paren_type ')' 2888 2731 { $$ = $2; } … … 2895 2738 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2896 2739 | '(' type_ptr ')' attribute_list_opt 2897 { $$ = $2->addQualifiers( $4 ); } // redundant parenthesis2740 { $$ = $2->addQualifiers( $4 ); } 2898 2741 ; 2899 2742 … … 2987 2830 typedef: 2988 2831 TYPEDEFname 2989 { $$ = DeclarationNode::newName( $1 ); } 2832 { 2833 typedefTable.setNextIdentifier( *$1 ); 2834 $$ = DeclarationNode::newName( $1 ); 2835 } 2990 2836 | TYPEGENname 2991 { $$ = DeclarationNode::newName( $1 ); } 2837 { 2838 typedefTable.setNextIdentifier( *$1 ); 2839 $$ = DeclarationNode::newName( $1 ); 2840 } 2992 2841 ; 2993 2842 … … 3174 3023 '[' ']' 3175 3024 { $$ = DeclarationNode::newArray( 0, 0, false ); } 3176 // multi_array_dimension handles the '[' '*' ']' case3025 // multi_array_dimension handles the '[' '*' ']' case 3177 3026 | '[' push type_qualifier_list '*' pop ']' // remaining C99 3178 3027 { $$ = DeclarationNode::newVarArray( $3 ); } 3179 3028 | '[' push type_qualifier_list pop ']' 3180 3029 { $$ = DeclarationNode::newArray( 0, $3, false ); } 3181 // multi_array_dimension handles the '[' assignment_expression ']' case3030 // multi_array_dimension handles the '[' assignment_expression ']' case 3182 3031 | '[' push type_qualifier_list assignment_expression pop ']' 3183 3032 { $$ = DeclarationNode::newArray( $4, $3, false ); } … … 3315 3164 // 3316 3165 // cfa_abstract_tuple identifier_or_type_name 3317 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ ellipsis_list_opt ')'3166 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_type_list_opt ')' 3318 3167 // 3319 3168 // since a function return type can be syntactically identical to a tuple type: … … 3374 3223 '[' push cfa_abstract_parameter_list pop ']' 3375 3224 { $$ = DeclarationNode::newTuple( $3 ); } 3376 | '[' push type_specifier_nobody ELLIPSIS pop ']'3377 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }3378 | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']'3379 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; }3380 3225 ; 3381 3226 3382 3227 cfa_abstract_function: // CFA 3383 // '[' ']' '(' cfa_parameter_ ellipsis_list_opt ')'3228 // '[' ']' '(' cfa_parameter_type_list_opt ')' 3384 3229 // { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 3385 cfa_abstract_tuple '(' push cfa_parameter_ ellipsis_list_opt pop ')'3230 cfa_abstract_tuple '(' push cfa_parameter_type_list_opt pop ')' 3386 3231 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 3387 | cfa_function_return '(' push cfa_parameter_ ellipsis_list_opt pop ')'3232 | cfa_function_return '(' push cfa_parameter_type_list_opt pop ')' 3388 3233 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 3389 3234 ; … … 3416 3261 3417 3262 %% 3418 3419 3263 // ----end of grammar---- 3420 3264
Note:
See TracChangeset
for help on using the changeset viewer.