Changes in src/Parser/parser.yy [3ed994e:35718a9]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (54 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r3ed994e 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 22 08:41:57201813 // Update Count : 3 35312 // Last Modified On : Wed May 30 20:29:03 2018 13 // Update Count : 3432 14 14 // 15 15 … … 175 175 bool flag; 176 176 CatchStmt::Kind catch_kind; 177 GenericExpr * genexpr;178 177 } 179 178 … … 260 259 %type<flag> asm_volatile_opt 261 260 %type<en> handler_predicate_opt 262 %type<genexpr> generic_association generic_assoc_list263 261 264 262 // statements … … 326 324 %type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr 327 325 328 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ type_list_opt326 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt 329 327 330 328 %type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier … … 332 330 %type<decl> c_declaration static_assert 333 331 %type<decl> KR_function_declarator KR_function_no_ptr KR_function_ptr KR_function_array 334 %type<decl> KR_ declaration_list KR_declaration_list_opt332 %type<decl> KR_parameter_list KR_parameter_list_opt 335 333 336 334 %type<decl> parameter_declaration parameter_list parameter_type_list_opt … … 503 501 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 504 502 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 505 { 506 // add the missing control expression to the GenericExpr and return it 507 $5->control = maybeMoveBuild<Expression>( $3 ); 508 $$ = new ExpressionNode( $5 ); 509 } 503 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } 510 504 ; 511 505 512 506 generic_assoc_list: // C11 513 generic_association507 | generic_association 514 508 | generic_assoc_list ',' generic_association 515 {516 // steal the association node from the singleton and delete the wrapper517 $1->associations.splice($1->associations.end(), $3->associations);518 delete $3;519 $$ = $1;520 }521 509 ; 522 510 523 511 generic_association: // C11 524 512 type_no_function ':' assignment_expression 525 {526 // create a GenericExpr wrapper with one association pair527 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );528 }529 513 | DEFAULT ':' assignment_expression 530 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }531 514 ; 532 515 … … 852 835 // '[' ']' 853 836 // { $$ = new ExpressionNode( build_tuple() ); } 854 // '[' push assignment_expression pop ']'837 // | '[' push assignment_expression pop ']' 855 838 // { $$ = new ExpressionNode( build_tuple( $3 ) ); } 856 839 '[' ',' tuple_expression_list ']' 857 840 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 858 | '[' assignment_expression',' tuple_expression_list ']'859 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$ 2->set_last( $4) ) ); }841 | '[' push assignment_expression pop ',' tuple_expression_list ']' 842 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)$3->set_last( $6 ) ) ); } 860 843 ; 861 844 … … 883 866 labeled_statement 884 867 | compound_statement 885 | expression_statement { $$ = $1; }868 | expression_statement 886 869 | selection_statement 887 870 | iteration_statement … … 909 892 '{' '}' 910 893 { $$ = 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 894 | '{' push 915 895 local_label_declaration_opt // GCC, local labels 916 896 statement_decl_list // C99, intermix declarations and statements 917 897 pop '}' 918 { $$ = new StatementNode( build_compound( $ 5) ); }898 { $$ = new StatementNode( build_compound( $4 ) ); } 919 899 ; 920 900 921 901 statement_decl_list: // C99 922 902 statement_decl 923 | statement_decl_list pushstatement_decl924 { if ( $1 != 0 ) { $1->set_last( $ 3); $$ = $1; } }903 | statement_decl_list statement_decl 904 { if ( $1 != 0 ) { $1->set_last( $2 ); $$ = $1; } } 925 905 ; 926 906 … … 940 920 $$ = new StatementNode( $2 ); 941 921 } 942 | statement pop922 | statement 943 923 ; 944 924 … … 955 935 956 936 selection_statement: 957 IF '(' push if_control_expression ')' statement %prec THEN937 IF '(' push if_control_expression ')' statement pop %prec THEN 958 938 // explicitly deal with the shift/reduce conflict on if/else 959 939 { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); } 960 | IF '(' push if_control_expression ')' statement ELSE statement 940 | IF '(' push if_control_expression ')' statement ELSE statement pop 961 941 { $$ = new StatementNode( build_if( $4, $6, $8 ) ); } 962 942 | SWITCH '(' comma_expression ')' case_clause 963 943 { $$ = new StatementNode( build_switch( true, $3, $5 ) ); } 964 | 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 965 945 { 966 946 StatementNode *sw = new StatementNode( build_switch( true, $3, $8 ) ); … … 974 954 | CHOOSE '(' comma_expression ')' case_clause // CFA 975 955 { $$ = new StatementNode( build_switch( false, $3, $5 ) ); } 976 | 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 977 957 { 978 958 StatementNode *sw = new StatementNode( build_switch( false, $3, $8 ) ); … … 982 962 983 963 if_control_expression: 984 comma_expression pop964 comma_expression 985 965 { $$ = new IfCtl( nullptr, $1 ); } 986 | c_declaration pop// no semi-colon966 | c_declaration // no semi-colon 987 967 { $$ = new IfCtl( $1, nullptr ); } 988 | cfa_declaration pop// no semi-colon968 | cfa_declaration // no semi-colon 989 969 { $$ = new IfCtl( $1, nullptr ); } 990 970 | declaration comma_expression // semi-colon separated … … 1047 1027 | DO statement WHILE '(' comma_expression ')' ';' 1048 1028 { $$ = new StatementNode( build_while( $5, $2, true ) ); } 1049 | FOR '(' push for_control_expression ')' statement 1029 | FOR '(' push for_control_expression ')' statement pop 1050 1030 { $$ = new StatementNode( build_for( $4, $6 ) ); } 1051 1031 ; 1052 1032 1053 1033 for_control_expression: 1054 comma_expression_opt pop';' comma_expression_opt ';' comma_expression_opt1055 { $$ = new ForCtl( $1, $ 4, $6); }1034 comma_expression_opt ';' comma_expression_opt ';' comma_expression_opt 1035 { $$ = new ForCtl( $1, $3, $5 ); } 1056 1036 | declaration comma_expression_opt ';' comma_expression_opt // C99 1057 1037 { $$ = new ForCtl( $1, $2, $4 ); } … … 1200 1180 type_specifier_nobody 1201 1181 | type_specifier_nobody declarator 1202 { 1203 $$ = $2->addType( $1 ); 1204 } 1182 { $$ = $2->addType( $1 ); } 1205 1183 | type_specifier_nobody variable_abstract_declarator 1206 1184 { $$ = $2->addType( $1 ); } 1207 1185 | cfa_abstract_declarator_tuple no_attr_identifier // CFA 1208 { 1209 $$ = $1->addName( $2 ); 1210 } 1186 { $$ = $1->addName( $2 ); } 1211 1187 | cfa_abstract_declarator_tuple // CFA 1212 1188 ; … … 1286 1262 1287 1263 declaration_list_opt: // used at beginning of switch statement 1288 pop1264 // empty 1289 1265 { $$ = nullptr; } 1290 1266 | declaration_list … … 1293 1269 declaration_list: 1294 1270 declaration 1295 | declaration_list pushdeclaration1296 { $$ = $1->appendList( $ 3); }1297 ; 1298 1299 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 1300 1276 // empty 1301 1277 { $$ = nullptr; } 1302 | KR_ declaration_list1303 ; 1304 1305 KR_ declaration_list:1278 | KR_parameter_list 1279 ; 1280 1281 KR_parameter_list: 1306 1282 push c_declaration pop ';' 1307 1283 { $$ = $2; } 1308 | KR_ declaration_list push c_declaration pop ';'1284 | KR_parameter_list push c_declaration pop ';' 1309 1285 { $$ = $1->appendList( $3 ); } 1310 1286 ; … … 1321 1297 1322 1298 local_label_list: // GCC, local label 1323 no_attr_identifier_or_type_name {}1324 | local_label_list ',' no_attr_identifier_or_type_name {}1299 no_attr_identifier_or_type_name 1300 | local_label_list ',' no_attr_identifier_or_type_name 1325 1301 ; 1326 1302 1327 1303 declaration: // old & new style declarations 1328 c_declaration pop';'1329 | cfa_declaration pop ';'// CFA1304 c_declaration ';' 1305 | cfa_declaration ';' // CFA 1330 1306 | static_assert 1331 1307 ; … … 1385 1361 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 1386 1362 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); } 1387 | cfa_function_declaration ',' identifier_or_type_name '(' cfa_parameter_type_list_opt')'1363 | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1388 1364 { 1389 1365 // Append the return type at the start (left-hand-side) to each identifier in the list. 1390 1366 DeclarationNode * ret = new DeclarationNode; 1391 1367 ret->type = maybeClone( $1->type->base ); 1392 $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $ 5, nullptr ) );1368 $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) ); 1393 1369 } 1394 1370 ; 1395 1371 1396 1372 cfa_function_specifier: // CFA 1397 // '[' ']' identifier_or_type_name '(' push cfa_parameter_ type_list_opt pop ')' // S/R conflict1373 // '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict 1398 1374 // { 1399 1375 // $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, 0, true ); 1400 1376 // } 1401 // '[' ']' identifier '(' push cfa_parameter_ type_list_opt pop ')'1377 // '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')' 1402 1378 // { 1403 1379 // typedefTable.setNextIdentifier( *$5 ); 1404 1380 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, 0, true ); 1405 1381 // } 1406 // | '[' ']' TYPEDEFname '(' push cfa_parameter_ type_list_opt pop ')'1382 // | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')' 1407 1383 // { 1408 1384 // typedefTable.setNextIdentifier( *$5 ); … … 1412 1388 // identifier_or_type_name must be broken apart because of the sequence: 1413 1389 // 1414 // '[' ']' identifier_or_type_name '(' cfa_parameter_ type_list_opt ')'1390 // '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')' 1415 1391 // '[' ']' type_specifier 1416 1392 // 1417 1393 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1418 1394 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1419 cfa_abstract_tuple identifier_or_type_name '(' cfa_parameter_type_list_opt')'1395 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1420 1396 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1421 { $$ = DeclarationNode::newFunction( $2, $1, $ 4, 0 ); }1422 | cfa_function_return identifier_or_type_name '(' cfa_parameter_type_list_opt')'1423 { $$ = DeclarationNode::newFunction( $2, $1, $ 4, 0 ); }1397 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1398 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1399 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ); } 1424 1400 ; 1425 1401 1426 1402 cfa_function_return: // CFA 1427 '[' cfa_parameter_list ']' 1428 { $$ = DeclarationNode::newTuple( $2 ); } 1429 | '[' cfa_parameter_list ',' cfa_abstract_parameter_list ']' 1430 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the 1431 // ']'. 1432 { $$ = DeclarationNode::newTuple( $2->appendList( $4 ) ); } 1403 '[' push cfa_parameter_list pop ']' 1404 { $$ = DeclarationNode::newTuple( $3 ); } 1405 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 1406 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 1407 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 1433 1408 ; 1434 1409 … … 1436 1411 TYPEDEF cfa_variable_specifier 1437 1412 { 1438 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1413 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "1"*/ ); 1439 1414 $$ = $2->addTypedef(); 1440 1415 } 1441 1416 | TYPEDEF cfa_function_specifier 1442 1417 { 1443 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname );1418 typedefTable.addToEnclosingScope( *$2->name, TYPEDEFname /*, "2"*/ ); 1444 1419 $$ = $2->addTypedef(); 1445 1420 } 1446 1421 | cfa_typedef_declaration pop ',' push no_attr_identifier 1447 1422 { 1448 typedefTable.addToEnclosingScope( *$5, TYPEDEFname );1423 typedefTable.addToEnclosingScope( *$5, TYPEDEFname /*, "3"*/ ); 1449 1424 $$ = $1->appendList( $1->cloneType( $5 ) ); 1450 1425 } … … 1457 1432 TYPEDEF type_specifier declarator 1458 1433 { 1459 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1434 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "4"*/ ); 1460 1435 $$ = $3->addType( $2 )->addTypedef(); 1461 1436 } 1462 1437 | typedef_declaration pop ',' push declarator 1463 1438 { 1464 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname );1439 typedefTable.addToEnclosingScope( *$5->name, TYPEDEFname /*, "5"*/ ); 1465 1440 $$ = $1->appendList( $1->cloneBaseType( $5 )->addTypedef() ); 1466 1441 } 1467 1442 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) 1468 1443 { 1469 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1444 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "6"*/ ); 1470 1445 $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef(); 1471 1446 } 1472 1447 | type_specifier TYPEDEF declarator 1473 1448 { 1474 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname );1449 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname /*, "7"*/ ); 1475 1450 $$ = $3->addType( $1 )->addTypedef(); 1476 1451 } 1477 1452 | type_specifier TYPEDEF type_qualifier_list declarator 1478 1453 { 1479 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname );1454 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname /*, "8"*/ ); 1480 1455 $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 ); 1481 1456 } … … 1604 1579 1605 1580 forall: 1606 FORALL '(' 1607 { 1608 typedefTable.enterScope(); 1609 } 1610 type_parameter_list ')' // CFA 1611 { 1612 typedefTable.leaveScope(); 1613 $$ = DeclarationNode::newForall( $4 ); 1614 } 1581 FORALL '(' type_parameter_list ')' // CFA 1582 { $$ = DeclarationNode::newForall( $3 ); } 1615 1583 ; 1616 1584 … … 1980 1948 ; 1981 1949 1982 cfa_parameter_ type_list_opt: // CFA, abstract + real1950 cfa_parameter_ellipsis_list_opt: // CFA, abstract + real 1983 1951 // empty 1984 1952 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } … … 1987 1955 | cfa_abstract_parameter_list 1988 1956 | cfa_parameter_list 1989 | cfa_parameter_list ','cfa_abstract_parameter_list1990 { $$ = $1->appendList( $ 3); }1991 | cfa_abstract_parameter_list ','ELLIPSIS1957 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list 1958 { $$ = $1->appendList( $5 ); } 1959 | cfa_abstract_parameter_list pop ',' push ELLIPSIS 1992 1960 { $$ = $1->addVarArgs(); } 1993 | cfa_parameter_list ','ELLIPSIS1961 | cfa_parameter_list pop ',' push ELLIPSIS 1994 1962 { $$ = $1->addVarArgs(); } 1995 1963 ; … … 1999 1967 // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'. 2000 1968 cfa_parameter_declaration 2001 | cfa_abstract_parameter_list ','cfa_parameter_declaration2002 { $$ = $1->appendList( $ 3); }2003 | cfa_parameter_list ','cfa_parameter_declaration2004 { $$ = $1->appendList( $ 3); }2005 | cfa_parameter_list ',' cfa_abstract_parameter_list ','cfa_parameter_declaration2006 { $$ = $1->appendList( $ 3 )->appendList( $5); }1969 | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 1970 { $$ = $1->appendList( $5 ); } 1971 | cfa_parameter_list pop ',' push cfa_parameter_declaration 1972 { $$ = $1->appendList( $5 ); } 1973 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 1974 { $$ = $1->appendList( $5 )->appendList( $9 ); } 2007 1975 ; 2008 1976 2009 1977 cfa_abstract_parameter_list: // CFA, new & old style abstract 2010 1978 cfa_abstract_parameter_declaration 2011 | cfa_abstract_parameter_list ','cfa_abstract_parameter_declaration2012 { $$ = $1->appendList( $ 3); }1979 | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration 1980 { $$ = $1->appendList( $5 ); } 2013 1981 ; 2014 1982 … … 2113 2081 { $$ = $2; } 2114 2082 | '=' VOID 2115 { $$ = n ew InitializerNode( true ); }2083 { $$ = nullptr; } 2116 2084 | ATassign initializer 2117 2085 { $$ = $2->set_maybeConstructed( false ); } … … 2159 2127 '.' no_attr_identifier // C99, field name 2160 2128 { $$ = new ExpressionNode( build_varref( $2 ) ); } 2161 | '[' assignment_expression ']'// C99, single array element2129 | '[' push assignment_expression pop ']' // C99, single array element 2162 2130 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple. 2163 { $$ = $2; }2164 | '[' subrange ']' // CFA, multiple array elements2165 { $$ = $2; }2166 | '[' constant_expression ELLIPSIS constant_expression ']' // GCC, multiple array elements2167 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $2 ), maybeMoveBuild< Expression >( $4 ) ) ); }2168 | '.' '[' field_list ']' // CFA, tuple field selector2169 2131 { $$ = $3; } 2132 | '[' push subrange pop ']' // CFA, multiple array elements 2133 { $$ = $3; } 2134 | '[' push constant_expression ELLIPSIS constant_expression pop ']' // GCC, multiple array elements 2135 { $$ = new ExpressionNode( new RangeExpr( maybeMoveBuild< Expression >( $3 ), maybeMoveBuild< Expression >( $5 ) ) ); } 2136 | '.' '[' push field_list pop ']' // CFA, tuple field selector 2137 { $$ = $4; } 2170 2138 ; 2171 2139 … … 2204 2172 type_parameter: // CFA 2205 2173 type_class no_attr_identifier_or_type_name 2206 { typedefTable.addTo EnclosingScope( *$2, TYPEDEFname); }2174 { typedefTable.addToScope( *$2, TYPEDEFname /*, "9"*/ ); } 2207 2175 type_initializer_opt assertion_list_opt 2208 2176 { $$ = DeclarationNode::newTypeParam( $1, $2 )->addTypeInitializer( $4 )->addAssertions( $5 ); } … … 2238 2206 '|' no_attr_identifier_or_type_name '(' type_list ')' 2239 2207 { $$ = DeclarationNode::newTraitUse( $2, $4 ); } 2240 | '|' '{' push trait_declaration_list '}'2208 | '|' '{' push trait_declaration_list pop '}' 2241 2209 { $$ = $4; } 2242 | '|' '(' push type_parameter_list pop ')' '{' push trait_declaration_list'}' '(' type_list ')'2243 { 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; } 2244 2212 ; 2245 2213 … … 2273 2241 no_attr_identifier_or_type_name 2274 2242 { 2275 typedefTable.addToEnclosingScope( *$1, TYPEDEFname );2243 typedefTable.addToEnclosingScope( *$1, TYPEDEFname /*, "10"*/ ); 2276 2244 $$ = DeclarationNode::newTypeDecl( $1, 0 ); 2277 2245 } 2278 | no_attr_identifier_or_type_name '(' push type_parameter_list pop')'2279 { 2280 typedefTable.addToEnclosingScope( *$1, TYPEGENname );2281 $$ = 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 ); 2282 2250 } 2283 2251 ; 2284 2252 2285 2253 trait_specifier: // CFA 2286 TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' '}' 2287 { $$ = DeclarationNode::newTrait( $2, $5, 0 ); } 2288 | TRAIT no_attr_identifier_or_type_name '(' push type_parameter_list pop ')' '{' 2289 { typedefTable.enterScope(); } 2290 trait_declaration_list '}' 2291 { $$ = 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 ); } 2292 2258 ; 2293 2259 2294 2260 trait_declaration_list: // CFA 2295 2261 trait_declaration 2296 | trait_declaration_list p ush trait_declaration2297 { $$ = $1->appendList( $ 3); }2262 | trait_declaration_list pop push trait_declaration 2263 { $$ = $1->appendList( $4 ); } 2298 2264 ; 2299 2265 2300 2266 trait_declaration: // CFA 2301 cfa_trait_declaring_list pop';'2302 | trait_declaring_list pop';'2267 cfa_trait_declaring_list ';' 2268 | trait_declaring_list ';' 2303 2269 ; 2304 2270 2305 2271 cfa_trait_declaring_list: // CFA 2306 2272 cfa_variable_specifier 2307 { $$ = $1; }2308 2273 | cfa_function_specifier 2309 { $$ = $1; }2310 2274 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 2311 2275 { $$ = $1->appendList( $1->cloneType( $5 ) ); } … … 2329 2293 2330 2294 external_definition_list: 2331 external_definition 2295 push external_definition pop 2296 { $$ = $2; } 2332 2297 | external_definition_list 2333 2298 { forall = xxx; } 2334 push external_definition 2299 push external_definition pop 2335 2300 { $$ = $1 ? $1->appendList( $4 ) : $4; } 2336 2301 ; … … 2354 2319 linkage = LinkageSpec::linkageUpdate( yylloc, linkage, $2 ); 2355 2320 } 2356 '{' 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 '}' 2357 2326 { 2358 2327 linkage = linkageStack.top(); 2359 2328 linkageStack.pop(); 2360 $$ = $ 5;2329 $$ = $6; 2361 2330 } 2362 2331 | EXTENSION external_definition // GCC, multiple __extension__ allowed, meaning unknown … … 2366 2335 } 2367 2336 | type_qualifier_list 2368 { 2369 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2370 } 2371 push '{' external_definition_list '}' // CFA, namespace 2372 { 2373 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2337 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2338 '{' external_definition_list push '}' // CFA, namespace 2339 { 2340 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2374 2341 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2375 2342 iter->addQualifiers( $1->clone() ); … … 2378 2345 xxx = false; 2379 2346 delete $1; 2380 $$ = $ 5;2347 $$ = $4; 2381 2348 } 2382 2349 | declaration_qualifier_list 2383 { 2384 if ( $1->type->forall ) xxx = forall = true; // remember generic type 2385 } 2386 push '{' external_definition_list '}' // CFA, namespace 2387 { 2388 for ( DeclarationNode * iter = $5; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2350 { if ( $1->type->forall ) xxx = forall = true; } // remember generic type 2351 '{' external_definition_list '}' // CFA, namespace 2352 { 2353 for ( DeclarationNode * iter = $4; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 2389 2354 if ( isMangled( iter->linkage ) ) { // ignore extern "C" 2390 2355 iter->addQualifiers( $1->clone() ); … … 2393 2358 xxx = false; 2394 2359 delete $1; 2395 $$ = $ 5;2360 $$ = $4; 2396 2361 } 2397 2362 | declaration_qualifier_list type_qualifier_list … … 2400 2365 if ( $2->type->forall ) xxx = forall = true; // remember generic type 2401 2366 } 2402 push '{' external_definition_list '}'// CFA, namespace2403 { 2404 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() ) { 2405 2370 if ( isMangled( iter->linkage ) && isMangled( $2->linkage ) ) { // ignore extern "C" 2406 2371 iter->addQualifiers( $1->clone() ); … … 2411 2376 delete $1; 2412 2377 delete $2; 2413 $$ = $ 6;2378 $$ = $5; 2414 2379 } 2415 2380 ; … … 2423 2388 // declaration must still have a type_specifier. OBSOLESCENT (see 1) 2424 2389 | function_declarator compound_statement 2425 { 2426 typedefTable.leaveScope(); 2427 $$ = $1->addFunctionBody( $2 ); 2428 } 2429 | KR_function_declarator KR_declaration_list_opt compound_statement 2430 { 2431 typedefTable.leaveScope(); 2432 $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); 2433 } 2390 { $$ = $1->addFunctionBody( $2 ); } 2391 | KR_function_declarator KR_parameter_list_opt compound_statement 2392 { $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); } 2434 2393 ; 2435 2394 … … 2444 2403 cfa_function_declaration with_clause_opt compound_statement // CFA 2445 2404 { 2446 typedefTable.leaveScope();2447 2405 // Add the function body to the last identifier in the function definition list, i.e., foo3: 2448 2406 // [const double] foo1(), foo2( int ), foo3( double ) { return 3.0; } … … 2453 2411 { 2454 2412 rebindForall( $1, $2 ); 2455 typedefTable.leaveScope();2456 2413 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2457 2414 } … … 2459 2416 { 2460 2417 rebindForall( $1, $2 ); 2461 typedefTable.leaveScope();2462 2418 $$ = $2->addFunctionBody( $4, $3 )->addType( $1 ); 2463 2419 } 2464 2420 // handles default int return type, OBSOLESCENT (see 1) 2465 2421 | type_qualifier_list function_declarator with_clause_opt compound_statement 2466 { 2467 typedefTable.leaveScope(); 2468 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2469 } 2422 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2470 2423 // handles default int return type, OBSOLESCENT (see 1) 2471 2424 | declaration_qualifier_list function_declarator with_clause_opt compound_statement 2472 { 2473 typedefTable.leaveScope(); 2474 $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); 2475 } 2425 { $$ = $2->addFunctionBody( $4, $3 )->addQualifiers( $1 ); } 2476 2426 // handles default int return type, OBSOLESCENT (see 1) 2477 2427 | declaration_qualifier_list type_qualifier_list function_declarator with_clause_opt compound_statement 2478 { 2479 typedefTable.leaveScope(); 2480 $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); 2481 } 2428 { $$ = $3->addFunctionBody( $5, $4 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2482 2429 2483 2430 // Old-style K&R function definition, OBSOLESCENT (see 4) 2484 | 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 2485 2432 { 2486 2433 rebindForall( $1, $2 ); 2487 typedefTable.leaveScope();2488 2434 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addType( $1 ); 2489 2435 } 2490 2436 // handles default int return type, OBSOLESCENT (see 1) 2491 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2492 { 2493 typedefTable.leaveScope(); 2494 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2495 } 2437 | type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2438 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2496 2439 // handles default int return type, OBSOLESCENT (see 1) 2497 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2498 { 2499 typedefTable.leaveScope(); 2500 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); 2501 } 2440 | declaration_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2441 { $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5, $4 )->addQualifiers( $1 ); } 2502 2442 // handles default int return type, OBSOLESCENT (see 1) 2503 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2504 { 2505 typedefTable.leaveScope(); 2506 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); 2507 } 2443 | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_parameter_list_opt with_clause_opt compound_statement 2444 { $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6, $5 )->addQualifiers( $2 )->addQualifiers( $1 ); } 2508 2445 ; 2509 2446 … … 2702 2639 paren_identifier '(' identifier_list ')' // function_declarator handles empty parameter 2703 2640 { $$ = $1->addIdList( $3 ); } 2704 | '(' KR_function_ptr ')' '(' p arameter_type_list_opt')'2705 { $$ = $2->addParamList( $ 5); }2641 | '(' KR_function_ptr ')' '(' push parameter_type_list_opt pop ')' 2642 { $$ = $2->addParamList( $6 ); } 2706 2643 | '(' KR_function_no_ptr ')' // redundant parenthesis 2707 2644 { $$ = $2; } … … 2749 2686 typedef 2750 2687 // hide type name in enclosing scope by variable name 2751 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER ); }2688 { typedefTable.addToEnclosingScope( *$1->name, IDENTIFIER /*, "ID"*/ ); } 2752 2689 | '(' paren_type ')' 2753 2690 { $$ = $2; } … … 2821 2758 2822 2759 identifier_parameter_function: 2823 paren_identifier '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)2824 { $$ = $1->addParamList( $ 3); }2825 | '(' identifier_parameter_ptr ')' '(' p arameter_type_list_opt')' // empty parameter list OBSOLESCENT (see 3)2826 { $$ = $2->addParamList( $ 5); }2760 paren_identifier '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2761 { $$ = $1->addParamList( $4 ); } 2762 | '(' identifier_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2763 { $$ = $2->addParamList( $6 ); } 2827 2764 | '(' identifier_parameter_function ')' // redundant parenthesis 2828 2765 { $$ = $2; } … … 2874 2811 2875 2812 type_parameter_function: 2876 typedef '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)2877 { $$ = $1->addParamList( $ 3); }2878 | '(' type_parameter_ptr ')' '(' p arameter_type_list_opt')' // empty parameter list OBSOLESCENT (see 3)2879 { $$ = $2->addParamList( $ 5); }2813 typedef '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2814 { $$ = $1->addParamList( $4 ); } 2815 | '(' type_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2816 { $$ = $2->addParamList( $6 ); } 2880 2817 ; 2881 2818 … … 2924 2861 2925 2862 abstract_function: 2926 '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)2927 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $ 2, nullptr ); }2928 | '(' abstract_ptr ')' '(' p arameter_type_list_opt')' // empty parameter list OBSOLESCENT (see 3)2929 { $$ = $2->addParamList( $ 5); }2863 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2864 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2865 | '(' abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2866 { $$ = $2->addParamList( $6 ); } 2930 2867 | '(' abstract_function ')' // redundant parenthesis 2931 2868 { $$ = $2; } … … 2942 2879 2943 2880 multi_array_dimension: 2944 '[' assignment_expression']'2945 { $$ = DeclarationNode::newArray( $ 2, 0, false ); }2946 | '[' '*' ']'// C992881 '[' push assignment_expression pop ']' 2882 { $$ = DeclarationNode::newArray( $3, 0, false ); } 2883 | '[' push '*' pop ']' // C99 2947 2884 { $$ = DeclarationNode::newVarArray( 0 ); } 2948 | multi_array_dimension '[' assignment_expression']'2949 { $$ = $1->addArray( DeclarationNode::newArray( $ 3, 0, false ) ); }2950 | multi_array_dimension '[' '*' ']'// C992885 | multi_array_dimension '[' push assignment_expression pop ']' 2886 { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); } 2887 | multi_array_dimension '[' push '*' pop ']' // C99 2951 2888 { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); } 2952 2889 ; … … 3015 2952 3016 2953 abstract_parameter_function: 3017 '(' p arameter_type_list_opt ')'// empty parameter list OBSOLESCENT (see 3)3018 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $ 2, nullptr ); }3019 | '(' abstract_parameter_ptr ')' '(' p arameter_type_list_opt')' // empty parameter list OBSOLESCENT (see 3)3020 { $$ = $2->addParamList( $ 5); }2954 '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2955 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $3, nullptr ); } 2956 | '(' abstract_parameter_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 2957 { $$ = $2->addParamList( $6 ); } 3021 2958 | '(' abstract_parameter_function ')' // redundant parenthesis 3022 2959 { $$ = $2; } … … 3039 2976 '[' ']' 3040 2977 { $$ = DeclarationNode::newArray( 0, 0, false ); } 3041 // multi_array_dimension handles the '[' '*' ']' case3042 | '[' type_qualifier_list '*' ']'// remaining C993043 { $$ = DeclarationNode::newVarArray( $ 2); }3044 | '[' type_qualifier_list']'3045 { $$ = DeclarationNode::newArray( 0, $ 2, false ); }3046 // multi_array_dimension handles the '[' assignment_expression ']' case3047 | '[' type_qualifier_list assignment_expression']'3048 { $$ = DeclarationNode::newArray( $ 3, $2, false ); }3049 | '[' STATIC type_qualifier_list_opt assignment_expression']'3050 { $$ = DeclarationNode::newArray( $ 4, $3, true ); }3051 | '[' type_qualifier_list STATIC assignment_expression']'3052 { $$ = DeclarationNode::newArray( $ 4, $2, true ); }2978 // multi_array_dimension handles the '[' '*' ']' case 2979 | '[' push type_qualifier_list '*' pop ']' // remaining C99 2980 { $$ = DeclarationNode::newVarArray( $3 ); } 2981 | '[' push type_qualifier_list pop ']' 2982 { $$ = DeclarationNode::newArray( 0, $3, false ); } 2983 // multi_array_dimension handles the '[' assignment_expression ']' case 2984 | '[' push type_qualifier_list assignment_expression pop ']' 2985 { $$ = DeclarationNode::newArray( $4, $3, false ); } 2986 | '[' push STATIC type_qualifier_list_opt assignment_expression pop ']' 2987 { $$ = DeclarationNode::newArray( $5, $4, true ); } 2988 | '[' push type_qualifier_list STATIC assignment_expression pop ']' 2989 { $$ = DeclarationNode::newArray( $5, $3, true ); } 3053 2990 ; 3054 2991 … … 3094 3031 3095 3032 variable_abstract_function: 3096 '(' variable_abstract_ptr ')' '(' p arameter_type_list_opt')' // empty parameter list OBSOLESCENT (see 3)3097 { $$ = $2->addParamList( $ 5); }3033 '(' variable_abstract_ptr ')' '(' push parameter_type_list_opt pop ')' // empty parameter list OBSOLESCENT (see 3) 3034 { $$ = $2->addParamList( $6 ); } 3098 3035 | '(' variable_abstract_function ')' // redundant parenthesis 3099 3036 { $$ = $2; } … … 3158 3095 3159 3096 cfa_array_parameter_1st_dimension: 3160 '[' type_qualifier_list '*' ']'// remaining C993161 { $$ = DeclarationNode::newVarArray( $ 2); }3162 | '[' type_qualifier_list assignment_expression']'3163 { $$ = DeclarationNode::newArray( $ 3, $2, false ); }3164 | '[' declaration_qualifier_list assignment_expression']'3097 '[' push type_qualifier_list '*' pop ']' // remaining C99 3098 { $$ = DeclarationNode::newVarArray( $3 ); } 3099 | '[' push type_qualifier_list assignment_expression pop ']' 3100 { $$ = DeclarationNode::newArray( $4, $3, false ); } 3101 | '[' push declaration_qualifier_list assignment_expression pop ']' 3165 3102 // declaration_qualifier_list must be used because of shift/reduce conflict with 3166 3103 // assignment_expression, so a semantic check is necessary to preclude them as a type_qualifier cannot 3167 3104 // appear in this context. 3168 { $$ = DeclarationNode::newArray( $ 3, $2, true ); }3169 | '[' declaration_qualifier_list type_qualifier_list assignment_expression']'3170 { $$ = DeclarationNode::newArray( $ 4, $3->addQualifiers( $3 ), true ); }3105 { $$ = DeclarationNode::newArray( $4, $3, true ); } 3106 | '[' push declaration_qualifier_list type_qualifier_list assignment_expression pop ']' 3107 { $$ = DeclarationNode::newArray( $5, $4->addQualifiers( $3 ), true ); } 3171 3108 ; 3172 3109 … … 3180 3117 // 3181 3118 // cfa_abstract_tuple identifier_or_type_name 3182 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ type_list_opt ')'3119 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')' 3183 3120 // 3184 3121 // since a function return type can be syntactically identical to a tuple type: … … 3237 3174 3238 3175 cfa_abstract_tuple: // CFA 3239 '[' cfa_abstract_parameter_list ']' 3240 { $$ = DeclarationNode::newTuple( $2 ); } 3176 '[' push cfa_abstract_parameter_list pop ']' 3177 { $$ = DeclarationNode::newTuple( $3 ); } 3178 | '[' push type_specifier_nobody ELLIPSIS pop ']' 3179 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3180 | '[' push type_specifier_nobody ELLIPSIS constant_expression pop ']' 3181 { SemanticError( yylloc, "Tuple array currently unimplemented." ); $$ = nullptr; } 3241 3182 ; 3242 3183 3243 3184 cfa_abstract_function: // CFA 3244 // '[' ']' '(' cfa_parameter_ type_list_opt ')'3185 // '[' ']' '(' cfa_parameter_ellipsis_list_opt ')' 3245 3186 // { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 3246 cfa_abstract_tuple '(' cfa_parameter_type_list_opt')'3247 { $$ = DeclarationNode::newFunction( nullptr, $1, $ 3, nullptr ); }3248 | cfa_function_return '(' cfa_parameter_type_list_opt')'3249 { $$ = DeclarationNode::newFunction( nullptr, $1, $ 3, nullptr ); }3187 cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')' 3188 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 3189 | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')' 3190 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 3250 3191 ; 3251 3192
Note:
See TracChangeset
for help on using the changeset viewer.