Changeset 55266c7 for src/Parser
- Timestamp:
- Jun 7, 2023, 2:19:12 PM (14 months ago)
- Branches:
- ast-experimental, master
- Children:
- 918e4165
- Parents:
- 77afbb4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r77afbb4 r55266c7 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 26 16:45:37202313 // Update Count : 63 3012 // Last Modified On : Tue Jun 6 22:37:59 2023 13 // Update Count : 6340 14 14 // 15 15 … … 108 108 assert( declList ); 109 109 // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout ); 110 DeclarationNode * c ur = declList, * cl = (new DeclarationNode)->addType( typeSpec );110 DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); 111 111 // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout ); 112 112 // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name; 113 113 114 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() ) ) { 115 115 cl->cloneBaseType( cur ); 116 116 } // for … … 206 206 #define NEW_ONE new ExpressionNode( build_constantInteger( yylloc, *new string( "1" ) ) ) 207 207 #define UPDOWN( compop, left, right ) (compop == OperKinds::LThan || compop == OperKinds::LEThan ? left : right) 208 #define MISSING_ANON_FIELD " Missing loop fields with an anonymous loop index is meaningless as loop index is unavailable in loop body."209 #define MISSING_LOW " Missing low value for up-to range so index is uninitialized."210 #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." 211 211 212 212 static ForCtrl * makeForCtrl( … … 232 232 ForCtrl * forCtrl( const CodeLocation & location, DeclarationNode * index, ExpressionNode * start, enum OperKinds compop, ExpressionNode * comp, ExpressionNode * inc ) { 233 233 if ( index->initializer ) { 234 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." ); 235 235 } // if 236 236 if ( index->next ) { 237 SemanticError( yylloc, " Multiple loop indexes disallowed in for-loop declaration." );237 SemanticError( yylloc, "syntax error, multiple loop indexes disallowed in for-loop declaration." ); 238 238 } // if 239 239 DeclarationNode * initDecl = index->addInitializer( new InitializerNode( start ) ); … … 260 260 return forCtrl( location, type, new string( identifier->name ), start, compop, comp, inc ); 261 261 } else { 262 SemanticError( yylloc, " Expression disallowed. Only loop-index nameallowed." ); return nullptr;262 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed." ); return nullptr; 263 263 } // if 264 264 } else { 265 SemanticError( yylloc, " Expression disallowed. Only loop-index name allowed." ); return nullptr;265 SemanticError( yylloc, "syntax error, loop-index name missing. Expression disallowed. ." ); return nullptr; 266 266 } // if 267 267 } // forCtrl 268 268 269 269 static void IdentifierBeforeIdentifier( string & identifier1, string & identifier2, const char * kind ) { 270 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" 271 271 "Possible cause is misspelled type name or missing generic parameter." ) ); 272 272 } // IdentifierBeforeIdentifier 273 273 274 274 static void IdentifierBeforeType( string & identifier, const char * kind ) { 275 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" 276 276 "Possible cause is misspelled storage/CV qualifier, misspelled typename, or missing generic parameter." ) ); 277 277 } // IdentifierBeforeType … … 1154 1154 | identifier_or_type_name ':' attribute_list_opt error // syntax error 1155 1155 { 1156 SemanticError( yylloc, ::toString( " Label \"", *$1.str, "\" must be associated with a statement, "1156 SemanticError( yylloc, ::toString( "syntx error, label \"", *$1.str, "\" must be associated with a statement, " 1157 1157 "where a declaration, case, or default is not a statement. " 1158 1158 "Move the label or terminate with a semi-colon." ) ); … … 1194 1194 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1195 1195 | statement_list_nodecl error // syntax error 1196 { SemanticError( yylloc, " Declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; }1196 { SemanticError( yylloc, "syntax error, declarations only allowed at the start of the switch body, i.e., after the '{'." ); $$ = nullptr; } 1197 1197 ; 1198 1198 … … 1220 1220 } 1221 1221 | SWITCH '(' comma_expression ')' '{' error '}' // CFA, syntax error 1222 { SemanticError( yylloc, " Only declarations canappear before the list of case clauses." ); $$ = nullptr; }1222 { SemanticError( yylloc, "synatx error, declarations can only appear before the list of case clauses." ); $$ = nullptr; } 1223 1223 | CHOOSE '(' comma_expression ')' case_clause // CFA 1224 1224 { $$ = new StatementNode( build_switch( yylloc, false, $3, $5 ) ); } … … 1229 1229 } 1230 1230 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, syntax error 1231 { SemanticError( yylloc, " Only declarations canappear before the list of case clauses." ); $$ = nullptr; }1231 { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; } 1232 1232 ; 1233 1233 … … 1269 1269 case_label: // CFA 1270 1270 CASE error // syntax error 1271 { SemanticError( yylloc, " Missing case listafter case." ); $$ = nullptr; }1271 { SemanticError( yylloc, "syntax error, case list missing after case." ); $$ = nullptr; } 1272 1272 | CASE case_value_list ':' { $$ = $2; } 1273 1273 | CASE case_value_list error // syntax error 1274 { SemanticError( yylloc, " Missing colonafter case list." ); $$ = nullptr; }1274 { SemanticError( yylloc, "syntax error, colon missing after case list." ); $$ = nullptr; } 1275 1275 | DEFAULT ':' { $$ = new ClauseNode( build_default( yylloc ) ); } 1276 1276 // A semantic check is required to ensure only one default clause per switch/choose statement. 1277 1277 | DEFAULT error // syntax error 1278 { SemanticError( yylloc, " Missing colonafter default." ); $$ = nullptr; }1278 { SemanticError( yylloc, "syntax error, colon missing after default." ); $$ = nullptr; } 1279 1279 ; 1280 1280 … … 1431 1431 { 1432 1432 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1433 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; } 1434 1434 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, NEW_ONE ); 1435 1435 } 1436 1436 | comma_expression ';' '@' updowneq '@' // CFA, error 1437 { SemanticError( yylloc, " Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1437 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1438 1438 1439 1439 | comma_expression ';' comma_expression updowneq comma_expression '~' comma_expression // CFA … … 1447 1447 { 1448 1448 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1449 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; } 1450 1450 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, $7 ); 1451 1451 } … … 1460 1460 { 1461 1461 if ( $4 == OperKinds::GThan || $4 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1462 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; } 1463 1463 else $$ = forCtrl( yylloc, $3, $1, $3->clone(), $4, nullptr, nullptr ); 1464 1464 } 1465 1465 | comma_expression ';' '@' updowneq '@' '~' '@' // CFA 1466 { 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; } 1467 1467 1468 1468 | declaration comma_expression // CFA … … 1481 1481 { 1482 1482 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1483 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; } 1484 1484 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, NEW_ONE ); 1485 1485 } … … 1495 1495 { 1496 1496 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1497 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; } 1498 1498 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, $6 ); 1499 1499 } … … 1508 1508 { 1509 1509 if ( $3 == OperKinds::GThan || $3 == OperKinds::GEThan ) { SemanticError( yylloc, MISSING_HIGH ); $$ = nullptr; } 1510 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; } 1511 1511 else $$ = forCtrl( yylloc, $1, $2, $3, nullptr, nullptr ); 1512 1512 } 1513 1513 | declaration '@' updowneq '@' '~' '@' // CFA, error 1514 { SemanticError( yylloc, " Missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; }1514 { SemanticError( yylloc, "syntax error, missing low/high value for up/down-to range so index is uninitialized." ); $$ = nullptr; } 1515 1515 1516 1516 | comma_expression ';' TYPEDEFname // CFA, array type … … 1521 1521 | comma_expression ';' downupdowneq TYPEDEFname // CFA, array type 1522 1522 { 1523 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, "All enumeration ranges are equal (all values). Remove \"=~\"." ); $$ = nullptr; 1525 } 1524 1526 SemanticError( yylloc, "Type iterator is currently unimplemented." ); $$ = nullptr; 1525 1527 } … … 1616 1618 MUTEX '(' argument_expression_list_opt ')' statement 1617 1619 { 1618 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; } 1619 1621 $$ = new StatementNode( build_mutex( yylloc, $3, $5 ) ); 1620 1622 } … … 1665 1667 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1666 1668 | wor_waitfor_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1667 { SemanticError( yylloc, " else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }1669 { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1668 1670 | wor_waitfor_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1669 1671 { $$ = build_waitfor_else( yylloc, build_waitfor_timeout( yylloc, $1, $3, $4, maybe_build_compound( yylloc, $5 ) ), $7, maybe_build_compound( yylloc, $9 ) ); } … … 1710 1712 // "else" must be conditional after timeout or timeout is never triggered (i.e., it is meaningless) 1711 1713 | wor_waituntil_clause wor when_clause_opt timeout statement wor ELSE statement // syntax error 1712 { SemanticError( yylloc, " else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; }1714 { SemanticError( yylloc, "syntax error, else clause must be conditional after timeout or timeout never triggered." ); $$ = nullptr; } 1713 1715 | wor_waituntil_clause wor when_clause_opt timeout statement wor when_clause ELSE statement 1714 1716 { $$ = new ast::WaitUntilStmt::ClauseNode( ast::WaitUntilStmt::ClauseNode::Op::LEFT_OR, $1, … … 2065 2067 assert( $1->type ); 2066 2068 if ( $1->type->qualifiers.any() ) { // CV qualifiers ? 2067 SemanticError( yylloc, " Useless type qualifier(s) in empty declaration." ); $$ = nullptr;2069 SemanticError( yylloc, "syntax error, useless type qualifier(s) in empty declaration." ); $$ = nullptr; 2068 2070 } 2069 2071 // enums are never empty declarations because there must have at least one enumeration. 2070 2072 if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ? 2071 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; 2072 2074 } 2073 2075 } … … 2102 2104 | sue_declaration_specifier invalid_types 2103 2105 { 2104 SemanticError( yylloc, ::toString( " Missing ';' afterend of ",2106 SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of ", 2105 2107 $1->type->enumeration.name ? "enum" : ast::AggregateDecl::aggrString( $1->type->aggregate.kind ), 2106 " declaration " ) );2108 " declaration." ) ); 2107 2109 $$ = nullptr; 2108 2110 } … … 2584 2586 // } // for 2585 2587 } 2588 | type_specifier field_declaring_list_opt '}' 2589 { 2590 SemanticError( yylloc, ::toString( "syntax error, expecting ';' at end of previous declaration." ) ); 2591 $$ = nullptr; 2592 } 2586 2593 | EXTENSION type_specifier field_declaring_list_opt ';' // GCC 2587 2594 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } … … 2682 2689 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2683 2690 { 2684 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) 2685 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }2686 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 } 2687 2694 $$ = DeclarationNode::newEnum( nullptr, $7, true, true, $3 )->addQualifiers( $5 ); 2688 2695 } … … 2693 2700 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2694 2701 { 2695 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 } 2696 2705 typedefTable.makeTypedef( *$6 ); 2697 2706 } … … 3209 3218 | type_qualifier_list 3210 3219 { 3211 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 } 3212 3223 if ( $1->type->forall ) forall = true; // remember generic type 3213 3224 } … … 3220 3231 | declaration_qualifier_list 3221 3232 { 3222 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 } 3223 3236 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 3224 3237 } … … 3231 3244 | declaration_qualifier_list type_qualifier_list 3232 3245 { 3233 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 } 3234 3249 if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type 3235 3250 } … … 3262 3277 $$ = $3; forall = false; 3263 3278 if ( $5 ) { 3264 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." ); 3265 3280 $$ = nullptr; 3266 3281 } // if
Note: See TracChangeset
for help on using the changeset viewer.