Changeset 35718a9
- Timestamp:
- May 30, 2018, 9:28:14 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 94b1022a
- Parents:
- cb4bbb6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
rcb4bbb6 r35718a9 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 29 07:24:32201813 // Update Count : 3 38712 // Last Modified On : Wed May 30 20:29:03 2018 13 // Update Count : 3432 14 14 // 15 15 … … 330 330 %type<decl> c_declaration static_assert 331 331 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 332 %type<decl> KR_ declaration_list KR_declaration_list_opt332 %type<decl> KR_parameter_list KR_parameter_list_opt 333 333 334 334 %type<decl> parameter_declaration parameter_list parameter_type_list_opt … … 892 892 '{' '}' 893 893 { $$ = new StatementNode( build_compound( (StatementNode *)0 ) ); } 894 | '{' 895 // Two scopes are necessary because the block itself has a scope, but every declaration within the block also 896 // requires its own scope. 897 push push 894 | '{' push 898 895 local_label_declaration_opt // GCC, local labels 899 896 statement_decl_list // C99, intermix declarations and statements 900 897 pop '}' 901 { $$ = new StatementNode( build_compound( $ 5) ); }898 { $$ = new StatementNode( build_compound( $4 ) ); } 902 899 ; 903 900 904 901 statement_decl_list: // C99 905 902 statement_decl 906 | statement_decl_list pushstatement_decl907 { if ( $1 != 0 ) { $1->set_last( $ 3); $$ = $1; } }903 | statement_decl_list statement_decl 904 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 908 905 ; 909 906 … … 923 920 $$ = new StatementNode( $2 ); 924 921 } 925 | statement pop922 | statement 926 923 ; 927 924 … … 938 935 939 936 selection_statement: 940 IF '(' push if_control_expression ')' statement %prec THEN937 IF '(' push if_control_expression ')' statement pop %prec THEN 941 938 // explicitly deal with the shift/reduce conflict on if/else 942 939 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); } 943 | IF '(' push if_control_expression ')' statement ELSE statement 940 | IF '(' push if_control_expression ')' statement ELSE statement pop 944 941 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); } 945 942 | SWITCH '(' comma_expression ')' case_clause 946 943 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); } 947 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA944 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 948 945 { 949 946 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) ); … … 957 954 | CHOOSE '(' comma_expression ')' case_clause // CFA 958 955 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); } 959 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA956 | CHOOSE '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt pop '}' // CFA 960 957 { 961 958 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) ); … … 965 962 966 963 if_control_expression: 967 comma_expression pop964 comma_expression 968 965 { $$ = new IfCtl( nullptr, $1 ); } 969 | c_declaration pop// no semi-colon966 | c_declaration // no semi-colon 970 967 { $$ = new IfCtl( $1, nullptr ); } 971 | cfa_declaration pop// no semi-colon968 | cfa_declaration // no semi-colon 972 969 { $$ = new IfCtl( $1, nullptr ); } 973 970 | declaration comma_expression // semi-colon separated … … 1030 1027 | DO statement WHILE '(' comma_expression ')' ';' 1031 1028 { $$ = new StatementNode( build_while( $5, $2, true ) ); } 1032 | FOR '(' push for_control_expression ')' statement 1029 | FOR '(' push for_control_expression ')' statement pop 1033 1030 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1034 1031 ; 1035 1032 1036 1033 for_control_expression: 1037 comma_expression_opt pop';' comma_expression_opt ';' comma_expression_opt1038 { $$ = new ForCtl( $1, $ 4, $6); }1034 comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1035 { $$ = new ForCtl( $1, $3, $5 ); } 1039 1036 | declaration comma_expression_opt ';' comma_expression_opt // C99 1040 1037 { $$ = new ForCtl( $1, $2, $4 ); } … … 1265 1262 1266 1263 declaration_list_opt: // used at beginning of switch statement 1267 pop// empty1264 // empty 1268 1265 { $$ = nullptr; } 1269 1266 | declaration_list … … 1272 1269 declaration_list: 1273 1270 declaration 1274 | declaration_list pushdeclaration1275 { $$ = $1->appendList( $ 3); }1276 ; 1277 1278 KR_ declaration_list_opt: // used to declare parameter types in K&R style functions1271 | declaration_list declaration 1272 { $$ = $1->appendList( $2 ); } 1273 ; 1274 1275 KR_parameter_list_opt: // used to declare parameter types in K&R style functions 1279 1276 // empty 1280 1277 { $$ = nullptr; } 1281 | KR_ declaration_list1282 ; 1283 1284 KR_ declaration_list:1278 | KR_parameter_list 1279 ; 1280 1281 KR_parameter_list: 1285 1282 push c_declaration pop ';' 1286 1283 { $$ = $2; } 1287 | KR_ declaration_list push c_declaration pop ';'1284 | KR_parameter_list push c_declaration pop ';' 1288 1285 { $$ = $1->appendList( $3 ); } 1289 1286 ; … … 1305 1302 1306 1303 declaration: // old & new style declarations 1307 c_declaration pop';'1308 | cfa_declaration pop ';'// CFA1304 c_declaration ';' 1305 | cfa_declaration ';' // CFA 1309 1306 | static_assert 1310 1307 ; … … 1414 1411 TYPEDEF cfa_variable_specifier 1415 1412 { 1416 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1413 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ ); 1417 1414 $$ = $2->addTypedef(); 1418 1415 } 1419 1416 | TYPEDEF cfa_function_specifier 1420 1417 { 1421 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1418 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ ); 1422 1419 $$ = $2->addTypedef(); 1423 1420 } 1424 1421 | cfa_typedef_declaration pop ',' push no_attr_identifier 1425 1422 { 1426 typedefTable.addToEnclosingScope( *$5, TYPEDEFname );1423 typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ ); 1427 1424 $$ = $1->appendList( $1->cloneType( $5 ) ); 1428 1425 } … … 1435 1432 TYPEDEF type_specifier declarator 1436 1433 { 1437 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1434 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ ); 1438 1435 $$ = $3->addType( $2 )->addTypedef(); 1439 1436 } 1440 1437 | typedef_declaration pop ',' push declarator 1441 1438 { 1442 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );1439 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ ); 1443 1440 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1444 1441 } 1445 1442 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1446 1443 { 1447 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1444 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ ); 1448 1445 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1449 1446 } 1450 1447 | type_specifier TYPEDEF declarator 1451 1448 { 1452 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1449 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ ); 1453 1450 $$ = $3->addType( $1 )->addTypedef(); 1454 1451 } 1455 1452 | type_specifier TYPEDEF type_qualifier_list declarator 1456 1453 { 1457 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1454 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ ); 1458 1455 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1459 1456 } … … 1582 1579 1583 1580 forall: 1584 FORALL '(' push type_parameter_list pop')' // CFA1585 { $$ = DeclarationNode::newForall( $ 4); }1581 FORALL '(' type_parameter_list ')' // CFA 1582 { $$ = DeclarationNode::newForall( $3 ); } 1586 1583 ; 1587 1584 … … 2175 2172 type_parameter: // CFA 2176 2173 type_class no_attr_identifier_or_type_name 2177 { typedefTable.addTo EnclosingScope( *$2, TYPEDEFname); }2174 { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); } 2178 2175 type_initializer_opt assertion_list_opt 2179 2176 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2211 2208 | '|' '{' push trait_declaration_list pop '}' 2212 2209 { $$ = $4; } 2213 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')'2214 { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; }2210 // | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list pop '}' '(' type_list ')' 2211 // { SemanticError( yylloc, "Generic data-type assertion is currently unimplemented." ); $$ = nullptr; } 2215 2212 ; 2216 2213 … … 2244 2241 no_attr_identifier_or_type_name 2245 2242 { 2246 typedefTable.addToEnclosingScope( *$1, TYPEDEFname );2243 typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ ); 2247 2244 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2248 2245 } 2249 | no_attr_identifier_or_type_name '(' push type_parameter_list pop')'2250 { 2251 typedefTable.addToEnclosingScope( *$1, TYPEGENname );2252 $$ = DeclarationNode::newTypeDecl( $1, $ 4);2246 | no_attr_identifier_or_type_name '(' type_parameter_list ')' 2247 { 2248 typedefTable.addToEnclosingScope( *$1, TYPEGENname /*, "11"*/ ); 2249 $$ = DeclarationNode::newTypeDecl( $1, $3 ); 2253 2250 } 2254 2251 ; 2255 2252 2256 2253 trait_specifier: // CFA 2257 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop')' '{' '}'2258 { $$ = DeclarationNode::newTrait( $2, $ 5, 0 ); }2259 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop')' '{' push trait_declaration_list pop '}'2260 { $$ = DeclarationNode::newTrait( $2, $ 5, $10); }2254 TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2255 { $$ = DeclarationNode::newTrait( $2, $4, 0 ); } 2256 | TRAIT no_attr_identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2257 { $$ = DeclarationNode::newTrait( $2, $4, $8 ); } 2261 2258 ; 2262 2259 … … 2296 2293 2297 2294 external_definition_list: 2298 external_definition 2295 push external_definition pop 2296 { $$ = $2; } 2299 2297 | external_definition_list 2300 2298 { forall = xxx; } 2301 push external_definition 2299 push external_definition pop 2302 2300 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2303 2301 ; … … 2321 2319 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2322 2320 } 2323 '{' external_definition_list_opt '}' 2321 // SKULLDUGGERY: Declarations in extern "X" need to be added to the current lexical scope. However, 2322 // external_definition_list_opt creates a new scope that loses the types at the end of the extern block. The 2323 // correction is a pop/push (reverse order) to undo the push/pop from external_definition_list_opt. This 2324 // trick works for nested extern "X"s, as each one undoes itself in the nesting. 2325 '{' pop external_definition_list_opt push '}' 2324 2326 { 2325 2327 linkage = linkageStack.top(); 2326 2328 linkageStack.pop(); 2327 $$ = $ 5;2329 $$ = $6; 2328 2330 } 2329 2331 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown … … 2334 2336 | type_qualifier_list 2335 2337 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2336 push '{' external_definition_list '}'// CFA, namespace2337 { 2338 for ( DeclarationNode * iter = $ 5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2338 '{' external_definition_list push '}' // CFA, namespace 2339 { 2340 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2339 2341 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2340 2342 iter->addQualifiers( $1->clone() ); … … 2343 2345 xxx = false; 2344 2346 delete $1; 2345 $$ = $ 5;2347 $$ = $4; 2346 2348 } 2347 2349 | declaration_qualifier_list 2348 2350 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2349 push '{' external_definition_list '}'// CFA, namespace2350 { 2351 for ( DeclarationNode * iter = $ 5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2351 '{' external_definition_list '}' // CFA, namespace 2352 { 2353 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2352 2354 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2353 2355 iter->addQualifiers( $1->clone() ); … … 2356 2358 xxx = false; 2357 2359 delete $1; 2358 $$ = $ 5;2360 $$ = $4; 2359 2361 } 2360 2362 | declaration_qualifier_list type_qualifier_list … … 2363 2365 if ( $2->type->forall ) xxx = forall = true; // remember generic type 2364 2366 } 2365 push '{' external_definition_list '}'// CFA, namespace2366 { 2367 for ( DeclarationNode * iter = $ 6; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) {2367 '{' external_definition_list '}' // CFA, namespace 2368 { 2369 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2368 2370 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2369 2371 iter->addQualifiers( $1->clone() ); … … 2374 2376 delete $1; 2375 2377 delete $2; 2376 $$ = $ 6;2378 $$ = $5; 2377 2379 } 2378 2380 ; … … 2387 2389 | function_declarator compound_statement 2388 2390 { $$ = $1->addFunctionBody( $2 ); } 2389 | KR_function_declarator KR_ declaration_list_opt compound_statement2391 | KR_function_declarator KR_parameter_list_opt compound_statement 2390 2392 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2391 2393 ; … … 2427 2429 2428 2430 // Old-style K&R function definition, OBSOLESCENT (see 4) 2429 | declaration_specifier KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2431 | declaration_specifier KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2430 2432 { 2431 2433 rebindForall( $1, $2 ); … … 2433 2435 } 2434 2436 // handles default int return type, OBSOLESCENT (see 1) 2435 | type_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2437 | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2436 2438 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2437 2439 // handles default int return type, OBSOLESCENT (see 1) 2438 | declaration_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2440 | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2439 2441 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2440 2442 // handles default int return type, OBSOLESCENT (see 1) 2441 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_ declaration_list_opt with_clause_opt compound_statement2443 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2442 2444 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2443 2445 ; … … 2684 2686 typedef 2685 2687 // hide type name in enclosing scope by variable name 2686 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }2688 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); } 2687 2689 | '(' paren_type ')' 2688 2690 { $$ = $2; } … … 3174 3176 '[' push cfa_abstract_parameter_list pop ']' 3175 3177 { $$ = DeclarationNode::newTuple( $3 ); } 3176 | '[' push type_specifier_nobody ELLIPSIS ']'3178 | '[' push type_specifier_nobody ELLIPSIS pop ']' 3177 3179 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3178 | '[' push type_specifier_nobody ELLIPSIS constant_expression ']'3180 | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']' 3179 3181 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3180 3182 ;
Note: See TracChangeset
for help on using the changeset viewer.