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