Changes in src/Parser/parser.yy [a983cbf:c86b08d]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (54 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
ra983cbf rc86b08d 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jun 17 18:53:24202313 // Update Count : 63 4711 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Apr 4 14:02:00 2023 13 // Update Count : 6329 14 14 // 15 15 … … 48 48 using namespace std; 49 49 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_... 50 #include "SynTree/Declaration.h" 51 #include "ParseNode.h" 56 52 #include "TypedefTable.h" 57 53 #include "TypeData.h" 54 #include "SynTree/LinkageSpec.h" 58 55 #include "Common/SemanticError.h" // error_str 59 56 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... … … 108 105 assert( declList ); 109 106 // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout ); 110 DeclarationNode * c l = (new DeclarationNode)->addType( typeSpec );107 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec ); 111 108 // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout ); 112 109 // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name; 113 110 114 for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) {111 for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 115 112 cl->cloneBaseType( cur ); 116 113 } // for … … 206 203 #define NEW_ONE new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) ) 207 204 #define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right) 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."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." 211 208 212 209 static ForCtrl * makeForCtrl( … … 232 229 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 233 230 if ( index->initializer ) { 234 SemanticError( yylloc, " syntax error, direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." );231 SemanticError( yylloc, "Direct initialization disallowed. Use instead: type var; initialization ~ comparison ~ increment." ); 235 232 } // if 236 233 if ( index->next ) { 237 SemanticError( yylloc, " syntax error, multiple loop indexes disallowed in for-loop declaration." );234 SemanticError( yylloc, "Multiple loop indexes disallowed in for-loop declaration." ); 238 235 } // if 239 236 DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) ); … … 260 257 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 261 258 } else { 262 SemanticError( yylloc, " syntax error, loop-index name missing. Expression disallowed." ); return nullptr;259 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 263 260 } // if 264 261 } else { 265 SemanticError( yylloc, " syntax error, loop-index name missing. Expression disallowed.." ); return nullptr;262 SemanticError( yylloc, "Expression disallowed. Only loop-index name allowed." ); return nullptr; 266 263 } // if 267 264 } // forCtrl 268 265 269 266 static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) { 270 SemanticError( yylloc, ::toString( " syntax error, adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n"267 SemanticError( yylloc, ::toString( "Adjacent identifiers \"", identifier1, "\" and \"", identifier2, "\" are not meaningful in a", kind, ".\n" 271 268 "Possible cause is misspelled type name or missing generic parameter." ) ); 272 269 } // IdentifierBeforeIdentifier 273 270 274 271 static void IdentifierBeforeType( string & identifier, const char * kind ) { 275 SemanticError( yylloc, ::toString( " syntax error, identifier \"", identifier, "\" cannot appear before a ", kind, ".\n"272 SemanticError( yylloc, ::toString( "Identifier \"", identifier, "\" cannot appear before a ", kind, ".\n" 276 273 "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) ); 277 274 } // IdentifierBeforeType … … 300 297 %union { 301 298 Token tok; 302 ExpressionNode * expr; 299 ParseNode * pn; 300 ExpressionNode * en; 303 301 DeclarationNode * decl; 304 302 ast::AggregateDecl::Aggregate aggKey; 305 303 ast::TypeDecl::Kind tclass; 306 StatementNode * stmt; 307 ClauseNode * clause; 304 StatementNode * sn; 308 305 ast::WaitForStmt * wfs; 309 ast::WaitUntilStmt::ClauseNode * wucn; 306 ast::WaitUntilStmt::ClauseNode * wuscn; 307 ast::Expr * constant; 310 308 CondCtl * ifctl; 311 ForCtrl * forctl; 312 LabelNode * labels; 313 InitializerNode * init; 314 OperKinds oper; 309 ForCtrl * fctl; 310 OperKinds compop; 311 LabelNode * label; 312 InitializerNode * in; 313 OperKinds op; 315 314 std::string * str; 316 bool is_volatile;317 EnumHiding enum_hiding;318 ast::ExceptionKind except_kind;315 bool flag; 316 EnumHiding hide; 317 ast::ExceptionKind catch_kind; 319 318 ast::GenericExpr * genexpr; 320 319 } … … 382 381 %type<tok> identifier identifier_at identifier_or_type_name attr_name 383 382 %type<tok> quasi_keyword 384 %type< expr> string_literal383 %type<constant> string_literal 385 384 %type<str> string_literal_list 386 385 387 %type< enum_hiding> hide_opt visible_hide_opt386 %type<hide> hide_opt visible_hide_opt 388 387 389 388 // expressions 390 %type<e xpr> constant391 %type<e xpr> tuple tuple_expression_list392 %type<op er> ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator393 %type<e xpr> primary_expression postfix_expression unary_expression394 %type<e xpr> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression395 %type<e xpr> shift_expression relational_expression equality_expression396 %type<e xpr> AND_expression exclusive_OR_expression inclusive_OR_expression397 %type<e xpr> logical_AND_expression logical_OR_expression398 %type<e xpr> conditional_expression constant_expression assignment_expression assignment_expression_opt399 %type<e xpr> comma_expression comma_expression_opt400 %type<e xpr> argument_expression_list_opt argument_expression_list argument_expression default_initializer_opt389 %type<en> constant 390 %type<en> tuple tuple_expression_list 391 %type<op> ptrref_operator unary_operator assignment_operator simple_assignment_operator compound_assignment_operator 392 %type<en> primary_expression postfix_expression unary_expression 393 %type<en> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression 394 %type<en> shift_expression relational_expression equality_expression 395 %type<en> AND_expression exclusive_OR_expression inclusive_OR_expression 396 %type<en> logical_AND_expression logical_OR_expression 397 %type<en> conditional_expression constant_expression assignment_expression assignment_expression_opt 398 %type<en> comma_expression comma_expression_opt 399 %type<en> argument_expression_list_opt argument_expression_list argument_expression default_initializer_opt 401 400 %type<ifctl> conditional_declaration 402 %type<f orctl> for_control_expression for_control_expression_list403 %type< oper> upupeq updown updowneq downupdowneq404 %type<e xpr> subrange401 %type<fctl> for_control_expression for_control_expression_list 402 %type<compop> upupeq updown updowneq downupdowneq 403 %type<en> subrange 405 404 %type<decl> asm_name_opt 406 %type<e xpr> asm_operands_opt asm_operands_list asm_operand407 %type<label s> label_list408 %type<e xpr> asm_clobbers_list_opt409 %type< is_volatile> asm_volatile_opt410 %type<e xpr> handler_predicate_opt405 %type<en> asm_operands_opt asm_operands_list asm_operand 406 %type<label> label_list 407 %type<en> asm_clobbers_list_opt 408 %type<flag> asm_volatile_opt 409 %type<en> handler_predicate_opt 411 410 %type<genexpr> generic_association generic_assoc_list 412 411 413 412 // statements 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 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 430 428 %type<wfs> wor_waitfor_clause 431 %type<wu cn> waituntil_clause wand_waituntil_clause wor_waituntil_clause429 %type<wuscn> waituntil_clause wand_waituntil_clause wor_waituntil_clause 432 430 433 431 // declarations … … 441 439 %type<decl> assertion assertion_list assertion_list_opt 442 440 443 %type<e xpr> bit_subrange_size_opt bit_subrange_size441 %type<en> bit_subrange_size_opt bit_subrange_size 444 442 445 443 %type<decl> basic_declaration_specifier basic_type_name basic_type_specifier direct_type indirect_type … … 454 452 455 453 %type<decl> enumerator_list enum_type enum_type_nobody 456 %type<in it> enumerator_value_opt454 %type<in> enumerator_value_opt 457 455 458 456 %type<decl> external_definition external_definition_list external_definition_list_opt … … 461 459 462 460 %type<decl> field_declaration_list_opt field_declaration field_declaring_list_opt field_declarator field_abstract_list_opt field_abstract 463 %type<e xpr> field field_name_list field_name fraction_constants_opt461 %type<en> field field_name_list field_name fraction_constants_opt 464 462 465 463 %type<decl> external_function_definition function_definition function_array function_declarator function_no_ptr function_ptr … … 510 508 %type<decl> type_parameter type_parameter_list type_initializer_opt 511 509 512 %type<e xpr> type_parameters_opt type_list array_type_list510 %type<en> type_parameters_opt type_list array_type_list 513 511 514 512 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 521 519 522 520 // initializers 523 %type<in it> initializer initializer_list_opt initializer_opt521 %type<in> initializer initializer_list_opt initializer_opt 524 522 525 523 // designators 526 %type<e xpr> designator designator_list designation524 %type<en> designator designator_list designation 527 525 528 526 … … 646 644 647 645 string_literal: 648 string_literal_list { $$ = new ExpressionNode( build_constantStr( yylloc, *$1 )); }646 string_literal_list { $$ = build_constantStr( yylloc, *$1 ); } 649 647 ; 650 648 … … 689 687 // | RESUME '(' comma_expression ')' compound_statement 690 688 // { SemanticError( yylloc, "Resume expression is currently unimplemented." ); $$ = nullptr; } 691 | IDENTIFIER IDENTIFIER // invalid syntax rules689 | IDENTIFIER IDENTIFIER // syntax error 692 690 { IdentifierBeforeIdentifier( *$1.str, *$2.str, "n expression" ); $$ = nullptr; } 693 | IDENTIFIER type_qualifier // invalid syntax rules691 | IDENTIFIER type_qualifier // syntax error 694 692 { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; } 695 | IDENTIFIER storage_class // invalid syntax rules693 | IDENTIFIER storage_class // syntax error 696 694 { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; } 697 | IDENTIFIER basic_type_name // invalid syntax rules695 | IDENTIFIER basic_type_name // syntax error 698 696 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 699 | IDENTIFIER TYPEDEFname // invalid syntax rules697 | IDENTIFIER TYPEDEFname // syntax error 700 698 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 701 | IDENTIFIER TYPEGENname // invalid syntax rules699 | IDENTIFIER TYPEGENname // syntax error 702 700 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 703 701 ; … … 741 739 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); } 742 740 | string_literal '[' assignment_expression ']' // "abc"[3], 3["abc"] 743 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, $1, $3 ) ); }741 { $$ = new ExpressionNode( build_binary_val( yylloc, OperKinds::Index, new ExpressionNode( $1 ), $3 ) ); } 744 742 | postfix_expression '{' argument_expression_list_opt '}' // CFA, constructor call 745 743 { … … 759 757 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 760 758 | string_literal '`' identifier // CFA, postfix call 761 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1) ); }759 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); } 762 760 | postfix_expression '.' identifier 763 761 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } … … 859 857 | constant 860 858 | string_literal 861 { $$ = $1; }859 { $$ = new ExpressionNode( $1 ); } 862 860 | EXTENSION cast_expression // GCC 863 861 { $$ = $2->set_extension( true ); } … … 931 929 { $$ = new ExpressionNode( new ast::VirtualCastExpr( yylloc, maybeMoveBuild( $5 ), maybeMoveBuildType( $3 ) ) ); } 932 930 | '(' RETURN type_no_function ')' cast_expression // CFA 933 { $$ = new ExpressionNode( build_cast( yylloc, $3, $5, ast::CastExpr::Return ) ); }931 { SemanticError( yylloc, "Return cast is currently unimplemented." ); $$ = nullptr; } 934 932 | '(' COERCE type_no_function ')' cast_expression // CFA 935 933 { SemanticError( yylloc, "Coerce cast is currently unimplemented." ); $$ = nullptr; } … … 1040 1038 // FIX ME: computes $1 twice 1041 1039 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 1042 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1 ->clone(), $4 ) ); }1040 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1, $4 ) ); } 1043 1041 ; 1044 1042 … … 1152 1150 identifier_or_type_name ':' attribute_list_opt statement 1153 1151 { $$ = $4->add_label( yylloc, $1, $3 ); } 1154 | identifier_or_type_name ':' attribute_list_opt error // invalid syntax rule1155 { 1156 SemanticError( yylloc, ::toString( " syntx error, label \"", *$1.str, "\" must be associated with a statement, "1152 | identifier_or_type_name ':' attribute_list_opt error // syntax error 1153 { 1154 SemanticError( yylloc, ::toString( "Label \"", *$1.str, "\" must be associated with a statement, " 1157 1155 "where a declaration, case, or default is not a statement. " 1158 1156 "Move the label or terminate with a semi-colon." ) ); … … 1193 1191 | statement_list_nodecl statement 1194 1192 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1195 | statement_list_nodecl error // invalid syntax rule1196 { SemanticError( yylloc, " syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }1193 | statement_list_nodecl error // syntax error 1194 { SemanticError( yylloc, "Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; } 1197 1195 ; 1198 1196 … … 1219 1217 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1220 1218 } 1221 | SWITCH '(' comma_expression ')' '{' error '}' // CFA, invalid syntax ruleerror1222 { SemanticError( yylloc, " synatx error, declarations can onlyappear before the list of case clauses." ); $$ = nullptr; }1219 | SWITCH '(' comma_expression ')' '{' error '}' // CFA, syntax error 1220 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; } 1223 1221 | CHOOSE '(' comma_expression ')' case_clause // CFA 1224 1222 { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); } … … 1228 1226 $$ = $7 ? new StatementNode( build_compound( yylloc, (StatementNode *)((new StatementNode( $7 ))->set_last( sw )) ) ) : sw; 1229 1227 } 1230 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, invalid syntax rule1231 { SemanticError( yylloc, " syntax error, declarations can onlyappear before the list of case clauses." ); $$ = nullptr; }1228 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, syntax error 1229 { SemanticError( yylloc, "Only declarations can appear before the list of case clauses." ); $$ = nullptr; } 1232 1230 ; 1233 1231 … … 1262 1260 1263 1261 case_value_list: // CFA 1264 case_value { $$ = new ClauseNode( build_case( yylloc,$1 ) ); }1262 case_value { $$ = new StatementNode( build_case( $1 ) ); } 1265 1263 // convert case list, e.g., "case 1, 3, 5:" into "case 1: case 3: case 5" 1266 | case_value_list ',' case_value { $$ = $1->set_last( new ClauseNode( build_case( yylloc, $3) ) ); }1264 | case_value_list ',' case_value { $$ = (StatementNode *)($1->set_last( new StatementNode( build_case( $3 ) ) ) ); } 1267 1265 ; 1268 1266 1269 1267 case_label: // CFA 1270 CASE error // invalid syntax rule1271 { SemanticError( yylloc, " syntax error, case list missingafter case." ); $$ = nullptr; }1268 CASE error // syntax error 1269 { SemanticError( yylloc, "Missing case list after case." ); $$ = nullptr; } 1272 1270 | CASE case_value_list ':' { $$ = $2; } 1273 | CASE case_value_list error // invalid syntax rule1274 { SemanticError( yylloc, " syntax error, colon missingafter case list." ); $$ = nullptr; }1275 | DEFAULT ':' { $$ = new ClauseNode( build_default( yylloc ) ); }1271 | CASE case_value_list error // syntax error 1272 { SemanticError( yylloc, "Missing colon after case list." ); $$ = nullptr; } 1273 | DEFAULT ':' { $$ = new StatementNode( build_default( yylloc ) ); } 1276 1274 // A semantic check is required to ensure only one default clause per switch/choose statement. 1277 | DEFAULT error // invalid syntax rules1278 { SemanticError( yylloc, " syntax error, colon missingafter default." ); $$ = nullptr; }1275 | DEFAULT error // syntax error 1276 { SemanticError( yylloc, "Missing colon after default." ); $$ = nullptr; } 1279 1277 ; 1280 1278 1281 1279 case_label_list: // CFA 1282 1280 case_label 1283 | case_label_list case_label { $$ = $1->set_last( $2); }1281 | case_label_list case_label { $$ = (StatementNode *)( $1->set_last( $2 )); } 1284 1282 ; 1285 1283 … … 1298 1296 { $$ = $1->append_last_case( new StatementNode( build_compound( yylloc, $2 ) ) ); } 1299 1297 | switch_clause_list case_label_list statement_list_nodecl 1300 { $$ = $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3) ) ) ); }1298 { $$ = (StatementNode *)( $1->set_last( $2->append_last_case( new StatementNode( build_compound( yylloc, $3 ) ) ) ) ); } 1301 1299 ; 1302 1300 … … 1405 1403 else { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1406 1404 } 1407 | comma_expression updowneq comma_expression '~' '@' // CFA, invalid syntax rules1405 | comma_expression updowneq comma_expression '~' '@' // CFA, error 1408 1406 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1409 | '@' updowneq '@' // CFA, invalid syntax rules1407 | '@' updowneq '@' // CFA, error 1410 1408 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1411 | '@' updowneq comma_expression '~' '@' // CFA, invalid syntax rules1409 | '@' updowneq comma_expression '~' '@' // CFA, error 1412 1410 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1413 | comma_expression updowneq '@' '~' '@' // CFA, invalid syntax rules1411 | comma_expression updowneq '@' '~' '@' // CFA, error 1414 1412 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1415 | '@' updowneq '@' '~' '@' // CFA, invalid syntax rules1413 | '@' updowneq '@' '~' '@' // CFA, error 1416 1414 { SemanticError( yylloc, MISSING_ANON_FIELD ); $$ = nullptr; } 1417 1415 … … 1431 1429 { 1432 1430 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1433 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1431 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1434 1432 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); 1435 1433 } 1436 | comma_expression ';' '@' updowneq '@' // CFA, invalid syntax rules1437 { SemanticError( yylloc, " syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1434 | comma_expression ';' '@' updowneq '@' // CFA, error 1435 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1438 1436 1439 1437 | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA 1440 1438 { $$ = 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 rules1439 | comma_expression ';' '@' updowneq comma_expression '~' comma_expression // CFA, error 1442 1440 { 1443 1441 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } … … 1447 1445 { 1448 1446 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1449 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1447 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1450 1448 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 ); 1451 1449 } 1452 1450 | comma_expression ';' comma_expression updowneq comma_expression '~' '@' // CFA 1453 1451 { $$ = 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 rules1452 | comma_expression ';' '@' updowneq comma_expression '~' '@' // CFA, error 1455 1453 { 1456 1454 if ( $4 == OperKinds::LThan || $4 == OperKinds::LEThan ) { SemanticError( yylloc, MISSING_LOW ); $$ = nullptr; } … … 1460 1458 { 1461 1459 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1462 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, " syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1460 else if ( $4 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1463 1461 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr ); 1464 1462 } 1465 1463 | comma_expression ';' '@' updowneq '@' '~' '@' // CFA 1466 { SemanticError( yylloc, " syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1464 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1467 1465 1468 1466 | declaration comma_expression // CFA … … 1481 1479 { 1482 1480 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1483 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1481 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1484 1482 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE ); 1485 1483 } … … 1495 1493 { 1496 1494 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1497 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1495 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1498 1496 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 ); 1499 1497 } … … 1508 1506 { 1509 1507 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1510 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, " syntax error, equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; }1508 else if ( $3 == OperKinds::LEThan ) { SemanticError( yylloc, "Equality with missing high value is meaningless. Use \"~\"." ); $$ = nullptr; } 1511 1509 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr ); 1512 1510 } 1513 | declaration '@' updowneq '@' '~' '@' // CFA, invalid syntax rules1514 { SemanticError( yylloc, " syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1511 | declaration '@' updowneq '@' '~' '@' // CFA, error 1512 { SemanticError( yylloc, "Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1515 1513 1516 1514 | comma_expression ';' TYPEDEFname // CFA, array type … … 1521 1519 | comma_expression ';' downupdowneq TYPEDEFname // CFA, array type 1522 1520 { 1523 if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { 1524 SemanticError( yylloc, "syntax error, all enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; 1525 } 1521 if ( $3 == OperKinds::LEThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, "All enumation ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; } 1526 1522 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1527 1523 } … … 1618 1614 MUTEX '(' argument_expression_list_opt ')' statement 1619 1615 { 1620 if ( ! $3 ) { SemanticError( yylloc, " syntax error,mutex argument list cannot be empty." ); $$ = nullptr; }1616 if ( ! $3 ) { SemanticError( yylloc, "mutex argument list cannot be empty." ); $$ = nullptr; } 1621 1617 $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) ); 1622 1618 } … … 1666 1662 { $$ = build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ); } 1667 1663 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1668 | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // invalid syntax rules1669 { SemanticError( yylloc, " syntax error,else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }1664 | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1665 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1670 1666 | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1671 1667 { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); } … … 1683 1679 1684 1680 waituntil: 1685 WAITUNTIL '(' c omma_expression ')'1681 WAITUNTIL '(' cast_expression ')' 1686 1682 { $$ = $3; } 1687 1683 ; … … 1711 1707 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, build_waituntil_timeout( yylloc, $3, $4, maybe_build_compound( yylloc, $5 ) ) ); } 1712 1708 // "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 rules1714 { SemanticError( yylloc, " syntax error,else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }1709 | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1710 { SemanticError( yylloc, "else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1715 1711 | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1716 1712 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, … … 1740 1736 handler_clause: 1741 1737 handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1742 { $$ = new ClauseNode( build_catch( yylloc, $1, $4, $6, $8 ) ); }1738 { $$ = new StatementNode( build_catch( yylloc, $1, $4, $6, $8 ) ); } 1743 1739 | handler_clause handler_key '(' push exception_declaration pop handler_predicate_opt ')' compound_statement 1744 { $$ = $1->set_last( new ClauseNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); }1740 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( yylloc, $2, $5, $7, $9 ) ) ); } 1745 1741 ; 1746 1742 … … 1759 1755 1760 1756 finally_clause: 1761 FINALLY compound_statement { $$ = new ClauseNode( build_finally( yylloc, $2 ) ); }1757 FINALLY compound_statement { $$ = new StatementNode( build_finally( yylloc, $2 ) ); } 1762 1758 ; 1763 1759 … … 1817 1813 asm_operand: // GCC 1818 1814 string_literal '(' constant_expression ')' 1819 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", maybeMoveBuild( $1 ), maybeMoveBuild( $3 ) ) ); }1815 { $$ = new ExpressionNode( new ast::AsmExpr( yylloc, "", $1, maybeMoveBuild( $3 ) ) ); } 1820 1816 | '[' IDENTIFIER ']' string_literal '(' constant_expression ')' 1821 1817 { 1822 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, maybeMoveBuild( $4 ), maybeMoveBuild( $6 ) ) );1818 $$ = new ExpressionNode( new ast::AsmExpr( yylloc, *$2.str, $4, maybeMoveBuild( $6 ) ) ); 1823 1819 delete $2.str; 1824 1820 } … … 1829 1825 { $$ = nullptr; } // use default argument 1830 1826 | string_literal 1831 { $$ = $1; }1827 { $$ = new ExpressionNode( $1 ); } 1832 1828 | asm_clobbers_list_opt ',' string_literal 1833 { $$ = (ExpressionNode *)( $1->set_last( $3 )); }1829 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); } 1834 1830 ; 1835 1831 … … 1903 1899 static_assert: 1904 1900 STATICASSERT '(' constant_expression ',' string_literal ')' ';' // C11 1905 { $$ = DeclarationNode::newStaticAssert( $3, maybeMoveBuild( $5 )); }1901 { $$ = DeclarationNode::newStaticAssert( $3, $5 ); } 1906 1902 | STATICASSERT '(' constant_expression ')' ';' // CFA 1907 1903 { $$ = DeclarationNode::newStaticAssert( $3, build_constantStr( yylloc, *new string( "\"\"" ) ) ); } … … 2067 2063 assert( $1->type ); 2068 2064 if ( $1->type->qualifiers.any() ) { // CV qualifiers ? 2069 SemanticError( yylloc, " syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr;2065 SemanticError( yylloc, "Useless type qualifier(s) in empty declaration." ); $$ = nullptr; 2070 2066 } 2071 2067 // enums are never empty declarations because there must have at least one enumeration. 2072 2068 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;2069 SemanticError( yylloc, "Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr; 2074 2070 } 2075 2071 } … … 2102 2098 | type_declaration_specifier 2103 2099 | sue_declaration_specifier 2104 | sue_declaration_specifier invalid_types // invalid syntax rule2105 { 2106 SemanticError( yylloc, ::toString( " syntax error, expecting ';' atend of ",2100 | sue_declaration_specifier invalid_types 2101 { 2102 SemanticError( yylloc, ::toString( "Missing ';' after end of ", 2107 2103 $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ), 2108 " declaration ." ) );2104 " declaration" ) ); 2109 2105 $$ = nullptr; 2110 2106 } … … 2586 2582 // } // for 2587 2583 } 2588 | type_specifier field_declaring_list_opt '}' // invalid syntax rule2589 {2590 SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of previous declaration." ) );2591 $$ = nullptr;2592 }2593 2584 | EXTENSION type_specifier field_declaring_list_opt ';' // GCC 2594 2585 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } … … 2689 2680 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2690 2681 { 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 } 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 2694 2685 $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 ); 2695 2686 } … … 2700 2691 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2701 2692 { 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 } 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." ); } 2705 2694 typedefTable.makeTypedef( *$6 ); 2706 2695 } … … 3175 3164 | IDENTIFIER IDENTIFIER 3176 3165 { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; } 3177 | IDENTIFIER type_qualifier // invalid syntax rules3166 | IDENTIFIER type_qualifier // syntax error 3178 3167 { IdentifierBeforeType( *$1.str, "type qualifier" ); $$ = nullptr; } 3179 | IDENTIFIER storage_class // invalid syntax rules3168 | IDENTIFIER storage_class // syntax error 3180 3169 { IdentifierBeforeType( *$1.str, "storage class" ); $$ = nullptr; } 3181 | IDENTIFIER basic_type_name // invalid syntax rules3170 | IDENTIFIER basic_type_name // syntax error 3182 3171 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3183 | IDENTIFIER TYPEDEFname // invalid syntax rules3172 | IDENTIFIER TYPEDEFname // syntax error 3184 3173 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3185 | IDENTIFIER TYPEGENname // invalid syntax rules3174 | IDENTIFIER TYPEGENname // syntax error 3186 3175 { IdentifierBeforeType( *$1.str, "type" ); $$ = nullptr; } 3187 3176 | external_function_definition … … 3218 3207 | type_qualifier_list 3219 3208 { 3220 if ( $1->type->qualifiers.any() ) { 3221 SemanticError( yylloc, "syntax error, CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); 3222 } 3209 if ( $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3223 3210 if ( $1->type->forall ) forall = true; // remember generic type 3224 3211 } … … 3231 3218 | declaration_qualifier_list 3232 3219 { 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 } 3220 if ( $1->type && $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3236 3221 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 3237 3222 } … … 3244 3229 | declaration_qualifier_list type_qualifier_list 3245 3230 { 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 } 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." ); } 3249 3232 if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type 3250 3233 } … … 3277 3260 $$ = $3; forall = false; 3278 3261 if ( $5 ) { 3279 SemanticError( yylloc, " syntax error, attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." );3262 SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." ); 3280 3263 $$ = nullptr; 3281 3264 } // if … … 3346 3329 { 3347 3330 DeclarationNode * name = new DeclarationNode(); 3348 name->asmName = maybeMoveBuild( $3 );3331 name->asmName = $3; 3349 3332 $$ = name->addQualifiers( $5 ); 3350 3333 }
Note:
See TracChangeset
for help on using the changeset viewer.