Changes in src/Parser/parser.yy [c86b08d:0442f93f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rc86b08d r0442f93f 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tue Apr 4 14:02:00202313 // Update Count : 63 2911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 7 14:32:28 2023 13 // Update Count : 6341 14 14 // 15 15 … … 48 48 using namespace std; 49 49 50 #include "SynTree/Declaration.h" 51 #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_... 52 56 #include "TypedefTable.h" 53 57 #include "TypeData.h" 54 #include "SynTree/LinkageSpec.h"55 58 #include "Common/SemanticError.h" // error_str 56 59 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... … … 105 108 assert( declList ); 106 109 // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout ); 107 DeclarationNode * c ur = declList, * cl = (new DeclarationNode)->addType( typeSpec );110 DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); 108 111 // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout ); 109 112 // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name; 110 113 111 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() ) ) { 112 115 cl->cloneBaseType( cur ); 113 116 } // for … … 203 206 #define NEW_ONE new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) ) 204 207 #define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right) 205 #define MISSING_ANON_FIELD " Missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."206 #define MISSING_LOW " Missing low value for up-to range so index is uninitialized."207 #define MISSING_HIGH " Missing high value for down-to range so index is uninitialized."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." 208 211 209 212 static ForCtrl * makeForCtrl( … … 229 232 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 230 233 if ( index->initializer ) { 231 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." ); 232 235 } // if 233 236 if ( index->next ) { 234 SemanticError( yylloc, " Multiple loop indexes disallowed in for-loop declaration." );237 SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." ); 235 238 } // if 236 239 DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) ); … … 257 260 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 258 261 } else { 259 SemanticError( yylloc, " Expression disallowed. Only loop-index nameallowed." ); return nullptr;262 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr; 260 263 } // if 261 264 } else { 262 SemanticError( yylloc, " Expression disallowed. Only loop-index name allowed." ); return nullptr;265 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed. ." ); return nullptr; 263 266 } // if 264 267 } // forCtrl 265 268 266 269 static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) { 267 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" 268 271 "Possible cause is misspelled type name or missing generic parameter." ) ); 269 272 } // IdentifierBeforeIdentifier 270 273 271 274 static void IdentifierBeforeType( string & identifier, const char * kind ) { 272 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" 273 276 "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) ); 274 277 } // IdentifierBeforeType … … 297 300 %union { 298 301 Token tok; 299 ParseNode * pn; 300 ExpressionNode * en; 302 ExpressionNode * expr; 301 303 DeclarationNode * decl; 302 304 ast::AggregateDecl::Aggregate aggKey; 303 305 ast::TypeDecl::Kind tclass; 304 StatementNode * sn; 306 StatementNode * stmt; 307 ClauseNode * clause; 305 308 ast::WaitForStmt * wfs; 306 ast::WaitUntilStmt::ClauseNode * wuscn; 307 ast::Expr * constant; 309 ast::WaitUntilStmt::ClauseNode * wucn; 308 310 CondCtl * ifctl; 309 ForCtrl * fctl; 310 OperKinds compop; 311 LabelNode * label; 312 InitializerNode * in; 313 OperKinds op; 311 ForCtrl * forctl; 312 LabelNode * labels; 313 InitializerNode * init; 314 OperKinds oper; 314 315 std::string * str; 315 bool flag;316 EnumHiding hide;317 ast::ExceptionKind catch_kind;316 bool is_volatile; 317 EnumHiding enum_hiding; 318 ast::ExceptionKind except_kind; 318 319 ast::GenericExpr * genexpr; 319 320 } … … 381 382 %type<tok> identifier identifier_at identifier_or_type_name attr_name 382 383 %type<tok> quasi_keyword 383 %type< constant> string_literal384 %type<expr> string_literal 384 385 %type<str> string_literal_list 385 386 386 %type< hide> hide_opt visible_hide_opt387 %type<enum_hiding> hide_opt visible_hide_opt 387 388 388 389 // expressions 389 %type<e n> constant390 %type<e n> tuple tuple_expression_list391 %type<op > ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator392 %type<e n> primary_expression postfix_expression unary_expression393 %type<e n> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression394 %type<e n> shift_expression relational_expression equality_expression395 %type<e n> AND_expression exclusive_OR_expression inclusive_OR_expression396 %type<e n> logical_AND_expression logical_OR_expression397 %type<e n> conditional_expression constant_expression assignment_expression assignment_expression_opt398 %type<e n> comma_expression comma_expression_opt399 %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 400 401 %type<ifctl> conditional_declaration 401 %type<f ctl> for_control_expression for_control_expression_list402 %type< compop> upupeq updown updowneq downupdowneq403 %type<e n> subrange402 %type<forctl> for_control_expression for_control_expression_list 403 %type<oper> upupeq updown updowneq downupdowneq 404 %type<expr> subrange 404 405 %type<decl> asm_name_opt 405 %type<e n> asm_operands_opt asm_operands_list asm_operand406 %type<label > label_list407 %type<e n> asm_clobbers_list_opt408 %type< flag> asm_volatile_opt409 %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 410 411 %type<genexpr> generic_association generic_assoc_list 411 412 412 413 // statements 413 %type<sn> statement labeled_statement compound_statement 414 %type<sn> statement_decl statement_decl_list statement_list_nodecl 415 %type<sn> selection_statement if_statement 416 %type<sn> switch_clause_list_opt switch_clause_list 417 %type<en> case_value 418 %type<sn> case_clause case_value_list case_label case_label_list 419 %type<sn> iteration_statement jump_statement 420 %type<sn> expression_statement asm_statement 421 %type<sn> with_statement 422 %type<en> with_clause_opt 423 %type<sn> exception_statement handler_clause finally_clause 424 %type<catch_kind> handler_key 425 %type<sn> mutex_statement 426 %type<en> when_clause when_clause_opt waitfor waituntil timeout 427 %type<sn> waitfor_statement waituntil_statement 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 428 430 %type<wfs> wor_waitfor_clause 429 %type<wu scn> waituntil_clause wand_waituntil_clause wor_waituntil_clause431 %type<wucn> waituntil_clause wand_waituntil_clause wor_waituntil_clause 430 432 431 433 // declarations … … 439 441 %type<decl> assertion assertion_list assertion_list_opt 440 442 441 %type<e n> bit_subrange_size_opt bit_subrange_size443 %type<expr> bit_subrange_size_opt bit_subrange_size 442 444 443 445 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type … … 452 454 453 455 %type<decl> enumerator_list enum_type enum_type_nobody 454 %type<in > enumerator_value_opt456 %type<init> enumerator_value_opt 455 457 456 458 %type<decl> external_definition external_definition_list external_definition_list_opt … … 459 461 460 462 %type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract 461 %type<e n> field field_name_list field_name fraction_constants_opt463 %type<expr> field field_name_list field_name fraction_constants_opt 462 464 463 465 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 508 510 %type<decl> type_parameter type_parameter_list type_initializer_opt 509 511 510 %type<e n> type_parameters_opt type_list array_type_list512 %type<expr> type_parameters_opt type_list array_type_list 511 513 512 514 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 519 521 520 522 // initializers 521 %type<in > initializer initializer_list_opt initializer_opt523 %type<init> initializer initializer_list_opt initializer_opt 522 524 523 525 // designators 524 %type<e n> designator designator_list designation526 %type<expr> designator designator_list designation 525 527 526 528 … … 644 646 645 647 string_literal: 646 string_literal_list { $$ = build_constantStr( yylloc, *$1); }648 string_literal_list { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 ) ); } 647 649 ; 648 650 … … 687 689 // | RESUME '(' comma_expression ')' compound_statement 688 690 // { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; } 689 | IDENTIFIER IDENTIFIER // syntax error691 | IDENTIFIER IDENTIFIER // invalid syntax rules 690 692 { IdentifierBeforeIdentifier( *$1.str, *$2.str, "n expression" ); $$ = nullptr; } 691 | IDENTIFIER type_qualifier // syntax error693 | IDENTIFIER type_qualifier // invalid syntax rules 692 694 { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; } 693 | IDENTIFIER storage_class // syntax error695 | IDENTIFIER storage_class // invalid syntax rules 694 696 { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; } 695 | IDENTIFIER basic_type_name // syntax error697 | IDENTIFIER basic_type_name // invalid syntax rules 696 698 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 697 | IDENTIFIER TYPEDEFname // syntax error699 | IDENTIFIER TYPEDEFname // invalid syntax rules 698 700 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 699 | IDENTIFIER TYPEGENname // syntax error701 | IDENTIFIER TYPEGENname // invalid syntax rules 700 702 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 701 703 ; … … 739 741 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 740 742 | string_literal '[' assignment_expression ']' // "abc"[3], 3["abc"] 741 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); }743 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 742 744 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 743 745 { … … 757 759 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 758 760 | string_literal '`' identifier // CFA, postfix call 759 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), new ExpressionNode( $1 )) ); }761 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 760 762 | postfix_expression '.' identifier 761 763 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } … … 857 859 | constant 858 860 | string_literal 859 { $$ = new ExpressionNode( $1 ); }861 { $$ = $1; } 860 862 | EXTENSION cast_expression // GCC 861 863 { $$ = $2->set_extension( true ); } … … 1150 1152 identifier_or_type_name ':' attribute_list_opt statement 1151 1153 { $$ = $4->add_label( yylloc, $1, $3 ); } 1152 | identifier_or_type_name ':' attribute_list_opt error // syntax error1153 { 1154 SemanticError( yylloc, ::toString( " Label \"", *$1.str, "\" must be associated with a statement, "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, " 1155 1157 "where a declaration, case, or default is not a statement. " 1156 1158 "Move the label or terminate with a semi-colon." ) ); … … 1191 1193 | statement_list_nodecl statement 1192 1194 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1193 | statement_list_nodecl error // syntax error1194 { 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; } 1195 1197 ; 1196 1198 … … 1217 1219 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1218 1220 } 1219 | SWITCH '(' comma_expression ')' '{' error '}' // CFA, syntaxerror1220 { SemanticError( yylloc, " Only declarations canappear before the list of case clauses." ); $$ = nullptr; }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; } 1221 1223 | CHOOSE '(' comma_expression ')' case_clause // CFA 1222 1224 { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); } … … 1226 1228 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1227 1229 } 1228 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, syntax error1229 { SemanticError( yylloc, " Only declarations canappear before the list of case clauses." ); $$ = nullptr; }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; } 1230 1232 ; 1231 1233 … … 1260 1262 1261 1263 case_value_list: // CFA 1262 case_value { $$ = new StatementNode( build_case($1 ) ); }1264 case_value { $$ = new ClauseNode( build_case( yylloc, $1 ) ); } 1263 1265 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5" 1264 | 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 ) ) ); } 1265 1267 ; 1266 1268 1267 1269 case_label: // CFA 1268 CASE error // syntax error1269 { SemanticError( yylloc, " Missing case listafter case." ); $$ = nullptr; }1270 CASE error // invalid syntax rule 1271 { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; } 1270 1272 | CASE case_value_list ':' { $$ = $2; } 1271 | CASE case_value_list error // syntax error1272 { SemanticError( yylloc, " Missing colonafter case list." ); $$ = nullptr; }1273 | DEFAULT ':' { $$ = new StatementNode( build_default( yylloc ) ); }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 ) ); } 1274 1276 // A semantic check is required to ensure only one default clause per switch/choose statement. 1275 | DEFAULT error // syntax error1276 { SemanticError( yylloc, " Missing colonafter default." ); $$ = nullptr; }1277 | DEFAULT error // invalid syntax rules 1278 { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; } 1277 1279 ; 1278 1280 1279 1281 case_label_list: // CFA 1280 1282 case_label 1281 | case_label_list case_label { $$ = (StatementNode *)( $1->set_last( $2 )); }1283 | case_label_list case_label { $$ = $1->set_last( $2 ); } 1282 1284 ; 1283 1285 … … 1296 1298 { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); } 1297 1299 | switch_clause_list case_label_list statement_list_nodecl 1298 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 )) ) ) ); }1300 { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ); } 1299 1301 ; 1300 1302 … … 1403 1405 else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1404 1406 } 1405 | comma_expression updowneq comma_expression '~' '@' // CFA, error1407 | comma_expression updowneq comma_expression '~' '@' // CFA, invalid syntax rules 1406 1408 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1407 | '@' updowneq '@' // CFA, error1409 | '@' updowneq '@' // CFA, invalid syntax rules 1408 1410 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1409 | '@' updowneq comma_expression '~' '@' // CFA, error1411 | '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rules 1410 1412 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1411 | comma_expression updowneq '@' '~' '@' // CFA, error1413 | comma_expression updowneq '@' '~' '@' // CFA, invalid syntax rules 1412 1414 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1413 | '@' updowneq '@' '~' '@' // CFA, error1415 | '@' updowneq '@' '~' '@' // CFA, invalid syntax rules 1414 1416 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1415 1417 … … 1429 1431 { 1430 1432 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1431 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1433 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1432 1434 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); 1433 1435 } 1434 | comma_expression ';' '@' updowneq '@' // CFA, error1435 { SemanticError( yylloc, " Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }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; } 1436 1438 1437 1439 | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA 1438 1440 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), $7 ); } 1439 | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, error1441 | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, invalid syntax rules 1440 1442 { 1441 1443 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } … … 1445 1447 { 1446 1448 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1447 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1449 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1448 1450 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 ); 1449 1451 } 1450 1452 | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA 1451 1453 { $$ = forCtrl( yylloc, $3, $1, UPDOWN( $4, $3->clone(), $5 ), $4, UPDOWN( $4, $5->clone(), $3->clone() ), nullptr ); } 1452 | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, error1454 | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rules 1453 1455 { 1454 1456 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } … … 1458 1460 { 1459 1461 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1460 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1462 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1461 1463 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr ); 1462 1464 } 1463 1465 | comma_expression ';' '@' updowneq '@' '~' '@' // CFA 1464 { 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; } 1465 1467 1466 1468 | declaration comma_expression // CFA … … 1479 1481 { 1480 1482 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1481 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1483 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1482 1484 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE ); 1483 1485 } … … 1493 1495 { 1494 1496 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1495 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1497 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1496 1498 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 ); 1497 1499 } … … 1506 1508 { 1507 1509 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1508 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1510 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1509 1511 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr ); 1510 1512 } 1511 | declaration '@' updowneq '@' '~' '@' // CFA, error1512 { SemanticError( yylloc, " Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }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; } 1513 1515 1514 1516 | comma_expression ';' TYPEDEFname // CFA, array type … … 1519 1521 | comma_expression ';' downupdowneq TYPEDEFname // CFA, array type 1520 1522 { 1521 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 } 1522 1526 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1523 1527 } … … 1614 1618 MUTEX '(' argument_expression_list_opt ')' statement 1615 1619 { 1616 if ( ! $3 ) { SemanticError( yylloc, " mutex argument list cannot be empty." ); $$ = nullptr; }1620 if ( ! $3 ) { SemanticError( yylloc, "syntax error, mutex argument list cannot be empty." ); $$ = nullptr; } 1617 1621 $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) ); 1618 1622 } … … 1662 1666 { $$ = build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); } 1663 1667 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1664 | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error1665 { SemanticError( yylloc, " else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }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; } 1666 1670 | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1667 1671 { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); } … … 1679 1683 1680 1684 waituntil: 1681 WAITUNTIL '(' c ast_expression ')'1685 WAITUNTIL '(' comma_expression ')' 1682 1686 { $$ = $3; } 1683 1687 ; … … 1707 1711 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); } 1708 1712 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1709 | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error1710 { SemanticError( yylloc, " else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }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; } 1711 1715 | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1712 1716 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, … … 1736 1740 handler_clause: 1737 1741 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1738 { $$ = new StatementNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }1742 { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); } 1739 1743 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1740 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }1744 { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); } 1741 1745 ; 1742 1746 … … 1755 1759 1756 1760 finally_clause: 1757 FINALLY compound_statement { $$ = new StatementNode( build_finally( yylloc, $2 ) ); }1761 FINALLY compound_statement { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); } 1758 1762 ; 1759 1763 … … 1813 1817 asm_operand: // GCC 1814 1818 string_literal '(' constant_expression ')' 1815 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); }1819 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); } 1816 1820 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1817 1821 { 1818 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) );1822 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) ); 1819 1823 delete $2.str; 1820 1824 } … … 1825 1829 { $$ = nullptr; } // use default argument 1826 1830 | string_literal 1827 { $$ = new ExpressionNode( $1 ); }1831 { $$ = $1; } 1828 1832 | asm_clobbers_list_opt ',' string_literal 1829 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( $3 ) )); }1833 { $$ = (ExpressionNode *)( $1->set_last( $3 ) ); } 1830 1834 ; 1831 1835 … … 1899 1903 static_assert: 1900 1904 STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11 1901 { $$ = DeclarationNode::newStaticAssert( $3, $5); }1905 { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 ) ); } 1902 1906 | STATICASSERT '(' constant_expression ')' ';' // CFA 1903 1907 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); } … … 2063 2067 assert( $1->type ); 2064 2068 if ( $1->type->qualifiers.any() ) { // CV qualifiers ? 2065 SemanticError( yylloc, " Useless type qualifier(s) in empty declaration." ); $$ = nullptr;2069 SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr; 2066 2070 } 2067 2071 // enums are never empty declarations because there must have at least one enumeration. 2068 2072 if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ? 2069 SemanticError( yylloc, " Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr;2073 SemanticError( yylloc, "syntax error, useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr; 2070 2074 } 2071 2075 } … … 2098 2102 | type_declaration_specifier 2099 2103 | sue_declaration_specifier 2100 | sue_declaration_specifier invalid_types 2101 { 2102 SemanticError( yylloc, ::toString( " Missing ';' afterend of ",2104 | sue_declaration_specifier invalid_types // invalid syntax rule 2105 { 2106 SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of ", 2103 2107 $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ), 2104 " declaration " ) );2108 " declaration." ) ); 2105 2109 $$ = nullptr; 2106 2110 } … … 2582 2586 // } // for 2583 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 } 2584 2593 | EXTENSION type_specifier field_declaring_list_opt ';' // GCC 2585 2594 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } … … 2680 2689 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2681 2690 { 2682 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) 2683 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }2684 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 } 2685 2694 $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 ); 2686 2695 } … … 2691 2700 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2692 2701 { 2693 if ( $3->storageClasses.any() || $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 } 2694 2705 typedefTable.makeTypedef( *$6 ); 2695 2706 } … … 3164 3175 | IDENTIFIER IDENTIFIER 3165 3176 { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; } 3166 | IDENTIFIER type_qualifier // syntax error3177 | IDENTIFIER type_qualifier // invalid syntax rules 3167 3178 { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; } 3168 | IDENTIFIER storage_class // syntax error3179 | IDENTIFIER storage_class // invalid syntax rules 3169 3180 { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; } 3170 | IDENTIFIER basic_type_name // syntax error3181 | IDENTIFIER basic_type_name // invalid syntax rules 3171 3182 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3172 | IDENTIFIER TYPEDEFname // syntax error3183 | IDENTIFIER TYPEDEFname // invalid syntax rules 3173 3184 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3174 | IDENTIFIER TYPEGENname // syntax error3185 | IDENTIFIER TYPEGENname // invalid syntax rules 3175 3186 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3176 3187 | external_function_definition … … 3207 3218 | type_qualifier_list 3208 3219 { 3209 if ( $1->type->qualifiers.any() ) { 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 } 3210 3223 if ( $1->type->forall ) forall = true; // remember generic type 3211 3224 } … … 3218 3231 | declaration_qualifier_list 3219 3232 { 3220 if ( $1->type && $1->type->qualifiers.any() ) { 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 } 3221 3236 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 3222 3237 } … … 3229 3244 | declaration_qualifier_list type_qualifier_list 3230 3245 { 3231 if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { 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 } 3232 3249 if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type 3233 3250 } … … 3260 3277 $$ = $3; forall = false; 3261 3278 if ( $5 ) { 3262 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." ); 3263 3280 $$ = nullptr; 3264 3281 } // if … … 3329 3346 { 3330 3347 DeclarationNode * name = new DeclarationNode(); 3331 name->asmName = $3;3348 name->asmName = maybeMoveBuild( $3 ); 3332 3349 $$ = name->addQualifiers( $5 ); 3333 3350 }
Note: See TracChangeset
for help on using the changeset viewer.