Changeset 90152a4 for src/Parser/parser.yy
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (95 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rf9feab8 r90152a4 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Nov 27 17:23:35 201713 // Update Count : 299212 // Last Modified On : Wed Aug 8 17:50:07 2018 13 // Update Count : 3998 14 14 // 15 15 … … 115 115 } // distExt 116 116 117 void distInl( DeclarationNode * declaration ) { 118 // distribute EXTENSION across all declarations 119 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 120 iter->set_inLine( true ); 121 } // for 122 } // distInl 123 124 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) { 125 // distribute qualifiers across all non-variable declarations in a distribution statemement 126 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. Since 128 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To 129 // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to 130 // 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 } // if 147 } else { // just SC qualifiers 148 iter->addQualifiers( clone ); 149 } // if 150 } // for 151 delete qualifiers; 152 } // distQual 153 117 154 // There is an ambiguity for inline generic-routine return-types and generic routines. 118 155 // forall( otype T ) struct S { int i; } bar( T ) {} 119 156 // Does the forall bind to the struct or the routine, and how would it be possible to explicitly specify the binding. 120 157 // 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 ) {} 121 161 122 162 void rebindForall( DeclarationNode * declSpec, DeclarationNode * funcDecl ) { 123 if ( declSpec->type->kind == TypeData::Aggregate ) { // return isaggregate definition163 if ( declSpec->type->kind == TypeData::Aggregate ) { // ignore aggregate definition 124 164 funcDecl->type->forall = declSpec->type->aggregate.params; // move forall from aggregate to function type 125 165 declSpec->type->aggregate.params = nullptr; … … 127 167 } // rebindForall 128 168 129 bool forall = false; // aggregate have one or more forall qualifiers ? 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 ? 130 197 131 198 // https://www.gnu.org/software/bison/manual/bison.html#Location-Type … … 158 225 WaitForStmt * wfs; 159 226 Expression * constant; 160 IfCtl * ifctl; 161 ForCtl * fctl; 227 IfCtrl * ifctl; 228 ForCtrl * fctl; 229 enum OperKinds compop; 162 230 LabelNode * label; 163 231 InitializerNode * in; … … 166 234 bool flag; 167 235 CatchStmt::Kind catch_kind; 236 GenericExpr * genexpr; 168 237 } 169 238 … … 187 256 %token TYPEOF LABEL // GCC 188 257 %token ENUM STRUCT UNION 258 %token EXCEPTION // CFA 189 259 %token COROUTINE MONITOR THREAD // CFA 190 260 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA … … 201 271 %token<tok> ATTR_IDENTIFIER ATTR_TYPEDEFname ATTR_TYPEGENname 202 272 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 273 %token<tok> DIRECTIVE 203 274 // Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and 204 275 // overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically … … 219 290 %token ANDassign ERassign ORassign // &= ^= |= 220 291 292 %token Erange // ~= 221 293 %token ATassign // @= 222 294 … … 241 313 %type<ifctl> if_control_expression 242 314 %type<fctl> for_control_expression 315 %type<compop> inclexcl 243 316 %type<en> subrange 244 317 %type<decl> asm_name_opt … … 248 321 %type<flag> asm_volatile_opt 249 322 %type<en> handler_predicate_opt 323 %type<genexpr> generic_association generic_assoc_list 250 324 251 325 // statements 252 326 %type<sn> statement labeled_statement compound_statement 253 327 %type<sn> statement_decl statement_decl_list statement_list_nodecl 254 %type<sn> selection_statement 255 %type<sn> switch_clause_list_opt switch_clause_list choose_clause_list_opt choose_clause_list328 %type<sn> selection_statement if_statement 329 %type<sn> switch_clause_list_opt switch_clause_list 256 330 %type<en> case_value 257 331 %type<sn> case_clause case_value_list case_label case_label_list 258 %type<sn> fall_through fall_through_opt259 332 %type<sn> iteration_statement jump_statement 260 333 %type<sn> expression_statement asm_statement 261 %type<sn> with_statement with_clause_opt 334 %type<sn> with_statement 335 %type<en> with_clause_opt 262 336 %type<sn> exception_statement handler_clause finally_clause 263 337 %type<catch_kind> handler_key … … 275 349 %type<decl> aggregate_type aggregate_type_nobody 276 350 277 %type<decl> assertion assertion_list _opt351 %type<decl> assertion assertion_list assertion_list_opt 278 352 279 353 %type<en> bit_subrange_size_opt bit_subrange_size … … 291 365 %type<en> enumerator_value_opt 292 366 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 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 297 373 298 374 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 307 383 %type<decl> cfa_array_parameter_1st_dimension 308 384 309 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list 385 %type<decl> cfa_trait_declaring_list cfa_declaration cfa_field_declaring_list cfa_field_abstract_list 310 386 %type<decl> cfa_function_declaration cfa_function_return cfa_function_specifier 311 387 … … 313 389 %type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr 314 390 315 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ type_list cfa_parameter_type_list_opt391 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt 316 392 317 393 %type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier 318 394 319 %type<decl> c_declaration 395 %type<decl> c_declaration static_assert 320 396 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 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 397 %type<decl> KR_parameter_list KR_parameter_list_opt 398 399 %type<decl> parameter_declaration parameter_list parameter_type_list_opt 325 400 326 401 %type<decl> paren_identifier paren_type … … 343 418 %type<decl> type_parameter type_parameter_list type_initializer_opt 344 419 345 %type<en> type_ list420 %type<en> type_parameters_opt type_list 346 421 347 422 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 354 429 355 430 // initializers 356 %type<in> initializer initializer_list initializer_opt431 %type<in> initializer initializer_list_opt initializer_opt 357 432 358 433 // designators … … 378 453 // Foo ( *fp )( int ); 379 454 // `---' matches start of TYPEGENname '(' 380 // Must be:455 // must be: 381 456 // 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 ); 382 461 383 462 // Order of these lines matters (low-to-high precedence). 384 463 %precedence TYPEGENname 464 %precedence '}' 385 465 %precedence '(' 386 466 387 %locations // support location tracking for error messages467 %locations // support location tracking for error messages 388 468 389 469 %start translation_unit // parse-tree root … … 392 472 //************************* Namespace Management ******************************** 393 473 394 // The grammar in the ANSI C standard is not strictly context-free, since it relies upon the distinct terminal symbols395 // "identifier", "TYPEDEFname", and "TYPEGENname" that are lexically identical. While it is possible to write a purely396 // 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, those400 // introduced through "forall" qualifiers), and by introducing "type generators" -- parameterized types. This latter401 // 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, it404 // accesses a data structure (TypedefTable) to allow classification of an identifier that it has just read. Semantic405 // 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 a408 // local scope; it must revert to its original class at the end of the block. Since type names can be local to a409 // particular declaration, each declaration is itself a scope. This requires distinguishing between type names that are410 // local to the current declaration scope and those that persist past the end of the declaration (i.e., names defined in411 // "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 of414 // scopes. Every push must have a matching pop, although it is regrettable the matching pairs do not always occur415 // within the same rule. These non-terminals may appear in more contexts than strictly necessary from a semantic point416 // of view. Unfortunately, these extra rules are necessary to prevent parsing conflicts -- the parser may not have417 // enough context and look-ahead information to decide whether a new scope is necessary, so the effect of these extra418 // rules is to open a new scope unconditionally. As the grammar evolves, it may be neccesary to add or move around419 // "push" and "pop" nonterminals to resolve conflicts of this sort.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 TYPEDEFname 478 // foo f; // to allow it to appear in this context 479 // 480 // While it may be possible to write a purely context-free grammar, such a grammar would obscure the relationship 481 // between syntactic and semantic constructs. Cforall compounds this problem by introducing type names local to the 482 // scope of a declaration (for instance, those introduced through "forall" qualifiers), and by introducing "type 483 // generators" -- parameterized types. This latter type name creates a third class of identifiers, "TYPEGENname", which 484 // 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 named 488 // scope. During parsing, semantic actions update the type table by adding new identifiers in the current scope. For 489 // each context that introduces a name scope, a new level is created in the type table and that level is popped on 490 // 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 that 492 // 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 in 495 // the production rule. There are multiple lists of declarations, where each declaration is a named scope, so pop/push 496 // around the list separator. 497 // 498 // int f( forall(T) T (*f1) T , forall( S ) S (*f2)( S ) ); 499 // push pop push pop 420 500 421 501 push: … … 443 523 ; 444 524 445 identifier:446 IDENTIFIER447 | ATTR_IDENTIFIER // CFA448 | quasi_keyword449 ;450 451 525 no_attr_identifier: 452 526 IDENTIFIER 453 527 | quasi_keyword 528 | '@' // CFA 529 { Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; } 530 ; 531 532 identifier: 533 no_attr_identifier 534 | ATTR_IDENTIFIER // CFA 454 535 ; 455 536 … … 480 561 | '(' compound_statement ')' // GCC, lambda expression 481 562 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); } 563 | constant '`' IDENTIFIER // CFA, postfix call 564 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); } 565 | string_literal '`' IDENTIFIER // CFA, postfix call 566 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); } 567 | IDENTIFIER '`' IDENTIFIER // CFA, postfix call 568 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); } 569 | tuple '`' IDENTIFIER // CFA, postfix call 570 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); } 571 | '(' comma_expression ')' '`' IDENTIFIER // CFA, postfix call 572 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); } 482 573 | type_name '.' no_attr_identifier // CFA, nested type 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 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) } } ); } 486 604 ; 487 605 488 606 postfix_expression: 489 607 primary_expression 490 | postfix_expression '[' push assignment_expression pop']'608 | postfix_expression '[' assignment_expression ']' 491 609 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a 492 610 // matrix with x[i,j] instead of x[i][j]. While this change is not backwards compatible, there seems to be 493 611 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 494 612 // equivalent to the old x[i,j]. 495 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $ 4) ); }613 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); } 496 614 | postfix_expression '{' argument_expression_list '}' // CFA, constructor call 497 615 { … … 504 622 | postfix_expression '.' no_attr_identifier 505 623 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } 506 | postfix_expression '.' '[' push field_list pop ']' // CFA, tuple field selector507 { $$ = new ExpressionNode( build_fieldSel( $1, build_ tuple( $5) ) ); }624 | postfix_expression '.' INTEGERconstant // CFA, tuple index 625 { $$ = new ExpressionNode( build_fieldSel( $1, build_constantInteger( *$3 ) ) ); } 508 626 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 509 627 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant( *$2 ) ) ); } 628 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 629 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 510 630 | postfix_expression ARROW no_attr_identifier 511 631 { 512 632 $$ = new ExpressionNode( build_pfieldSel( $1, *$3 == "0" || *$3 == "1" ? build_constantInteger( *$3 ) : build_varref( $3 ) ) ); 513 633 } 514 | postfix_expression ARROW '[' push field_list pop ']' // CFA, tuple field selector515 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $5 ) ) ); }516 634 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 517 635 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger( *$3 ) ) ); } 636 | postfix_expression ARROW '[' field_name_list ']' // CFA, tuple field selector 637 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 518 638 | postfix_expression ICR 519 639 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::IncrPost, $1 ) ); } 520 640 | postfix_expression DECR 521 641 { $$ = new ExpressionNode( build_unary_ptr( OperKinds::DecrPost, $1 ) ); } 522 | '(' type_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal642 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 523 643 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 644 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 645 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 524 646 | '^' primary_expression '{' argument_expression_list '}' // CFA 525 647 { … … 539 661 // empty 540 662 { $$ = nullptr; } 541 // | '@' // use default argument 542 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 663 | '?' // CFA, default parameter 664 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; } 665 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 543 666 | assignment_expression 544 667 ; 545 668 546 field_ list:// CFA, tuple field selector669 field_name_list: // CFA, tuple field selector 547 670 field 548 | field_ list ',' field{ $$ = (ExpressionNode *)$1->set_last( $3 ); }671 | field_name_list ',' field { $$ = (ExpressionNode *)$1->set_last( $3 ); } 549 672 ; 550 673 … … 553 676 | FLOATING_DECIMALconstant field 554 677 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); } 555 | FLOATING_DECIMALconstant '[' push field_list pop']'556 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $ 4) ) ); }678 | FLOATING_DECIMALconstant '[' field_name_list ']' 679 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple( $3 ) ) ); } 557 680 | field_name '.' field 558 681 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 559 | field_name '.' '[' push field_list pop']'560 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $ 5) ) ); }682 | field_name '.' '[' field_name_list ']' 683 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 561 684 | field_name ARROW field 562 685 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); } 563 | field_name ARROW '[' push field_list pop']'564 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $ 5) ) ); }686 | field_name ARROW '[' field_name_list ']' 687 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple( $4 ) ) ); } 565 688 ; 566 689 567 690 field_name: 568 INTEGERconstant fraction_constants 691 INTEGERconstant fraction_constants_opt 569 692 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger( *$1 ), $2 ) ); } 570 | FLOATINGconstant fraction_constants 693 | FLOATINGconstant fraction_constants_opt 571 694 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); } 572 | no_attr_identifier fraction_constants 695 | no_attr_identifier fraction_constants_opt 573 696 { 574 697 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) ); … … 576 699 ; 577 700 578 fraction_constants :701 fraction_constants_opt: 579 702 // empty 580 703 { $$ = nullptr; } 581 | fraction_constants FLOATING_FRACTIONconstant704 | fraction_constants_opt FLOATING_FRACTIONconstant 582 705 { 583 706 Expression * constant = build_field_name_FLOATING_FRACTIONconstant( *$2 ); … … 591 714 // semantics checks, e.g., ++3, 3--, *3, &&3 592 715 | constant 593 { $$ = $1; }594 716 | string_literal 595 717 { $$ = new ExpressionNode( $1 ); } … … 657 779 | '(' type_no_function ')' cast_expression 658 780 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 781 | '(' COROUTINE '&' ')' cast_expression // CFA 782 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 783 | '(' THREAD '&' ')' cast_expression // CFA 784 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); } 785 | '(' MONITOR '&' ')' cast_expression // CFA 786 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); } 659 787 // VIRTUAL cannot be opt because of look ahead issues 660 | '(' VIRTUAL ')' cast_expression 788 | '(' VIRTUAL ')' cast_expression // CFA 661 789 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $4 ), maybeMoveBuildType( nullptr ) ) ); } 662 | '(' VIRTUAL type_no_function ')' cast_expression 790 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 663 791 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild< Expression >( $5 ), maybeMoveBuildType( $3 ) ) ); } 664 792 // | '(' type_no_function ')' tuple … … 752 880 | logical_OR_expression '?' comma_expression ':' conditional_expression 753 881 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); } 754 // FIX ME: this hackcomputes $1 twice882 // FIX ME: computes $1 twice 755 883 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 756 884 { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); } … … 766 894 | unary_expression assignment_operator assignment_expression 767 895 { $$ = 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; } 768 898 ; 769 899 … … 795 925 // '[' ']' 796 926 // { $$ = new ExpressionNode( build_tuple() ); } 797 // '[' push assignment_expression pop ']'927 // | '[' push assignment_expression pop ']' 798 928 // { $$ = new ExpressionNode( build_tuple( $3 ) ); } 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) ) ); }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 ) ) ); } 803 933 ; 804 934 … … 826 956 labeled_statement 827 957 | compound_statement 828 | expression_statement { $$ = $1; }958 | expression_statement 829 959 | selection_statement 830 960 | iteration_statement … … 834 964 | waitfor_statement 835 965 | exception_statement 966 | enable_disable_statement 967 { SemanticError( yylloc, "enable/disable statement is currently unimplemented." ); $$ = nullptr; } 836 968 | asm_statement 969 | DIRECTIVE 970 { $$ = new StatementNode( build_directive( $1 ) ); } 971 ; 837 972 838 973 labeled_statement: … … 847 982 '{' '}' 848 983 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 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 984 | '{' push 853 985 local_label_declaration_opt // GCC, local labels 854 986 statement_decl_list // C99, intermix declarations and statements 855 987 pop '}' 856 { $$ = new StatementNode( build_compound( $ 5) ); }988 { $$ = new StatementNode( build_compound( $4 ) ); } 857 989 ; 858 990 859 991 statement_decl_list: // C99 860 992 statement_decl 861 | statement_decl_list pushstatement_decl862 { if ( $1 != 0 ) { $1->set_last( $ 3); $$ = $1; } }993 | statement_decl_list statement_decl 994 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 863 995 ; 864 996 … … 878 1010 $$ = new StatementNode( $2 ); 879 1011 } 880 | statement pop1012 | statement 881 1013 ; 882 1014 … … 893 1025 894 1026 selection_statement: 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 ) ); } 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; } 900 1031 | SWITCH '(' comma_expression ')' case_clause 901 { $$ = new StatementNode( build_switch( $3, $5 ) ); }902 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA903 { 904 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );1032 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); } 1033 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 1034 { 1035 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) ); 905 1036 // The semantics of the declaration list is changed to include associated initialization, which is performed 906 1037 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound … … 911 1042 } 912 1043 | CHOOSE '(' comma_expression ')' case_clause // CFA 913 { $$ = new StatementNode( build_switch( $3, $5 ) ); }914 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt choose_clause_list_opt'}' // CFA915 { 916 StatementNode *sw = new StatementNode( build_switch( $3, $8 ) );1044 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); } 1045 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 1046 { 1047 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) ); 917 1048 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 918 1049 } 919 1050 ; 920 1051 1052 if_statement: 1053 IF '(' if_control_expression ')' statement %prec THEN 1054 // explicitly deal with the shift/reduce conflict on if/else 1055 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); } 1056 | IF '(' if_control_expression ')' statement ELSE statement 1057 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); } 1058 ; 1059 921 1060 if_control_expression: 922 comma_expression pop923 { $$ = new IfCt l( nullptr, $1 ); }924 | c_declaration pop// no semi-colon925 { $$ = new IfCt l( $1, nullptr ); }926 | cfa_declaration pop// no semi-colon927 { $$ = new IfCt l( $1, nullptr ); }1061 comma_expression 1062 { $$ = new IfCtrl( nullptr, $1 ); } 1063 | c_declaration // no semi-colon 1064 { $$ = new IfCtrl( $1, nullptr ); } 1065 | cfa_declaration // no semi-colon 1066 { $$ = new IfCtrl( $1, nullptr ); } 928 1067 | declaration comma_expression // semi-colon separated 929 { $$ = new IfCt l( $1, $2 ); }1068 { $$ = new IfCtrl( $1, $2 ); } 930 1069 ; 931 1070 … … 952 1091 ; 953 1092 1093 //label_list_opt: 1094 // // empty 1095 // | identifier_or_type_name ':' 1096 // | label_list_opt identifier_or_type_name ':' 1097 // ; 1098 954 1099 case_label_list: // CFA 955 1100 case_label … … 974 1119 ; 975 1120 976 choose_clause_list_opt: // CFA977 // empty978 { $$ = nullptr; }979 | choose_clause_list980 ;981 982 choose_clause_list: // CFA983 case_label_list fall_through984 { $$ = $1->append_last_case( $2 ); }985 | case_label_list statement_list_nodecl fall_through_opt986 { $$ = $1->append_last_case( new StatementNode( build_compound( (StatementNode *)$2->set_last( $3 ) ) ) ); }987 | choose_clause_list case_label_list fall_through988 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( $3 ))); }989 | choose_clause_list case_label_list statement_list_nodecl fall_through_opt990 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( (StatementNode *)$3->set_last( $4 ) ) ) ) ) ); }991 ;992 993 fall_through_opt: // CFA994 // empty995 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); } // insert implicit break996 | fall_through997 ;998 999 fall_through_name: // CFA1000 FALLTHRU1001 | FALLTHROUGH1002 ;1003 1004 fall_through: // CFA1005 fall_through_name1006 { $$ = nullptr; }1007 | fall_through_name ';'1008 { $$ = nullptr; }1009 ;1010 1011 1121 iteration_statement: 1012 WHILE '(' comma_expression ')' statement 1013 { $$ = new StatementNode( build_while( $3, $5 ) ); } 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 ) ); } 1014 1126 | DO statement WHILE '(' comma_expression ')' ';' 1015 { $$ = new StatementNode( build_while( $5, $2, true ) ); } 1016 | FOR '(' push for_control_expression ')' statement 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 1017 1131 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1018 1132 ; 1019 1133 1020 1134 for_control_expression: 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 ); } 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; } 1025 1198 ; 1026 1199 … … 1032 1205 // whereas normal operator precedence yields goto (*i)+3; 1033 1206 { $$ = 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 ';' // CFA 1209 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); } 1210 | fall_through_name identifier_or_type_name ';' // CFA 1211 { $$ = new StatementNode( build_branch( $2, BranchStmt::FallThrough ) ); } 1212 | fall_through_name DEFAULT ';' // CFA 1213 { $$ = new StatementNode( build_branch( BranchStmt::FallThroughDefault ) ); } 1034 1214 | CONTINUE ';' 1035 1215 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. … … 1048 1228 | RETURN comma_expression_opt ';' 1049 1229 { $$ = new StatementNode( build_return( $2 ) ); } 1230 | RETURN '{' initializer_list_opt comma_opt '}' 1231 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1050 1232 | THROW assignment_expression_opt ';' // handles rethrow 1051 1233 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1056 1238 ; 1057 1239 1240 fall_through_name: // CFA 1241 FALLTHRU 1242 | FALLTHROUGH 1243 ; 1244 1058 1245 with_statement: 1059 1246 WITH '(' tuple_expression_list ')' statement … … 1066 1253 mutex_statement: 1067 1254 MUTEX '(' argument_expression_list ')' statement 1068 { throw SemanticError("Mutex statement is currently unimplemented."); $$ = nullptr; } // FIX ME1255 { SemanticError( yylloc, "Mutex statement is currently unimplemented." ); $$ = nullptr; } 1069 1256 ; 1070 1257 1071 1258 when_clause: 1072 WHEN '(' comma_expression ')' 1073 { $$ = $3; } 1259 WHEN '(' comma_expression ')' { $$ = $3; } 1074 1260 ; 1075 1261 … … 1081 1267 1082 1268 waitfor: 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 } 1269 WAITFOR '(' cast_expression ')' 1270 { $$ = $3; } 1271 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1272 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1094 1273 ; 1095 1274 1096 1275 timeout: 1097 TIMEOUT '(' comma_expression ')' 1098 { $$ = $3; } 1276 TIMEOUT '(' comma_expression ')' { $$ = $3; } 1099 1277 ; 1100 1278 … … 1109 1287 { $$ = build_waitfor_timeout( nullptr, $3, $1 ); } 1110 1288 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1289 | when_clause_opt timeout statement WOR ELSE statement 1290 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1111 1291 | when_clause_opt timeout statement WOR when_clause ELSE statement 1112 1292 { $$ = build_waitfor_timeout( $2, $3, $1, $7, $5 ); } … … 1130 1310 1131 1311 handler_clause: 1132 handler_key '(' push pushexception_declaration pop handler_predicate_opt ')' compound_statement pop1133 { $$ = new StatementNode( build_catch( $1, $ 5, $7, $9) ); }1134 | handler_clause handler_key '(' push pushexception_declaration pop handler_predicate_opt ')' compound_statement pop1135 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $ 6, $8, $10) ) ); }1312 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1313 { $$ = new StatementNode( build_catch( $1, $4, $6, $8 ) ); } 1314 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement pop 1315 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $5, $7, $9 ) ) ); } 1136 1316 ; 1137 1317 1138 1318 handler_predicate_opt: 1139 // empty1319 // empty 1140 1320 { $$ = nullptr; } 1141 | ';' conditional_expression 1142 { $$ = $2; } 1321 | ';' conditional_expression { $$ = $2; } 1143 1322 ; 1144 1323 1145 1324 handler_key: 1146 CATCH 1147 { $$ = CatchStmt::Terminate; } 1148 | CATCHRESUME 1149 { $$ = CatchStmt::Resume; } 1325 CATCH { $$ = CatchStmt::Terminate; } 1326 | CATCHRESUME { $$ = CatchStmt::Resume; } 1150 1327 ; 1151 1328 1152 1329 finally_clause: 1153 FINALLY compound_statement 1154 { 1155 $$ = new StatementNode( build_finally( $2 ) ); 1156 } 1330 FINALLY compound_statement { $$ = new StatementNode( build_finally( $2 ) ); } 1157 1331 ; 1158 1332 … … 1161 1335 type_specifier_nobody 1162 1336 | type_specifier_nobody declarator 1163 { 1164 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1165 $$ = $2->addType( $1 ); 1166 } 1337 { $$ = $2->addType( $1 ); } 1167 1338 | type_specifier_nobody variable_abstract_declarator 1168 1339 { $$ = $2->addType( $1 ); } 1169 1340 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 1170 { 1171 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1172 $$ = $1->addName( $2 ); 1173 } 1341 { $$ = $1->addName( $2 ); } 1174 1342 | cfa_abstract_declarator_tuple // CFA 1343 ; 1344 1345 enable_disable_statement: 1346 enable_disable_key identifier_list compound_statement 1347 ; 1348 1349 enable_disable_key: 1350 ENABLE 1351 | DISABLE 1175 1352 ; 1176 1353 1177 1354 asm_statement: 1178 1355 ASM asm_volatile_opt '(' string_literal ')' ';' 1179 { $$ = new StatementNode( build_asm stmt( $2, $4, 0 ) ); }1356 { $$ = new StatementNode( build_asm( $2, $4, 0 ) ); } 1180 1357 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC 1181 { $$ = new StatementNode( build_asm stmt( $2, $4, $6 ) ); }1358 { $$ = new StatementNode( build_asm( $2, $4, $6 ) ); } 1182 1359 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';' 1183 { $$ = new StatementNode( build_asm stmt( $2, $4, $6, $8 ) ); }1360 { $$ = new StatementNode( build_asm( $2, $4, $6, $8 ) ); } 1184 1361 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 1185 { $$ = new StatementNode( build_asm stmt( $2, $4, $6, $8, $10 ) ); }1362 { $$ = new StatementNode( build_asm( $2, $4, $6, $8, $10 ) ); } 1186 1363 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 1187 { $$ = new StatementNode( build_asm stmt( $2, $5, 0, $8, $10, $12 ) ); }1364 { $$ = new StatementNode( build_asm( $2, $5, 0, $8, $10, $12 ) ); } 1188 1365 ; 1189 1366 … … 1240 1417 1241 1418 declaration_list_opt: // used at beginning of switch statement 1242 pop1419 // empty 1243 1420 { $$ = nullptr; } 1244 1421 | declaration_list … … 1247 1424 declaration_list: 1248 1425 declaration 1249 | declaration_list pushdeclaration1250 { $$ = $1->appendList( $ 3); }1251 ; 1252 1253 KR_ declaration_list_opt:// used to declare parameter types in K&R style functions1426 | declaration_list declaration 1427 { $$ = $1->appendList( $2 ); } 1428 ; 1429 1430 KR_parameter_list_opt: // used to declare parameter types in K&R style functions 1254 1431 // empty 1255 1432 { $$ = nullptr; } 1256 | KR_ declaration_list1257 ; 1258 1259 KR_ declaration_list:1433 | KR_parameter_list 1434 ; 1435 1436 KR_parameter_list: 1260 1437 push c_declaration pop ';' 1261 1438 { $$ = $2; } 1262 | KR_ declaration_list push c_declaration pop ';'1439 | KR_parameter_list push c_declaration pop ';' 1263 1440 { $$ = $1->appendList( $3 ); } 1264 1441 ; … … 1275 1452 1276 1453 local_label_list: // GCC, local label 1277 no_attr_identifier_or_type_name {}1278 | local_label_list ',' no_attr_identifier_or_type_name {}1454 no_attr_identifier_or_type_name 1455 | local_label_list ',' no_attr_identifier_or_type_name 1279 1456 ; 1280 1457 1281 1458 declaration: // old & new style declarations 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 ; 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( "\"\"" ) ) ); } 1287 1469 1288 1470 // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function … … 1307 1489 cfa_variable_declaration: // CFA 1308 1490 cfa_variable_specifier initializer_opt 1309 { 1310 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1311 $$ = $1->addInitializer( $2 ); 1312 } 1491 { $$ = $1->addInitializer( $2 ); } 1313 1492 | declaration_qualifier_list cfa_variable_specifier initializer_opt 1314 1493 // declaration_qualifier_list also includes type_qualifier_list, so a semantic check is necessary to preclude 1315 1494 // them as a type_qualifier cannot appear in that context. 1316 { 1317 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1318 $$ = $2->addQualifiers( $1 )->addInitializer( $3 );; 1319 } 1495 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); } 1320 1496 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1321 { 1322 typedefTable.addToEnclosingScope( *$5, TypedefTable::ID ); 1323 $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); 1324 } 1497 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); } 1325 1498 ; 1326 1499 … … 1329 1502 // storage-class 1330 1503 cfa_abstract_declarator_no_tuple identifier_or_type_name asm_name_opt 1331 { 1332 typedefTable.setNextIdentifier( *$2 ); 1333 $$ = $1->addName( $2 )->addAsmName( $3 ); 1334 } 1504 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1335 1505 | cfa_abstract_tuple identifier_or_type_name asm_name_opt 1336 { 1337 typedefTable.setNextIdentifier( *$2 ); 1338 $$ = $1->addName( $2 )->addAsmName( $3 ); 1339 } 1506 { $$ = $1->addName( $2 )->addAsmName( $3 ); } 1340 1507 | type_qualifier_list cfa_abstract_tuple identifier_or_type_name asm_name_opt 1341 { 1342 typedefTable.setNextIdentifier( *$3 ); 1343 $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); 1344 } 1508 { $$ = $2->addQualifiers( $1 )->addName( $3 )->addAsmName( $4 ); } 1345 1509 ; 1346 1510 1347 1511 cfa_function_declaration: // CFA 1348 1512 cfa_function_specifier 1349 {1350 typedefTable.addToEnclosingScope( TypedefTable::ID );1351 $$ = $1;1352 }1353 1513 | type_qualifier_list cfa_function_specifier 1354 { 1355 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1356 $$ = $2->addQualifiers( $1 ); 1357 } 1514 { $$ = $2->addQualifiers( $1 ); } 1358 1515 | declaration_qualifier_list cfa_function_specifier 1359 { 1360 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1361 $$ = $2->addQualifiers( $1 ); 1362 } 1516 { $$ = $2->addQualifiers( $1 ); } 1363 1517 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 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 ')' 1518 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); } 1519 | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1369 1520 { 1370 1521 // Append the return type at the start (left-hand-side) to each identifier in the list. 1371 1522 DeclarationNode * ret = new DeclarationNode; 1372 1523 ret->type = maybeClone( $1->type->base ); 1373 $$ = $1->appendList( DeclarationNode::newFunction( $ 5, ret, $8, nullptr, true) );1524 $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) ); 1374 1525 } 1375 1526 ; 1376 1527 1377 1528 cfa_function_specifier: // CFA 1378 // '[' ']' identifier_or_type_name '(' push cfa_parameter_ type_list_opt pop ')' // S/R conflict1529 // '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict 1379 1530 // { 1380 1531 // $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true ); 1381 1532 // } 1382 // '[' ']' identifier '(' push cfa_parameter_ type_list_opt pop ')'1533 // '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')' 1383 1534 // { 1384 1535 // typedefTable.setNextIdentifier( *$5 ); 1385 1536 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1386 1537 // } 1387 // | '[' ']' TYPEDEFname '(' push cfa_parameter_ type_list_opt pop ')'1538 // | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')' 1388 1539 // { 1389 1540 // typedefTable.setNextIdentifier( *$5 ); … … 1393 1544 // identifier_or_type_name must be broken apart because of the sequence: 1394 1545 // 1395 // '[' ']' identifier_or_type_name '(' cfa_parameter_ type_list_opt ')'1546 // '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')' 1396 1547 // '[' ']' type_specifier 1397 1548 // 1398 1549 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1399 1550 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1400 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ type_list_opt pop ')'1551 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1401 1552 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 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 } 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 ); } 1409 1556 ; 1410 1557 … … 1413 1560 { $$ = DeclarationNode::newTuple( $3 ); } 1414 1561 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 1415 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the 1416 // ']'. 1562 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 1417 1563 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1418 1564 ; … … 1421 1567 TYPEDEF cfa_variable_specifier 1422 1568 { 1423 typedefTable.addToEnclosingScope( TypedefTable::TD);1569 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "1" ); 1424 1570 $$ = $2->addTypedef(); 1425 1571 } 1426 1572 | TYPEDEF cfa_function_specifier 1427 1573 { 1428 typedefTable.addToEnclosingScope( TypedefTable::TD);1574 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname, "2" ); 1429 1575 $$ = $2->addTypedef(); 1430 1576 } 1431 1577 | cfa_typedef_declaration pop ',' push no_attr_identifier 1432 1578 { 1433 typedefTable.addToEnclosingScope( *$5, T ypedefTable::TD);1579 typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "3" ); 1434 1580 $$ = $1->appendList( $1->cloneType( $5 ) ); 1435 1581 } … … 1442 1588 TYPEDEF type_specifier declarator 1443 1589 { 1444 typedefTable.addToEnclosingScope( TypedefTable::TD);1590 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" ); 1445 1591 $$ = $3->addType( $2 )->addTypedef(); 1446 1592 } 1447 1593 | typedef_declaration pop ',' push declarator 1448 1594 { 1449 typedefTable.addToEnclosingScope( TypedefTable::TD);1595 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname, "5" ); 1450 1596 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1451 1597 } 1452 1598 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1453 1599 { 1454 typedefTable.addToEnclosingScope( TypedefTable::TD);1600 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" ); 1455 1601 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1456 1602 } 1457 1603 | type_specifier TYPEDEF declarator 1458 1604 { 1459 typedefTable.addToEnclosingScope( TypedefTable::TD);1605 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" ); 1460 1606 $$ = $3->addType( $1 )->addTypedef(); 1461 1607 } 1462 1608 | type_specifier TYPEDEF type_qualifier_list declarator 1463 1609 { 1464 typedefTable.addToEnclosingScope( TypedefTable::TD);1610 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" ); 1465 1611 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1466 1612 } … … 1471 1617 TYPEDEF no_attr_identifier '=' assignment_expression 1472 1618 { 1473 typedefTable.addToEnclosingScope( *$2, TypedefTable::TD );1474 $$ = DeclarationNode::newName( 0 ); // unimplemented1619 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1620 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1475 1621 } 1476 1622 | typedef_expression pop ',' push no_attr_identifier '=' assignment_expression 1477 1623 { 1478 typedefTable.addToEnclosingScope( *$5, TypedefTable::TD );1479 $$ = DeclarationNode::newName( 0 ); // unimplemented1624 // $$ = DeclarationNode::newName( 0 ); // unimplemented 1625 SemanticError( yylloc, "Typedef expression is currently unimplemented." ); $$ = nullptr; 1480 1626 } 1481 1627 ; … … 1493 1639 // declarator asm_name_opt initializer_opt 1494 1640 // { 1495 // typedefTable.addToEnclosingScope( TypedefTable::ID);1641 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1496 1642 // $$ = ( $2->addType( $1 ))->addAsmName( $3 )->addInitializer( $4 ); 1497 1643 // } 1498 1644 // | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1499 1645 // { 1500 // typedefTable.addToEnclosingScope( TypedefTable::ID);1646 // typedefTable.addToEnclosingScope( IDENTIFIER ); 1501 1647 // $$ = $1->appendList( $1->cloneBaseType( $4->addAsmName( $5 )->addInitializer( $6 ) ) ); 1502 1648 // } … … 1505 1651 c_declaration: 1506 1652 declaration_specifier declaring_list 1507 { 1508 $$ = distAttr( $1, $2 ); 1509 } 1653 { $$ = distAttr( $1, $2 ); } 1510 1654 | typedef_declaration 1511 1655 | typedef_expression // GCC, naming expression type … … 1517 1661 // storage-class 1518 1662 declarator asm_name_opt initializer_opt 1519 { 1520 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1521 $$ = $1->addAsmName( $2 )->addInitializer( $3 ); 1522 } 1663 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); } 1523 1664 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1524 { 1525 typedefTable.addToEnclosingScope( TypedefTable::ID ); 1526 $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); 1527 } 1665 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 1528 1666 ; 1529 1667 … … 1597 1735 1598 1736 forall: 1599 FORALL '(' 1600 { 1601 typedefTable.enterScope(); 1602 } 1603 type_parameter_list ')' // CFA 1604 { 1605 typedefTable.leaveScope(); 1606 $$ = DeclarationNode::newForall( $4 ); 1607 } 1737 FORALL '(' type_parameter_list ')' // CFA 1738 { $$ = DeclarationNode::newForall( $3 ); } 1608 1739 ; 1609 1740 … … 1678 1809 | LONG 1679 1810 { $$ = DeclarationNode::newLength( DeclarationNode::Long ); } 1680 | ZERO_T1681 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); }1682 | ONE_T1683 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); }1684 1811 | VALIST // GCC, __builtin_va_list 1685 1812 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Valist ); } … … 1701 1828 basic_type_specifier: 1702 1829 direct_type 1830 // Cannot have type modifiers, e.g., short, long, etc. 1703 1831 | type_qualifier_list_opt indirect_type type_qualifier_list_opt 1704 1832 { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); } … … 1706 1834 1707 1835 direct_type: 1708 // A semantic check is necessary for conflicting type qualifiers.1709 1836 basic_type_name 1710 1837 | type_qualifier_list basic_type_name … … 1725 1852 | ATTR_TYPEGENname '(' comma_expression ')' // CFA: e.g., @type(a+b) y; 1726 1853 { $$ = DeclarationNode::newAttr( $1, $3 ); } 1854 | ZERO_T // CFA 1855 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::Zero ); } 1856 | ONE_T // CFA 1857 { $$ = DeclarationNode::newBuiltinType( DeclarationNode::One ); } 1727 1858 ; 1728 1859 … … 1744 1875 { $$ = $3->addQualifiers( $1 ); } 1745 1876 | sue_type_specifier type_qualifier 1746 { $$ = $1->addQualifiers( $2 ); } 1877 { 1878 if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type 1879 $$ = $1->addQualifiers( $2 ); 1880 } 1747 1881 ; 1748 1882 … … 1787 1921 { $$ = DeclarationNode::newFromTypedef( $1 ); } 1788 1922 | '.' TYPEDEFname 1789 { $$ = DeclarationNode::new FromTypedef( $2 ); } // FIX ME1923 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), DeclarationNode::newFromTypedef( $2 ) ); } 1790 1924 | type_name '.' TYPEDEFname 1791 { $$ = DeclarationNode::new FromTypedef( $3 ); } // FIX ME1925 { $$ = DeclarationNode::newQualifiedType( $1, DeclarationNode::newFromTypedef( $3 ) ); } 1792 1926 | typegen_name 1793 1927 | '.' typegen_name 1794 { $$ = $2; } // FIX ME1928 { $$ = DeclarationNode::newQualifiedType( DeclarationNode::newFromGlobalScope(), $2 ); } 1795 1929 | type_name '.' typegen_name 1796 { $$ = $3; } // FIX ME1930 { $$ = DeclarationNode::newQualifiedType( $1, $3 ); } 1797 1931 ; 1798 1932 … … 1816 1950 ; 1817 1951 1952 fred: 1953 // empty 1954 { yyy = false; } 1955 ; 1956 1818 1957 aggregate_type: // struct, union 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 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 1825 1965 forall = false; // reset 1826 1966 } 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 ); } 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 ); } 1831 1977 | aggregate_type_nobody 1832 1978 ; 1833 1979 1980 type_parameters_opt: 1981 // empty 1982 { $$ = nullptr; } %prec '}' 1983 | '(' type_list ')' 1984 { $$ = $2; } 1985 ; 1986 1834 1987 aggregate_type_nobody: // struct, union - {...} 1835 aggregate_key attribute_list_opt no_attr_identifier 1836 { 1837 typedefTable.makeTypedef( *$3 ); 1988 aggregate_key attribute_list_opt no_attr_identifier fred 1989 { 1990 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname ); 1991 forall = false; // reset 1838 1992 $$ = DeclarationNode::newAggregate( $1, $3, nullptr, nullptr, false )->addQualifiers( $2 ); 1839 1993 } 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 { 1994 | aggregate_key attribute_list_opt type_name fred 1995 { 1996 forall = false; // reset 1847 1997 // Create new generic declaration with same name as previous forward declaration, where the IDENTIFIER is 1848 1998 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and … … 1857 2007 aggregate_key: 1858 2008 STRUCT 1859 { $$ = DeclarationNode::Struct; }2009 { yyy = true; $$ = DeclarationNode::Struct; } 1860 2010 | UNION 1861 { $$ = DeclarationNode::Union; } 2011 { yyy = true; $$ = DeclarationNode::Union; } 2012 | EXCEPTION 2013 { yyy = true; $$ = DeclarationNode::Exception; } 1862 2014 | COROUTINE 1863 { $$ = DeclarationNode::Coroutine; }2015 { yyy = true; $$ = DeclarationNode::Coroutine; } 1864 2016 | MONITOR 1865 { $$ = DeclarationNode::Monitor; }2017 { yyy = true; $$ = DeclarationNode::Monitor; } 1866 2018 | THREAD 1867 { $$ = DeclarationNode::Thread; }1868 ; 1869 1870 field_declaration_list :2019 { yyy = true; $$ = DeclarationNode::Thread; } 2020 ; 2021 2022 field_declaration_list_opt: 1871 2023 // empty 1872 2024 { $$ = nullptr; } 1873 | field_declaration_list field_declaration2025 | field_declaration_list_opt field_declaration 1874 2026 { $$ = $1 ? $1->appendList( $2 ) : $2; } 1875 2027 ; 1876 2028 1877 2029 field_declaration: 1878 cfa_field_declaring_list ';' // CFA, new style 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 1879 2045 | EXTENSION cfa_field_declaring_list ';' // GCC 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 } 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 1892 2083 ; 1893 2084 1894 2085 cfa_field_declaring_list: // CFA, new style field declaration 1895 cfa_abstract_declarator_tuple // CFA, no field name1896 |cfa_abstract_declarator_tuple no_attr_identifier_or_type_name2086 // bit-fields are handled by C declarations 2087 cfa_abstract_declarator_tuple no_attr_identifier_or_type_name 1897 2088 { $$ = $1->addName( $2 ); } 1898 2089 | cfa_field_declaring_list ',' no_attr_identifier_or_type_name 1899 2090 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 1900 | cfa_field_declaring_list ',' // CFA, no field name 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 ',' 1901 2097 { $$ = $1->appendList( $1->cloneType( 0 ) ); } 1902 ;1903 1904 field_declaring_list:1905 field_declarator1906 | field_declaring_list ',' attribute_list_opt field_declarator1907 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); }1908 ;1909 1910 field_declarator:1911 // empty1912 { $$ = DeclarationNode::newName( 0 ); /* XXX */ } // CFA, no field name1913 // '@'1914 // { $$ = DeclarationNode::newName( new string( DeclarationNode::anonymous.newName() ) ); } // CFA, no field name1915 | bit_subrange_size // no field name1916 { $$ = DeclarationNode::newBitfield( $1 ); }1917 | variable_declarator bit_subrange_size_opt1918 // 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_opt1921 // 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 name1924 2098 ; 1925 2099 … … 1928 2102 { $$ = nullptr; } 1929 2103 | bit_subrange_size 1930 { $$ = $1; }1931 2104 ; 1932 2105 … … 1938 2111 enum_type: // enum 1939 2112 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 1940 { $$ = DeclarationNode::newEnum( n ew string( DeclarationNode::anonymous.newName() ), $4, true )->addQualifiers( $2 ); }1941 | ENUM attribute_list_opt no_attr_identifier _or_type_name2113 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } 2114 | ENUM attribute_list_opt no_attr_identifier 1942 2115 { typedefTable.makeTypedef( *$3 ); } 1943 2116 '{' enumerator_list comma_opt '}' 1944 2117 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2118 | ENUM attribute_list_opt type_name 2119 '{' enumerator_list comma_opt '}' 2120 { $$ = DeclarationNode::newEnum( $3->type->symbolic.name, $5, true )->addQualifiers( $2 ); } 1945 2121 | enum_type_nobody 1946 2122 ; 1947 2123 1948 2124 enum_type_nobody: // enum - {...} 1949 ENUM attribute_list_opt no_attr_identifier _or_type_name2125 ENUM attribute_list_opt no_attr_identifier 1950 2126 { 1951 2127 typedefTable.makeTypedef( *$3 ); 1952 2128 $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); 2129 } 2130 | ENUM attribute_list_opt type_name 2131 { 2132 typedefTable.makeTypedef( *$3->type->symbolic.name ); 2133 $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); 1953 2134 } 1954 2135 ; … … 1968 2149 ; 1969 2150 1970 // Minimum of one parameter after which ellipsis is allowed only at the end. 1971 1972 cfa_parameter_type_list_opt: // CFA 2151 cfa_parameter_ellipsis_list_opt: // CFA, abstract + real 1973 2152 // empty 2153 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } 2154 | ELLIPSIS 1974 2155 { $$ = nullptr; } 1975 | cfa_parameter_type_list 1976 ; 1977 1978 cfa_parameter_type_list: // CFA, abstract + real 1979 cfa_abstract_parameter_list 2156 | cfa_abstract_parameter_list 1980 2157 | cfa_parameter_list 1981 2158 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list … … 2008 2185 // empty 2009 2186 { $$ = nullptr; } 2010 | parameter_type_list 2011 ; 2012 2013 parameter_type_list: 2014 parameter_list 2187 | ELLIPSIS 2188 { $$ = nullptr; } 2189 | parameter_list 2015 2190 | parameter_list pop ',' push ELLIPSIS 2016 2191 { $$ = $1->addVarArgs(); } … … 2054 2229 // No SUE declaration in parameter list. 2055 2230 declaration_specifier_nobody identifier_parameter_declarator default_initialize_opt 2056 { 2057 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2058 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2059 } 2231 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2060 2232 | declaration_specifier_nobody type_parameter_redeclarator default_initialize_opt 2061 { 2062 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2063 $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); 2064 } 2233 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2065 2234 ; 2066 2235 … … 2113 2282 { $$ = $2; } 2114 2283 | '=' VOID 2115 { $$ = n ullptr; }2284 { $$ = new InitializerNode( true ); } 2116 2285 | ATassign initializer 2117 2286 { $$ = $2->set_maybeConstructed( false ); } … … 2120 2289 initializer: 2121 2290 assignment_expression { $$ = new InitializerNode( $1 ); } 2122 | '{' initializer_list comma_opt '}'{ $$ = new InitializerNode( $2, true ); }2123 ; 2124 2125 initializer_list :2291 | '{' initializer_list_opt comma_opt '}' { $$ = new InitializerNode( $2, true ); } 2292 ; 2293 2294 initializer_list_opt: 2126 2295 // empty 2127 2296 { $$ = nullptr; } 2128 2297 | initializer 2129 2298 | designation initializer { $$ = $2->set_designators( $1 ); } 2130 | initializer_list ',' initializer{ $$ = (InitializerNode *)( $1->set_last( $3 ) ); }2131 | initializer_list ',' designation initializer2299 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2300 | initializer_list_opt ',' designation initializer 2132 2301 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) ) ); } 2133 2302 ; … … 2166 2335 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2167 2336 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); } 2168 | '.' '[' push field_ list pop ']'// CFA, tuple field selector2337 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2169 2338 { $$ = $4; } 2170 2339 ; … … 2190 2359 type_parameter_list: // CFA 2191 2360 type_parameter 2192 { $$ = $1; }2193 2361 | type_parameter_list ',' type_parameter 2194 2362 { $$ = $1->appendList( $3 ); } … … 2204 2372 type_parameter: // CFA 2205 2373 type_class no_attr_identifier_or_type_name 2206 { typedefTable.addTo EnclosingScope( *$2, TypedefTable::TD); }2374 { typedefTable.addToScope( *$2, TYPEDEFname, "9" ); } 2207 2375 type_initializer_opt assertion_list_opt 2208 2376 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } 2209 2377 | type_specifier identifier_parameter_declarator 2378 | assertion_list 2379 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2210 2380 ; 2211 2381 … … 2224 2394 // empty 2225 2395 { $$ = nullptr; } 2226 | assertion_list_opt assertion 2396 | assertion_list 2397 ; 2398 2399 assertion_list: // CFA 2400 assertion 2401 | assertion_list assertion 2227 2402 { $$ = $1 ? $1->appendList( $2 ) : $2; } 2228 2403 ; … … 2230 2405 assertion: // CFA 2231 2406 '|' no_attr_identifier_or_type_name '(' type_list ')' 2232 { 2233 typedefTable.openTrait( *$2 ); 2234 $$ = DeclarationNode::newTraitUse( $2, $4 ); 2235 } 2236 | '|' '{' push trait_declaration_list '}' 2407 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2408 | '|' '{' push trait_declaration_list pop '}' 2237 2409 { $$ = $4; } 2238 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list'}' '(' type_list ')'2239 {$$ = nullptr; }2410 // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')' 2411 // { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; } 2240 2412 ; 2241 2413 … … 2244 2416 { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( $1 ) ) ); } 2245 2417 | assignment_expression 2418 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2246 2419 | type_list ',' type 2247 2420 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) ) ); } 2248 2421 | type_list ',' assignment_expression 2249 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2422 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } 2423 // { $$ = (ExpressionNode *)( $1->set_last( $3 )); } 2250 2424 ; 2251 2425 … … 2269 2443 no_attr_identifier_or_type_name 2270 2444 { 2271 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TD);2445 typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" ); 2272 2446 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2273 2447 } 2274 | no_attr_identifier_or_type_name '(' push type_parameter_list pop')'2275 { 2276 typedefTable.addToEnclosingScope( *$1, T ypedefTable::TG);2277 $$ = DeclarationNode::newTypeDecl( $1, $ 4);2448 | no_attr_identifier_or_type_name '(' type_parameter_list ')' 2449 { 2450 typedefTable.addToEnclosingScope( *$1, TYPEGENname, "11" ); 2451 $$ = DeclarationNode::newTypeDecl( $1, $3 ); 2278 2452 } 2279 2453 ; 2280 2454 2281 2455 trait_specifier: // CFA 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 } 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 ); } 2298 2460 ; 2299 2461 2300 2462 trait_declaration_list: // CFA 2301 2463 trait_declaration 2302 | trait_declaration_list p ush trait_declaration2303 { $$ = $1->appendList( $ 3); }2464 | trait_declaration_list pop push trait_declaration 2465 { $$ = $1->appendList( $4 ); } 2304 2466 ; 2305 2467 2306 2468 trait_declaration: // CFA 2307 cfa_trait_declaring_list pop';'2308 | trait_declaring_list pop';'2469 cfa_trait_declaring_list ';' 2470 | trait_declaring_list ';' 2309 2471 ; 2310 2472 2311 2473 cfa_trait_declaring_list: // CFA 2312 2474 cfa_variable_specifier 2313 {2314 typedefTable.addToEnclosingScope2( TypedefTable::ID );2315 $$ = $1;2316 }2317 2475 | cfa_function_specifier 2318 {2319 typedefTable.addToEnclosingScope2( TypedefTable::ID );2320 $$ = $1;2321 }2322 2476 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 2323 { 2324 typedefTable.addToEnclosingScope2( *$5, TypedefTable::ID ); 2325 $$ = $1->appendList( $1->cloneType( $5 ) ); 2326 } 2477 { $$ = $1->appendList( $1->cloneType( $5 ) ); } 2327 2478 ; 2328 2479 2329 2480 trait_declaring_list: // CFA 2330 2481 type_specifier declarator 2331 { 2332 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2333 $$ = $2->addType( $1 ); 2334 } 2482 { $$ = $2->addType( $1 ); } 2335 2483 | trait_declaring_list pop ',' push declarator 2336 { 2337 typedefTable.addToEnclosingScope2( TypedefTable::ID ); 2338 $$ = $1->appendList( $1->cloneBaseType( $5 ) ); 2339 } 2484 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); } 2340 2485 ; 2341 2486 … … 2343 2488 2344 2489 translation_unit: 2345 // empty 2346 {} // empty input file 2490 // empty, input file 2347 2491 | external_definition_list 2348 2492 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1; } … … 2350 2494 2351 2495 external_definition_list: 2352 external_definition 2353 | external_definition_list push external_definition 2496 push external_definition pop 2497 { $$ = $2; } 2498 | external_definition_list push external_definition pop 2354 2499 { $$ = $1 ? $1->appendList( $3 ) : $3; } 2355 2500 ; … … 2361 2506 ; 2362 2507 2508 up: 2509 { typedefTable.up( forall ); forall = false; } 2510 ; 2511 2512 down: 2513 { typedefTable.down(); } 2514 ; 2515 2363 2516 external_definition: 2364 2517 declaration 2365 2518 | external_function_definition 2519 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown 2520 { 2521 distExt( $2 ); // mark all fields in list 2522 $$ = $2; 2523 } 2366 2524 | ASM '(' string_literal ')' ';' // GCC, global assembler statement 2367 2525 { 2368 $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm stmt( false, $3, 0 ) ) );2526 $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0 ) ) ); 2369 2527 } 2370 2528 | EXTERN STRINGliteral // C++-style linkage specifier 2371 2529 { 2372 2530 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2373 linkage = LinkageSpec::linkageUpdate( linkage, $2 );2374 } 2375 '{' external_definition_list_opt'}'2531 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2532 } 2533 '{' up external_definition_list_opt down '}' 2376 2534 { 2377 2535 linkage = linkageStack.top(); 2378 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; 2379 2548 $$ = $5; 2380 2549 } 2381 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown 2382 { 2383 distExt( $2 ); // mark all fields in list 2384 $$ = $2; 2385 } 2386 | forall '{' external_definition_list '}' // CFA, namespace 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 } 2387 2572 ; 2388 2573 … … 2395 2580 // declaration must still have a type_specifier. OBSOLESCENT (see 1) 2396 2581 | function_declarator compound_statement 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 } 2582 { $$ = $1->addFunctionBody( $2 ); } 2583 | KR_function_declarator KR_parameter_list_opt compound_statement 2584 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2408 2585 ; 2409 2586 2410 2587 with_clause_opt: 2411 2588 // empty 2412 { $$ = nullptr; }2589 { $$ = nullptr; forall = false; } 2413 2590 | WITH '(' tuple_expression_list ')' 2414 { $$ = new StatementNode( build_with( $3, nullptr ) ); }2591 { $$ = $3; forall = false; } 2415 2592 ; 2416 2593 … … 2418 2595 cfa_function_declaration with_clause_opt compound_statement // CFA 2419 2596 { 2420 typedefTable.addToEnclosingScope( TypedefTable::ID );2421 typedefTable.leaveScope();2422 2597 // Add the function body to the last identifier in the function definition list, i.e., foo3: 2423 2598 // [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; } … … 2428 2603 { 2429 2604 rebindForall( $1, $2 ); 2430 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2431 typedefTable.leaveScope(); 2605 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2606 } 2607 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement 2608 { 2609 rebindForall( $1, $2 ); 2432 2610 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2433 2611 } 2434 2612 // handles default int return type, OBSOLESCENT (see 1) 2435 2613 | type_qualifier_list function_declarator with_clause_opt compound_statement 2436 { 2437 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2438 typedefTable.leaveScope(); 2439 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2440 } 2614 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2441 2615 // handles default int return type, OBSOLESCENT (see 1) 2442 2616 | declaration_qualifier_list function_declarator with_clause_opt compound_statement 2443 { 2444 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2445 typedefTable.leaveScope(); 2446 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2447 } 2617 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2448 2618 // handles default int return type, OBSOLESCENT (see 1) 2449 2619 | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement 2450 { 2451 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2452 typedefTable.leaveScope(); 2453 $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); 2454 } 2620 { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2455 2621 2456 2622 // Old-style K&R function definition, OBSOLESCENT (see 4) 2457 | declaration_specifier KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2623 | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2458 2624 { 2459 2625 rebindForall( $1, $2 ); 2460 typedefTable.addToEnclosingScope( TypedefTable::ID );2461 typedefTable.leaveScope();2462 2626 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 ); 2463 2627 } 2464 2628 // handles default int return type, OBSOLESCENT (see 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 } 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 ); } 2471 2631 // handles default int return type, OBSOLESCENT (see 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 } 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 ); } 2478 2634 // handles default int return type, OBSOLESCENT (see 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 } 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 ); } 2485 2637 ; 2486 2638 … … 2592 2744 paren_identifier: 2593 2745 identifier 2594 { 2595 typedefTable.setNextIdentifier( *$1 ); 2596 $$ = DeclarationNode::newName( $1 ); 2597 } 2746 { $$ = DeclarationNode::newName( $1 ); } 2598 2747 | '(' paren_identifier ')' // redundant parenthesis 2599 2748 { $$ = $2; } … … 2728 2877 paren_type: 2729 2878 typedef 2879 // hide type name in enclosing scope by variable name 2880 { 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 // } // if 2886 } 2730 2887 | '(' paren_type ')' 2731 2888 { $$ = $2; } … … 2738 2895 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 2739 2896 | '(' type_ptr ')' attribute_list_opt 2740 { $$ = $2->addQualifiers( $4 ); } 2897 { $$ = $2->addQualifiers( $4 ); } // redundant parenthesis 2741 2898 ; 2742 2899 … … 2830 2987 typedef: 2831 2988 TYPEDEFname 2832 { 2833 typedefTable.setNextIdentifier( *$1 ); 2834 $$ = DeclarationNode::newName( $1 ); 2835 } 2989 { $$ = DeclarationNode::newName( $1 ); } 2836 2990 | TYPEGENname 2837 { 2838 typedefTable.setNextIdentifier( *$1 ); 2839 $$ = DeclarationNode::newName( $1 ); 2840 } 2991 { $$ = DeclarationNode::newName( $1 ); } 2841 2992 ; 2842 2993 … … 3023 3174 '[' ']' 3024 3175 { $$ = DeclarationNode::newArray( 0, 0, false ); } 3025 // multi_array_dimension handles the '[' '*' ']' case3176 // multi_array_dimension handles the '[' '*' ']' case 3026 3177 | '[' push type_qualifier_list '*' pop ']' // remaining C99 3027 3178 { $$ = DeclarationNode::newVarArray( $3 ); } 3028 3179 | '[' push type_qualifier_list pop ']' 3029 3180 { $$ = DeclarationNode::newArray( 0, $3, false ); } 3030 // multi_array_dimension handles the '[' assignment_expression ']' case3181 // multi_array_dimension handles the '[' assignment_expression ']' case 3031 3182 | '[' push type_qualifier_list assignment_expression pop ']' 3032 3183 { $$ = DeclarationNode::newArray( $4, $3, false ); } … … 3164 3315 // 3165 3316 // cfa_abstract_tuple identifier_or_type_name 3166 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ type_list_opt ')'3317 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')' 3167 3318 // 3168 3319 // since a function return type can be syntactically identical to a tuple type: … … 3223 3374 '[' push cfa_abstract_parameter_list pop ']' 3224 3375 { $$ = 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; } 3225 3380 ; 3226 3381 3227 3382 cfa_abstract_function: // CFA 3228 // '[' ']' '(' cfa_parameter_ type_list_opt ')'3383 // '[' ']' '(' cfa_parameter_ellipsis_list_opt ')' 3229 3384 // { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 3230 cfa_abstract_tuple '(' push cfa_parameter_ type_list_opt pop ')'3385 cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')' 3231 3386 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 3232 | cfa_function_return '(' push cfa_parameter_ type_list_opt pop ')'3387 | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')' 3233 3388 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 3234 3389 ; … … 3261 3416 3262 3417 %% 3418 3263 3419 // ----end of grammar---- 3264 3420
Note:
See TracChangeset
for help on using the changeset viewer.