Changes in / [ae32d96:94b1022a]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rae32d96 r94b1022a 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 28 17:01:36201813 // Update Count : 3 38312 // Last Modified On : Wed May 30 20:29:03 2018 13 // Update Count : 3432 14 14 // 15 15 … … 332 332 %type<decl> c_declaration static_assert 333 333 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 334 %type<decl> KR_ declaration_list KR_declaration_list_opt334 %type<decl> KR_parameter_list KR_parameter_list_opt 335 335 336 336 %type<decl> parameter_declaration parameter_list parameter_type_list_opt … … 854 854 // | '[' push assignment_expression pop ']' 855 855 // { $$ = new ExpressionNode( build_tuple( $3 ) ); } 856 '[' push ',' tuple_expression_list pop']'857 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $ 4) ) ); }858 | '[' push assignment_expression ',' tuple_expression_list pop']'859 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $ 5) ) ); }856 '[' ',' tuple_expression_list ']' 857 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 858 | '[' push assignment_expression pop ',' tuple_expression_list ']' 859 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); } 860 860 ; 861 861 … … 909 909 '{' '}' 910 910 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 911 | '{' 912 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also 913 // requires its own scope. 914 push push 911 | '{' push 915 912 local_label_declaration_opt // GCC, local labels 916 913 statement_decl_list // C99, intermix declarations and statements 917 914 pop '}' 918 { $$ = new StatementNode( build_compound( $ 5) ); }915 { $$ = new StatementNode( build_compound( $4 ) ); } 919 916 ; 920 917 921 918 statement_decl_list: // C99 922 919 statement_decl 923 | statement_decl_list pushstatement_decl924 { if ( $1 != 0 ) { $1->set_last( $ 3); $$ = $1; } }920 | statement_decl_list statement_decl 921 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 925 922 ; 926 923 … … 940 937 $$ = new StatementNode( $2 ); 941 938 } 942 | statement pop939 | statement 943 940 ; 944 941 … … 955 952 956 953 selection_statement: 957 IF '(' push if_control_expression ')' statement %prec THEN954 IF '(' push if_control_expression ')' statement pop %prec THEN 958 955 // explicitly deal with the shift/reduce conflict on if/else 959 956 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); } 960 | IF '(' push if_control_expression ')' statement ELSE statement 957 | IF '(' push if_control_expression ')' statement ELSE statement pop 961 958 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); } 962 959 | SWITCH '(' comma_expression ')' case_clause 963 960 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); } 964 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA961 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 965 962 { 966 963 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) ); … … 974 971 | CHOOSE '(' comma_expression ')' case_clause // CFA 975 972 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); } 976 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA973 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 977 974 { 978 975 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) ); … … 982 979 983 980 if_control_expression: 984 comma_expression pop981 comma_expression 985 982 { $$ = new IfCtl( nullptr, $1 ); } 986 | c_declaration pop// no semi-colon983 | c_declaration // no semi-colon 987 984 { $$ = new IfCtl( $1, nullptr ); } 988 | cfa_declaration pop// no semi-colon985 | cfa_declaration // no semi-colon 989 986 { $$ = new IfCtl( $1, nullptr ); } 990 987 | declaration comma_expression // semi-colon separated … … 1047 1044 | DO statement WHILE '(' comma_expression ')' ';' 1048 1045 { $$ = new StatementNode( build_while( $5, $2, true ) ); } 1049 | FOR '(' push for_control_expression ')' statement 1046 | FOR '(' push for_control_expression ')' statement pop 1050 1047 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1051 1048 ; 1052 1049 1053 1050 for_control_expression: 1054 comma_expression_opt pop';' comma_expression_opt ';' comma_expression_opt1055 { $$ = new ForCtl( $1, $ 4, $6); }1051 comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1052 { $$ = new ForCtl( $1, $3, $5 ); } 1056 1053 | declaration comma_expression_opt ';' comma_expression_opt // C99 1057 1054 { $$ = new ForCtl( $1, $2, $4 ); } … … 1282 1279 1283 1280 declaration_list_opt: // used at beginning of switch statement 1284 pop// empty1281 // empty 1285 1282 { $$ = nullptr; } 1286 1283 | declaration_list … … 1289 1286 declaration_list: 1290 1287 declaration 1291 | declaration_list pushdeclaration1292 { $$ = $1->appendList( $ 3); }1293 ; 1294 1295 KR_ declaration_list_opt: // used to declare parameter types in K&R style functions1288 | declaration_list declaration 1289 { $$ = $1->appendList( $2 ); } 1290 ; 1291 1292 KR_parameter_list_opt: // used to declare parameter types in K&R style functions 1296 1293 // empty 1297 1294 { $$ = nullptr; } 1298 | KR_ declaration_list1299 ; 1300 1301 KR_ declaration_list:1295 | KR_parameter_list 1296 ; 1297 1298 KR_parameter_list: 1302 1299 push c_declaration pop ';' 1303 1300 { $$ = $2; } 1304 | KR_ declaration_list push c_declaration pop ';'1301 | KR_parameter_list push c_declaration pop ';' 1305 1302 { $$ = $1->appendList( $3 ); } 1306 1303 ; … … 1322 1319 1323 1320 declaration: // old & new style declarations 1324 c_declaration pop';'1325 | cfa_declaration pop ';'// CFA1321 c_declaration ';' 1322 | cfa_declaration ';' // CFA 1326 1323 | static_assert 1327 1324 ; … … 1431 1428 TYPEDEF cfa_variable_specifier 1432 1429 { 1433 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1430 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ ); 1434 1431 $$ = $2->addTypedef(); 1435 1432 } 1436 1433 | TYPEDEF cfa_function_specifier 1437 1434 { 1438 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1435 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ ); 1439 1436 $$ = $2->addTypedef(); 1440 1437 } 1441 1438 | cfa_typedef_declaration pop ',' push no_attr_identifier 1442 1439 { 1443 typedefTable.addToEnclosingScope( *$5, TYPEDEFname );1440 typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ ); 1444 1441 $$ = $1->appendList( $1->cloneType( $5 ) ); 1445 1442 } … … 1452 1449 TYPEDEF type_specifier declarator 1453 1450 { 1454 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1451 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ ); 1455 1452 $$ = $3->addType( $2 )->addTypedef(); 1456 1453 } 1457 1454 | typedef_declaration pop ',' push declarator 1458 1455 { 1459 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );1456 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ ); 1460 1457 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1461 1458 } 1462 1459 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1463 1460 { 1464 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1461 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ ); 1465 1462 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1466 1463 } 1467 1464 | type_specifier TYPEDEF declarator 1468 1465 { 1469 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1466 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ ); 1470 1467 $$ = $3->addType( $1 )->addTypedef(); 1471 1468 } 1472 1469 | type_specifier TYPEDEF type_qualifier_list declarator 1473 1470 { 1474 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1471 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ ); 1475 1472 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1476 1473 } … … 1599 1596 1600 1597 forall: 1601 FORALL '(' push type_parameter_list pop')' // CFA1602 { $$ = DeclarationNode::newForall( $ 4); }1598 FORALL '(' type_parameter_list ')' // CFA 1599 { $$ = DeclarationNode::newForall( $3 ); } 1603 1600 ; 1604 1601 … … 2192 2189 type_parameter: // CFA 2193 2190 type_class no_attr_identifier_or_type_name 2194 { typedefTable.addTo EnclosingScope( *$2, TYPEDEFname); }2191 { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); } 2195 2192 type_initializer_opt assertion_list_opt 2196 2193 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2228 2225 | '|' '{' push trait_declaration_list pop '}' 2229 2226 { $$ = $4; } 2230 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'2231 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }2227 // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')' 2228 // { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; } 2232 2229 ; 2233 2230 … … 2261 2258 no_attr_identifier_or_type_name 2262 2259 { 2263 typedefTable.addToEnclosingScope( *$1, TYPEDEFname );2260 typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ ); 2264 2261 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2265 2262 } 2266 | no_attr_identifier_or_type_name '(' push type_parameter_list pop')'2267 { 2268 typedefTable.addToEnclosingScope( *$1, TYPEGENname );2269 $$ = DeclarationNode::newTypeDecl( $1, $ 4);2263 | no_attr_identifier_or_type_name '(' type_parameter_list ')' 2264 { 2265 typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ ); 2266 $$ = DeclarationNode::newTypeDecl( $1, $3 ); 2270 2267 } 2271 2268 ; 2272 2269 2273 2270 trait_specifier: // CFA 2274 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop')' '{' '}'2275 { $$ = DeclarationNode::newTrait( $2, $ 5, 0 ); }2276 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop')' '{' push trait_declaration_list pop '}'2277 { $$ = DeclarationNode::newTrait( $2, $ 5, $10); }2271 TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2272 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); } 2273 | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2274 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); } 2278 2275 ; 2279 2276 … … 2313 2310 2314 2311 external_definition_list: 2315 external_definition 2312 push external_definition pop 2313 { $$ = $2; } 2316 2314 | external_definition_list 2317 2315 { forall = xxx; } 2318 push external_definition 2316 push external_definition pop 2319 2317 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2320 2318 ; … … 2338 2336 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2339 2337 } 2340 '{' external_definition_list_opt '}' 2338 // SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope. However, 2339 // external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The 2340 // correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt. This 2341 // trick works for nested extern "X"s, as each one undoes itself in the nesting. 2342 '{' pop external_definition_list_opt push '}' 2341 2343 { 2342 2344 linkage = linkageStack.top(); 2343 2345 linkageStack.pop(); 2344 $$ = $ 5;2346 $$ = $6; 2345 2347 } 2346 2348 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown … … 2351 2353 | type_qualifier_list 2352 2354 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2353 push '{' external_definition_list '}'// CFA, namespace2354 { 2355 for ( DeclarationNode * iter = $ 5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2355 '{' external_definition_list push '}' // CFA, namespace 2356 { 2357 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2356 2358 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2357 2359 iter->addQualifiers( $1->clone() ); … … 2360 2362 xxx = false; 2361 2363 delete $1; 2362 $$ = $ 5;2364 $$ = $4; 2363 2365 } 2364 2366 | declaration_qualifier_list 2365 2367 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2366 push '{' external_definition_list '}'// CFA, namespace2367 { 2368 for ( DeclarationNode * iter = $ 5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2368 '{' external_definition_list '}' // CFA, namespace 2369 { 2370 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2369 2371 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2370 2372 iter->addQualifiers( $1->clone() ); … … 2373 2375 xxx = false; 2374 2376 delete $1; 2375 $$ = $ 5;2377 $$ = $4; 2376 2378 } 2377 2379 | declaration_qualifier_list type_qualifier_list … … 2380 2382 if ( $2->type->forall ) xxx = forall = true; // remember generic type 2381 2383 } 2382 push '{' external_definition_list '}'// CFA, namespace2383 { 2384 for ( DeclarationNode * iter = $ 6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2384 '{' external_definition_list '}' // CFA, namespace 2385 { 2386 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2385 2387 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2386 2388 iter->addQualifiers( $1->clone() ); … … 2391 2393 delete $1; 2392 2394 delete $2; 2393 $$ = $ 6;2395 $$ = $5; 2394 2396 } 2395 2397 ; … … 2404 2406 | function_declarator compound_statement 2405 2407 { $$ = $1->addFunctionBody( $2 ); } 2406 | KR_function_declarator KR_ declaration_list_opt compound_statement2408 | KR_function_declarator KR_parameter_list_opt compound_statement 2407 2409 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2408 2410 ; … … 2444 2446 2445 2447 // Old-style K&R function definition, OBSOLESCENT (see 4) 2446 | declaration_specifier KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2448 | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2447 2449 { 2448 2450 rebindForall( $1, $2 ); … … 2450 2452 } 2451 2453 // handles default int return type, OBSOLESCENT (see 1) 2452 | type_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2454 | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2453 2455 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2454 2456 // handles default int return type, OBSOLESCENT (see 1) 2455 | declaration_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2457 | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2456 2458 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2457 2459 // handles default int return type, OBSOLESCENT (see 1) 2458 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2460 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2459 2461 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2460 2462 ; … … 2701 2703 typedef 2702 2704 // hide type name in enclosing scope by variable name 2703 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }2705 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); } 2704 2706 | '(' paren_type ')' 2705 2707 { $$ = $2; } … … 3191 3193 '[' push cfa_abstract_parameter_list pop ']' 3192 3194 { $$ = DeclarationNode::newTuple( $3 ); } 3193 | '[' push type_specifier_nobody ELLIPSIS ']'3195 | '[' push type_specifier_nobody ELLIPSIS pop ']' 3194 3196 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3195 | '[' push type_specifier_nobody ELLIPSIS constant_expression ']'3197 | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']' 3196 3198 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3197 3199 ;
Note:
See TracChangeset
for help on using the changeset viewer.