Changes in src/Parser/parser.yy [44adf1b:0522ebe]
- File:
-
- 1 edited
-
src/Parser/parser.yy (modified) (65 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/parser.yy
r44adf1b r0522ebe 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Mar 4 08:44:25 202413 // Update Count : 6 56212 // Last Modified On : Sun Nov 26 13:18:06 2023 13 // Update Count : 6398 14 14 // 15 15 … … 102 102 103 103 DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) { 104 // Distribute type specifier across all declared variables, e.g., static, const,__attribute__.104 // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__. 105 105 assert( declList ); 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 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 ); 131 113 } // for 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!!! 114 declList->addType( cl ); 115 // printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 ); 136 116 return declList; 137 117 } // distAttr … … 139 119 void distExt( DeclarationNode * declaration ) { 140 120 // distribute EXTENSION across all declarations 141 for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next) {121 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 142 122 iter->set_extension( true ); 143 123 } // for … … 146 126 void distInl( DeclarationNode * declaration ) { 147 127 // distribute INLINE across all declarations 148 for ( DeclarationNode *iter = declaration ; iter != nullptr ; iter = iter->next) {128 for ( DeclarationNode *iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 149 129 iter->set_inLine( true ); 150 130 } // for … … 153 133 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) { 154 134 // distribute qualifiers across all non-variable declarations in a distribution statemement 155 for ( DeclarationNode * iter = declaration ; iter != nullptr ; iter = iter->next) {135 for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 156 136 // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since 157 137 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To … … 212 192 fieldList = DeclarationNode::newName( nullptr ); 213 193 } // if 194 // return distAttr( typeSpec, fieldList ); // mark all fields in list 214 195 215 196 // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 ); 216 DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list197 DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list 217 198 // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 ); 218 199 return temp; … … 389 370 %token LE GE EQ NE // <= >= == != 390 371 %token ANDAND OROR // && || 391 %token ATTR ELLIPSIS // @@...372 %token ELLIPSIS // ... 392 373 393 374 %token EXPassign MULTassign DIVassign MODassign // \= *= /= %= … … 433 414 %type<stmt> statement labeled_statement compound_statement 434 415 %type<stmt> statement_decl statement_decl_list statement_list_nodecl 435 %type<stmt> selection_statement 416 %type<stmt> selection_statement if_statement 436 417 %type<clause> switch_clause_list_opt switch_clause_list 437 418 %type<expr> case_value … … 500 481 %type<decl> cfa_identifier_parameter_declarator_tuple cfa_identifier_parameter_ptr 501 482 502 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ list_ellipsis_opt483 %type<decl> cfa_parameter_declaration cfa_parameter_list cfa_parameter_ellipsis_list_opt 503 484 504 485 %type<decl> cfa_typedef_declaration cfa_variable_declaration cfa_variable_specifier … … 508 489 %type<decl> KR_parameter_list KR_parameter_list_opt 509 490 510 %type<decl> parameter_declaration parameter_list parameter_ list_ellipsis_opt491 %type<decl> parameter_declaration parameter_list parameter_type_list_opt 511 492 512 493 %type<decl> paren_identifier paren_type … … 530 511 %type<decl> type_parameter type_parameter_list type_initializer_opt 531 512 532 %type<expr> type_parameters_opt type_list array_type_list // array_dimension_list513 %type<expr> type_parameters_opt type_list array_type_list 533 514 534 515 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 780 761 | string_literal '`' identifier // CFA, postfix call 781 762 { $$ = 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 qualified784 // name, it is assumed all name-tokens after the first are identifiers, regardless of how the lexer identifies785 // 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 TYPEDEFname795 // z.T; // lexer returns T is TYPEGENname796 // z.Z; // lexer returns Z is TYPEDEFname797 // z.U; // lexer returns U is TYPEDEFname798 // z.E; // lexer returns E is TYPEDEFname799 // }800 763 | postfix_expression '.' identifier 801 764 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); } 802 | postfix_expression '.' TYPEDEFname // CFA, SKULLDUGGERY803 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }804 | postfix_expression '.' TYPEGENname // CFA, SKULLDUGGERY805 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_varref( yylloc, $3 ) ) ); }806 807 765 | postfix_expression '.' INTEGERconstant // CFA, tuple index 808 766 { $$ = new ExpressionNode( build_fieldSel( yylloc, $1, build_constantInteger( yylloc, *$3 ) ) ); } … … 1081 1039 | logical_OR_expression '?' comma_expression ':' conditional_expression 1082 1040 { $$ = new ExpressionNode( build_cond( yylloc, $1, $3, $5 ) ); } 1041 // FIX ME: computes $1 twice 1083 1042 | logical_OR_expression '?' /* empty */ ':' conditional_expression // GCC, omitted first operand 1084 { $$ = new ExpressionNode( build_cond( yylloc, $1, nullptr, $4 ) ); }1043 { $$ = new ExpressionNode( build_cond( yylloc, $1, $1->clone(), $4 ) ); } 1085 1044 ; 1086 1045 … … 1246 1205 ; 1247 1206 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... } ... or1253 1254 1207 selection_statement: 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 ) ) ); } 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; } 1260 1212 | SWITCH '(' comma_expression ')' case_clause 1261 1213 { $$ = new StatementNode( build_switch( yylloc, true, $3, $5 ) ); } … … 1281 1233 | CHOOSE '(' comma_expression ')' '{' error '}' // CFA, invalid syntax rule 1282 1234 { 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 THEN 1239 // explicitly deal with the shift/reduce conflict on if/else 1240 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), nullptr ) ); } 1241 | IF '(' conditional_declaration ')' statement ELSE statement 1242 { $$ = new StatementNode( build_if( yylloc, $3, maybe_build_compound( yylloc, $5 ), maybe_build_compound( yylloc, $7 ) ) ); } 1283 1243 ; 1284 1244 … … 1897 1857 declaration 1898 1858 | declaration_list declaration 1899 { $$ = $1-> set_last( $2 ); }1859 { $$ = $1->appendList( $2 ); } 1900 1860 ; 1901 1861 … … 1910 1870 { $$ = $1; } 1911 1871 | KR_parameter_list c_declaration ';' 1912 { $$ = $1-> set_last( $2 ); }1872 { $$ = $1->appendList( $2 ); } 1913 1873 ; 1914 1874 … … 1930 1890 declaration: // old & new style declarations 1931 1891 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 // } // for 1897 } 1932 1898 | cfa_declaration ';' // CFA 1933 1899 | static_assert // C11 … … 1968 1934 { $$ = $2->addQualifiers( $1 )->addInitializer( $3 ); } 1969 1935 | cfa_variable_declaration pop ',' push identifier_or_type_name initializer_opt 1970 { $$ = $1-> set_last( $1->cloneType( $5 )->addInitializer( $6 ) ); }1936 { $$ = $1->appendList( $1->cloneType( $5 )->addInitializer( $6 ) ); } 1971 1937 ; 1972 1938 … … 1990 1956 | declaration_qualifier_list type_qualifier_list cfa_function_specifier 1991 1957 { $$ = $3->addQualifiers( $1 )->addQualifiers( $2 ); } 1992 | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ list_ellipsis_opt pop ')'1958 | cfa_function_declaration ',' identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1993 1959 { 1994 1960 // Append the return type at the start (left-hand-side) to each identifier in the list. 1995 1961 DeclarationNode * ret = new DeclarationNode; 1996 1962 ret->type = maybeCopy( $1->type->base ); 1997 $$ = $1-> set_last( DeclarationNode::newFunction( $3, ret, $6, nullptr ) );1963 $$ = $1->appendList( DeclarationNode::newFunction( $3, ret, $6, nullptr ) ); 1998 1964 } 1999 1965 ; 2000 1966 2001 1967 cfa_function_specifier: // CFA 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 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 2009 1983 // identifier_or_type_name must be broken apart because of the sequence: 2010 1984 // 2011 // '[' ']' identifier_or_type_name '(' cfa_parameter_ list_ellipsis_opt ')'1985 // '[' ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')' 2012 1986 // '[' ']' type_specifier 2013 1987 // 2014 1988 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 2015 1989 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 2016 | cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_list_ellipsis_opt pop ')' attribute_list_opt1990 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 2017 1991 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 2018 1992 { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); } 2019 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ list_ellipsis_opt pop ')' attribute_list_opt1993 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 2020 1994 { $$ = DeclarationNode::newFunction( $2, $1, $5, nullptr )->addQualifiers( $8 ); } 2021 1995 ; … … 2024 1998 '[' push cfa_parameter_list pop ']' 2025 1999 { $$ = DeclarationNode::newTuple( $3 ); } 2026 | '[' push cfa_parameter_list ','cfa_abstract_parameter_list pop ']'2000 | '[' push cfa_parameter_list pop ',' push cfa_abstract_parameter_list pop ']' 2027 2001 // To obtain LR(1 ), the last cfa_abstract_parameter_list is added into this flattened rule to lookahead to the ']'. 2028 { $$ = DeclarationNode::newTuple( $3-> set_last( $5) ); }2002 { $$ = DeclarationNode::newTuple( $3->appendList( $7 ) ); } 2029 2003 ; 2030 2004 … … 2040 2014 $$ = $2->addTypedef(); 2041 2015 } 2042 | cfa_typedef_declaration ','identifier2043 { 2044 typedefTable.addToEnclosingScope( *$ 3, TYPEDEFname, "cfa_typedef_declaration 3" );2045 $$ = $1-> set_last( $1->cloneType( $3) );2016 | cfa_typedef_declaration pop ',' push identifier 2017 { 2018 typedefTable.addToEnclosingScope( *$5, TYPEDEFname, "cfa_typedef_declaration 3" ); 2019 $$ = $1->appendList( $1->cloneType( $5 ) ); 2046 2020 } 2047 2021 ; … … 2061 2035 { 2062 2036 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "typedef_declaration 2" ); 2063 $$ = $1-> set_last( $1->cloneBaseType( $3 )->addTypedef() );2037 $$ = $1->appendList( $1->cloneBaseType( $3 )->addTypedef() ); 2064 2038 } 2065 2039 | type_qualifier_list TYPEDEF type_specifier declarator // remaining OBSOLESCENT (see 2 ) … … 2115 2089 2116 2090 | declaring_list ',' attribute_list_opt declarator asm_name_opt initializer_opt 2117 { $$ = $1-> set_last( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); }2091 { $$ = $1->appendList( $4->addQualifiers( $3 )->addAsmName( $5 )->addInitializer( $6 ) ); } 2118 2092 ; 2119 2093 … … 2374 2348 sue_declaration_specifier: // struct, union, enum + storage class + type specifier 2375 2349 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 // } // for 2355 } 2376 2356 | declaration_qualifier_list sue_type_specifier 2377 2357 { $$ = $2->addQualifiers( $1 ); } … … 2384 2364 sue_type_specifier: // struct, union, enum + type specifier 2385 2365 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 // } // for 2371 } 2386 2372 | type_qualifier_list 2387 2373 { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type … … 2456 2442 elaborated_type: // struct, union, enum 2457 2443 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 // } // for 2449 } 2458 2450 | enum_type 2459 2451 ; … … 2579 2571 { $$ = nullptr; } 2580 2572 | field_declaration_list_opt field_declaration 2581 { $$ = $1 ? $1-> set_last( $2 ) : $2; }2573 { $$ = $1 ? $1->appendList( $2 ) : $2; } 2582 2574 ; 2583 2575 … … 2627 2619 | field_declarator 2628 2620 | field_declaring_list_opt ',' attribute_list_opt field_declarator 2629 { $$ = $1-> set_last( $4->addQualifiers( $3 ) ); }2621 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 2630 2622 ; 2631 2623 … … 2649 2641 | field_abstract 2650 2642 | field_abstract_list_opt ',' attribute_list_opt field_abstract 2651 { $$ = $1-> set_last( $4->addQualifiers( $3 ) ); }2643 { $$ = $1->appendList( $4->addQualifiers( $3 ) ); } 2652 2644 ; 2653 2645 … … 2662 2654 { $$ = $1->addName( $2 ); } 2663 2655 | cfa_field_declaring_list ',' identifier_or_type_name 2664 { $$ = $1-> set_last( $1->cloneType( $3 ) ); }2656 { $$ = $1->appendList( $1->cloneType( $3 ) ); } 2665 2657 ; 2666 2658 … … 2669 2661 cfa_abstract_declarator_tuple 2670 2662 | cfa_field_abstract_list ',' 2671 { $$ = $1-> set_last( $1->cloneType( 0 ) ); }2663 { $$ = $1->appendList( $1->cloneType( 0 ) ); } 2672 2664 ; 2673 2665 … … 2683 2675 ; 2684 2676 2685 // ***********2686 // Enumeration2687 // ***********2688 2689 2677 enum_type: 2690 2678 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2691 2679 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); } 2692 2680 | ENUM attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule 2693 { SemanticError( yylloc, "syntax error, hiding ('!')the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }2681 { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; } 2694 2682 | ENUM attribute_list_opt identifier 2695 2683 { typedefTable.makeTypedef( *$3, "enum_type 1" ); } … … 2706 2694 } 2707 2695 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // unqualified type name 2708 { SemanticError( yylloc, "syntax error, hiding ('!')the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }2696 { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; } 2709 2697 | ENUM '(' ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2710 2698 { … … 2712 2700 } 2713 2701 | ENUM '(' ')' attribute_list_opt '!' '{' enumerator_list comma_opt '}' // invalid syntax rule 2714 { SemanticError( yylloc, "syntax error, hiding ('!')the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; }2702 { SemanticError( yylloc, "syntax error, hiding '!' the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; } 2715 2703 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2716 2704 { 2717 if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0 )) {2705 if ( $3 && ($3->storageClasses.any() || $3->type->qualifiers.val != 0 )) { 2718 2706 SemanticError( yylloc, "syntax error, storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); 2719 2707 } … … 2765 2753 { $$ = DeclarationNode::newEnumInLine( *$2->type->symbolic.name ); } 2766 2754 | enumerator_list ',' visible_hide_opt identifier_or_type_name enumerator_value_opt 2767 { $$ = $1-> set_last( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); }2755 { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $4, $5 ) ); } 2768 2756 | enumerator_list ',' INLINE type_name enumerator_value_opt 2769 { $$ = $1-> set_last( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); }2757 { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); } 2770 2758 ; 2771 2759 … … 2785 2773 ; 2786 2774 2787 // ******************* 2788 // Function parameters 2789 // ******************* 2790 2791 parameter_list_ellipsis_opt: 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: 2792 2809 // empty 2793 2810 { $$ = nullptr; } … … 2800 2817 2801 2818 parameter_list: // abstract + real 2802 parameter_declaration 2803 | abstract_parameter_declaration 2819 abstract_parameter_declaration 2820 | parameter_declaration 2821 | parameter_list ',' abstract_parameter_declaration 2822 { $$ = $1->appendList( $3 ); } 2804 2823 | parameter_list ',' parameter_declaration 2805 { $$ = $1->set_last( $3 ); } 2806 | parameter_list ',' abstract_parameter_declaration 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 ); } 2824 { $$ = $1->appendList( $3 ); } 2841 2825 ; 2842 2826 2843 2827 // Provides optional identifier names (abstract_declarator/variable_declarator), no initialization, different semantics 2844 2828 // 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_opt2849 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }2850 | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt2851 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }2852 ;2853 2854 abstract_parameter_declaration:2855 declaration_specifier_nobody default_initializer_opt2856 { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); }2857 | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt2858 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); }2859 ;2860 2829 2861 2830 cfa_parameter_declaration: // CFA, new & old style parameter declaration … … 2881 2850 ; 2882 2851 2852 parameter_declaration: 2853 // No SUE declaration in parameter list. 2854 declaration_specifier_nobody identifier_parameter_declarator default_initializer_opt 2855 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2856 | declaration_specifier_nobody type_parameter_redeclarator default_initializer_opt 2857 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2858 ; 2859 2860 abstract_parameter_declaration: 2861 declaration_specifier_nobody default_initializer_opt 2862 { $$ = $1->addInitializer( $2 ? new InitializerNode( $2 ) : nullptr ); } 2863 | declaration_specifier_nobody abstract_parameter_declarator default_initializer_opt 2864 { $$ = $2->addType( $1 )->addInitializer( $3 ? new InitializerNode( $3 ) : nullptr ); } 2865 ; 2866 2883 2867 // ISO/IEC 9899:1999 Section 6.9.1(6) : "An identifier declared as a typedef name shall not be redeclared as a 2884 2868 // parameter." Because the scope of the K&R-style parameter-list sees the typedef first, the following is based only on … … 2889 2873 { $$ = DeclarationNode::newName( $1 ); } 2890 2874 | identifier_list ',' identifier 2891 { $$ = $1-> set_last( DeclarationNode::newName( $3 ) ); }2875 { $$ = $1->appendList( DeclarationNode::newName( $3 ) ); } 2892 2876 ; 2893 2877 … … 2990 2974 type_parameter 2991 2975 | type_parameter_list ',' type_parameter 2992 { $$ = $1-> set_last( $3 ); }2976 { $$ = $1->appendList( $3 ); } 2993 2977 ; 2994 2978 … … 3063 3047 assertion 3064 3048 | assertion_list assertion 3065 { $$ = $1-> set_last( $2 ); }3049 { $$ = $1->appendList( $2 ); } 3066 3050 ; 3067 3051 … … 3091 3075 { $$ = $3->addQualifiers( $1 ); } 3092 3076 | type_declaring_list ',' type_declarator 3093 { $$ = $1-> set_last( $3->copySpecifiers( $1 ) ); }3077 { $$ = $1->appendList( $3->copySpecifiers( $1 ) ); } 3094 3078 ; 3095 3079 … … 3134 3118 trait_declaration 3135 3119 | trait_declaration_list pop push trait_declaration 3136 { $$ = $1-> set_last( $4 ); }3120 { $$ = $1->appendList( $4 ); } 3137 3121 ; 3138 3122 … … 3146 3130 | cfa_function_specifier 3147 3131 | cfa_trait_declaring_list pop ',' push identifier_or_type_name 3148 { $$ = $1-> set_last( $1->cloneType( $5 ) ); }3132 { $$ = $1->appendList( $1->cloneType( $5 ) ); } 3149 3133 ; 3150 3134 … … 3153 3137 { $$ = $2->addType( $1 ); } 3154 3138 | trait_declaring_list pop ',' push declarator 3155 { $$ = $1-> set_last( $1->cloneBaseType( $5 ) ); }3139 { $$ = $1->appendList( $1->cloneBaseType( $5 ) ); } 3156 3140 ; 3157 3141 … … 3161 3145 // empty, input file 3162 3146 | external_definition_list 3163 { parseTree = parseTree ? parseTree-> set_last( $1 ) : $1; }3147 { parseTree = parseTree ? parseTree->appendList( $1 ) : $1; } 3164 3148 ; 3165 3149 … … 3168 3152 { $$ = $2; } 3169 3153 | external_definition_list push external_definition pop 3170 { $$ = $1 ? $1-> set_last( $3 ) : $3; }3154 { $$ = $1 ? $1->appendList( $3 ) : $3; } 3171 3155 ; 3172 3156 … … 3193 3177 // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is 3194 3178 // disallowed at the moment. 3195 if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && 3196 $1->type && $1->type->kind == TypeData::AggregateInst ) { 3179 if ( $1->linkage == ast::Linkage::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) { 3197 3180 if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) { 3198 3181 SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr; … … 3395 3378 ATTRIBUTE '(' '(' attribute_name_list ')' ')' 3396 3379 { $$ = $4; } 3397 | ATTRIBUTE '(' attribute_name_list ')' // CFA3398 { $$ = $3; }3399 | ATTR '(' attribute_name_list ')' // CFA3400 { $$ = $3; }3401 3380 ; 3402 3381 … … 3503 3482 3504 3483 variable_function: 3505 '(' variable_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3484 '(' variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3506 3485 { $$ = $2->addParamList( $5 ); } 3507 | '(' attribute_list variable_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3486 | '(' attribute_list variable_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3508 3487 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3509 3488 | '(' variable_function ')' // redundant parenthesis … … 3526 3505 3527 3506 function_no_ptr: 3528 paren_identifier '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3507 paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3529 3508 { $$ = $1->addParamList( $3 ); } 3530 | '(' function_ptr ')' '(' parameter_ list_ellipsis_opt ')'3509 | '(' function_ptr ')' '(' parameter_type_list_opt ')' 3531 3510 { $$ = $2->addParamList( $5 ); } 3532 | '(' attribute_list function_ptr ')' '(' parameter_ list_ellipsis_opt ')'3511 | '(' attribute_list function_ptr ')' '(' parameter_type_list_opt ')' 3533 3512 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3534 3513 | '(' function_no_ptr ')' // redundant parenthesis … … 3580 3559 paren_identifier '(' identifier_list ')' // function_declarator handles empty parameter 3581 3560 { $$ = $1->addIdList( $3 ); } 3582 | '(' KR_function_ptr ')' '(' parameter_ list_ellipsis_opt ')'3561 | '(' KR_function_ptr ')' '(' parameter_type_list_opt ')' 3583 3562 { $$ = $2->addParamList( $5 ); } 3584 | '(' attribute_list KR_function_ptr ')' '(' parameter_ list_ellipsis_opt ')'3563 | '(' attribute_list KR_function_ptr ')' '(' parameter_type_list_opt ')' 3585 3564 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3586 3565 | '(' KR_function_no_ptr ')' // redundant parenthesis … … 3672 3651 3673 3652 variable_type_function: 3674 '(' variable_type_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3653 '(' variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3675 3654 { $$ = $2->addParamList( $5 ); } 3676 | '(' attribute_list variable_type_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3655 | '(' attribute_list variable_type_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3677 3656 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3678 3657 | '(' variable_type_function ')' // redundant parenthesis … … 3695 3674 3696 3675 function_type_no_ptr: 3697 paren_type '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3676 paren_type '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3698 3677 { $$ = $1->addParamList( $3 ); } 3699 | '(' function_type_ptr ')' '(' parameter_ list_ellipsis_opt ')'3678 | '(' function_type_ptr ')' '(' parameter_type_list_opt ')' 3700 3679 { $$ = $2->addParamList( $5 ); } 3701 | '(' attribute_list function_type_ptr ')' '(' parameter_ list_ellipsis_opt ')'3680 | '(' attribute_list function_type_ptr ')' '(' parameter_type_list_opt ')' 3702 3681 { $$ = $3->addQualifiers( $2 )->addParamList( $6 ); } 3703 3682 | '(' function_type_no_ptr ')' // redundant parenthesis … … 3742 3721 { $$ = $1->addQualifiers( $2 ); } 3743 3722 | '&' MUTEX paren_identifier attribute_list_opt 3744 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), 3745 OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3723 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3746 3724 | identifier_parameter_ptr 3747 3725 | identifier_parameter_array attribute_list_opt … … 3772 3750 3773 3751 identifier_parameter_function: 3774 paren_identifier '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3752 paren_identifier '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3775 3753 { $$ = $1->addParamList( $3 ); } 3776 | '(' identifier_parameter_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3754 | '(' identifier_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3777 3755 { $$ = $2->addParamList( $5 ); } 3778 3756 | '(' identifier_parameter_function ')' // redundant parenthesis … … 3793 3771 { $$ = $1->addQualifiers( $2 ); } 3794 3772 | '&' MUTEX typedef_name attribute_list_opt 3795 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), 3796 OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3773 { $$ = $3->addPointer( DeclarationNode::newPointer( DeclarationNode::newTypeQualifier( ast::CV::Mutex ), OperKinds::AddressOf ) )->addQualifiers( $4 ); } 3797 3774 | type_parameter_ptr 3798 3775 | type_parameter_array attribute_list_opt … … 3826 3803 3827 3804 type_parameter_function: 3828 typedef_name '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3805 typedef_name '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3829 3806 { $$ = $1->addParamList( $3 ); } 3830 | '(' type_parameter_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3807 | '(' type_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3831 3808 { $$ = $2->addParamList( $5 ); } 3832 3809 ; … … 3876 3853 3877 3854 abstract_function: 3878 '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3855 '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3879 3856 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); } 3880 | '(' abstract_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3857 | '(' abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 3881 3858 { $$ = $2->addParamList( $5 ); } 3882 3859 | '(' abstract_function ')' // redundant parenthesis … … 3894 3871 { $$ = DeclarationNode::newArray( $3, nullptr, false )->addArray( DeclarationNode::newArray( $6, nullptr, false ) ); } 3895 3872 // { 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 ']' // CFA3899 3900 3873 | '[' push array_type_list pop ']' // CFA 3901 3874 { $$ = DeclarationNode::newArray( $3, nullptr, false ); } 3902 3875 | multi_array_dimension 3903 3876 ; 3904 3905 // array_dimension_list:3906 // assignment_expression3907 // | array_dimension_list ',' assignment_expression3908 // ;3909 3877 3910 3878 array_type_list: … … 4008 3976 4009 3977 abstract_parameter_function: 4010 '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3978 '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 4011 3979 { $$ = DeclarationNode::newFunction( nullptr, nullptr, $2, nullptr ); } 4012 | '(' abstract_parameter_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)3980 | '(' abstract_parameter_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 4013 3981 { $$ = $2->addParamList( $5 ); } 4014 3982 | '(' abstract_parameter_function ')' // redundant parenthesis … … 4087 4055 4088 4056 variable_abstract_function: 4089 '(' variable_abstract_ptr ')' '(' parameter_ list_ellipsis_opt ')' // empty parameter list OBSOLESCENT (see 3)4057 '(' variable_abstract_ptr ')' '(' parameter_type_list_opt ')' // empty parameter list OBSOLESCENT (see 3) 4090 4058 { $$ = $2->addParamList( $5 ); } 4091 4059 | '(' variable_abstract_function ')' // redundant parenthesis … … 4173 4141 // 4174 4142 // cfa_abstract_tuple identifier_or_type_name 4175 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ list_ellipsis_opt ')'4143 // '[' cfa_parameter_list ']' identifier_or_type_name '(' cfa_parameter_ellipsis_list_opt ')' 4176 4144 // 4177 4145 // since a function return type can be syntactically identical to a tuple type: … … 4239 4207 4240 4208 cfa_abstract_function: // CFA 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 ')'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 ')' 4244 4212 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 4245 | cfa_function_return '(' push cfa_parameter_ list_ellipsis_opt pop ')'4213 | cfa_function_return '(' push cfa_parameter_ellipsis_list_opt pop ')' 4246 4214 { $$ = DeclarationNode::newFunction( nullptr, $1, $4, nullptr ); } 4247 4215 ;
Note:
See TracChangeset
for help on using the changeset viewer.