Changes in src/Parser/parser.yy [0522ebe:44adf1b]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (65 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r0522ebe r44adf1b 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Nov 26 13:18:06 202313 // Update Count : 6 39812 // Last Modified On : Mon Mar 4 08:44:25 2024 13 // Update Count : 6562 14 14 // 15 15 … … 102 102 103 103 DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) { 104 // distribute declaration_specifier across all declared variables, e.g., static, const, but not__attribute__.104 // Distribute type specifier across all declared variables, e.g., static, const, __attribute__. 105 105 assert( declList ); 106 // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout ); 107 DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); 108 // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout ); 109 // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name; 110 111 for ( DeclarationNode * cur = dynamic_cast<DeclarationNode *>( declList->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 112 cl->cloneBaseType( cur ); 106 107 // Do not distribute attributes for aggregates because the attributes surrounding the aggregate belong it not the 108 // variables in the declaration list, e.g., 109 // 110 // struct __attribute__(( aligned(128) )) S { ... 111 // } v1 __attribute__(( aligned(64) )), v2 __attribute__(( aligned(32) )), v3; 112 // struct S v4; 113 // 114 // v1 => 64, v2 =>32, v3 => 128, v2 => 128 115 // 116 // Anonymous aggregates are a special case because there is no aggregate to bind the attribute to; hence it floats 117 // to the declaration list. 118 // 119 // struct __attribute__(( aligned(128) )) /*anonymous */ { ... } v1; 120 // 121 // v1 => 128 122 123 bool copyattr = ! (typeSpec->type && typeSpec->type->kind == TypeData::Aggregate && ! typeSpec->type->aggregate.anon ); 124 125 // addType copies the type information for the aggregate instances from typeSpec into cl's aggInst.aggregate. 126 DeclarationNode * cl = (new DeclarationNode)->addType( typeSpec ); // typeSpec IS DELETED!!! 127 128 // Start at second variable in declaration list and clone the type specifiers for each variable. 129 for ( DeclarationNode * cur = declList->next ; cur != nullptr; cur = cur->next ) { 130 cl->cloneBaseType( cur, copyattr ); // cur is modified 113 131 } // for 114 declList->addType( cl ); 115 // printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 ); 132 133 // Add first variable in declaration list with hidden type information in aggInst.aggregate, which is used by 134 // extractType to recover the type for the aggregate instances. 135 declList->addType( cl, copyattr ); // cl IS DELETED!!! 116 136 return declList; 117 137 } // distAttr … … 119 139 void distExt( DeclarationNode * declaration ) { 120 140 // distribute EXTENSION across all declarations 121 for ( DeclarationNode *iter = declaration ; iter != nullptr; iter = (DeclarationNode *)iter->get_next()) {141 for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next ) { 122 142 iter->set_extension( true ); 123 143 } // for … … 126 146 void distInl( DeclarationNode * declaration ) { 127 147 // distribute INLINE across all declarations 128 for ( DeclarationNode *iter = declaration ; iter != nullptr; iter = (DeclarationNode *)iter->get_next()) {148 for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next ) { 129 149 iter->set_inLine( true ); 130 150 } // for … … 133 153 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) { 134 154 // distribute qualifiers across all non-variable declarations in a distribution statemement 135 for ( DeclarationNode * iter = declaration ; iter != nullptr; iter = (DeclarationNode *)iter->get_next()) {155 for ( DeclarationNode * iter = declaration ; iter != nullptr ; iter = iter->next ) { 136 156 // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since 137 157 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To … … 192 212 fieldList = DeclarationNode::newName( nullptr ); 193 213 } // if 194 // return distAttr( typeSpec, fieldList ); // mark all fields in list195 214 196 215 // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 ); 197 DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list216 DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list 198 217 // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 ); 199 218 return temp; … … 370 389 %token LE GE EQ NE // <= >= == != 371 390 %token ANDAND OROR // && || 372 %token ELLIPSIS //...391 %token ATTR ELLIPSIS // @@ ... 373 392 374 393 %token EXPassign MULTassign DIVassign MODassign // \= *= /= %= … … 414 433 %type<stmt> statement labeled_statement compound_statement 415 434 %type<stmt> statement_decl statement_decl_list statement_list_nodecl 416 %type<stmt> selection_statement if_statement435 %type<stmt> selection_statement 417 436 %type<clause> switch_clause_list_opt switch_clause_list 418 437 %type<expr> case_value … … 481 500 %type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr 482 501 483 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ ellipsis_list_opt502 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_list_ellipsis_opt 484 503 485 504 %type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier … … 489 508 %type<decl> KR_parameter_list KR_parameter_list_opt 490 509 491 %type<decl> parameter_declaration parameter_list parameter_ type_list_opt510 %type<decl> parameter_declaration parameter_list parameter_list_ellipsis_opt 492 511 493 512 %type<decl> paren_identifier paren_type … … 511 530 %type<decl> type_parameter type_parameter_list type_initializer_opt 512 531 513 %type<expr> type_parameters_opt type_list array_type_list 532 %type<expr> type_parameters_opt type_list array_type_list // array_dimension_list 514 533 515 534 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 761 780 | string_literal '`' identifier // CFA, postfix call 762 781 { $$ = new ExpressionNode( build_func( yylloc, new ExpressionNode( build_varref( yylloc, build_postfix_name( $3 ) ) ), $1 ) ); } 782 783 // SKULLDUGGERY: The typedef table used for parsing does not store fields in structures. To parse a qualified 784 // name, it is assumed all name-tokens after the first are identifiers, regardless of how the lexer identifies 785 // them. For example: 786 // 787 // struct S; 788 // forall(T) struct T; 789 // union U; 790 // enum E { S, T, E }; 791 // struct Z { int S, T, Z, E, U; }; 792 // void fred () { 793 // Z z; 794 // z.S; // lexer returns S is TYPEDEFname 795 // z.T; // lexer returns T is TYPEGENname 796 // z.Z; // lexer returns Z is TYPEDEFname 797 // z.U; // lexer returns U is TYPEDEFname 798 // z.E; // lexer returns E is TYPEDEFname 799 // } 763 800 | postfix_expression '.' identifier 764 801 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 802 | postfix_expression '.' TYPEDEFname // CFA, SKULLDUGGERY 803 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 804 | postfix_expression '.' TYPEGENname // CFA, SKULLDUGGERY 805 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 806 765 807 | postfix_expression '.' INTEGERconstant // CFA, tuple index 766 808 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); } … … 1039 1081 | logical_OR_expression '?' comma_expression ':' conditional_expression 1040 1082 { $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); } 1041 // FIX ME: computes $1 twice1042 1083 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 1043 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); }1084 { $$ = new ExpressionNode( build_cond( yylloc, $1, nullptr, $4 ) ); } 1044 1085 ; 1045 1086 … … 1205 1246 ; 1206 1247 1248 // if, switch, and choose require parenthesis around the conditional because it can be followed by a statement. 1249 // For example, without parenthesis: 1250 // 1251 // if x + y + z; => "if ( x + y ) + z" or "if ( x ) + y + z" 1252 // switch ( S ) { ... } => switch ( S ) { compound literal... } ... or 1253 1207 1254 selection_statement: 1208 // pop causes a S/R conflict without separating the IF statement into a non-terminal even after resolving 1209 // the inherent S/R conflict with THEN/ELSE. 1210 push if_statement pop 1211 { $$ = $2; } 1255 IF '(' conditional_declaration ')' statement %prec THEN 1256 // explicitly deal with the shift/reduce conflict on if/else 1257 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); } 1258 | IF '(' conditional_declaration ')' statement ELSE statement 1259 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); } 1212 1260 | SWITCH '(' comma_expression ')' case_clause 1213 1261 { $$ = new StatementNode( build_switch( yylloc, true, $3, $5 ) ); } … … 1233 1281 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, invalid syntax rule 1234 1282 { SemanticError( yylloc, "syntax error, declarations can only appear before the list of case clauses." ); $$ = nullptr; } 1235 ;1236 1237 if_statement:1238 IF '(' conditional_declaration ')' statement %prec THEN1239 // explicitly deal with the shift/reduce conflict on if/else1240 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); }1241 | IF '(' conditional_declaration ')' statement ELSE statement1242 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); }1243 1283 ; 1244 1284 … … 1857 1897 declaration 1858 1898 | declaration_list declaration 1859 { $$ = $1-> appendList( $2 ); }1899 { $$ = $1->set_last( $2 ); } 1860 1900 ; 1861 1901 … … 1870 1910 { $$ = $1; } 1871 1911 | KR_parameter_list c_declaration ';' 1872 { $$ = $1-> appendList( $2 ); }1912 { $$ = $1->set_last( $2 ); } 1873 1913 ; 1874 1914 … … 1890 1930 declaration: // old & new style declarations 1891 1931 c_declaration ';' 1892 {1893 // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" );1894 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {1895 // printf( "\tattr %s\n", attr->name.c_str() );1896 // } // for1897 }1898 1932 | cfa_declaration ';' // CFA 1899 1933 | static_assert // C11 … … 1934 1968 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); } 1935 1969 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1936 { $$ = $1-> appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); }1970 { $$ = $1->set_last( $1->cloneType( $5 )->addInitializer( $6 ) ); } 1937 1971 ; 1938 1972 … … 1956 1990 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 1957 1991 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); } 1958 | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ ellipsis_list_opt pop ')'1992 | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' 1959 1993 { 1960 1994 // Append the return type at the start (left-hand-side) to each identifier in the list. 1961 1995 DeclarationNode * ret = new DeclarationNode; 1962 1996 ret->type = maybeCopy( $1->type->base ); 1963 $$ = $1-> appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );1997 $$ = $1->set_last( DeclarationNode::newFunction( $3, ret, $6, nullptr ) ); 1964 1998 } 1965 1999 ; 1966 2000 1967 2001 cfa_function_specifier: // CFA 1968 // '[' ']' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' // S/R conflict 1969 // { 1970 // $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( 0 ), $6, nullptr, true ); 1971 // } 1972 // '[' ']' identifier '(' push cfa_parameter_ellipsis_list_opt pop ')' 1973 // { 1974 // typedefTable.setNextIdentifier( *$5 ); 1975 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true ); 1976 // } 1977 // | '[' ']' TYPEDEFname '(' push cfa_parameter_ellipsis_list_opt pop ')' 1978 // { 1979 // typedefTable.setNextIdentifier( *$5 ); 1980 // $$ = DeclarationNode::newFunction( $5, DeclarationNode::newTuple( 0 ), $8, nullptr, true ); 1981 // } 1982 // | '[' ']' typegen_name 2002 '[' ']' identifier '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt 2003 { $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( nullptr ), $6, nullptr )->addQualifiers( $9 ); } 2004 | '[' ']' TYPEDEFname '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt 2005 { $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( nullptr ), $6, nullptr )->addQualifiers( $9 ); } 2006 // | '[' ']' TYPEGENname '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt 2007 // { $$ = DeclarationNode::newFunction( $3, DeclarationNode::newTuple( nullptr ), $6, nullptr )->addQualifiers( $9 ); } 2008 1983 2009 // identifier_or_type_name must be broken apart because of the sequence: 1984 2010 // 1985 // '[' ']' identifier_or_type_name '(' cfa_parameter_ ellipsis_list_opt ')'2011 // '[' ']' identifier_or_type_name '(' cfa_parameter_list_ellipsis_opt ')' 1986 2012 // '[' ']' type_specifier 1987 2013 // 1988 2014 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1989 2015 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1990 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt2016 | cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt 1991 2017 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1992 2018 { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); } 1993 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ ellipsis_list_opt pop ')' attribute_list_opt2019 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt 1994 2020 { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); } 1995 2021 ; … … 1998 2024 '[' push cfa_parameter_list pop ']' 1999 2025 { $$ = DeclarationNode::newTuple( $3 ); } 2000 | '[' push cfa_parameter_list pop ',' pushcfa_abstract_parameter_list pop ']'2026 | '[' push cfa_parameter_list ',' cfa_abstract_parameter_list pop ']' 2001 2027 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 2002 { $$ = DeclarationNode::newTuple( $3-> appendList( $7) ); }2028 { $$ = DeclarationNode::newTuple( $3->set_last( $5 ) ); } 2003 2029 ; 2004 2030 … … 2014 2040 $$ = $2->addTypedef(); 2015 2041 } 2016 | cfa_typedef_declaration pop ',' pushidentifier2017 { 2018 typedefTable.addToEnclosingScope( *$ 5, TYPEDEFname, "cfa_typedef_declaration 3" );2019 $$ = $1-> appendList( $1->cloneType( $5) );2042 | cfa_typedef_declaration ',' identifier 2043 { 2044 typedefTable.addToEnclosingScope( *$3, TYPEDEFname, "cfa_typedef_declaration 3" ); 2045 $$ = $1->set_last( $1->cloneType( $3 ) ); 2020 2046 } 2021 2047 ; … … 2035 2061 { 2036 2062 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "typedef_declaration 2" ); 2037 $$ = $1-> appendList( $1->cloneBaseType( $3 )->addTypedef() );2063 $$ = $1->set_last( $1->cloneBaseType( $3 )->addTypedef() ); 2038 2064 } 2039 2065 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) … … 2089 2115 2090 2116 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 2091 { $$ = $1-> appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }2117 { $$ = $1->set_last( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 2092 2118 ; 2093 2119 … … 2348 2374 sue_declaration_specifier: // struct, union, enum + storage class + type specifier 2349 2375 sue_type_specifier 2350 {2351 // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );2352 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {2353 // printf( "\tattr %s\n", attr->name.c_str() );2354 // } // for2355 }2356 2376 | declaration_qualifier_list sue_type_specifier 2357 2377 { $$ = $2->addQualifiers( $1 ); } … … 2364 2384 sue_type_specifier: // struct, union, enum + type specifier 2365 2385 elaborated_type 2366 {2367 // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );2368 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {2369 // printf( "\tattr %s\n", attr->name.c_str() );2370 // } // for2371 }2372 2386 | type_qualifier_list 2373 2387 { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type … … 2442 2456 elaborated_type: // struct, union, enum 2443 2457 aggregate_type 2444 {2445 // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" );2446 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) {2447 // printf( "\tattr %s\n", attr->name.c_str() );2448 // } // for2449 }2450 2458 | enum_type 2451 2459 ; … … 2571 2579 { $$ = nullptr; } 2572 2580 | field_declaration_list_opt field_declaration 2573 { $$ = $1 ? $1-> appendList( $2 ) : $2; }2581 { $$ = $1 ? $1->set_last( $2 ) : $2; } 2574 2582 ; 2575 2583 … … 2619 2627 | field_declarator 2620 2628 | field_declaring_list_opt ',' attribute_list_opt field_declarator 2621 { $$ = $1-> appendList( $4->addQualifiers( $3 ) ); }2629 { $$ = $1->set_last( $4->addQualifiers( $3 ) ); } 2622 2630 ; 2623 2631 … … 2641 2649 | field_abstract 2642 2650 | field_abstract_list_opt ',' attribute_list_opt field_abstract 2643 { $$ = $1-> appendList( $4->addQualifiers( $3 ) ); }2651 { $$ = $1->set_last( $4->addQualifiers( $3 ) ); } 2644 2652 ; 2645 2653 … … 2654 2662 { $$ = $1->addName( $2 ); } 2655 2663 | cfa_field_declaring_list ',' identifier_or_type_name 2656 { $$ = $1-> appendList( $1->cloneType( $3 ) ); }2664 { $$ = $1->set_last( $1->cloneType( $3 ) ); } 2657 2665 ; 2658 2666 … … 2661 2669 cfa_abstract_declarator_tuple 2662 2670 | cfa_field_abstract_list ',' 2663 { $$ = $1-> appendList( $1->cloneType( 0 ) ); }2671 { $$ = $1->set_last( $1->cloneType( 0 ) ); } 2664 2672 ; 2665 2673 … … 2675 2683 ; 2676 2684 2685 // *********** 2686 // Enumeration 2687 // *********** 2688 2677 2689 enum_type: 2678 2690 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2679 2691 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); } 2680 2692 | ENUM attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule 2681 { SemanticError( yylloc, "syntax error, hiding '!'the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }2693 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; } 2682 2694 | ENUM attribute_list_opt identifier 2683 2695 { typedefTable.makeTypedef( *$3, "enum_type 1" ); } … … 2694 2706 } 2695 2707 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // unqualified type name 2696 { SemanticError( yylloc, "syntax error, hiding '!'the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }2708 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; } 2697 2709 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2698 2710 { … … 2700 2712 } 2701 2713 | ENUM '(' ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule 2702 { SemanticError( yylloc, "syntax error, hiding '!'the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }2714 { SemanticError( yylloc, "syntax error, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; } 2703 2715 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2704 2716 { 2705 if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0 )) {2717 if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0) ) { 2706 2718 SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); 2707 2719 } … … 2753 2765 { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); } 2754 2766 | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt 2755 { $$ = $1-> appendList( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }2767 { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); } 2756 2768 | enumerator_list ',' INLINE type_name enumerator_value_opt 2757 { $$ = $1-> appendList( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }2769 { $$ = $1->set_last( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); } 2758 2770 ; 2759 2771 … … 2773 2785 ; 2774 2786 2775 cfa_parameter_ellipsis_list_opt: // CFA, abstract + real 2776 // empty 2777 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } 2778 | ELLIPSIS 2779 { $$ = nullptr; } 2780 | cfa_abstract_parameter_list 2781 | cfa_parameter_list 2782 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list 2783 { $$ = $1->appendList( $5 ); } 2784 | cfa_abstract_parameter_list pop ',' push ELLIPSIS 2785 { $$ = $1->addVarArgs(); } 2786 | cfa_parameter_list pop ',' push ELLIPSIS 2787 { $$ = $1->addVarArgs(); } 2788 ; 2789 2790 cfa_parameter_list: // CFA 2791 // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is 2792 // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'. 2793 cfa_parameter_declaration 2794 | cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 2795 { $$ = $1->appendList( $5 ); } 2796 | cfa_parameter_list pop ',' push cfa_parameter_declaration 2797 { $$ = $1->appendList( $5 ); } 2798 | cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ',' push cfa_parameter_declaration 2799 { $$ = $1->appendList( $5 )->appendList( $9 ); } 2800 ; 2801 2802 cfa_abstract_parameter_list: // CFA, new & old style abstract 2803 cfa_abstract_parameter_declaration 2804 | cfa_abstract_parameter_list pop ',' push cfa_abstract_parameter_declaration 2805 { $$ = $1->appendList( $5 ); } 2806 ; 2807 2808 parameter_type_list_opt: 2787 // ******************* 2788 // Function parameters 2789 // ******************* 2790 2791 parameter_list_ellipsis_opt: 2809 2792 // empty 2810 2793 { $$ = nullptr; } … … 2817 2800 2818 2801 parameter_list: // abstract + real 2819 abstract_parameter_declaration 2820 | parameter_declaration 2802 parameter_declaration 2803 | abstract_parameter_declaration 2804 | parameter_list ',' parameter_declaration 2805 { $$ = $1->set_last( $3 ); } 2821 2806 | parameter_list ',' abstract_parameter_declaration 2822 { $$ = $1->appendList( $3 ); } 2823 | parameter_list ',' parameter_declaration 2824 { $$ = $1->appendList( $3 ); } 2807 { $$ = $1->set_last( $3 ); } 2808 ; 2809 2810 cfa_parameter_list_ellipsis_opt: // CFA, abstract + real 2811 // empty 2812 { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); } 2813 | ELLIPSIS 2814 { $$ = nullptr; } 2815 | cfa_parameter_list 2816 | cfa_abstract_parameter_list 2817 | cfa_parameter_list ',' cfa_abstract_parameter_list 2818 { $$ = $1->set_last( $3 ); } 2819 | cfa_parameter_list ',' ELLIPSIS 2820 { $$ = $1->addVarArgs(); } 2821 | cfa_abstract_parameter_list ',' ELLIPSIS 2822 { $$ = $1->addVarArgs(); } 2823 ; 2824 2825 cfa_parameter_list: // CFA 2826 // To obtain LR(1) between cfa_parameter_list and cfa_abstract_tuple, the last cfa_abstract_parameter_list is 2827 // factored out from cfa_parameter_list, flattening the rules to get lookahead to the ']'. 2828 cfa_parameter_declaration 2829 | cfa_abstract_parameter_list ',' cfa_parameter_declaration 2830 { $$ = $1->set_last( $3 ); } 2831 | cfa_parameter_list ',' cfa_parameter_declaration 2832 { $$ = $1->set_last( $3 ); } 2833 | cfa_parameter_list ',' cfa_abstract_parameter_list ',' cfa_parameter_declaration 2834 { $$ = $1->set_last( $3 )->set_last( $5 ); } 2835 ; 2836 2837 cfa_abstract_parameter_list: // CFA, new & old style abstract 2838 cfa_abstract_parameter_declaration 2839 | cfa_abstract_parameter_list ',' cfa_abstract_parameter_declaration 2840 { $$ = $1->set_last( $3 ); } 2825 2841 ; 2826 2842 2827 2843 // Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics 2828 2844 // for typedef name by using type_parameter_redeclarator instead of typedef_redeclarator, and function prototypes. 2845 2846 parameter_declaration: 2847 // No SUE declaration in parameter list. 2848 declaration_specifier_nobody identifier_parameter_declarator default_initializer_opt 2849 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2850 | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt 2851 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2852 ; 2853 2854 abstract_parameter_declaration: 2855 declaration_specifier_nobody default_initializer_opt 2856 { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); } 2857 | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt 2858 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2859 ; 2829 2860 2830 2861 cfa_parameter_declaration: // CFA, new & old style parameter declaration … … 2850 2881 ; 2851 2882 2852 parameter_declaration:2853 // No SUE declaration in parameter list.2854 declaration_specifier_nobody identifier_parameter_declarator default_initializer_opt2855 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }2856 | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt2857 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }2858 ;2859 2860 abstract_parameter_declaration:2861 declaration_specifier_nobody default_initializer_opt2862 { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }2863 | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt2864 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }2865 ;2866 2867 2883 // ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a 2868 2884 // parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on … … 2873 2889 { $$ = DeclarationNode::newName( $1 ); } 2874 2890 | identifier_list ',' identifier 2875 { $$ = $1-> appendList( DeclarationNode::newName( $3 ) ); }2891 { $$ = $1->set_last( DeclarationNode::newName( $3 ) ); } 2876 2892 ; 2877 2893 … … 2974 2990 type_parameter 2975 2991 | type_parameter_list ',' type_parameter 2976 { $$ = $1-> appendList( $3 ); }2992 { $$ = $1->set_last( $3 ); } 2977 2993 ; 2978 2994 … … 3047 3063 assertion 3048 3064 | assertion_list assertion 3049 { $$ = $1-> appendList( $2 ); }3065 { $$ = $1->set_last( $2 ); } 3050 3066 ; 3051 3067 … … 3075 3091 { $$ = $3->addQualifiers( $1 ); } 3076 3092 | type_declaring_list ',' type_declarator 3077 { $$ = $1-> appendList( $3->copySpecifiers( $1 ) ); }3093 { $$ = $1->set_last( $3->copySpecifiers( $1 ) ); } 3078 3094 ; 3079 3095 … … 3118 3134 trait_declaration 3119 3135 | trait_declaration_list pop push trait_declaration 3120 { $$ = $1-> appendList( $4 ); }3136 { $$ = $1->set_last( $4 ); } 3121 3137 ; 3122 3138 … … 3130 3146 | cfa_function_specifier 3131 3147 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 3132 { $$ = $1-> appendList( $1->cloneType( $5 ) ); }3148 { $$ = $1->set_last( $1->cloneType( $5 ) ); } 3133 3149 ; 3134 3150 … … 3137 3153 { $$ = $2->addType( $1 ); } 3138 3154 | trait_declaring_list pop ',' push declarator 3139 { $$ = $1-> appendList( $1->cloneBaseType( $5 ) ); }3155 { $$ = $1->set_last( $1->cloneBaseType( $5 ) ); } 3140 3156 ; 3141 3157 … … 3145 3161 // empty, input file 3146 3162 | external_definition_list 3147 { parseTree = parseTree ? parseTree-> appendList( $1 ) : $1; }3163 { parseTree = parseTree ? parseTree->set_last( $1 ) : $1; } 3148 3164 ; 3149 3165 … … 3152 3168 { $$ = $2; } 3153 3169 | external_definition_list push external_definition pop 3154 { $$ = $1 ? $1-> appendList( $3 ) : $3; }3170 { $$ = $1 ? $1->set_last( $3 ) : $3; } 3155 3171 ; 3156 3172 … … 3177 3193 // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is 3178 3194 // disallowed at the moment. 3179 if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) { 3195 if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && 3196 $1->type && $1->type->kind == TypeData::AggregateInst ) { 3180 3197 if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) { 3181 3198 SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr; … … 3378 3395 ATTRIBUTE '(' '(' attribute_name_list ')' ')' 3379 3396 { $$ = $4; } 3397 | ATTRIBUTE '(' attribute_name_list ')' // CFA 3398 { $$ = $3; } 3399 | ATTR '(' attribute_name_list ')' // CFA 3400 { $$ = $3; } 3380 3401 ; 3381 3402 … … 3482 3503 3483 3504 variable_function: 3484 '(' variable_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3505 '(' variable_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3485 3506 { $$ = $2->addParamList( $5 ); } 3486 | '(' attribute_list variable_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3507 | '(' attribute_list variable_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3487 3508 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3488 3509 | '(' variable_function ')' // redundant parenthesis … … 3505 3526 3506 3527 function_no_ptr: 3507 paren_identifier '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3528 paren_identifier '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3508 3529 { $$ = $1->addParamList( $3 ); } 3509 | '(' function_ptr ')' '(' parameter_ type_list_opt ')'3530 | '(' function_ptr ')' '(' parameter_list_ellipsis_opt ')' 3510 3531 { $$ = $2->addParamList( $5 ); } 3511 | '(' attribute_list function_ptr ')' '(' parameter_ type_list_opt ')'3532 | '(' attribute_list function_ptr ')' '(' parameter_list_ellipsis_opt ')' 3512 3533 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3513 3534 | '(' function_no_ptr ')' // redundant parenthesis … … 3559 3580 paren_identifier '(' identifier_list ')' // function_declarator handles empty parameter 3560 3581 { $$ = $1->addIdList( $3 ); } 3561 | '(' KR_function_ptr ')' '(' parameter_ type_list_opt ')'3582 | '(' KR_function_ptr ')' '(' parameter_list_ellipsis_opt ')' 3562 3583 { $$ = $2->addParamList( $5 ); } 3563 | '(' attribute_list KR_function_ptr ')' '(' parameter_ type_list_opt ')'3584 | '(' attribute_list KR_function_ptr ')' '(' parameter_list_ellipsis_opt ')' 3564 3585 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3565 3586 | '(' KR_function_no_ptr ')' // redundant parenthesis … … 3651 3672 3652 3673 variable_type_function: 3653 '(' variable_type_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3674 '(' variable_type_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3654 3675 { $$ = $2->addParamList( $5 ); } 3655 | '(' attribute_list variable_type_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3676 | '(' attribute_list variable_type_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3656 3677 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3657 3678 | '(' variable_type_function ')' // redundant parenthesis … … 3674 3695 3675 3696 function_type_no_ptr: 3676 paren_type '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3697 paren_type '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3677 3698 { $$ = $1->addParamList( $3 ); } 3678 | '(' function_type_ptr ')' '(' parameter_ type_list_opt ')'3699 | '(' function_type_ptr ')' '(' parameter_list_ellipsis_opt ')' 3679 3700 { $$ = $2->addParamList( $5 ); } 3680 | '(' attribute_list function_type_ptr ')' '(' parameter_ type_list_opt ')'3701 | '(' attribute_list function_type_ptr ')' '(' parameter_list_ellipsis_opt ')' 3681 3702 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3682 3703 | '(' function_type_no_ptr ')' // redundant parenthesis … … 3721 3742 { $$ = $1->addQualifiers( $2 ); } 3722 3743 | '&' MUTEX paren_identifier attribute_list_opt 3723 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3744 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), 3745 OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3724 3746 | identifier_parameter_ptr 3725 3747 | identifier_parameter_array attribute_list_opt … … 3750 3772 3751 3773 identifier_parameter_function: 3752 paren_identifier '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3774 paren_identifier '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3753 3775 { $$ = $1->addParamList( $3 ); } 3754 | '(' identifier_parameter_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3776 | '(' identifier_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3755 3777 { $$ = $2->addParamList( $5 ); } 3756 3778 | '(' identifier_parameter_function ')' // redundant parenthesis … … 3771 3793 { $$ = $1->addQualifiers( $2 ); } 3772 3794 | '&' MUTEX typedef_name attribute_list_opt 3773 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3795 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), 3796 OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3774 3797 | type_parameter_ptr 3775 3798 | type_parameter_array attribute_list_opt … … 3803 3826 3804 3827 type_parameter_function: 3805 typedef_name '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3828 typedef_name '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3806 3829 { $$ = $1->addParamList( $3 ); } 3807 | '(' type_parameter_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3830 | '(' type_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3808 3831 { $$ = $2->addParamList( $5 ); } 3809 3832 ; … … 3853 3876 3854 3877 abstract_function: 3855 '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3878 '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3856 3879 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); } 3857 | '(' abstract_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)3880 | '(' abstract_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3858 3881 { $$ = $2->addParamList( $5 ); } 3859 3882 | '(' abstract_function ')' // redundant parenthesis … … 3871 3894 { $$ = DeclarationNode::newArray( $3, nullptr, false )->addArray( DeclarationNode::newArray( $6, nullptr, false ) ); } 3872 3895 // { SemanticError( yylloc, "New array dimension is currently unimplemented." ); $$ = nullptr; } 3896 3897 // If needed, the following parses and does not use comma_expression, so the array structure can be built. 3898 // | '[' push assignment_expression pop ',' push array_dimension_list pop ']' // CFA 3899 3873 3900 | '[' push array_type_list pop ']' // CFA 3874 3901 { $$ = DeclarationNode::newArray( $3, nullptr, false ); } 3875 3902 | multi_array_dimension 3876 3903 ; 3904 3905 // array_dimension_list: 3906 // assignment_expression 3907 // | array_dimension_list ',' assignment_expression 3908 // ; 3877 3909 3878 3910 array_type_list: … … 3976 4008 3977 4009 abstract_parameter_function: 3978 '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)4010 '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3979 4011 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); } 3980 | '(' abstract_parameter_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)4012 | '(' abstract_parameter_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 3981 4013 { $$ = $2->addParamList( $5 ); } 3982 4014 | '(' abstract_parameter_function ')' // redundant parenthesis … … 4055 4087 4056 4088 variable_abstract_function: 4057 '(' variable_abstract_ptr ')' '(' parameter_ type_list_opt ')' // empty parameter list OBSOLESCENT (see 3)4089 '(' variable_abstract_ptr ')' '(' parameter_list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3) 4058 4090 { $$ = $2->addParamList( $5 ); } 4059 4091 | '(' variable_abstract_function ')' // redundant parenthesis … … 4141 4173 // 4142 4174 // cfa_abstract_tuple identifier_or_type_name 4143 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ ellipsis_list_opt ')'4175 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_list_ellipsis_opt ')' 4144 4176 // 4145 4177 // since a function return type can be syntactically identical to a tuple type: … … 4207 4239 4208 4240 cfa_abstract_function: // CFA 4209 // '[' ']' '(' cfa_parameter_ellipsis_list_opt ')'4210 //{ $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); }4211 cfa_abstract_tuple '(' push cfa_parameter_ellipsis_list_opt pop ')'4241 '[' ']' '(' cfa_parameter_list_ellipsis_opt ')' 4242 { $$ = DeclarationNode::newFunction( nullptr, DeclarationNode::newTuple( nullptr ), $4, nullptr ); } 4243 | cfa_abstract_tuple '(' push cfa_parameter_list_ellipsis_opt pop ')' 4212 4244 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 4213 | cfa_function_return '(' push cfa_parameter_ ellipsis_list_opt pop ')'4245 | cfa_function_return '(' push cfa_parameter_list_ellipsis_opt pop ')' 4214 4246 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 4215 4247 ;
Note:
See TracChangeset
for help on using the changeset viewer.