Changes in src/Parser/parser.yy [46da46b:0442f93f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r46da46b r0442f93f 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 21 22:34:30 202213 // Update Count : 584812 // Last Modified On : Wed Jun 7 14:32:28 2023 13 // Update Count : 6341 14 14 // 15 15 … … 44 44 45 45 #include <cstdio> 46 #include <sstream> 46 47 #include <stack> 47 48 using namespace std; 48 49 49 #include "SynTree/Declaration.h" 50 #include "ParseNode.h" 50 #include "SynTree/Type.h" // for Type 51 #include "DeclarationNode.h" // for DeclarationNode, ... 52 #include "ExpressionNode.h" // for ExpressionNode, ... 53 #include "InitializerNode.h" // for InitializerNode, ... 54 #include "ParserTypes.h" 55 #include "StatementNode.h" // for build_... 51 56 #include "TypedefTable.h" 52 57 #include "TypeData.h" 53 #include "SynTree/LinkageSpec.h"54 58 #include "Common/SemanticError.h" // error_str 55 59 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... 56 60 57 #include "SynTree/Attribute.h" 61 #include "SynTree/Attribute.h" // for Attribute 58 62 59 63 // lex uses __null in a boolean context, it's fine. … … 63 67 64 68 extern DeclarationNode * parseTree; 65 extern LinkageSpec::Spec linkage;69 extern ast::Linkage::Spec linkage; 66 70 extern TypedefTable typedefTable; 67 71 68 stack< LinkageSpec::Spec> linkageStack;72 stack<ast::Linkage::Spec> linkageStack; 69 73 70 74 bool appendStr( string & to, string & from ) { … … 104 108 assert( declList ); 105 109 // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout ); 106 DeclarationNode * c ur = declList, * cl = (new DeclarationNode)->addType( typeSpec );110 DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); 107 111 // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout ); 108 112 // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name; 109 113 110 for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {114 for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 111 115 cl->cloneBaseType( cur ); 112 116 } // for … … 199 203 } // fieldDecl 200 204 201 #define NEW_ZERO new ExpressionNode( build_constantInteger( *new string( "0" ) ) )202 #define NEW_ONE new ExpressionNode( build_constantInteger( *new string( "1" ) ) )205 #define NEW_ZERO new ExpressionNode( build_constantInteger( yylloc, *new string( "0" ) ) ) 206 #define NEW_ONE new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) ) 203 207 #define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right) 204 #define MISSING_ANON_FIELD "Missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body." 205 #define MISSING_LOW "Missing low value for up-to range so index is uninitialized." 206 #define MISSING_HIGH "Missing high value for down-to range so index is uninitialized." 207 208 ForCtrl * forCtrl( DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 208 #define MISSING_ANON_FIELD "syntax error, missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body." 209 #define MISSING_LOW "syntax error, missing low value for up-to range so index is uninitialized." 210 #define MISSING_HIGH "syntax error, missing high value for down-to range so index is uninitialized." 211 212 static ForCtrl * makeForCtrl( 213 const CodeLocation & location, 214 DeclarationNode * init, 215 enum OperKinds compop, 216 ExpressionNode * comp, 217 ExpressionNode * inc ) { 218 // Wrap both comp/inc if they are non-null. 219 if ( comp ) comp = new ExpressionNode( build_binary_val( location, 220 compop, 221 new ExpressionNode( build_varref( location, new string( *init->name ) ) ), 222 comp ) ); 223 if ( inc ) inc = new ExpressionNode( build_binary_val( location, 224 // choose += or -= for upto/downto 225 compop == OperKinds::LThan || compop == OperKinds::LEThan ? OperKinds::PlusAssn : OperKinds::MinusAssn, 226 new ExpressionNode( build_varref( location, new string( *init->name ) ) ), 227 inc ) ); 228 // The StatementNode call frees init->name, it must happen later. 229 return new ForCtrl( new StatementNode( init ), comp, inc ); 230 } 231 232 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 209 233 if ( index->initializer ) { 210 SemanticError( yylloc, " Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );234 SemanticError( yylloc, "syntax error, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." ); 211 235 } // if 212 236 if ( index->next ) { 213 SemanticError( yylloc, " Multiple loop indexes disallowed in for-loop declaration." );237 SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." ); 214 238 } // if 215 return new ForCtrl( index->addInitializer( new InitializerNode( start ) ), 216 // NULL comp/inc => leave blank 217 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index->name ) ) ), comp ) ) : nullptr, 218 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 219 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index->name ) ) ), inc ) ) : nullptr ); 239 DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) ); 240 return makeForCtrl( location, initDecl, compop, comp, inc ); 220 241 } // forCtrl 221 242 222 ForCtrl * forCtrl( ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {223 ConstantExpr * constant = dynamic_cast<ConstantExpr *>(type->expr.get());224 if ( constant && (constant-> get_constant()->get_value() == "0" || constant->get_constant()->get_value()== "1") ) {225 type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(),BasicType::SignedInt ) ) );243 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, string * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 244 ast::ConstantExpr * constant = dynamic_cast<ast::ConstantExpr *>(type->expr.get()); 245 if ( constant && (constant->rep == "0" || constant->rep == "1") ) { 246 type = new ExpressionNode( new ast::CastExpr( location, maybeMoveBuild(type), new ast::BasicType( ast::BasicType::SignedInt ) ) ); 226 247 } // if 227 // type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) ); 228 return new ForCtrl( 229 distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ), 230 // NULL comp/inc => leave blank 231 comp ? new ExpressionNode( build_binary_val( compop, new ExpressionNode( build_varref( new string( *index ) ) ), comp ) ) : nullptr, 232 inc ? new ExpressionNode( build_binary_val( compop == OperKinds::LThan || compop == OperKinds::LEThan ? // choose += or -= for upto/downto 233 OperKinds::PlusAssn : OperKinds::MinusAssn, new ExpressionNode( build_varref( new string( *index ) ) ), inc ) ) : nullptr ); 248 DeclarationNode * initDecl = distAttr( 249 DeclarationNode::newTypeof( type, true ), 250 DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) 251 ); 252 return makeForCtrl( location, initDecl, compop, comp, inc ); 234 253 } // forCtrl 235 254 236 ForCtrl * forCtrl( ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) {237 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(index->expr.get()) ) {238 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );239 } else if ( CommaExpr * commaExpr = dynamic_cast<CommaExpr *>(index->expr.get()) ) {240 if ( NameExpr * identifier = dynamic_cast<NameExpr *>(commaExpr->arg1) ) {241 return forCtrl( type, new string( identifier->name ), start, compop, comp, inc );255 ForCtrl * forCtrl( const CodeLocation & location, ExpressionNode * type, ExpressionNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 256 if ( auto identifier = dynamic_cast<ast::NameExpr *>(index->expr.get()) ) { 257 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 258 } else if ( auto commaExpr = dynamic_cast<ast::CommaExpr *>( index->expr.get() ) ) { 259 if ( auto identifier = commaExpr->arg1.as<ast::NameExpr>() ) { 260 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 242 261 } else { 243 SemanticError( yylloc, " Expression disallowed. Only loop-index nameallowed." ); return nullptr;262 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr; 244 263 } // if 245 264 } else { 246 SemanticError( yylloc, " Expression disallowed. Only loop-index name allowed." ); return nullptr;265 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed. ." ); return nullptr; 247 266 } // if 248 267 } // forCtrl 249 268 250 269 static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) { 251 SemanticError( yylloc, ::toString( " Adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"270 SemanticError( yylloc, ::toString( "syntax error, adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n" 252 271 "Possible cause is misspelled type name or missing generic parameter." ) ); 253 272 } // IdentifierBeforeIdentifier 254 273 255 274 static void IdentifierBeforeType( string & identifier, const char * kind ) { 256 SemanticError( yylloc, ::toString( " Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"275 SemanticError( yylloc, ::toString( "syntax error, identifier \"", identifier, "\" cannot appear before a ", kind, ".\n" 257 276 "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) ); 258 277 } // IdentifierBeforeType … … 281 300 %union { 282 301 Token tok; 283 ParseNode * pn; 284 ExpressionNode * en; 302 ExpressionNode * expr; 285 303 DeclarationNode * decl; 286 AggregateDecl::Aggregate aggKey; 287 TypeDecl::Kind tclass; 288 StatementNode * sn; 289 WaitForStmt * wfs; 290 Expression * constant; 304 ast::AggregateDecl::Aggregate aggKey; 305 ast::TypeDecl::Kind tclass; 306 StatementNode * stmt; 307 ClauseNode * clause; 308 ast::WaitForStmt * wfs; 309 ast::WaitUntilStmt::ClauseNode * wucn; 291 310 CondCtl * ifctl; 292 ForCtrl * fctl; 293 OperKinds compop; 294 LabelNode * label; 295 InitializerNode * in; 296 OperKinds op; 311 ForCtrl * forctl; 312 LabelNode * labels; 313 InitializerNode * init; 314 OperKinds oper; 297 315 std::string * str; 298 bool flag;299 EnumHiding hide;300 CatchStmt::Kind catch_kind;301 GenericExpr * genexpr;316 bool is_volatile; 317 EnumHiding enum_hiding; 318 ast::ExceptionKind except_kind; 319 ast::GenericExpr * genexpr; 302 320 } 303 321 304 // ************************* TERMINAL TOKENS ********************************322 // ************************ TERMINAL TOKENS ******************************** 305 323 306 324 // keywords … … 331 349 %token ATTRIBUTE EXTENSION // GCC 332 350 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN 333 %token CHOOSE FALLTHRU FALLTHROUGH WITH WHEN WAITFOR 351 %token CHOOSE FALLTHRU FALLTHROUGH WITH WHEN WAITFOR WAITUNTIL // CFA 334 352 %token DISABLE ENABLE TRY THROW THROWRESUME AT // CFA 335 353 %token ASM // C99, extension ISO/IEC 9899:1999 Section J.5.10(1) … … 337 355 338 356 // names and constants: lexer differentiates between identifier and typedef names 339 %token<tok> IDENTIFIER QUOTED_IDENTIFIERTYPEDIMname TYPEDEFname TYPEGENname340 %token<tok> TIMEOUT W ORCATCH RECOVER CATCHRESUME FIXUP FINALLY // CFA357 %token<tok> IDENTIFIER TYPEDIMname TYPEDEFname TYPEGENname 358 %token<tok> TIMEOUT WAND WOR CATCH RECOVER CATCHRESUME FIXUP FINALLY // CFA 341 359 %token<tok> INTEGERconstant CHARACTERconstant STRINGliteral 342 360 %token<tok> DIRECTIVE … … 364 382 %type<tok> identifier identifier_at identifier_or_type_name attr_name 365 383 %type<tok> quasi_keyword 366 %type< constant> string_literal384 %type<expr> string_literal 367 385 %type<str> string_literal_list 368 386 369 %type< hide> hide_opt visible_hide_opt387 %type<enum_hiding> hide_opt visible_hide_opt 370 388 371 389 // expressions 372 %type<e n> constant373 %type<e n> tuple tuple_expression_list374 %type<op > ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator375 %type<e n> primary_expression postfix_expression unary_expression376 %type<e n> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression377 %type<e n> shift_expression relational_expression equality_expression378 %type<e n> AND_expression exclusive_OR_expression inclusive_OR_expression379 %type<e n> logical_AND_expression logical_OR_expression380 %type<e n> conditional_expression constant_expression assignment_expression assignment_expression_opt381 %type<e n> comma_expression comma_expression_opt382 %type<e n> argument_expression_list_opt argument_expression_list argument_expression default_initializer_opt390 %type<expr> constant 391 %type<expr> tuple tuple_expression_list 392 %type<oper> ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator 393 %type<expr> primary_expression postfix_expression unary_expression 394 %type<expr> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression 395 %type<expr> shift_expression relational_expression equality_expression 396 %type<expr> AND_expression exclusive_OR_expression inclusive_OR_expression 397 %type<expr> logical_AND_expression logical_OR_expression 398 %type<expr> conditional_expression constant_expression assignment_expression assignment_expression_opt 399 %type<expr> comma_expression comma_expression_opt 400 %type<expr> argument_expression_list_opt argument_expression_list argument_expression default_initializer_opt 383 401 %type<ifctl> conditional_declaration 384 %type<f ctl> for_control_expression for_control_expression_list385 %type< compop> upupeq updown updowneq downupdowneq386 %type<e n> subrange402 %type<forctl> for_control_expression for_control_expression_list 403 %type<oper> upupeq updown updowneq downupdowneq 404 %type<expr> subrange 387 405 %type<decl> asm_name_opt 388 %type<e n> asm_operands_opt asm_operands_list asm_operand389 %type<label > label_list390 %type<e n> asm_clobbers_list_opt391 %type< flag> asm_volatile_opt392 %type<e n> handler_predicate_opt406 %type<expr> asm_operands_opt asm_operands_list asm_operand 407 %type<labels> label_list 408 %type<expr> asm_clobbers_list_opt 409 %type<is_volatile> asm_volatile_opt 410 %type<expr> handler_predicate_opt 393 411 %type<genexpr> generic_association generic_assoc_list 394 412 395 413 // statements 396 %type<sn> statement labeled_statement compound_statement 397 %type<sn> statement_decl statement_decl_list statement_list_nodecl 398 %type<sn> selection_statement if_statement 399 %type<sn> switch_clause_list_opt switch_clause_list 400 %type<en> case_value 401 %type<sn> case_clause case_value_list case_label case_label_list 402 %type<sn> iteration_statement jump_statement 403 %type<sn> expression_statement asm_statement 404 %type<sn> with_statement 405 %type<en> with_clause_opt 406 %type<sn> exception_statement handler_clause finally_clause 407 %type<catch_kind> handler_key 408 %type<sn> mutex_statement 409 %type<en> when_clause when_clause_opt waitfor timeout 410 %type<sn> waitfor_statement 411 %type<wfs> waitfor_clause 414 %type<stmt> statement labeled_statement compound_statement 415 %type<stmt> statement_decl statement_decl_list statement_list_nodecl 416 %type<stmt> selection_statement if_statement 417 %type<clause> switch_clause_list_opt switch_clause_list 418 %type<expr> case_value 419 %type<clause> case_clause case_value_list case_label case_label_list 420 %type<stmt> iteration_statement jump_statement 421 %type<stmt> expression_statement asm_statement 422 %type<stmt> with_statement 423 %type<expr> with_clause_opt 424 %type<stmt> exception_statement 425 %type<clause> handler_clause finally_clause 426 %type<except_kind> handler_key 427 %type<stmt> mutex_statement 428 %type<expr> when_clause when_clause_opt waitfor waituntil timeout 429 %type<stmt> waitfor_statement waituntil_statement 430 %type<wfs> wor_waitfor_clause 431 %type<wucn> waituntil_clause wand_waituntil_clause wor_waituntil_clause 412 432 413 433 // declarations … … 421 441 %type<decl> assertion assertion_list assertion_list_opt 422 442 423 %type<e n> bit_subrange_size_opt bit_subrange_size443 %type<expr> bit_subrange_size_opt bit_subrange_size 424 444 425 445 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type … … 434 454 435 455 %type<decl> enumerator_list enum_type enum_type_nobody 436 %type<in > enumerator_value_opt456 %type<init> enumerator_value_opt 437 457 438 458 %type<decl> external_definition external_definition_list external_definition_list_opt … … 441 461 442 462 %type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract 443 %type<e n> field field_name_list field_name fraction_constants_opt463 %type<expr> field field_name_list field_name fraction_constants_opt 444 464 445 465 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 482 502 %type<decl> typedef_name typedef_declaration typedef_expression 483 503 484 %type<decl> variable_type_redeclarator type_ptr type_array type_function 504 %type<decl> variable_type_redeclarator variable_type_ptr variable_type_array variable_type_function 505 %type<decl> general_function_declarator function_type_redeclarator function_type_array function_type_no_ptr function_type_ptr 485 506 486 507 %type<decl> type_parameter_redeclarator type_parameter_ptr type_parameter_array type_parameter_function … … 489 510 %type<decl> type_parameter type_parameter_list type_initializer_opt 490 511 491 %type<e n> type_parameters_opt type_list array_type_list512 %type<expr> type_parameters_opt type_list array_type_list 492 513 493 514 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 500 521 501 522 // initializers 502 %type<in > initializer initializer_list_opt initializer_opt523 %type<init> initializer initializer_list_opt initializer_opt 503 524 504 525 // designators 505 %type<e n> designator designator_list designation526 %type<expr> designator designator_list designation 506 527 507 528 … … 512 533 // Similar issues exit with the waitfor statement. 513 534 514 // Order of these lines matters (low-to-high precedence). THEN is left associative over W OR/TIMEOUT/ELSE, WOR is left515 // associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE.535 // Order of these lines matters (low-to-high precedence). THEN is left associative over WAND/WOR/TIMEOUT/ELSE, WAND/WOR 536 // is left associative over TIMEOUT/ELSE, and TIMEOUT is left associative over ELSE. 516 537 %precedence THEN // rule precedence for IF/WAITFOR statement 538 %precedence ANDAND // token precedence for start of WAND in WAITFOR statement 539 %precedence WAND // token precedence for start of WAND in WAITFOR statement 540 %precedence OROR // token precedence for start of WOR in WAITFOR statement 517 541 %precedence WOR // token precedence for start of WOR in WAITFOR statement 518 542 %precedence TIMEOUT // token precedence for start of TIMEOUT in WAITFOR statement … … 592 616 constant: 593 617 // ENUMERATIONconstant is not included here; it is treated as a variable with type "enumeration constant". 594 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( *$1 ) ); }595 | FLOATING_DECIMALconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }596 | FLOATING_FRACTIONconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }597 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( *$1 ) ); }598 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( *$1 ) ); }618 INTEGERconstant { $$ = new ExpressionNode( build_constantInteger( yylloc, *$1 ) ); } 619 | FLOATING_DECIMALconstant { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); } 620 | FLOATING_FRACTIONconstant { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); } 621 | FLOATINGconstant { $$ = new ExpressionNode( build_constantFloat( yylloc, *$1 ) ); } 622 | CHARACTERconstant { $$ = new ExpressionNode( build_constantChar( yylloc, *$1 ) ); } 599 623 ; 600 624 601 625 quasi_keyword: // CFA 602 626 TIMEOUT 627 | WAND 603 628 | WOR 604 629 | CATCH … … 621 646 622 647 string_literal: 623 string_literal_list { $$ = build_constantStr( *$1); }648 string_literal_list { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); } 624 649 ; 625 650 … … 638 663 primary_expression: 639 664 IDENTIFIER // typedef name cannot be used as a variable name 640 { $$ = new ExpressionNode( build_varref( $1 ) ); }665 { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); } 641 666 | quasi_keyword 642 { $$ = new ExpressionNode( build_varref( $1 ) ); }667 { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); } 643 668 | TYPEDIMname // CFA, generic length argument 644 669 // { $$ = new ExpressionNode( new TypeExpr( maybeMoveBuildType( DeclarationNode::newFromTypedef( $1 ) ) ) ); } 645 670 // { $$ = new ExpressionNode( build_varref( $1 ) ); } 646 { $$ = new ExpressionNode( build_dimensionref( $1 ) ); }671 { $$ = new ExpressionNode( build_dimensionref( yylloc, $1 ) ); } 647 672 | tuple 648 673 | '(' comma_expression ')' 649 674 { $$ = $2; } 650 675 | '(' compound_statement ')' // GCC, lambda expression 651 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast<CompoundStmt *>(maybeMoveBuild<Statement>($2) ) ) ); }676 { $$ = new ExpressionNode( new ast::StmtExpr( yylloc, dynamic_cast<ast::CompoundStmt *>( maybeMoveBuild( $2 ) ) ) ); } 652 677 | type_name '.' identifier // CFA, nested type 653 { $$ = new ExpressionNode( build_qualified_expr( $1, build_varref($3 ) ) ); }678 { $$ = new ExpressionNode( build_qualified_expr( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 654 679 | type_name '.' '[' field_name_list ']' // CFA, nested type / tuple field selector 655 680 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 657 682 { 658 683 // add the missing control expression to the GenericExpr and return it 659 $5->control = maybeMoveBuild <Expression>( $3 );684 $5->control = maybeMoveBuild( $3 ); 660 685 $$ = new ExpressionNode( $5 ); 661 686 } … … 664 689 // | RESUME '(' comma_expression ')' compound_statement 665 690 // { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; } 666 | IDENTIFIER IDENTIFIER // syntax error691 | IDENTIFIER IDENTIFIER // invalid syntax rules 667 692 { IdentifierBeforeIdentifier( *$1.str, *$2.str, "n expression" ); $$ = nullptr; } 668 | IDENTIFIER type_qualifier // syntax error693 | IDENTIFIER type_qualifier // invalid syntax rules 669 694 { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; } 670 | IDENTIFIER storage_class // syntax error695 | IDENTIFIER storage_class // invalid syntax rules 671 696 { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; } 672 | IDENTIFIER basic_type_name // syntax error697 | IDENTIFIER basic_type_name // invalid syntax rules 673 698 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 674 | IDENTIFIER TYPEDEFname // syntax error699 | IDENTIFIER TYPEDEFname // invalid syntax rules 675 700 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 676 | IDENTIFIER TYPEGENname // syntax error701 | IDENTIFIER TYPEGENname // invalid syntax rules 677 702 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 678 703 ; … … 683 708 { 684 709 // steal the association node from the singleton and delete the wrapper 685 $1->associations.splice($1->associations.end(), $3->associations); 710 assert( 1 == $3->associations.size() ); 711 $1->associations.push_back( $3->associations.front() ); 686 712 delete $3; 687 713 $$ = $1; … … 693 719 { 694 720 // create a GenericExpr wrapper with one association pair 695 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>( $3 ) } } );721 $$ = new ast::GenericExpr( yylloc, nullptr, { { maybeMoveBuildType( $1 ), maybeMoveBuild( $3 ) } } ); 696 722 } 697 723 | DEFAULT ':' assignment_expression 698 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>( $3 ) } } ); }724 { $$ = new ast::GenericExpr( yylloc, nullptr, { { maybeMoveBuild( $3 ) } } ); } 699 725 ; 700 726 … … 705 731 // Switching to this behaviour may help check if a C compatibilty case uses comma-exprs in subscripts. 706 732 // Current: Commas in subscripts make tuples. 707 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, new ExpressionNode( build_tuple((ExpressionNode *)($3->set_last( $5 ) ) )) ) ); }733 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)($3->set_last( $5 ) ) )) ) ); } 708 734 | postfix_expression '[' assignment_expression ']' 709 735 // CFA, comma_expression disallowed in this context because it results in a common user error: subscripting a … … 711 737 // little advantage to this feature and many disadvantages. It is possible to write x[(i,j)] in CFA, which is 712 738 // equivalent to the old x[i,j]. 713 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }739 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 714 740 | constant '[' assignment_expression ']' // 3[a], 'a'[a], 3.5[a] 715 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, $1, $3 ) ); }741 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 716 742 | string_literal '[' assignment_expression ']' // "abc"[3], 3["abc"] 717 { $$ = new ExpressionNode( build_binary_val( OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }743 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 718 744 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 719 745 { 720 746 Token fn; 721 747 fn.str = new std::string( "?{}" ); // location undefined - use location of '{'? 722 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref(fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) );748 $$ = new ExpressionNode( new ast::ConstructorExpr( yylloc, build_func( yylloc, new ExpressionNode( build_varref( yylloc, fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 723 749 } 724 750 | postfix_expression '(' argument_expression_list_opt ')' 725 { $$ = new ExpressionNode( build_func( $1, $3 ) ); }751 { $$ = new ExpressionNode( build_func( yylloc, $1, $3 ) ); } 726 752 | VA_ARG '(' primary_expression ',' declaration_specifier_nobody abstract_parameter_declarator_opt ')' 727 753 // { SemanticError( yylloc, "va_arg is currently unimplemented." ); $$ = nullptr; } 728 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(new string( "__builtin_va_arg") ) ),754 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, new string( "__builtin_va_arg") ) ), 729 755 (ExpressionNode *)($3->set_last( (ExpressionNode *)($6 ? $6->addType( $5 ) : $5) )) ) ); } 730 756 | postfix_expression '`' identifier // CFA, postfix call 731 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(build_postfix_name( $3 ) ) ), $1 ) ); }757 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 732 758 | constant '`' identifier // CFA, postfix call 733 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(build_postfix_name( $3 ) ) ), $1 ) ); }759 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 734 760 | string_literal '`' identifier // CFA, postfix call 735 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 )) ); }761 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 736 762 | postfix_expression '.' identifier 737 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref($3 ) ) ); }763 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 738 764 | postfix_expression '.' INTEGERconstant // CFA, tuple index 739 { $$ = new ExpressionNode( build_fieldSel( $1, build_constantInteger(*$3 ) ) ); }765 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); } 740 766 | postfix_expression FLOATING_FRACTIONconstant // CFA, tuple index 741 { $$ = new ExpressionNode( build_fieldSel( $1, build_field_name_FLOATING_FRACTIONconstant(*$2 ) ) ); }767 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_field_name_FLOATING_FRACTIONconstant( yylloc, *$2 ) ) ); } 742 768 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 743 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple($4 ) ) ); }769 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 744 770 | postfix_expression '.' aggregate_control 745 { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); }771 { $$ = new ExpressionNode( build_keyword_cast( yylloc, $3, $1 ) ); } 746 772 | postfix_expression ARROW identifier 747 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref($3 ) ) ); }773 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 748 774 | postfix_expression ARROW INTEGERconstant // CFA, tuple index 749 { $$ = new ExpressionNode( build_pfieldSel( $1, build_constantInteger(*$3 ) ) ); }775 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); } 750 776 | postfix_expression ARROW '[' field_name_list ']' // CFA, tuple field selector 751 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple($4 ) ) ); }777 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 752 778 | postfix_expression ICR 753 { $$ = new ExpressionNode( build_unary_ptr(OperKinds::IncrPost, $1 ) ); }779 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::IncrPost, $1 ) ); } 754 780 | postfix_expression DECR 755 { $$ = new ExpressionNode( build_unary_ptr(OperKinds::DecrPost, $1 ) ); }781 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::DecrPost, $1 ) ); } 756 782 | '(' type_no_function ')' '{' initializer_list_opt comma_opt '}' // C99, compound-literal 757 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); }783 { $$ = new ExpressionNode( build_compoundLiteral( yylloc, $2, new InitializerNode( $5, true ) ) ); } 758 784 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 759 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); }785 { $$ = new ExpressionNode( build_compoundLiteral( yylloc, $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 760 786 | '^' primary_expression '{' argument_expression_list_opt '}' // CFA, destructor call 761 787 { 762 788 Token fn; 763 789 fn.str = new string( "^?{}" ); // location undefined 764 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref(fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) );790 $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ); 765 791 } 766 792 ; … … 781 807 '@' // CFA, default parameter 782 808 { SemanticError( yylloc, "Default parameter for argument is currently unimplemented." ); $$ = nullptr; } 783 809 // { $$ = new ExpressionNode( build_constantInteger( *new string( "2" ) ) ); } 784 810 | assignment_expression 785 811 ; … … 793 819 field_name 794 820 | FLOATING_DECIMALconstant field 795 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), maybeMoveBuild<Expression>( $2 ) ) ); }821 { $$ = new ExpressionNode( build_fieldSel( yylloc, new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( yylloc, *$1 ) ), maybeMoveBuild( $2 ) ) ); } 796 822 | FLOATING_DECIMALconstant '[' field_name_list ']' 797 { $$ = new ExpressionNode( build_fieldSel( new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( *$1 ) ), build_tuple($3 ) ) ); }823 { $$ = new ExpressionNode( build_fieldSel( yylloc, new ExpressionNode( build_field_name_FLOATING_DECIMALconstant( yylloc, *$1 ) ), build_tuple( yylloc, $3 ) ) ); } 798 824 | field_name '.' field 799 { $$ = new ExpressionNode( build_fieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }825 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, maybeMoveBuild( $3 ) ) ); } 800 826 | field_name '.' '[' field_name_list ']' 801 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple($4 ) ) ); }827 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 802 828 | field_name ARROW field 803 { $$ = new ExpressionNode( build_pfieldSel( $1, maybeMoveBuild<Expression>( $3 ) ) ); }829 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, maybeMoveBuild( $3 ) ) ); } 804 830 | field_name ARROW '[' field_name_list ']' 805 { $$ = new ExpressionNode( build_pfieldSel( $1, build_tuple($4 ) ) ); }831 { $$ = new ExpressionNode( build_pfieldSel( yylloc, $1, build_tuple( yylloc, $4 ) ) ); } 806 832 ; 807 833 808 834 field_name: 809 835 INTEGERconstant fraction_constants_opt 810 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantInteger(*$1 ), $2 ) ); }836 { $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_constantInteger( yylloc, *$1 ), $2 ) ); } 811 837 | FLOATINGconstant fraction_constants_opt 812 { $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant(*$1 ), $2 ) ); }838 { $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_field_name_FLOATINGconstant( yylloc, *$1 ), $2 ) ); } 813 839 | identifier_at fraction_constants_opt // CFA, allow anonymous fields 814 840 { 815 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref($1 ), $2 ) );841 $$ = new ExpressionNode( build_field_name_fraction_constants( yylloc, build_varref( yylloc, $1 ), $2 ) ); 816 842 } 817 843 ; … … 822 848 | fraction_constants_opt FLOATING_FRACTIONconstant 823 849 { 824 Expression * constant = build_field_name_FLOATING_FRACTIONconstant(*$2 );825 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( $1,constant ) ) : new ExpressionNode( constant );850 ast::Expr * constant = build_field_name_FLOATING_FRACTIONconstant( yylloc, *$2 ); 851 $$ = $1 != nullptr ? new ExpressionNode( build_fieldSel( yylloc, $1, constant ) ) : new ExpressionNode( constant ); 826 852 } 827 853 ; … … 833 859 | constant 834 860 | string_literal 835 { $$ = new ExpressionNode( $1 ); }861 { $$ = $1; } 836 862 | EXTENSION cast_expression // GCC 837 863 { $$ = $2->set_extension( true ); } … … 842 868 { 843 869 switch ( $1 ) { 844 845 $$ = new ExpressionNode( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) );870 case OperKinds::AddressOf: 871 $$ = new ExpressionNode( new ast::AddressExpr( maybeMoveBuild( $2 ) ) ); 846 872 break; 847 848 $$ = new ExpressionNode( build_unary_val( $1, $2 ) );873 case OperKinds::PointTo: 874 $$ = new ExpressionNode( build_unary_val( yylloc, $1, $2 ) ); 849 875 break; 850 851 $$ = new ExpressionNode( new AddressExpr( new AddressExpr( maybeMoveBuild<Expression>( $2 ) ) ) );876 case OperKinds::And: 877 $$ = new ExpressionNode( new ast::AddressExpr( new ast::AddressExpr( maybeMoveBuild( $2 ) ) ) ); 852 878 break; 853 879 default: 854 880 assert( false ); 855 881 } 856 882 } 857 883 | unary_operator cast_expression 858 { $$ = new ExpressionNode( build_unary_val($1, $2 ) ); }884 { $$ = new ExpressionNode( build_unary_val( yylloc, $1, $2 ) ); } 859 885 | ICR unary_expression 860 { $$ = new ExpressionNode( build_unary_ptr(OperKinds::Incr, $2 ) ); }886 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::Incr, $2 ) ); } 861 887 | DECR unary_expression 862 { $$ = new ExpressionNode( build_unary_ptr(OperKinds::Decr, $2 ) ); }888 { $$ = new ExpressionNode( build_unary_val( yylloc, OperKinds::Decr, $2 ) ); } 863 889 | SIZEOF unary_expression 864 { $$ = new ExpressionNode( new SizeofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }890 { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuild( $2 ) ) ); } 865 891 | SIZEOF '(' type_no_function ')' 866 { $$ = new ExpressionNode( new SizeofExpr(maybeMoveBuildType( $3 ) ) ); }892 { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); } 867 893 | ALIGNOF unary_expression // GCC, variable alignment 868 { $$ = new ExpressionNode( new AlignofExpr( maybeMoveBuild<Expression>( $2 ) ) ); }894 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuild( $2 ) ) ); } 869 895 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 870 { $$ = new ExpressionNode( new AlignofExpr(maybeMoveBuildType( $3 ) ) ); }896 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); } 871 897 | OFFSETOF '(' type_no_function ',' identifier ')' 872 { $$ = new ExpressionNode( build_offsetOf( $3, build_varref($5 ) ) ); }898 { $$ = new ExpressionNode( build_offsetOf( yylloc, $3, build_varref( yylloc, $5 ) ) ); } 873 899 | TYPEID '(' type_no_function ')' 874 900 { … … 895 921 unary_expression 896 922 | '(' type_no_function ')' cast_expression 897 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }923 { $$ = new ExpressionNode( build_cast( yylloc, $2, $4 ) ); } 898 924 | '(' aggregate_control '&' ')' cast_expression // CFA 899 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }925 { $$ = new ExpressionNode( build_keyword_cast( yylloc, $2, $5 ) ); } 900 926 | '(' aggregate_control '*' ')' cast_expression // CFA 901 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }927 { $$ = new ExpressionNode( build_keyword_cast( yylloc, $2, $5 ) ); } 902 928 | '(' VIRTUAL ')' cast_expression // CFA 903 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $4 ), maybeMoveBuildType( nullptr ) ) ); }929 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $4 ), maybeMoveBuildType( nullptr ) ) ); } 904 930 | '(' VIRTUAL type_no_function ')' cast_expression // CFA 905 { $$ = new ExpressionNode( new VirtualCastExpr( maybeMoveBuild<Expression>( $5 ), maybeMoveBuildType( $3 ) ) ); }931 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); } 906 932 | '(' RETURN type_no_function ')' cast_expression // CFA 907 { $$ = new ExpressionNode( build_cast( $3, $5, CastExpr::Return ) ); }933 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } 908 934 | '(' COERCE type_no_function ')' cast_expression // CFA 909 935 { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; } … … 911 937 { SemanticError( yylloc, "Qualifier cast is currently unimplemented." ); $$ = nullptr; } 912 938 // | '(' type_no_function ')' tuple 913 // { $$ = new ExpressionNode( build_cast($2, $4 ) ); }939 // { $$ = new ast::ExpressionNode( build_cast( yylloc, $2, $4 ) ); } 914 940 ; 915 941 … … 929 955 cast_expression 930 956 | exponential_expression '\\' cast_expression 931 { $$ = new ExpressionNode( build_binary_val( OperKinds::Exp, $1, $3 ) ); }957 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Exp, $1, $3 ) ); } 932 958 ; 933 959 … … 935 961 exponential_expression 936 962 | multiplicative_expression '*' exponential_expression 937 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mul, $1, $3 ) ); }963 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Mul, $1, $3 ) ); } 938 964 | multiplicative_expression '/' exponential_expression 939 { $$ = new ExpressionNode( build_binary_val( OperKinds::Div, $1, $3 ) ); }965 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Div, $1, $3 ) ); } 940 966 | multiplicative_expression '%' exponential_expression 941 { $$ = new ExpressionNode( build_binary_val( OperKinds::Mod, $1, $3 ) ); }967 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Mod, $1, $3 ) ); } 942 968 ; 943 969 … … 945 971 multiplicative_expression 946 972 | additive_expression '+' multiplicative_expression 947 { $$ = new ExpressionNode( build_binary_val( OperKinds::Plus, $1, $3 ) ); }973 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Plus, $1, $3 ) ); } 948 974 | additive_expression '-' multiplicative_expression 949 { $$ = new ExpressionNode( build_binary_val( OperKinds::Minus, $1, $3 ) ); }975 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Minus, $1, $3 ) ); } 950 976 ; 951 977 … … 953 979 additive_expression 954 980 | shift_expression LS additive_expression 955 { $$ = new ExpressionNode( build_binary_val( OperKinds::LShift, $1, $3 ) ); }981 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LShift, $1, $3 ) ); } 956 982 | shift_expression RS additive_expression 957 { $$ = new ExpressionNode( build_binary_val( OperKinds::RShift, $1, $3 ) ); }983 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::RShift, $1, $3 ) ); } 958 984 ; 959 985 … … 961 987 shift_expression 962 988 | relational_expression '<' shift_expression 963 { $$ = new ExpressionNode( build_binary_val( OperKinds::LThan, $1, $3 ) ); }989 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LThan, $1, $3 ) ); } 964 990 | relational_expression '>' shift_expression 965 { $$ = new ExpressionNode( build_binary_val( OperKinds::GThan, $1, $3 ) ); }991 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::GThan, $1, $3 ) ); } 966 992 | relational_expression LE shift_expression 967 { $$ = new ExpressionNode( build_binary_val( OperKinds::LEThan, $1, $3 ) ); }993 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::LEThan, $1, $3 ) ); } 968 994 | relational_expression GE shift_expression 969 { $$ = new ExpressionNode( build_binary_val( OperKinds::GEThan, $1, $3 ) ); }995 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::GEThan, $1, $3 ) ); } 970 996 ; 971 997 … … 973 999 relational_expression 974 1000 | equality_expression EQ relational_expression 975 { $$ = new ExpressionNode( build_binary_val( OperKinds::Eq, $1, $3 ) ); }1001 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Eq, $1, $3 ) ); } 976 1002 | equality_expression NE relational_expression 977 { $$ = new ExpressionNode( build_binary_val( OperKinds::Neq, $1, $3 ) ); }1003 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Neq, $1, $3 ) ); } 978 1004 ; 979 1005 … … 981 1007 equality_expression 982 1008 | AND_expression '&' equality_expression 983 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitAnd, $1, $3 ) ); }1009 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::BitAnd, $1, $3 ) ); } 984 1010 ; 985 1011 … … 987 1013 AND_expression 988 1014 | exclusive_OR_expression '^' AND_expression 989 { $$ = new ExpressionNode( build_binary_val( OperKinds::Xor, $1, $3 ) ); }1015 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Xor, $1, $3 ) ); } 990 1016 ; 991 1017 … … 993 1019 exclusive_OR_expression 994 1020 | inclusive_OR_expression '|' exclusive_OR_expression 995 { $$ = new ExpressionNode( build_binary_val( OperKinds::BitOr, $1, $3 ) ); }1021 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::BitOr, $1, $3 ) ); } 996 1022 ; 997 1023 … … 999 1025 inclusive_OR_expression 1000 1026 | logical_AND_expression ANDAND inclusive_OR_expression 1001 { $$ = new ExpressionNode( build_and_or( $1, $3, true) ); }1027 { $$ = new ExpressionNode( build_and_or( yylloc, $1, $3, ast::AndExpr ) ); } 1002 1028 ; 1003 1029 … … 1005 1031 logical_AND_expression 1006 1032 | logical_OR_expression OROR logical_AND_expression 1007 { $$ = new ExpressionNode( build_and_or( $1, $3, false) ); }1033 { $$ = new ExpressionNode( build_and_or( yylloc, $1, $3, ast::OrExpr ) ); } 1008 1034 ; 1009 1035 … … 1011 1037 logical_OR_expression 1012 1038 | logical_OR_expression '?' comma_expression ':' conditional_expression 1013 { $$ = new ExpressionNode( build_cond( $1, $3, $5 ) ); }1039 { $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); } 1014 1040 // FIX ME: computes $1 twice 1015 1041 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 1016 { $$ = new ExpressionNode( build_cond( $1, $1, $4 ) ); }1042 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1, $4 ) ); } 1017 1043 ; 1018 1044 … … 1029 1055 // SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr; 1030 1056 // } else { 1031 $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) );1057 $$ = new ExpressionNode( build_binary_val( yylloc, $2, $1, $3 ) ); 1032 1058 // } // if 1033 1059 } … … 1074 1100 // { $$ = new ExpressionNode( build_tuple( $3 ) ); } 1075 1101 '[' ',' tuple_expression_list ']' 1076 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); }1102 { $$ = new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 1077 1103 | '[' push assignment_expression pop ',' tuple_expression_list ']' 1078 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); }1104 { $$ = new ExpressionNode( build_tuple( yylloc, (ExpressionNode *)($3->set_last( $6 ) ) )); } 1079 1105 ; 1080 1106 … … 1092 1118 assignment_expression 1093 1119 | comma_expression ',' assignment_expression 1094 { $$ = new ExpressionNode( new CommaExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }1120 { $$ = new ExpressionNode( new ast::CommaExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1095 1121 ; 1096 1122 … … 1113 1139 | mutex_statement 1114 1140 | waitfor_statement 1141 | waituntil_statement 1115 1142 | exception_statement 1116 1143 | enable_disable_statement … … 1118 1145 | asm_statement 1119 1146 | DIRECTIVE 1120 { $$ = new StatementNode( build_directive( $1 ) ); }1147 { $$ = new StatementNode( build_directive( yylloc, $1 ) ); } 1121 1148 ; 1122 1149 … … 1124 1151 // labels cannot be identifiers 0 or 1 1125 1152 identifier_or_type_name ':' attribute_list_opt statement 1126 { $$ = $4->add_label( $1, $3 ); }1127 | identifier_or_type_name ':' attribute_list_opt error // syntax error1128 { 1129 SemanticError( yylloc, ::toString( " Label \"", *$1.str, "\" must be associated with a statement, "1153 { $$ = $4->add_label( yylloc, $1, $3 ); } 1154 | identifier_or_type_name ':' attribute_list_opt error // invalid syntax rule 1155 { 1156 SemanticError( yylloc, ::toString( "syntx error, label \"", *$1.str, "\" must be associated with a statement, " 1130 1157 "where a declaration, case, or default is not a statement. " 1131 1158 "Move the label or terminate with a semi-colon." ) ); … … 1136 1163 compound_statement: 1137 1164 '{' '}' 1138 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); }1165 { $$ = new StatementNode( build_compound( yylloc, (StatementNode *)0 ) ); } 1139 1166 | '{' push 1140 1167 local_label_declaration_opt // GCC, local labels appear at start of block 1141 1168 statement_decl_list // C99, intermix declarations and statements 1142 1169 pop '}' 1143 { $$ = new StatementNode( build_compound( $4 ) ); }1170 { $$ = new StatementNode( build_compound( yylloc, $4 ) ); } 1144 1171 ; 1145 1172 … … 1166 1193 | statement_list_nodecl statement 1167 1194 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1168 | statement_list_nodecl error // syntax error1169 { SemanticError( yylloc, " Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }1195 | statement_list_nodecl error // invalid syntax rule 1196 { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; } 1170 1197 ; 1171 1198 1172 1199 expression_statement: 1173 1200 comma_expression_opt ';' 1174 { $$ = new StatementNode( build_expr( $1 ) ); } 1175 | MUTEX '(' ')' comma_expression ';' 1176 { $$ = new StatementNode( build_mutex( nullptr, new StatementNode( build_expr( $4 ) ) ) ); } 1201 { $$ = new StatementNode( build_expr( yylloc, $1 ) ); } 1177 1202 ; 1178 1203 … … 1183 1208 { $$ = $2; } 1184 1209 | SWITCH '(' comma_expression ')' case_clause 1185 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); }1210 { $$ = new StatementNode( build_switch( yylloc, true, $3, $5 ) ); } 1186 1211 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 1187 1212 { 1188 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) );1213 StatementNode *sw = new StatementNode( build_switch( yylloc, true, $3, $8 ) ); 1189 1214 // The semantics of the declaration list is changed to include associated initialization, which is performed 1190 1215 // *before* the transfer to the appropriate case clause by hoisting the declarations into a compound … … 1192 1217 // therefore, are removed from the grammar even though C allows it. The change also applies to choose 1193 1218 // statement. 1194 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;1195 } 1196 | SWITCH '(' comma_expression ')' '{' error '}' // CFA, syntaxerror1197 { SemanticError( yylloc, " Only declarations canappear before the list of case clauses." ); $$ = nullptr; }1219 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1220 } 1221 | SWITCH '(' comma_expression ')' '{' error '}' // CFA, invalid syntax rule error 1222 { SemanticError( yylloc, "synatx error, declarations can only appear before the list of case clauses." ); $$ = nullptr; } 1198 1223 | CHOOSE '(' comma_expression ')' case_clause // CFA 1199 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); }1224 { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); } 1200 1225 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 1201 1226 { 1202 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) );1203 $$ = $7 ? new StatementNode( build_compound( (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw;1204 } 1205 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, syntax error1206 { SemanticError( yylloc, " Only declarations canappear before the list of case clauses." ); $$ = nullptr; }1227 StatementNode *sw = new StatementNode( build_switch( yylloc, false, $3, $8 ) ); 1228 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1229 } 1230 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, invalid syntax rule 1231 { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; } 1207 1232 ; 1208 1233 … … 1210 1235 IF '(' conditional_declaration ')' statement %prec THEN 1211 1236 // explicitly deal with the shift/reduce conflict on if/else 1212 { $$ = new StatementNode( build_if( $3, maybe_build_compound($5 ), nullptr ) ); }1237 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); } 1213 1238 | IF '(' conditional_declaration ')' statement ELSE statement 1214 { $$ = new StatementNode( build_if( $3, maybe_build_compound( $5 ), maybe_build_compound($7 ) ) ); }1239 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); } 1215 1240 ; 1216 1241 … … 1224 1249 | declaration comma_expression // semi-colon separated 1225 1250 { $$ = new CondCtl( $1, $2 ); } 1226 1251 ; 1227 1252 1228 1253 // CASE and DEFAULT clauses are only allowed in the SWITCH statement, precluding Duff's device. In addition, a case … … 1232 1257 constant_expression { $$ = $1; } 1233 1258 | constant_expression ELLIPSIS constant_expression // GCC, subrange 1234 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }1259 { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1235 1260 | subrange // CFA, subrange 1236 1261 ; 1237 1262 1238 1263 case_value_list: // CFA 1239 case_value { $$ = new StatementNode( build_case($1 ) ); }1264 case_value { $$ = new ClauseNode( build_case( yylloc, $1 ) ); } 1240 1265 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5" 1241 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 )) ) ); }1266 | case_value_list ',' case_value { $$ = $1->set_last( new ClauseNode( build_case( yylloc, $3 ) ) ); } 1242 1267 ; 1243 1268 1244 1269 case_label: // CFA 1245 CASE error // syntax error1246 { SemanticError( yylloc, " Missing case listafter case." ); $$ = nullptr; }1270 CASE error // invalid syntax rule 1271 { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; } 1247 1272 | CASE case_value_list ':' { $$ = $2; } 1248 | CASE case_value_list error // syntax error1249 { SemanticError( yylloc, " Missing colonafter case list." ); $$ = nullptr; }1250 | DEFAULT ':' { $$ = new StatementNode( build_default() ); }1273 | CASE case_value_list error // invalid syntax rule 1274 { SemanticError( yylloc, "syntax error, colon missing after case list." ); $$ = nullptr; } 1275 | DEFAULT ':' { $$ = new ClauseNode( build_default( yylloc ) ); } 1251 1276 // A semantic check is required to ensure only one default clause per switch/choose statement. 1252 | DEFAULT error // syntax error1253 { SemanticError( yylloc, " Missing colonafter default." ); $$ = nullptr; }1277 | DEFAULT error // invalid syntax rules 1278 { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; } 1254 1279 ; 1255 1280 1256 1281 case_label_list: // CFA 1257 1282 case_label 1258 | case_label_list case_label { $$ = (StatementNode *)( $1->set_last( $2 )); }1283 | case_label_list case_label { $$ = $1->set_last( $2 ); } 1259 1284 ; 1260 1285 1261 1286 case_clause: // CFA 1262 case_label_list statement { $$ = $1->append_last_case( maybe_build_compound( $2 ) ); }1287 case_label_list statement { $$ = $1->append_last_case( maybe_build_compound( yylloc, $2 ) ); } 1263 1288 ; 1264 1289 … … 1271 1296 switch_clause_list: // CFA 1272 1297 case_label_list statement_list_nodecl 1273 { $$ = $1->append_last_case( new StatementNode( build_compound( $2 ) ) ); }1298 { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); } 1274 1299 | switch_clause_list case_label_list statement_list_nodecl 1275 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( $3 )) ) ) ); }1300 { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ); } 1276 1301 ; 1277 1302 1278 1303 iteration_statement: 1279 1304 WHILE '(' ')' statement %prec THEN // CFA => while ( 1 ) 1280 { $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound($4 ) ) ); }1305 { $$ = new StatementNode( build_while( yylloc, new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( yylloc, $4 ) ) ); } 1281 1306 | WHILE '(' ')' statement ELSE statement // CFA 1282 1307 { 1283 $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound($4 ) ) );1284 SemanticWarning( yylloc, Warning::SuperfluousElse , "");1308 $$ = new StatementNode( build_while( yylloc, new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( yylloc, $4 ) ) ); 1309 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1285 1310 } 1286 1311 | WHILE '(' conditional_declaration ')' statement %prec THEN 1287 { $$ = new StatementNode( build_while( $3, maybe_build_compound($5 ) ) ); }1312 { $$ = new StatementNode( build_while( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); } 1288 1313 | WHILE '(' conditional_declaration ')' statement ELSE statement // CFA 1289 { $$ = new StatementNode( build_while( $3, maybe_build_compound($5 ), $7 ) ); }1314 { $$ = new StatementNode( build_while( yylloc, $3, maybe_build_compound( yylloc, $5 ), $7 ) ); } 1290 1315 | DO statement WHILE '(' ')' ';' // CFA => do while( 1 ) 1291 { $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound($2 ) ) ); }1316 { $$ = new StatementNode( build_do_while( yylloc, NEW_ONE, maybe_build_compound( yylloc, $2 ) ) ); } 1292 1317 | DO statement WHILE '(' ')' ELSE statement // CFA 1293 1318 { 1294 $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound($2 ) ) );1295 SemanticWarning( yylloc, Warning::SuperfluousElse , "");1319 $$ = new StatementNode( build_do_while( yylloc, NEW_ONE, maybe_build_compound( yylloc, $2 ) ) ); 1320 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1296 1321 } 1297 1322 | DO statement WHILE '(' comma_expression ')' ';' 1298 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound($2 ) ) ); }1323 { $$ = new StatementNode( build_do_while( yylloc, $5, maybe_build_compound( yylloc, $2 ) ) ); } 1299 1324 | DO statement WHILE '(' comma_expression ')' ELSE statement // CFA 1300 { $$ = new StatementNode( build_do_while( $5, maybe_build_compound($2 ), $8 ) ); }1325 { $$ = new StatementNode( build_do_while( yylloc, $5, maybe_build_compound( yylloc, $2 ), $8 ) ); } 1301 1326 | FOR '(' ')' statement %prec THEN // CFA => for ( ;; ) 1302 { $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound($4 ) ) ); }1327 { $$ = new StatementNode( build_for( yylloc, new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( yylloc, $4 ) ) ); } 1303 1328 | FOR '(' ')' statement ELSE statement // CFA 1304 1329 { 1305 $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound($4 ) ) );1306 SemanticWarning( yylloc, Warning::SuperfluousElse , "");1330 $$ = new StatementNode( build_for( yylloc, new ForCtrl( nullptr, nullptr, nullptr ), maybe_build_compound( yylloc, $4 ) ) ); 1331 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1307 1332 } 1308 1333 | FOR '(' for_control_expression_list ')' statement %prec THEN 1309 { $$ = new StatementNode( build_for( $3, maybe_build_compound($5 ) ) ); }1334 { $$ = new StatementNode( build_for( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); } 1310 1335 | FOR '(' for_control_expression_list ')' statement ELSE statement // CFA 1311 { $$ = new StatementNode( build_for( $3, maybe_build_compound($5 ), $7 ) ); }1336 { $$ = new StatementNode( build_for( yylloc, $3, maybe_build_compound( yylloc, $5 ), $7 ) ); } 1312 1337 ; 1313 1338 … … 1323 1348 if ( $1->condition ) { 1324 1349 if ( $3->condition ) { 1325 $1->condition->expr.reset( new LogicalExpr( $1->condition->expr.release(), $3->condition->expr.release(), true) );1350 $1->condition->expr.reset( new ast::LogicalExpr( yylloc, $1->condition->expr.release(), $3->condition->expr.release(), ast::AndExpr ) ); 1326 1351 } // if 1327 1352 } else $1->condition = $3->condition; 1328 1353 if ( $1->change ) { 1329 1354 if ( $3->change ) { 1330 $1->change->expr.reset( new CommaExpr($1->change->expr.release(), $3->change->expr.release() ) );1355 $1->change->expr.reset( new ast::CommaExpr( yylloc, $1->change->expr.release(), $3->change->expr.release() ) ); 1331 1356 } // if 1332 1357 } else $1->change = $3->change; … … 1337 1362 for_control_expression: 1338 1363 ';' comma_expression_opt ';' comma_expression_opt 1339 { $$ = new ForCtrl( (ExpressionNode * )nullptr, $2, $4 ); }1364 { $$ = new ForCtrl( nullptr, $2, $4 ); } 1340 1365 | comma_expression ';' comma_expression_opt ';' comma_expression_opt 1341 { $$ = new ForCtrl( $1, $3, $5 ); } 1366 { 1367 StatementNode * init = $1 ? new StatementNode( new ast::ExprStmt( yylloc, maybeMoveBuild( $1 ) ) ) : nullptr; 1368 $$ = new ForCtrl( init, $3, $5 ); 1369 } 1342 1370 | declaration comma_expression_opt ';' comma_expression_opt // C99, declaration has ';' 1343 { $$ = new ForCtrl( $1, $2, $4 ); }1371 { $$ = new ForCtrl( new StatementNode( $1 ), $2, $4 ); } 1344 1372 1345 1373 | '@' ';' comma_expression // CFA, empty loop-index 1346 { $$ = new ForCtrl( (ExpressionNode *)nullptr, $3, nullptr ); }1374 { $$ = new ForCtrl( nullptr, $3, nullptr ); } 1347 1375 | '@' ';' comma_expression ';' comma_expression // CFA, empty loop-index 1348 { $$ = new ForCtrl( (ExpressionNode *)nullptr, $3, $5 ); }1376 { $$ = new ForCtrl( nullptr, $3, $5 ); } 1349 1377 1350 1378 | comma_expression // CFA, anonymous loop-index 1351 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); }1379 { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), NEW_ZERO, OperKinds::LThan, $1->clone(), NEW_ONE ); } 1352 1380 | downupdowneq comma_expression // CFA, anonymous loop-index 1353 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $1, NEW_ZERO, $2->clone() ), $1, UPDOWN( $1, $2->clone(), NEW_ZERO ), NEW_ONE ); }1381 { $$ = forCtrl( yylloc, $2, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $1, NEW_ZERO, $2->clone() ), $1, UPDOWN( $1, $2->clone(), NEW_ZERO ), NEW_ONE ); } 1354 1382 1355 1383 | comma_expression updowneq comma_expression // CFA, anonymous loop-index 1356 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), NEW_ONE ); }1384 { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), NEW_ONE ); } 1357 1385 | '@' updowneq comma_expression // CFA, anonymous loop-index 1358 1386 { 1359 1387 if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1360 else $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, NEW_ONE );1388 else $$ = forCtrl( yylloc, $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, NEW_ONE ); 1361 1389 } 1362 1390 | comma_expression updowneq '@' // CFA, anonymous loop-index … … 1366 1394 } 1367 1395 | comma_expression updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index 1368 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), $5 ); }1396 { $$ = forCtrl( yylloc, $1, new string( DeclarationNode::anonymous.newName() ), UPDOWN( $2, $1->clone(), $3 ), $2, UPDOWN( $2, $3->clone(), $1->clone() ), $5 ); } 1369 1397 | '@' updowneq comma_expression '~' comma_expression // CFA, anonymous loop-index 1370 1398 { 1371 1399 if ( $2 == OperKinds::LThan || $2 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1372 else $$ = forCtrl( $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, $5 );1400 else $$ = forCtrl( yylloc, $3, new string( DeclarationNode::anonymous.newName() ), $3->clone(), $2, nullptr, $5 ); 1373 1401 } 1374 1402 | comma_expression updowneq '@' '~' comma_expression // CFA, anonymous loop-index … … 1377 1405 else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1378 1406 } 1379 | comma_expression updowneq comma_expression '~' '@' // CFA, error1407 | comma_expression updowneq comma_expression '~' '@' // CFA, invalid syntax rules 1380 1408 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1381 | '@' updowneq '@' // CFA, error1409 | '@' updowneq '@' // CFA, invalid syntax rules 1382 1410 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1383 | '@' updowneq comma_expression '~' '@' // CFA, error1411 | '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rules 1384 1412 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1385 | comma_expression updowneq '@' '~' '@' // CFA, error1413 | comma_expression updowneq '@' '~' '@' // CFA, invalid syntax rules 1386 1414 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1387 | '@' updowneq '@' '~' '@' // CFA, error1415 | '@' updowneq '@' '~' '@' // CFA, invalid syntax rules 1388 1416 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1389 1417 1390 1418 | comma_expression ';' comma_expression // CFA 1391 { $$ = forCtrl( $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); }1419 { $$ = forCtrl( yylloc, $3, $1, NEW_ZERO, OperKinds::LThan, $3->clone(), NEW_ONE ); } 1392 1420 | comma_expression ';' downupdowneq comma_expression // CFA 1393 { $$ = forCtrl( $4, $1, UPDOWN( $3, NEW_ZERO, $4->clone() ), $3, UPDOWN( $3, $4->clone(), NEW_ZERO ), NEW_ONE ); }1421 { $$ = forCtrl( yylloc, $4, $1, UPDOWN( $3, NEW_ZERO, $4->clone() ), $3, UPDOWN( $3, $4->clone(), NEW_ZERO ), NEW_ONE ); } 1394 1422 1395 1423 | comma_expression ';' comma_expression updowneq comma_expression // CFA 1396 { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), NEW_ONE ); }1424 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), NEW_ONE ); } 1397 1425 | comma_expression ';' '@' updowneq comma_expression // CFA 1398 1426 { 1399 1427 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1400 else $$ = forCtrl( $5, $1, $5->clone(), $4, nullptr, NEW_ONE );1428 else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, NEW_ONE ); 1401 1429 } 1402 1430 | comma_expression ';' comma_expression updowneq '@' // CFA 1403 1431 { 1404 1432 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1405 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1406 else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, NEW_ONE );1407 } 1408 | comma_expression ';' '@' updowneq '@' // CFA, error1409 { SemanticError( yylloc, " Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1433 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1434 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); 1435 } 1436 | comma_expression ';' '@' updowneq '@' // CFA, invalid syntax rules 1437 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1410 1438 1411 1439 | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA 1412 { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); }1413 | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, error1440 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); } 1441 | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, invalid syntax rules 1414 1442 { 1415 1443 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1416 else $$ = forCtrl( $5, $1, $5->clone(), $4, nullptr, $7 );1444 else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, $7 ); 1417 1445 } 1418 1446 | comma_expression ';' comma_expression updowneq '@' '~' comma_expression // CFA 1419 1447 { 1420 1448 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1421 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1422 else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, $7 );1449 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1450 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 ); 1423 1451 } 1424 1452 | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA 1425 { $$ = forCtrl( $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); }1426 | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, error1453 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); } 1454 | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rules 1427 1455 { 1428 1456 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1429 else $$ = forCtrl( $5, $1, $5->clone(), $4, nullptr, nullptr );1457 else $$ = forCtrl( yylloc, $5, $1, $5->clone(), $4, nullptr, nullptr ); 1430 1458 } 1431 1459 | comma_expression ';' comma_expression updowneq '@' '~' '@' // CFA 1432 1460 { 1433 1461 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1434 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1435 else $$ = forCtrl( $3, $1, $3->clone(), $4, nullptr, nullptr );1462 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1463 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr ); 1436 1464 } 1437 1465 | comma_expression ';' '@' updowneq '@' '~' '@' // CFA 1438 { SemanticError( yylloc, " Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1466 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1439 1467 1440 1468 | declaration comma_expression // CFA 1441 { $$ = forCtrl( $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); }1469 { $$ = forCtrl( yylloc, $1, NEW_ZERO, OperKinds::LThan, $2, NEW_ONE ); } 1442 1470 | declaration downupdowneq comma_expression // CFA 1443 { $$ = forCtrl( $1, UPDOWN( $2, NEW_ZERO, $3 ), $2, UPDOWN( $2, $3->clone(), NEW_ZERO ), NEW_ONE ); }1471 { $$ = forCtrl( yylloc, $1, UPDOWN( $2, NEW_ZERO, $3 ), $2, UPDOWN( $2, $3->clone(), NEW_ZERO ), NEW_ONE ); } 1444 1472 1445 1473 | declaration comma_expression updowneq comma_expression // CFA 1446 { $$ = forCtrl( $1, UPDOWN( $3, $2->clone(), $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), NEW_ONE ); }1474 { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2->clone(), $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), NEW_ONE ); } 1447 1475 | declaration '@' updowneq comma_expression // CFA 1448 1476 { 1449 1477 if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1450 else $$ = forCtrl( $1, $4, $3, nullptr, NEW_ONE );1478 else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, NEW_ONE ); 1451 1479 } 1452 1480 | declaration comma_expression updowneq '@' // CFA 1453 1481 { 1454 1482 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1455 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1456 else $$ = forCtrl( $1, $2, $3, nullptr, NEW_ONE );1483 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1484 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE ); 1457 1485 } 1458 1486 1459 1487 | declaration comma_expression updowneq comma_expression '~' comma_expression // CFA 1460 { $$ = forCtrl( $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), $6 ); }1488 { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), $6 ); } 1461 1489 | declaration '@' updowneq comma_expression '~' comma_expression // CFA 1462 1490 { 1463 1491 if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1464 else $$ = forCtrl( $1, $4, $3, nullptr, $6 );1492 else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, $6 ); 1465 1493 } 1466 1494 | declaration comma_expression updowneq '@' '~' comma_expression // CFA 1467 1495 { 1468 1496 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1469 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1470 else $$ = forCtrl( $1, $2, $3, nullptr, $6 );1497 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1498 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 ); 1471 1499 } 1472 1500 | declaration comma_expression updowneq comma_expression '~' '@' // CFA 1473 { $$ = forCtrl( $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), nullptr ); }1501 { $$ = forCtrl( yylloc, $1, UPDOWN( $3, $2, $4 ), $3, UPDOWN( $3, $4->clone(), $2->clone() ), nullptr ); } 1474 1502 | declaration '@' updowneq comma_expression '~' '@' // CFA 1475 1503 { 1476 1504 if ( $3 == OperKinds::LThan || $3 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } 1477 else $$ = forCtrl( $1, $4, $3, nullptr, nullptr );1505 else $$ = forCtrl( yylloc, $1, $4, $3, nullptr, nullptr ); 1478 1506 } 1479 1507 | declaration comma_expression updowneq '@' '~' '@' // CFA 1480 1508 { 1481 1509 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1482 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1483 else $$ = forCtrl( $1, $2, $3, nullptr, nullptr );1484 } 1485 | declaration '@' updowneq '@' '~' '@' // CFA, error1486 { SemanticError( yylloc, " Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1510 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1511 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr ); 1512 } 1513 | declaration '@' updowneq '@' '~' '@' // CFA, invalid syntax rules 1514 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1487 1515 1488 1516 | comma_expression ';' TYPEDEFname // CFA, array type … … 1493 1521 | comma_expression ';' downupdowneq TYPEDEFname // CFA, array type 1494 1522 { 1495 if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "All enumation ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; } 1523 if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { 1524 SemanticError( yylloc, "syntax error, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; 1525 } 1496 1526 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1497 1527 } 1498 1528 ; 1499 1529 1500 1530 downupdowneq: … … 1505 1535 | ErangeDownEq 1506 1536 { $$ = OperKinds::GEThan; } 1507 1537 ; 1508 1538 1509 1539 updown: … … 1512 1542 | ErangeDown 1513 1543 { $$ = OperKinds::GThan; } 1514 1544 ; 1515 1545 1516 1546 updowneq: … … 1520 1550 | ErangeDownEq 1521 1551 { $$ = OperKinds::GEThan; } 1522 1552 ; 1523 1553 1524 1554 jump_statement: 1525 1555 GOTO identifier_or_type_name ';' 1526 { $$ = new StatementNode( build_branch( $2,BranchStmt::Goto ) ); }1556 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Goto ) ); } 1527 1557 | GOTO '*' comma_expression ';' // GCC, computed goto 1528 1558 // The syntax for the GCC computed goto violates normal expression precedence, e.g., goto *i+3; => goto *(i+3); … … 1531 1561 // A semantic check is required to ensure fallthru appears only in the body of a choose statement. 1532 1562 | fall_through_name ';' // CFA 1533 { $$ = new StatementNode( build_branch( BranchStmt::FallThrough ) ); }1563 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::FallThrough ) ); } 1534 1564 | fall_through_name identifier_or_type_name ';' // CFA 1535 { $$ = new StatementNode( build_branch( $2,BranchStmt::FallThrough ) ); }1565 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::FallThrough ) ); } 1536 1566 | fall_through_name DEFAULT ';' // CFA 1537 { $$ = new StatementNode( build_branch( BranchStmt::FallThroughDefault ) ); }1567 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::FallThroughDefault ) ); } 1538 1568 | CONTINUE ';' 1539 1569 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 1540 { $$ = new StatementNode( build_branch( BranchStmt::Continue ) ); }1570 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::Continue ) ); } 1541 1571 | CONTINUE identifier_or_type_name ';' // CFA, multi-level continue 1542 1572 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 1543 1573 // the target of the transfer appears only at the start of an iteration statement. 1544 { $$ = new StatementNode( build_branch( $2,BranchStmt::Continue ) ); }1574 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Continue ) ); } 1545 1575 | BREAK ';' 1546 1576 // A semantic check is required to ensure this statement appears only in the body of an iteration statement. 1547 { $$ = new StatementNode( build_branch( BranchStmt::Break ) ); }1577 { $$ = new StatementNode( build_branch( yylloc, ast::BranchStmt::Break ) ); } 1548 1578 | BREAK identifier_or_type_name ';' // CFA, multi-level exit 1549 1579 // A semantic check is required to ensure this statement appears only in the body of an iteration statement, and 1550 1580 // the target of the transfer appears only at the start of an iteration statement. 1551 { $$ = new StatementNode( build_branch( $2,BranchStmt::Break ) ); }1581 { $$ = new StatementNode( build_branch( yylloc, $2, ast::BranchStmt::Break ) ); } 1552 1582 | RETURN comma_expression_opt ';' 1553 { $$ = new StatementNode( build_return( $2 ) ); }1583 { $$ = new StatementNode( build_return( yylloc, $2 ) ); } 1554 1584 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1555 1585 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1556 1586 | SUSPEND ';' 1557 { $$ = new StatementNode( build_suspend( nullptr) ); }1587 { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::None ) ); } 1558 1588 | SUSPEND compound_statement 1559 { $$ = new StatementNode( build_suspend( $2) ); }1589 { $$ = new StatementNode( build_suspend( yylloc, $2, ast::SuspendStmt::None ) ); } 1560 1590 | SUSPEND COROUTINE ';' 1561 { $$ = new StatementNode( build_suspend( nullptr,SuspendStmt::Coroutine ) ); }1591 { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::Coroutine ) ); } 1562 1592 | SUSPEND COROUTINE compound_statement 1563 { $$ = new StatementNode( build_suspend( $3,SuspendStmt::Coroutine ) ); }1593 { $$ = new StatementNode( build_suspend( yylloc, $3, ast::SuspendStmt::Coroutine ) ); } 1564 1594 | SUSPEND GENERATOR ';' 1565 { $$ = new StatementNode( build_suspend( nullptr,SuspendStmt::Generator ) ); }1595 { $$ = new StatementNode( build_suspend( yylloc, nullptr, ast::SuspendStmt::Generator ) ); } 1566 1596 | SUSPEND GENERATOR compound_statement 1567 { $$ = new StatementNode( build_suspend( $3,SuspendStmt::Generator ) ); }1597 { $$ = new StatementNode( build_suspend( yylloc, $3, ast::SuspendStmt::Generator ) ); } 1568 1598 | THROW assignment_expression_opt ';' // handles rethrow 1569 { $$ = new StatementNode( build_throw( $2 ) ); }1599 { $$ = new StatementNode( build_throw( yylloc, $2 ) ); } 1570 1600 | THROWRESUME assignment_expression_opt ';' // handles reresume 1571 { $$ = new StatementNode( build_resume( $2 ) ); }1601 { $$ = new StatementNode( build_resume( yylloc, $2 ) ); } 1572 1602 | THROWRESUME assignment_expression_opt AT assignment_expression ';' // handles reresume 1573 1603 { $$ = new StatementNode( build_resume_at( $2, $4 ) ); } … … 1581 1611 with_statement: 1582 1612 WITH '(' tuple_expression_list ')' statement 1583 { $$ = new StatementNode( build_with( $3, $5 ) ); }1584 ; 1585 1586 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".1613 { $$ = new StatementNode( build_with( yylloc, $3, $5 ) ); } 1614 ; 1615 1616 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so possibly change syntax to "with mutex". 1587 1617 mutex_statement: 1588 MUTEX '(' argument_expression_list ')' statement 1589 { $$ = new StatementNode( build_mutex( $3, $5 ) ); } 1618 MUTEX '(' argument_expression_list_opt ')' statement 1619 { 1620 if ( ! $3 ) { SemanticError( yylloc, "syntax error, mutex argument list cannot be empty." ); $$ = nullptr; } 1621 $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) ); 1622 } 1590 1623 ; 1591 1624 … … 1598 1631 { $$ = nullptr; } 1599 1632 | when_clause 1600 ;1601 1602 waitfor:1603 WAITFOR '(' cast_expression ')'1604 { $$ = $3; }1605 // | WAITFOR '(' cast_expression ',' argument_expression_list_opt ')'1606 // { $$ = (ExpressionNode *)$3->set_last( $5 ); }1607 | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')'1608 { $$ = (ExpressionNode *)($3->set_last( $5 )); }1609 1633 ; 1610 1634 … … 1617 1641 1618 1642 timeout: 1619 TIMEOUT '(' comma_expression ')' { $$ = $3; } 1620 ; 1621 1622 waitfor_clause: 1643 TIMEOUT '(' comma_expression ')' { $$ = $3; } 1644 ; 1645 1646 wor: 1647 OROR 1648 | WOR 1649 1650 waitfor: 1651 WAITFOR '(' cast_expression ')' 1652 { $$ = $3; } 1653 | WAITFOR '(' cast_expression_list ':' argument_expression_list_opt ')' 1654 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1655 ; 1656 1657 wor_waitfor_clause: 1623 1658 when_clause_opt waitfor statement %prec THEN 1624 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1 ); } 1625 | when_clause_opt waitfor statement WOR waitfor_clause 1626 { $$ = build_waitfor( $2, maybe_build_compound( $3 ), $1, $5 ); } 1627 | when_clause_opt timeout statement %prec THEN 1628 { $$ = build_waitfor_timeout( $2, maybe_build_compound( $3 ), $1 ); } 1629 | when_clause_opt ELSE statement 1630 { $$ = build_waitfor_timeout( nullptr, maybe_build_compound( $3 ), $1 ); } 1659 // Called first: create header for WaitForStmt. 1660 { $$ = build_waitfor( yylloc, new ast::WaitForStmt( yylloc ), $1, $2, maybe_build_compound( yylloc, $3 ) ); } 1661 | wor_waitfor_clause wor when_clause_opt waitfor statement 1662 { $$ = build_waitfor( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); } 1663 | wor_waitfor_clause wor when_clause_opt ELSE statement 1664 { $$ = build_waitfor_else( yylloc, $1, $3, maybe_build_compound( yylloc, $5 ) ); } 1665 | wor_waitfor_clause wor when_clause_opt timeout statement %prec THEN 1666 { $$ = build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); } 1631 1667 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1632 | w hen_clause_opt timeout statement WOR ELSE statement // syntax error1633 { SemanticError( yylloc, " else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }1634 | w hen_clause_opt timeout statement WORwhen_clause ELSE statement1635 { $$ = build_waitfor_ timeout( $2, maybe_build_compound( $3 ), $1, maybe_build_compound( $7 ), $5); }1668 | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rules 1669 { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1670 | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1671 { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); } 1636 1672 ; 1637 1673 1638 1674 waitfor_statement: 1639 when_clause_opt waitfor statement %prec THEN 1640 { $$ = new StatementNode( build_waitfor( $2, $3, $1 ) ); } 1641 | when_clause_opt waitfor statement WOR waitfor_clause 1642 { $$ = new StatementNode( build_waitfor( $2, $3, $1, $5 ) ); } 1675 wor_waitfor_clause %prec THEN 1676 { $$ = new StatementNode( $1 ); } 1677 ; 1678 1679 wand: 1680 ANDAND 1681 | WAND 1682 ; 1683 1684 waituntil: 1685 WAITUNTIL '(' comma_expression ')' 1686 { $$ = $3; } 1687 ; 1688 1689 waituntil_clause: 1690 when_clause_opt waituntil statement 1691 { $$ = build_waituntil_clause( yylloc, $1, $2, maybe_build_compound( yylloc, $3 ) ); } 1692 | '(' wor_waituntil_clause ')' 1693 { $$ = $2; } 1694 ; 1695 1696 wand_waituntil_clause: 1697 waituntil_clause %prec THEN 1698 { $$ = $1; } 1699 | waituntil_clause wand wand_waituntil_clause 1700 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::AND, $1, $3 ); } 1701 ; 1702 1703 wor_waituntil_clause: 1704 wand_waituntil_clause 1705 { $$ = $1; } 1706 | wor_waituntil_clause wor wand_waituntil_clause 1707 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, $1, $3 ); } 1708 | wor_waituntil_clause wor when_clause_opt ELSE statement 1709 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_else( yylloc, $3, maybe_build_compound( yylloc, $5 ) ) ); } 1710 | wor_waituntil_clause wor when_clause_opt timeout statement %prec THEN 1711 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); } 1712 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1713 | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rules 1714 { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1715 | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1716 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, 1717 new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::OR, 1718 build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ), 1719 build_waituntil_else( yylloc, $7, maybe_build_compound( yylloc, $9 ) ) ) ); } 1720 ; 1721 1722 waituntil_statement: 1723 wor_waituntil_clause %prec THEN 1724 // SKULLDUGGERY: create an empty compound statement to test parsing of waituntil statement. 1725 { 1726 $$ = new StatementNode( build_waituntil_stmt( yylloc, $1 ) ); 1727 // $$ = new StatementNode( build_compound( yylloc, nullptr ) ); 1728 } 1643 1729 ; 1644 1730 1645 1731 exception_statement: 1646 TRY compound_statement handler_clause 1647 { $$ = new StatementNode( build_try( $2, $3, 0) ); }1732 TRY compound_statement handler_clause %prec THEN 1733 { $$ = new StatementNode( build_try( yylloc, $2, $3, nullptr ) ); } 1648 1734 | TRY compound_statement finally_clause 1649 { $$ = new StatementNode( build_try( $2, 0, $3 ) ); }1735 { $$ = new StatementNode( build_try( yylloc, $2, nullptr, $3 ) ); } 1650 1736 | TRY compound_statement handler_clause finally_clause 1651 { $$ = new StatementNode( build_try( $2, $3, $4 ) ); }1737 { $$ = new StatementNode( build_try( yylloc, $2, $3, $4 ) ); } 1652 1738 ; 1653 1739 1654 1740 handler_clause: 1655 1741 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1656 { $$ = new StatementNode( build_catch($1, $4, $6, $8 ) ); }1742 { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); } 1657 1743 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1658 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch($2, $5, $7, $9 ) ) ); }1744 { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); } 1659 1745 ; 1660 1746 … … 1666 1752 1667 1753 handler_key: 1668 CATCH { $$ = CatchStmt::Terminate; }1669 | RECOVER { $$ = CatchStmt::Terminate; }1670 | CATCHRESUME { $$ = CatchStmt::Resume; }1671 | FIXUP { $$ = CatchStmt::Resume; }1754 CATCH { $$ = ast::Terminate; } 1755 | RECOVER { $$ = ast::Terminate; } 1756 | CATCHRESUME { $$ = ast::Resume; } 1757 | FIXUP { $$ = ast::Resume; } 1672 1758 ; 1673 1759 1674 1760 finally_clause: 1675 FINALLY compound_statement { $$ = new StatementNode( build_finally($2 ) ); }1761 FINALLY compound_statement { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); } 1676 1762 ; 1677 1763 … … 1699 1785 asm_statement: 1700 1786 ASM asm_volatile_opt '(' string_literal ')' ';' 1701 { $$ = new StatementNode( build_asm( $2, $4, 0) ); }1787 { $$ = new StatementNode( build_asm( yylloc, $2, $4, nullptr ) ); } 1702 1788 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ')' ';' // remaining GCC 1703 { $$ = new StatementNode( build_asm( $2, $4, $6 ) ); }1789 { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6 ) ); } 1704 1790 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ')' ';' 1705 { $$ = new StatementNode( build_asm( $2, $4, $6, $8 ) ); }1791 { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6, $8 ) ); } 1706 1792 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 1707 { $$ = new StatementNode( build_asm( $2, $4, $6, $8, $10 ) ); }1793 { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6, $8, $10 ) ); } 1708 1794 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';' 1709 { $$ = new StatementNode( build_asm( $2, $5, 0, $8, $10, $12 ) ); }1795 { $$ = new StatementNode( build_asm( yylloc, $2, $5, nullptr, $8, $10, $12 ) ); } 1710 1796 ; 1711 1797 … … 1731 1817 asm_operand: // GCC 1732 1818 string_literal '(' constant_expression ')' 1733 { $$ = new ExpressionNode( new AsmExpr( nullptr, $1, maybeMoveBuild<Expression>( $3 ) ) ); }1819 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1734 1820 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1735 { $$ = new ExpressionNode( new AsmExpr( $2, $4, maybeMoveBuild<Expression>( $6 ) ) ); } 1821 { 1822 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) ); 1823 delete $2.str; 1824 } 1736 1825 ; 1737 1826 … … 1740 1829 { $$ = nullptr; } // use default argument 1741 1830 | string_literal 1742 { $$ = new ExpressionNode( $1 ); }1831 { $$ = $1; } 1743 1832 | asm_clobbers_list_opt ',' string_literal 1744 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( $3 ) )); }1833 { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); } 1745 1834 ; 1746 1835 … … 1748 1837 identifier 1749 1838 { 1750 $$ = new LabelNode(); $$->labels. push_back(*$1 );1839 $$ = new LabelNode(); $$->labels.emplace_back( yylloc, *$1 ); 1751 1840 delete $1; // allocated by lexer 1752 1841 } 1753 1842 | label_list ',' identifier 1754 1843 { 1755 $$ = $1; $1->labels. push_back(*$3 );1844 $$ = $1; $1->labels.emplace_back( yylloc, *$3 ); 1756 1845 delete $3; // allocated by lexer 1757 1846 } … … 1804 1893 { 1805 1894 // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" ); 1806 1895 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 1807 1896 // printf( "\tattr %s\n", attr->name.c_str() ); 1808 1897 // } // for … … 1814 1903 static_assert: 1815 1904 STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11 1816 { $$ = DeclarationNode::newStaticAssert( $3, $5); }1905 { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); } 1817 1906 | STATICASSERT '(' constant_expression ')' ';' // CFA 1818 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( *new string( "\"\"" ) ) ); }1907 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); } 1819 1908 1820 1909 // C declaration syntax is notoriously confusing and error prone. Cforall provides its own type, variable and function … … 1880 1969 // '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict 1881 1970 // { 1882 // $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true );1971 // $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, nullptr, true ); 1883 1972 // } 1884 1973 // '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')' 1885 1974 // { 1886 1975 // typedefTable.setNextIdentifier( *$5 ); 1887 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );1976 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true ); 1888 1977 // } 1889 1978 // | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')' 1890 1979 // { 1891 1980 // typedefTable.setNextIdentifier( *$5 ); 1892 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true );1981 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true ); 1893 1982 // } 1894 1983 // | '[' ']' typegen_name … … 1902 1991 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1903 1992 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1904 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0)->addQualifiers( $8 ); }1993 { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); } 1905 1994 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1906 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0)->addQualifiers( $8 ); }1995 { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); } 1907 1996 ; 1908 1997 … … 1940 2029 { 1941 2030 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" ); 1942 $$ = $3->addType( $2 )->addTypedef(); 2031 if ( $2->type->forall || ($2->type->kind == TypeData::Aggregate && $2->type->aggregate.params) ) { 2032 SemanticError( yylloc, "forall qualifier in typedef is currently unimplemented." ); $$ = nullptr; 2033 } else $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3 1943 2034 } 1944 2035 | typedef_declaration pop ',' push declarator … … 1948 2039 } 1949 2040 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1950 { 1951 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" ); 1952 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1953 } 2041 { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; } 1954 2042 | type_specifier TYPEDEF declarator 1955 { 1956 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "7" ); 1957 $$ = $3->addType( $1 )->addTypedef(); 1958 } 2043 { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; } 1959 2044 | type_specifier TYPEDEF type_qualifier_list declarator 1960 { 1961 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" ); 1962 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1963 } 2045 { SemanticError( yylloc, "Type qualifiers/specifiers before TYPEDEF is deprecated, move after TYPEDEF." ); $$ = nullptr; } 1964 2046 ; 1965 2047 … … 1968 2050 TYPEDEF identifier '=' assignment_expression 1969 2051 { 1970 SemanticError( yylloc, "T ypedefexpression is deprecated, use typeof(...) instead." ); $$ = nullptr;2052 SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1971 2053 } 1972 2054 | typedef_expression pop ',' push identifier '=' assignment_expression 1973 2055 { 1974 SemanticError( yylloc, "T ypedefexpression is deprecated, use typeof(...) instead." ); $$ = nullptr;2056 SemanticError( yylloc, "TYPEDEF expression is deprecated, use typeof(...) instead." ); $$ = nullptr; 1975 2057 } 1976 2058 ; … … 1982 2064 | typedef_expression // deprecated GCC, naming expression type 1983 2065 | sue_declaration_specifier 2066 { 2067 assert( $1->type ); 2068 if ( $1->type->qualifiers.any() ) { // CV qualifiers ? 2069 SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr; 2070 } 2071 // enums are never empty declarations because there must have at least one enumeration. 2072 if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ? 2073 SemanticError( yylloc, "syntax error, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr; 2074 } 2075 } 1984 2076 ; 1985 2077 … … 1987 2079 // A semantic check is required to ensure asm_name only appears on declarations with implicit or explicit static 1988 2080 // storage-class 1989 declarator asm_name_opt initializer_opt2081 variable_declarator asm_name_opt initializer_opt 1990 2082 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); } 2083 | variable_type_redeclarator asm_name_opt initializer_opt 2084 { $$ = $1->addAsmName( $2 )->addInitializer( $3 ); } 2085 2086 | general_function_declarator asm_name_opt 2087 { $$ = $1->addAsmName( $2 )->addInitializer( nullptr ); } 2088 | general_function_declarator asm_name_opt '=' VOID 2089 { $$ = $1->addAsmName( $2 )->addInitializer( new InitializerNode( true ) ); } 2090 1991 2091 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 1992 2092 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 1993 2093 ; 1994 2094 2095 general_function_declarator: 2096 function_type_redeclarator 2097 | function_declarator 2098 ; 2099 1995 2100 declaration_specifier: // type specifier + storage class 1996 2101 basic_declaration_specifier 2102 | type_declaration_specifier 1997 2103 | sue_declaration_specifier 1998 | type_declaration_specifier 2104 | sue_declaration_specifier invalid_types // invalid syntax rule 2105 { 2106 SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of ", 2107 $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ), 2108 " declaration." ) ); 2109 $$ = nullptr; 2110 } 2111 ; 2112 2113 invalid_types: 2114 aggregate_key 2115 | basic_type_name 2116 | indirect_type 1999 2117 ; 2000 2118 … … 2013 2131 basic_type_specifier 2014 2132 | sue_type_specifier 2015 {2016 // printf( "sue_type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );2017 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {2018 // printf( "\tattr %s\n", attr->name.c_str() );2019 // } // for2020 }2021 2133 | type_type_specifier 2022 2134 ; … … 2065 2177 { $$ = DeclarationNode::newTypeQualifier( Type::Atomic ); } 2066 2178 | forall 2179 { $$ = DeclarationNode::newForall( $1 ); } 2067 2180 ; 2068 2181 2069 2182 forall: 2070 2183 FORALL '(' type_parameter_list ')' // CFA 2071 { $$ = DeclarationNode::newForall( $3 ); }2184 { $$ = $3; } 2072 2185 ; 2073 2186 … … 2226 2339 { $$ = DeclarationNode::newTypeof( $3 ); } 2227 2340 | BASETYPEOF '(' type ')' // CFA: basetypeof( x ) y; 2228 { $$ = DeclarationNode::newTypeof( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ), true ); }2341 { $$ = DeclarationNode::newTypeof( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ), true ); } 2229 2342 | BASETYPEOF '(' comma_expression ')' // CFA: basetypeof( a+b ) y; 2230 2343 { $$ = DeclarationNode::newTypeof( $3, true ); } … … 2239 2352 { 2240 2353 // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2241 2354 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2242 2355 // printf( "\tattr %s\n", attr->name.c_str() ); 2243 2356 // } // for … … 2255 2368 { 2256 2369 // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2257 2370 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2258 2371 // printf( "\tattr %s\n", attr->name.c_str() ); 2259 2372 // } // for … … 2333 2446 { 2334 2447 // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2335 2448 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2336 2449 // printf( "\tattr %s\n", attr->name.c_str() ); 2337 2450 // } // for … … 2357 2470 '{' field_declaration_list_opt '}' type_parameters_opt 2358 2471 { 2359 // printf( "aggregate_type1 %s\n", $3.str->c_str() );2360 // if ( $2 )2361 // for ( Attribute * attr: reverseIterate( $2->attributes ) ) {2362 // printf( "copySpecifiers12 %s\n", attr->name.c_str() );2363 // } // for2364 2472 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); 2365 // printf( "aggregate_type2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );2366 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {2367 // printf( "aggregate_type3 %s\n", attr->name.c_str() );2368 // } // for2369 2473 } 2370 2474 | aggregate_key attribute_list_opt TYPEDEFname // unqualified type name … … 2375 2479 '{' field_declaration_list_opt '}' type_parameters_opt 2376 2480 { 2377 // printf( "AGG3\n" );2378 2481 DeclarationNode::newFromTypedef( $3 ); 2379 2482 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); … … 2386 2489 '{' field_declaration_list_opt '}' type_parameters_opt 2387 2490 { 2388 // printf( "AGG4\n" );2389 2491 DeclarationNode::newFromTypeGen( $3, nullptr ); 2390 2492 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); … … 2413 2515 // switched to a TYPEGENname. Link any generic arguments from typegen_name to new generic declaration and 2414 2516 // delete newFromTypeGen. 2415 $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 ); 2416 $3->type->symbolic.name = nullptr; 2417 $3->type->symbolic.actuals = nullptr; 2418 delete $3; 2517 if ( $3->type->kind == TypeData::SymbolicInst && ! $3->type->symbolic.isTypedef ) { 2518 $$ = $3->addQualifiers( $2 ); 2519 } else { 2520 $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $3->type->symbolic.actuals, nullptr, false )->addQualifiers( $2 ); 2521 $3->type->symbolic.name = nullptr; // copied to $$ 2522 $3->type->symbolic.actuals = nullptr; 2523 delete $3; 2524 } 2419 2525 } 2420 2526 ; … … 2427 2533 aggregate_data: 2428 2534 STRUCT vtable_opt 2429 { $$ = AggregateDecl::Struct; }2535 { $$ = ast::AggregateDecl::Struct; } 2430 2536 | UNION 2431 { $$ = AggregateDecl::Union; }2537 { $$ = ast::AggregateDecl::Union; } 2432 2538 | EXCEPTION // CFA 2433 { $$ = AggregateDecl::Exception; }2434 // { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; }2539 { $$ = ast::AggregateDecl::Exception; } 2540 // { SemanticError( yylloc, "exception aggregate is currently unimplemented." ); $$ = ast::AggregateDecl::NoAggregate; } 2435 2541 ; 2436 2542 2437 2543 aggregate_control: // CFA 2438 2544 MONITOR 2439 { $$ = AggregateDecl::Monitor; }2545 { $$ = ast::AggregateDecl::Monitor; } 2440 2546 | MUTEX STRUCT 2441 { $$ = AggregateDecl::Monitor; }2547 { $$ = ast::AggregateDecl::Monitor; } 2442 2548 | GENERATOR 2443 { $$ = AggregateDecl::Generator; }2549 { $$ = ast::AggregateDecl::Generator; } 2444 2550 | MUTEX GENERATOR 2445 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2551 { 2552 SemanticError( yylloc, "monitor generator is currently unimplemented." ); 2553 $$ = ast::AggregateDecl::NoAggregate; 2554 } 2446 2555 | COROUTINE 2447 { $$ = AggregateDecl::Coroutine; }2556 { $$ = ast::AggregateDecl::Coroutine; } 2448 2557 | MUTEX COROUTINE 2449 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2558 { 2559 SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); 2560 $$ = ast::AggregateDecl::NoAggregate; 2561 } 2450 2562 | THREAD 2451 { $$ = AggregateDecl::Thread; }2563 { $$ = ast::AggregateDecl::Thread; } 2452 2564 | MUTEX THREAD 2453 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2565 { 2566 SemanticError( yylloc, "monitor thread is currently unimplemented." ); 2567 $$ = ast::AggregateDecl::NoAggregate; 2568 } 2454 2569 ; 2455 2570 … … 2467 2582 $$ = fieldDecl( $1, $2 ); 2468 2583 // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2469 2584 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2470 2585 // printf( "\tattr %s\n", attr->name.c_str() ); 2471 2586 // } // for 2472 2587 } 2588 | type_specifier field_declaring_list_opt '}' // invalid syntax rule 2589 { 2590 SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of previous declaration." ) ); 2591 $$ = nullptr; 2592 } 2473 2593 | EXTENSION type_specifier field_declaring_list_opt ';' // GCC 2474 2594 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } 2595 | STATIC type_specifier field_declaring_list_opt ';' // CFA 2596 { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; } 2475 2597 | INLINE type_specifier field_abstract_list_opt ';' // CFA 2476 2598 { … … 2483 2605 } 2484 2606 | INLINE aggregate_control ';' // CFA 2485 2607 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; } 2486 2608 | typedef_declaration ';' // CFA 2487 2609 | cfa_field_declaring_list ';' // CFA, new style field declaration … … 2509 2631 { $$ = $1->addBitfield( $2 ); } 2510 2632 | variable_type_redeclarator bit_subrange_size_opt 2633 // A semantic check is required to ensure bit_subrange only appears on integral types. 2634 { $$ = $1->addBitfield( $2 ); } 2635 | function_type_redeclarator bit_subrange_size_opt 2511 2636 // A semantic check is required to ensure bit_subrange only appears on integral types. 2512 2637 { $$ = $1->addBitfield( $2 ); } … … 2563 2688 { $$ = DeclarationNode::newEnum( $3->name, $6, true, false, nullptr, $4 )->addQualifiers( $2 ); } 2564 2689 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2565 2566 if ( $3->storageClasses.val != 0 || $3->type->qualifiers. val != 0 )2567 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }2568 2690 { 2691 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) { 2692 SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); 2693 } 2569 2694 $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 ); 2570 2695 } … … 2575 2700 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2576 2701 { 2577 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2702 if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) { 2703 SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); 2704 } 2578 2705 typedefTable.makeTypedef( *$6 ); 2579 2706 } … … 2609 2736 enum_type_nobody: // enum - {...} 2610 2737 ENUM attribute_list_opt identifier 2611 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); }2738 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, nullptr, false, false )->addQualifiers( $2 ); } 2612 2739 | ENUM attribute_list_opt type_name 2613 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); }2740 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, nullptr, false, false )->addQualifiers( $2 ); } 2614 2741 ; 2615 2742 … … 2751 2878 type_no_function: // sizeof, alignof, cast (constructor) 2752 2879 cfa_abstract_declarator_tuple // CFA 2753 | type_specifier 2880 | type_specifier // cannot be type_specifier_nobody, e.g., (struct S {}){} is a thing 2754 2881 | type_specifier abstract_declarator 2755 2882 { $$ = $2->addType( $1 ); } … … 2796 2923 designator_list ':' // C99, CFA uses ":" instead of "=" 2797 2924 | identifier_at ':' // GCC, field name 2798 { $$ = new ExpressionNode( build_varref( $1 ) ); }2925 { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); } 2799 2926 ; 2800 2927 … … 2808 2935 designator: 2809 2936 '.' identifier_at // C99, field name 2810 { $$ = new ExpressionNode( build_varref( $2 ) ); }2937 { $$ = new ExpressionNode( build_varref( yylloc, $2 ) ); } 2811 2938 | '[' push assignment_expression pop ']' // C99, single array element 2812 2939 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. … … 2815 2942 { $$ = $3; } 2816 2943 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2817 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $3 ), maybeMoveBuild<Expression>( $5 ) ) ); }2944 { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $3 ), maybeMoveBuild( $5 ) ) ); } 2818 2945 | '.' '[' push field_name_list pop ']' // CFA, tuple field selector 2819 2946 { $$ = $4; } … … 2855 2982 { 2856 2983 typedefTable.addToScope( *$2, TYPEDEFname, "9" ); 2857 if ( $1 == TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); }2858 if ( $1 == TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); }2859 if ( $1 == TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); }2984 if ( $1 == ast::TypeDecl::Otype ) { SemanticError( yylloc, "otype keyword is deprecated, use T " ); } 2985 if ( $1 == ast::TypeDecl::Dtype ) { SemanticError( yylloc, "dtype keyword is deprecated, use T &" ); } 2986 if ( $1 == ast::TypeDecl::Ttype ) { SemanticError( yylloc, "ttype keyword is deprecated, use T ..." ); } 2860 2987 } 2861 2988 type_initializer_opt assertion_list_opt … … 2868 2995 { 2869 2996 typedefTable.addToScope( *$2, TYPEDIMname, "9" ); 2870 $$ = DeclarationNode::newTypeParam( TypeDecl::Dimension, $2 );2997 $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dimension, $2 ); 2871 2998 } 2872 2999 // | type_specifier identifier_parameter_declarator 2873 3000 | assertion_list 2874 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }3001 { $$ = DeclarationNode::newTypeParam( ast::TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2875 3002 ; 2876 3003 2877 3004 new_type_class: // CFA 2878 3005 // empty 2879 { $$ = TypeDecl::Otype; }3006 { $$ = ast::TypeDecl::Otype; } 2880 3007 | '&' 2881 { $$ = TypeDecl::Dtype; }3008 { $$ = ast::TypeDecl::Dtype; } 2882 3009 | '*' 2883 { $$ = TypeDecl::DStype; } // dtype + sized3010 { $$ = ast::TypeDecl::DStype; } // dtype + sized 2884 3011 // | '(' '*' ')' 2885 // { $$ = TypeDecl::Ftype; }3012 // { $$ = ast::TypeDecl::Ftype; } 2886 3013 | ELLIPSIS 2887 { $$ = TypeDecl::Ttype; }3014 { $$ = ast::TypeDecl::Ttype; } 2888 3015 ; 2889 3016 2890 3017 type_class: // CFA 2891 3018 OTYPE 2892 { $$ = TypeDecl::Otype; }3019 { $$ = ast::TypeDecl::Otype; } 2893 3020 | DTYPE 2894 { $$ = TypeDecl::Dtype; }3021 { $$ = ast::TypeDecl::Dtype; } 2895 3022 | FTYPE 2896 { $$ = TypeDecl::Ftype; }3023 { $$ = ast::TypeDecl::Ftype; } 2897 3024 | TTYPE 2898 { $$ = TypeDecl::Ttype; }3025 { $$ = ast::TypeDecl::Ttype; } 2899 3026 ; 2900 3027 … … 2922 3049 type_list: // CFA 2923 3050 type 2924 { $$ = new ExpressionNode( new TypeExpr(maybeMoveBuildType( $1 ) ) ); }3051 { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); } 2925 3052 | assignment_expression 2926 3053 | type_list ',' type 2927 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ) )); }3054 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); } 2928 3055 | type_list ',' assignment_expression 2929 3056 { $$ = (ExpressionNode *)( $1->set_last( $3 )); } … … 2950 3077 { 2951 3078 typedefTable.addToEnclosingScope( *$1, TYPEDEFname, "10" ); 2952 $$ = DeclarationNode::newTypeDecl( $1, 0);3079 $$ = DeclarationNode::newTypeDecl( $1, nullptr ); 2953 3080 } 2954 3081 | identifier_or_type_name '(' type_parameter_list ')' … … 2961 3088 trait_specifier: // CFA 2962 3089 TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2963 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); } 3090 { 3091 SemanticWarning( yylloc, Warning::DeprecTraitSyntax ); 3092 $$ = DeclarationNode::newTrait( $2, $4, nullptr ); 3093 } 3094 | forall TRAIT identifier_or_type_name '{' '}' // alternate 3095 { $$ = DeclarationNode::newTrait( $3, $1, nullptr ); } 2964 3096 | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2965 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); } 3097 { 3098 SemanticWarning( yylloc, Warning::DeprecTraitSyntax ); 3099 $$ = DeclarationNode::newTrait( $2, $4, $8 ); 3100 } 3101 | forall TRAIT identifier_or_type_name '{' push trait_declaration_list pop '}' // alternate 3102 { $$ = DeclarationNode::newTrait( $3, $1, $6 ); } 2966 3103 ; 2967 3104 … … 3022 3159 external_definition: 3023 3160 DIRECTIVE 3024 { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( $1 ) ) ); }3161 { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( yylloc, $1 ) ) ); } 3025 3162 | declaration 3163 { 3164 // Variable declarations of anonymous types requires creating a unique type-name across multiple translation 3165 // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is 3166 // disallowed at the moment. 3167 if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) { 3168 if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) { 3169 SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr; 3170 } else if ( $1->type->aggInst.aggregate->aggregate.anon ) { // handles struct or union 3171 SemanticError( yylloc, "extern anonymous struct/union is currently unimplemented." ); $$ = nullptr; 3172 } 3173 } 3174 } 3026 3175 | IDENTIFIER IDENTIFIER 3027 3176 { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; } 3028 | IDENTIFIER type_qualifier // syntax error3177 | IDENTIFIER type_qualifier // invalid syntax rules 3029 3178 { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; } 3030 | IDENTIFIER storage_class // syntax error3179 | IDENTIFIER storage_class // invalid syntax rules 3031 3180 { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; } 3032 | IDENTIFIER basic_type_name // syntax error3181 | IDENTIFIER basic_type_name // invalid syntax rules 3033 3182 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3034 | IDENTIFIER TYPEDEFname // syntax error3183 | IDENTIFIER TYPEDEFname // invalid syntax rules 3035 3184 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3036 | IDENTIFIER TYPEGENname // syntax error3185 | IDENTIFIER TYPEGENname // invalid syntax rules 3037 3186 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3038 3187 | external_function_definition … … 3043 3192 } 3044 3193 | ASM '(' string_literal ')' ';' // GCC, global assembler statement 3045 { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( false, $3, 0) ) ); }3194 { $$ = DeclarationNode::newAsmStmt( new StatementNode( build_asm( yylloc, false, $3, nullptr ) ) ); } 3046 3195 | EXTERN STRINGliteral 3047 3196 { 3048 3197 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 3049 linkage = LinkageSpec::update( yylloc, linkage, $2 );3198 linkage = ast::Linkage::update( yylloc, linkage, $2 ); 3050 3199 } 3051 3200 up external_definition down … … 3058 3207 { 3059 3208 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 3060 linkage = LinkageSpec::update( yylloc, linkage, $2 );3209 linkage = ast::Linkage::update( yylloc, linkage, $2 ); 3061 3210 } 3062 3211 '{' up external_definition_list_opt down '}' … … 3069 3218 | type_qualifier_list 3070 3219 { 3071 if ( $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3220 if ( $1->type->qualifiers.any() ) { 3221 SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); 3222 } 3072 3223 if ( $1->type->forall ) forall = true; // remember generic type 3073 3224 } … … 3075 3226 { 3076 3227 distQual( $5, $1 ); 3077 3228 forall = false; 3078 3229 $$ = $5; 3079 3230 } 3080 3231 | declaration_qualifier_list 3081 3232 { 3082 if ( $1->type && $1->type->qualifiers.val ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3233 if ( $1->type && $1->type->qualifiers.any() ) { 3234 SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); 3235 } 3083 3236 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 3084 3237 } … … 3086 3239 { 3087 3240 distQual( $5, $1 ); 3088 3241 forall = false; 3089 3242 $$ = $5; 3090 3243 } 3091 3244 | declaration_qualifier_list type_qualifier_list 3092 3245 { 3093 if ( ($1->type && $1->type->qualifiers.val) || ($2->type && $2->type->qualifiers.val) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3246 if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { 3247 SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); 3248 } 3094 3249 if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type 3095 3250 } … … 3097 3252 { 3098 3253 distQual( $6, $1->addQualifiers( $2 ) ); 3099 3254 forall = false; 3100 3255 $$ = $6; 3101 3256 } … … 3122 3277 $$ = $3; forall = false; 3123 3278 if ( $5 ) { 3124 SemanticError( yylloc, " Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );3279 SemanticError( yylloc, "syntax error, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." ); 3125 3280 $$ = nullptr; 3126 3281 } // if … … 3141 3296 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 3142 3297 } 3143 | declaration_specifier variable_type_redeclarator with_clause_opt compound_statement3298 | declaration_specifier function_type_redeclarator with_clause_opt compound_statement 3144 3299 { 3145 3300 rebindForall( $1, $2 ); … … 3177 3332 | variable_type_redeclarator 3178 3333 | function_declarator 3334 | function_type_redeclarator 3179 3335 ; 3180 3336 3181 3337 subrange: 3182 3338 constant_expression '~' constant_expression // CFA, integer subrange 3183 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild<Expression>( $1 ), maybeMoveBuild<Expression>( $3 ) ) ); }3339 { $$ = new ExpressionNode( new ast::RangeExpr( yylloc, maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 3184 3340 ; 3185 3341 … … 3190 3346 { 3191 3347 DeclarationNode * name = new DeclarationNode(); 3192 name->asmName = $3;3348 name->asmName = maybeMoveBuild( $3 ); 3193 3349 $$ = name->addQualifiers( $5 ); 3194 3350 } … … 3287 3443 variable_ptr: 3288 3444 ptrref_operator variable_declarator 3289 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }3445 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3290 3446 | ptrref_operator type_qualifier_list variable_declarator 3291 3447 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3303 3459 | '(' attribute_list variable_ptr ')' array_dimension 3304 3460 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3305 | '(' variable_array ')' multi_array_dimension 3461 | '(' variable_array ')' multi_array_dimension // redundant parenthesis 3306 3462 { $$ = $2->addArray( $4 ); } 3307 3463 | '(' attribute_list variable_array ')' multi_array_dimension // redundant parenthesis … … 3351 3507 function_ptr: 3352 3508 ptrref_operator function_declarator 3353 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }3509 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3354 3510 | ptrref_operator type_qualifier_list function_declarator 3355 3511 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3403 3559 KR_function_ptr: 3404 3560 ptrref_operator KR_function_declarator 3405 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }3561 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3406 3562 | ptrref_operator type_qualifier_list KR_function_declarator 3407 3563 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3427 3583 ; 3428 3584 3429 // This pattern parses a declaration for a variable or function prototypethat redefines a type name, e.g.:3585 // This pattern parses a declaration for a variable that redefines a type name, e.g.: 3430 3586 // 3431 3587 // typedef int foo; … … 3433 3589 // int foo; // redefine typedef name in new scope 3434 3590 // } 3435 //3436 // The pattern precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays3437 // and functions versus pointers to arrays and functions.3438 3591 3439 3592 paren_type: … … 3450 3603 paren_type attribute_list_opt 3451 3604 { $$ = $1->addQualifiers( $2 ); } 3452 | type_ptr3453 | type_array attribute_list_opt3605 | variable_type_ptr 3606 | variable_type_array attribute_list_opt 3454 3607 { $$ = $1->addQualifiers( $2 ); } 3455 | type_function attribute_list_opt3608 | variable_type_function attribute_list_opt 3456 3609 { $$ = $1->addQualifiers( $2 ); } 3457 3610 ; 3458 3611 3459 type_ptr:3612 variable_type_ptr: 3460 3613 ptrref_operator variable_type_redeclarator 3461 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }3614 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3462 3615 | ptrref_operator type_qualifier_list variable_type_redeclarator 3463 3616 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 3464 | '(' type_ptr ')' attribute_list_opt// redundant parenthesis3617 | '(' variable_type_ptr ')' attribute_list_opt // redundant parenthesis 3465 3618 { $$ = $2->addQualifiers( $4 ); } 3466 | '(' attribute_list type_ptr ')' attribute_list_opt // redundant parenthesis3619 | '(' attribute_list variable_type_ptr ')' attribute_list_opt // redundant parenthesis 3467 3620 { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); } 3468 3621 ; 3469 3622 3470 type_array:3623 variable_type_array: 3471 3624 paren_type array_dimension 3472 3625 { $$ = $1->addArray( $2 ); } 3473 | '(' type_ptr ')' array_dimension3626 | '(' variable_type_ptr ')' array_dimension 3474 3627 { $$ = $2->addArray( $4 ); } 3475 | '(' attribute_list type_ptr ')' array_dimension3628 | '(' attribute_list variable_type_ptr ')' array_dimension 3476 3629 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3477 | '(' type_array ')' multi_array_dimension// redundant parenthesis3630 | '(' variable_type_array ')' multi_array_dimension // redundant parenthesis 3478 3631 { $$ = $2->addArray( $4 ); } 3479 | '(' attribute_list type_array ')' multi_array_dimension // redundant parenthesis3632 | '(' attribute_list variable_type_array ')' multi_array_dimension // redundant parenthesis 3480 3633 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3481 | '(' type_array ')'// redundant parenthesis3634 | '(' variable_type_array ')' // redundant parenthesis 3482 3635 { $$ = $2; } 3483 | '(' attribute_list type_array ')'// redundant parenthesis3636 | '(' attribute_list variable_type_array ')' // redundant parenthesis 3484 3637 { $$ = $3->addQualifiers( $2 ); } 3485 3638 ; 3486 3639 3487 type_function: 3640 variable_type_function: 3641 '(' variable_type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3642 { $$ = $2->addParamList( $6 ); } 3643 | '(' attribute_list variable_type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3644 { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); } 3645 | '(' variable_type_function ')' // redundant parenthesis 3646 { $$ = $2; } 3647 | '(' attribute_list variable_type_function ')' // redundant parenthesis 3648 { $$ = $3->addQualifiers( $2 ); } 3649 ; 3650 3651 // This pattern parses a declaration for a function prototype that redefines a type name. It precludes declaring an 3652 // array of functions versus a pointer to an array of functions, and returning arrays and functions versus pointers to 3653 // arrays and functions. 3654 3655 function_type_redeclarator: 3656 function_type_no_ptr attribute_list_opt 3657 { $$ = $1->addQualifiers( $2 ); } 3658 | function_type_ptr 3659 | function_type_array attribute_list_opt 3660 { $$ = $1->addQualifiers( $2 ); } 3661 ; 3662 3663 function_type_no_ptr: 3488 3664 paren_type '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3489 3665 { $$ = $1->addParamList( $4 ); } 3490 | '(' type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)3666 | '(' function_type_ptr ')' '(' push parameter_type_list_opt pop ')' 3491 3667 { $$ = $2->addParamList( $6 ); } 3492 | '(' attribute_list type_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3)3668 | '(' attribute_list function_type_ptr ')' '(' push parameter_type_list_opt pop ')' 3493 3669 { $$ = $3->addQualifiers( $2 )->addParamList( $7 ); } 3494 | '(' type_function ')'// redundant parenthesis3670 | '(' function_type_no_ptr ')' // redundant parenthesis 3495 3671 { $$ = $2; } 3496 | '(' attribute_list type_function ')' // redundant parenthesis 3672 | '(' attribute_list function_type_no_ptr ')' // redundant parenthesis 3673 { $$ = $3->addQualifiers( $2 ); } 3674 ; 3675 3676 function_type_ptr: 3677 ptrref_operator function_type_redeclarator 3678 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3679 | ptrref_operator type_qualifier_list function_type_redeclarator 3680 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } 3681 | '(' function_type_ptr ')' attribute_list_opt 3682 { $$ = $2->addQualifiers( $4 ); } 3683 | '(' attribute_list function_type_ptr ')' attribute_list_opt 3684 { $$ = $3->addQualifiers( $2 )->addQualifiers( $5 ); } 3685 ; 3686 3687 function_type_array: 3688 '(' function_type_ptr ')' array_dimension 3689 { $$ = $2->addArray( $4 ); } 3690 | '(' attribute_list function_type_ptr ')' array_dimension 3691 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3692 | '(' function_type_array ')' multi_array_dimension // redundant parenthesis 3693 { $$ = $2->addArray( $4 ); } 3694 | '(' attribute_list function_type_array ')' multi_array_dimension // redundant parenthesis 3695 { $$ = $3->addQualifiers( $2 )->addArray( $5 ); } 3696 | '(' function_type_array ')' // redundant parenthesis 3697 { $$ = $2; } 3698 | '(' attribute_list function_type_array ')' // redundant parenthesis 3497 3699 { $$ = $3->addQualifiers( $2 ); } 3498 3700 ; … … 3517 3719 identifier_parameter_ptr: 3518 3720 ptrref_operator identifier_parameter_declarator 3519 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }3721 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3520 3722 | ptrref_operator type_qualifier_list identifier_parameter_declarator 3521 3723 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3574 3776 type_parameter_ptr: 3575 3777 ptrref_operator type_parameter_redeclarator 3576 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }3778 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3577 3779 | ptrref_operator type_qualifier_list type_parameter_redeclarator 3578 3780 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3617 3819 abstract_ptr: 3618 3820 ptrref_operator 3619 { $$ = DeclarationNode::newPointer( 0, $1 ); }3821 { $$ = DeclarationNode::newPointer( nullptr, $1 ); } 3620 3822 | ptrref_operator type_qualifier_list 3621 3823 { $$ = DeclarationNode::newPointer( $2, $1 ); } 3622 3824 | ptrref_operator abstract_declarator 3623 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }3825 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3624 3826 | ptrref_operator type_qualifier_list abstract_declarator 3625 3827 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3650 3852 // Only the first dimension can be empty. 3651 3853 '[' ']' 3652 { $$ = DeclarationNode::newArray( 0, 0, false ); }3854 { $$ = DeclarationNode::newArray( nullptr, nullptr, false ); } 3653 3855 | '[' ']' multi_array_dimension 3654 { $$ = DeclarationNode::newArray( 0, 0, false )->addArray( $3 ); }3856 { $$ = DeclarationNode::newArray( nullptr, nullptr, false )->addArray( $3 ); } 3655 3857 // Cannot use constant_expression because of tuples => semantic check 3656 3858 | '[' push assignment_expression pop ',' comma_expression ']' // CFA 3657 { $$ = DeclarationNode::newArray( $3, 0, false )->addArray( DeclarationNode::newArray( $6, 0, false ) ); }3859 { $$ = DeclarationNode::newArray( $3, nullptr, false )->addArray( DeclarationNode::newArray( $6, nullptr, false ) ); } 3658 3860 // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; } 3659 3861 | '[' push array_type_list pop ']' // CFA … … 3664 3866 array_type_list: 3665 3867 basic_type_name 3666 { $$ = new ExpressionNode( new TypeExpr(maybeMoveBuildType( $1 ) ) ); }3868 { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); } 3667 3869 | type_name 3668 { $$ = new ExpressionNode( new TypeExpr(maybeMoveBuildType( $1 ) ) ); }3870 { $$ = new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $1 ) ) ); } 3669 3871 | assignment_expression upupeq assignment_expression 3670 3872 | array_type_list ',' basic_type_name 3671 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ) )); }3672 | array_type_list ',' type_name 3673 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr(maybeMoveBuildType( $3 ) ) ) )); }3873 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); } 3874 | array_type_list ',' type_name 3875 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new ast::TypeExpr( yylloc, maybeMoveBuildType( $3 ) ) ) )); } 3674 3876 | array_type_list ',' assignment_expression upupeq assignment_expression 3675 3877 ; … … 3680 3882 | ErangeUpEq 3681 3883 { $$ = OperKinds::LEThan; } 3682 3884 ; 3683 3885 3684 3886 multi_array_dimension: 3685 3887 '[' push assignment_expression pop ']' 3686 { $$ = DeclarationNode::newArray( $3, 0, false ); }3888 { $$ = DeclarationNode::newArray( $3, nullptr, false ); } 3687 3889 | '[' push '*' pop ']' // C99 3688 3890 { $$ = DeclarationNode::newVarArray( 0 ); } 3689 3891 | multi_array_dimension '[' push assignment_expression pop ']' 3690 { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }3892 { $$ = $1->addArray( DeclarationNode::newArray( $4, nullptr, false ) ); } 3691 3893 | multi_array_dimension '[' push '*' pop ']' // C99 3692 3894 { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); } … … 3785 3987 array_parameter_1st_dimension: 3786 3988 '[' ']' 3787 { $$ = DeclarationNode::newArray( 0, 0, false ); }3989 { $$ = DeclarationNode::newArray( nullptr, nullptr, false ); } 3788 3990 // multi_array_dimension handles the '[' '*' ']' case 3789 3991 | '[' push type_qualifier_list '*' pop ']' // remaining C99 3790 3992 { $$ = DeclarationNode::newVarArray( $3 ); } 3791 3993 | '[' push type_qualifier_list pop ']' 3792 { $$ = DeclarationNode::newArray( 0, $3, false ); }3994 { $$ = DeclarationNode::newArray( nullptr, $3, false ); } 3793 3995 // multi_array_dimension handles the '[' assignment_expression ']' case 3794 3996 | '[' push type_qualifier_list assignment_expression pop ']' … … 3819 4021 variable_abstract_ptr: 3820 4022 ptrref_operator 3821 { $$ = DeclarationNode::newPointer( 0, $1 ); }4023 { $$ = DeclarationNode::newPointer( nullptr, $1 ); } 3822 4024 | ptrref_operator type_qualifier_list 3823 4025 { $$ = DeclarationNode::newPointer( $2, $1 ); } 3824 4026 | ptrref_operator variable_abstract_declarator 3825 { $$ = $2->addPointer( DeclarationNode::newPointer( 0, $1 ) ); }4027 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3826 4028 | ptrref_operator type_qualifier_list variable_abstract_declarator 3827 4029 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3865 4067 // No SUE declaration in parameter list. 3866 4068 ptrref_operator type_specifier_nobody 3867 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }4069 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3868 4070 | type_qualifier_list ptrref_operator type_specifier_nobody 3869 4071 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 3870 4072 | ptrref_operator cfa_abstract_function 3871 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }4073 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3872 4074 | type_qualifier_list ptrref_operator cfa_abstract_function 3873 4075 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 3874 4076 | ptrref_operator cfa_identifier_parameter_declarator_tuple 3875 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }4077 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3876 4078 | type_qualifier_list ptrref_operator cfa_identifier_parameter_declarator_tuple 3877 4079 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } … … 3882 4084 // shift/reduce conflict with new-style empty (void) function return type. 3883 4085 '[' ']' type_specifier_nobody 3884 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }4086 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 3885 4087 | cfa_array_parameter_1st_dimension type_specifier_nobody 3886 4088 { $$ = $2->addNewArray( $1 ); } 3887 4089 | '[' ']' multi_array_dimension type_specifier_nobody 3888 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }4090 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 3889 4091 | cfa_array_parameter_1st_dimension multi_array_dimension type_specifier_nobody 3890 4092 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } … … 3893 4095 3894 4096 | '[' ']' cfa_identifier_parameter_ptr 3895 { $$ = $3->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }4097 { $$ = $3->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 3896 4098 | cfa_array_parameter_1st_dimension cfa_identifier_parameter_ptr 3897 4099 { $$ = $2->addNewArray( $1 ); } 3898 4100 | '[' ']' multi_array_dimension cfa_identifier_parameter_ptr 3899 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( 0, 0, false ) ); }4101 { $$ = $4->addNewArray( $3 )->addNewArray( DeclarationNode::newArray( nullptr, nullptr, false ) ); } 3900 4102 | cfa_array_parameter_1st_dimension multi_array_dimension cfa_identifier_parameter_ptr 3901 4103 { $$ = $3->addNewArray( $2 )->addNewArray( $1 ); } … … 3953 4155 cfa_abstract_ptr: // CFA 3954 4156 ptrref_operator type_specifier 3955 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }4157 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3956 4158 | type_qualifier_list ptrref_operator type_specifier 3957 4159 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 3958 4160 | ptrref_operator cfa_abstract_function 3959 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }4161 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3960 4162 | type_qualifier_list ptrref_operator cfa_abstract_function 3961 4163 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } 3962 4164 | ptrref_operator cfa_abstract_declarator_tuple 3963 { $$ = $2->addNewPointer( DeclarationNode::newPointer( 0, $1 ) ); }4165 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3964 4166 | type_qualifier_list ptrref_operator cfa_abstract_declarator_tuple 3965 4167 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
Note: See TracChangeset
for help on using the changeset viewer.