- Timestamp:
- Feb 6, 2025, 3:42:32 PM (8 months ago)
- Branches:
- master
- Children:
- eca364f7
- Parents:
- a8e2215
- Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/StatementNode.cpp
ra8e2215 rcd28605 10 10 // Author : Rodolfo G. Esteves 11 11 // Created On : Sat May 16 14:59:41 2015 12 // Last Modified By : Kyoung Seo13 // Last Modified On : Th d Jan 16 13:05:00202514 // Update Count : 43 312 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Thu Feb 6 11:38:39 2025 14 // Update Count : 434 15 15 // 16 16 … … 70 70 stmt.reset( new ast::DeclStmt( declLocation, maybeMoveBuild( agg ) ) ); 71 71 } // StatementNode::StatementNode 72 73 StatementNode * StatementNode::addQualifiers( DeclarationNode * attr ) { 74 if ( ! attr ) { return this; } // empty attribute list 75 attributes.insert( attributes.end(), attr->attributes.begin(), attr->attributes.end() ); 76 return this; 77 } 72 78 73 79 StatementNode * StatementNode::add_label( -
src/Parser/StatementNode.hpp
ra8e2215 rcd28605 10 10 // Created On : Wed Apr 5 11:42:00 2023 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 23 22:43:05 202413 // Update Count : 312 // Last Modified On : Thu Feb 6 11:39:26 2025 13 // Update Count : 6 14 14 // 15 15 … … 27 27 ast::Stmt * build() { return stmt.release(); } 28 28 29 StatementNode * addQualifiers( DeclarationNode * ); 29 30 StatementNode * add_label( 30 31 const CodeLocation & location, … … 36 37 } 37 38 39 std::vector<ast::ptr<ast::Attribute>> attributes; 38 40 std::unique_ptr<ast::Stmt> stmt; 39 41 }; // StatementNode -
src/Parser/parser.yy
ra8e2215 rcd28605 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jan 17 14:35:08202513 // Update Count : 693512 // Last Modified On : Thu Feb 6 11:40:06 2025 13 // Update Count : 7236 14 14 // 15 15 … … 54 54 #include "Common/SemanticError.hpp" // error_str 55 55 #include "Common/Utility.hpp" // for maybeMoveBuild, maybeBuild, CodeLo... 56 #include "AST/Attribute.hpp" // for Attribute 57 #include "AST/Print.hpp" // for print 58 #include "Common/Iterate.hpp" // for reverseIterate 56 59 57 60 // lex uses __null in a boolean context, it's fine. … … 98 101 } // appendStr 99 102 100 DeclarationNode * dist Attr( DeclarationNode * typeSpec, DeclarationNode * declList ) {103 DeclarationNode * distTypeSpec( DeclarationNode * typeSpec, DeclarationNode * declList ) { 101 104 // Distribute type specifier across all declared variables, e.g., static, const, __attribute__. 102 105 assert( declList ); … … 132 135 declList->addType( cl, copyattr ); // cl IS DELETED!!! 133 136 return declList; 137 } // distTypeSpec 138 139 void distAttr( DeclarationNode * attributes, DeclarationNode * declaration ) { 140 // distribute attributes across all declaring list 141 for ( DeclarationNode * attr = attributes; attr != nullptr ; attr = attr->next ) { 142 for ( DeclarationNode * decl = declaration ; decl != nullptr ; decl = decl->next ) { 143 decl->attributes.insert( decl->attributes.begin(), attr->attributes.begin(), attr->attributes.end() ); 144 } // for 145 } // for 134 146 } // distAttr 135 147 136 148 void distExt( DeclarationNode * declaration ) { 137 149 // distribute EXTENSION across all declarations 138 for ( DeclarationNode * iter = declaration ; iter != nullptr ; iter = iter->next ) {139 iter->set_extension( true );150 for ( DeclarationNode * decl = declaration ; decl != nullptr ; decl = decl->next ) { 151 decl->set_extension( true ); 140 152 } // for 141 153 } // distExt … … 143 155 void distInl( DeclarationNode * declaration ) { 144 156 // distribute INLINE across all declarations 145 for ( DeclarationNode * iter = declaration ; iter != nullptr ; iter = iter->next ) {146 iter->set_inLine( true );157 for ( DeclarationNode *decl = declaration ; decl != nullptr ; decl = decl->next ) { 158 decl->set_inLine( true ); 147 159 } // for 148 160 } // distInl … … 150 162 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) { 151 163 // distribute qualifiers across all non-variable declarations in a distribution statemement 152 for ( DeclarationNode * iter = declaration ; iter != nullptr ; iter = iter->next ) {164 for ( DeclarationNode * decl = declaration ; decl != nullptr ; decl = decl->next ) { 153 165 // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since 154 166 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To … … 157 169 DeclarationNode * clone = qualifiers->clone(); 158 170 if ( qualifiers->type ) { // forall clause ? (handles SC) 159 if ( iter->type->kind == TypeData::Aggregate ) { // struct/union ?160 swap( clone->type->forall, iter->type->aggregate.params );161 iter->addQualifiers( clone );162 } else if ( iter->type->kind == TypeData::AggregateInst && iter->type->aggInst.aggregate->aggregate.body ) { // struct/union ?171 if ( decl->type->kind == TypeData::Aggregate ) { // struct/union ? 172 swap( clone->type->forall, decl->type->aggregate.params ); 173 decl->addQualifiers( clone ); 174 } else if ( decl->type->kind == TypeData::AggregateInst && decl->type->aggInst.aggregate->aggregate.body ) { // struct/union ? 163 175 // Create temporary node to hold aggregate, call addQualifiers as above, then put nodes back together. 164 176 DeclarationNode newnode; 165 swap( newnode.type, iter->type->aggInst.aggregate );177 swap( newnode.type, decl->type->aggInst.aggregate ); 166 178 swap( clone->type->forall, newnode.type->aggregate.params ); 167 179 newnode.addQualifiers( clone ); 168 swap( newnode.type, iter->type->aggInst.aggregate );169 } else if ( iter->type->kind == TypeData::Function ) { // routines ?170 swap( clone->type->forall, iter->type->forall );171 iter->addQualifiers( clone );180 swap( newnode.type, decl->type->aggInst.aggregate ); 181 } else if ( decl->type->kind == TypeData::Function ) { // routines ? 182 swap( clone->type->forall, decl->type->forall ); 183 decl->addQualifiers( clone ); 172 184 } // if 173 185 } else { // just SC qualifiers 174 iter->addQualifiers( clone );186 decl->addQualifiers( clone ); 175 187 } // if 176 188 } // for … … 210 222 211 223 // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 ); 212 DeclarationNode * temp = dist Attr( typeSpec, fieldList ); // mark all fields in list224 DeclarationNode * temp = distTypeSpec( typeSpec, fieldList ); // mark all fields in list 213 225 // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 ); 214 226 return temp; … … 253 265 type = new ExpressionNode( new ast::CastExpr( location, maybeMoveBuild(type), new ast::BasicType( ast::BasicKind::SignedInt ) ) ); 254 266 } // if 255 DeclarationNode * initDecl = dist Attr(267 DeclarationNode * initDecl = distTypeSpec( 256 268 DeclarationNode::newTypeof( type, true ), 257 269 DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) … … 434 446 %type<decl> asm_name_opt 435 447 %type<expr> asm_operands_opt asm_operands_list asm_operand 436 %type<labels> label_list448 %type<labels> asm_label_list 437 449 %type<expr> asm_clobbers_list_opt 438 450 %type<is_volatile> asm_volatile_opt … … 441 453 442 454 // statements 443 %type<stmt> statement label ed_statement compound_statement455 %type<stmt> statement labelled_statement compound_statement 444 456 %type<stmt> statement_decl statement_decl_list statement_list_nodecl 445 457 %type<stmt> selection_statement … … 926 938 | SIZEOF '(' type_no_function ')' 927 939 { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $3 ) ) ); } 940 | SIZEOF '(' attribute_list type_no_function ')' 941 { $$ = new ExpressionNode( new ast::SizeofExpr( yylloc, maybeMoveBuildType( $4->addQualifiers( $3 ) ) ) ); } 928 942 | ALIGNOF unary_expression // GCC, variable alignment 929 943 { $$ = new ExpressionNode( new ast::AlignofExpr( yylloc, new ast::TypeofType( maybeMoveBuild( $2 ) ) ) ); } … … 1202 1216 1203 1217 statement: 1204 label ed_statement1218 labelled_statement 1205 1219 | compound_statement 1206 1220 | expression_statement … … 1220 1234 | DIRECTIVE 1221 1235 { $$ = new StatementNode( build_directive( yylloc, $1 ) ); } 1222 // | attribute ';' 1223 // { $$ = new StatementNode( $1 ); } 1224 ; 1225 1226 labeled_statement: 1236 ; 1237 1238 labelled_statement: 1227 1239 // labels cannot be identifiers 0 or 1 1228 1240 identifier_or_type_name ':' attribute_list_opt statement … … 1254 1266 1255 1267 statement_decl: 1256 declaration // CFA, new & old style declarations 1257 { $$ = new StatementNode( $1 ); } 1258 | EXTENSION declaration // GCC 1259 { distExt( $2 ); $$ = new StatementNode( $2 ); } 1260 | function_definition 1261 { $$ = new StatementNode( $1 ); } 1262 | EXTENSION function_definition // GCC 1263 { distExt( $2 ); $$ = new StatementNode( $2 ); } 1264 | statement 1268 attribute_list_opt declaration // CFA, new & old style declarations 1269 { distAttr( $1, $2 ); $$ = new StatementNode( $2 ); } 1270 | attribute_list_opt EXTENSION declaration // GCC 1271 { distAttr( $1, $3 ); distExt( $3 ); $$ = new StatementNode( $3 ); } 1272 | attribute_list_opt function_definition 1273 { distAttr( $1, $2 ); $$ = new StatementNode( $2 ); } 1274 | attribute_list_opt EXTENSION function_definition // GCC 1275 { distAttr( $1, $3 ); distExt( $3 ); $$ = new StatementNode( $3 ); } 1276 | attribute_list_opt statement // FIX ME! 1277 { $$ = $2->addQualifiers( $1 ); } 1265 1278 ; 1266 1279 1267 1280 statement_list_nodecl: 1268 statement 1269 | statement_list_nodecl statement 1270 { assert( $1 ); $1->set_last( $2 ); $$ = $1; } 1281 attribute_list_opt statement 1282 { $$ = $2->addQualifiers( $1 ); } // FIX ME! 1283 | statement_list_nodecl attribute_list_opt statement 1284 { assert( $1 ); $1->set_last( $3->addQualifiers( $2 ) ); $$ = $1; } // FIX ME! 1271 1285 | statement_list_nodecl error // invalid syntax rule 1272 1286 { SemanticError( yylloc, "illegal syntax, declarations only allowed at the start of the switch body," … … 1274 1288 ; 1275 1289 1276 expression_statement: 1290 expression_statement: // expression or null statement 1277 1291 comma_expression_opt ';' 1278 1292 { $$ = new StatementNode( build_expr( yylloc, $1 ) ); } … … 1903 1917 | ASM asm_volatile_opt '(' string_literal ':' asm_operands_opt ':' asm_operands_opt ':' asm_clobbers_list_opt ')' ';' 1904 1918 { $$ = new StatementNode( build_asm( yylloc, $2, $4, $6, $8, $10 ) ); } 1905 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' label_list ')' ';'1919 | ASM asm_volatile_opt GOTO '(' string_literal ':' ':' asm_operands_opt ':' asm_clobbers_list_opt ':' asm_label_list ')' ';' 1906 1920 { $$ = new StatementNode( build_asm( yylloc, $2, $5, nullptr, $8, $10, $12 ) ); } 1907 1921 ; … … 1945 1959 ; 1946 1960 1947 label_list: 1948 identifier 1949 { 1950 $$ = new LabelNode(); $$->labels.emplace_back( yylloc, *$1 ); 1951 delete $1; // allocated by lexer 1952 } 1953 | label_list ',' identifier 1954 { 1955 $$ = $1; $1->labels.emplace_back( yylloc, *$3 ); 1956 delete $3; // allocated by lexer 1957 } 1961 asm_label_list: 1962 identifier_or_type_name 1963 { $$ = new LabelNode(); $$->labels.emplace_back( yylloc, *$1 ); delete $1; } // allocated by lexer 1964 | asm_label_list ',' identifier_or_type_name 1965 { $$ = $1; $1->labels.emplace_back( yylloc, *$3 ); delete $3; } // allocated by lexer 1958 1966 ; 1959 1967 … … 1967 1975 1968 1976 declaration_list: 1969 declaration 1977 attribute_list_opt declaration 1978 { $$ = $2->addQualifiers( $1 ); } 1970 1979 | declaration_list declaration 1971 1980 { $$ = $1->set_last( $2 ); } … … 2142 2151 } else $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3 2143 2152 } 2153 | TYPEDEF attribute_list type_specifier declarator 2154 { 2155 typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "typedef_declaration 1" ); 2156 if ( $3->type->forall || ($3->type->kind == TypeData::Aggregate && $3->type->aggregate.params) ) { 2157 SemanticError( yylloc, "forall qualifier in typedef is currently unimplemented." ); $$ = nullptr; 2158 } else $$ = $4->addType( $3 )->addTypedef()->addQualifiers( $2 ); // watchout frees $3 and $4 2159 } 2144 2160 | typedef_declaration ',' declarator 2145 2161 { … … 2169 2185 c_declaration: 2170 2186 declaration_specifier declaring_list 2171 { $$ = dist Attr( $1, $2 ); }2187 { $$ = distTypeSpec( $1, $2 ); } 2172 2188 | typedef_declaration 2173 2189 | typedef_expression // deprecated GCC, naming expression type … … 2265 2281 // specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it 2266 2282 // appeared only once. 2267 type_qualifier 2268 | type_qualifier_list type_qualifier 2283 type_qualifier attribute_list_opt 2269 2284 { $$ = $1->addQualifiers( $2 ); } 2285 | type_qualifier_list type_qualifier attribute_list_opt 2286 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } 2270 2287 ; 2271 2288 … … 2273 2290 type_qualifier_name 2274 2291 { $$ = DeclarationNode::newFromTypeData( $1 ); } 2275 | attribute // trick handles most attribute locations2276 2292 ; 2277 2293 … … 2301 2317 declaration_qualifier_list: 2302 2318 storage_class_list 2303 | type_qualifier_list storage_class_list // remaining OBSOLESCENT (see 2 )2319 | type_qualifier_list storage_class_list 2304 2320 { $$ = $1->addQualifiers( $2 ); } 2305 2321 | declaration_qualifier_list type_qualifier_list storage_class_list … … 2313 2329 // ISO/IEC 9899:1999 Section 6.7.1(2) : At most, one storage-class specifier may be given in the declaration 2314 2330 // specifiers in a declaration. 2315 storage_class 2316 | storage_class_list storage_class 2331 storage_class attribute_list_opt 2317 2332 { $$ = $1->addQualifiers( $2 ); } 2333 | storage_class_list storage_class attribute_list_opt 2334 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } 2318 2335 ; 2319 2336 … … 2440 2457 | declaration_qualifier_list basic_type_specifier 2441 2458 { $$ = $2->addQualifiers( $1 ); } 2442 | basic_declaration_specifier storage_class 2443 { $$ = $1->addQualifiers( $2 ) ; }2459 | basic_declaration_specifier storage_class attribute_list_opt // remaining OBSOLESCENT (see 2) 2460 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } 2444 2461 | basic_declaration_specifier storage_class type_qualifier_list 2445 2462 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } … … 2449 2466 2450 2467 basic_type_specifier: 2451 direct_type 2468 direct_type attribute_list_opt 2469 { $$ = $1->addQualifiers( $2 ); } 2452 2470 // Cannot have type modifiers, e.g., short, long, etc. 2471 | type_qualifier_list_opt indirect_type attribute_list 2472 { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); } 2453 2473 | type_qualifier_list_opt indirect_type type_qualifier_list_opt 2454 2474 { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); } … … 2522 2542 2523 2543 type_declaration_specifier: 2524 type_type_specifier 2525 | declaration_qualifier_list type_type_specifier 2526 { $$ = $2->addQualifiers( $1 ); } 2527 | type_declaration_specifier storage_class // remaining OBSOLESCENT (see 2) 2544 type_type_specifier attribute_list_opt 2528 2545 { $$ = $1->addQualifiers( $2 ); } 2546 | declaration_qualifier_list type_type_specifier attribute_list_opt 2547 { $$ = $2->addQualifiers( $1 )->addQualifiers( $3 ); } 2548 | type_declaration_specifier storage_class attribute_list_opt // remaining OBSOLESCENT (see 2) 2549 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } 2529 2550 | type_declaration_specifier storage_class type_qualifier_list 2530 2551 { $$ = $1->addQualifiers( $2 )->addQualifiers( $3 ); } … … 2578 2599 aggregate_key attribute_list_opt 2579 2600 { forall = false; } // reset 2580 '{' field_declaration_list_opt '}' type_parameters_opt 2581 { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 ) ; }2582 | aggregate_key attribute_list_opt identifier 2601 '{' field_declaration_list_opt '}' type_parameters_opt attribute_list_opt 2602 { $$ = DeclarationNode::newAggregate( $1, nullptr, $7, $5, true )->addQualifiers( $2 )->addQualifiers( $8 ); } 2603 | aggregate_key attribute_list_opt identifier attribute_list_opt 2583 2604 { 2584 2605 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname, "aggregate_type: 1" ); 2585 2606 forall = false; // reset 2586 2607 } 2587 '{' field_declaration_list_opt '}' type_parameters_opt 2588 { 2589 $$ = DeclarationNode::newAggregate( $1, $3, $ 8, $6, true )->addQualifiers( $2);2590 } 2591 | aggregate_key attribute_list_opt TYPEDEFname 2608 '{' field_declaration_list_opt '}' type_parameters_opt attribute_list_opt 2609 { 2610 $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 )->addQualifiers( $4 )->addQualifiers( $10 ); 2611 } 2612 | aggregate_key attribute_list_opt TYPEDEFname attribute_list_opt // unqualified type name 2592 2613 { 2593 2614 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname, "aggregate_type: 2" ); 2594 2615 forall = false; // reset 2595 2616 } 2596 '{' field_declaration_list_opt '}' type_parameters_opt 2617 '{' field_declaration_list_opt '}' type_parameters_opt attribute_list_opt 2597 2618 { 2598 2619 DeclarationNode::newFromTypeData( build_typedef( $3 ) ); 2599 $$ = DeclarationNode::newAggregate( $1, $3, $ 8, $6, true )->addQualifiers( $2);2600 } 2601 | aggregate_key attribute_list_opt TYPEGENname 2620 $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 )->addQualifiers( $4 )->addQualifiers( $10 ); 2621 } 2622 | aggregate_key attribute_list_opt TYPEGENname attribute_list_opt // unqualified type name 2602 2623 { 2603 2624 typedefTable.makeTypedef( *$3, forall || typedefTable.getEnclForall() ? TYPEGENname : TYPEDEFname, "aggregate_type: 3" ); 2604 2625 forall = false; // reset 2605 2626 } 2606 '{' field_declaration_list_opt '}' type_parameters_opt 2627 '{' field_declaration_list_opt '}' type_parameters_opt attribute_list_opt 2607 2628 { 2608 2629 DeclarationNode::newFromTypeData( build_type_gen( $3, nullptr ) ); 2609 $$ = DeclarationNode::newAggregate( $1, $3, $ 8, $6, true )->addQualifiers( $2);2630 $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 )->addQualifiers( $10 ); 2610 2631 } 2611 2632 | aggregate_type_nobody … … 2686 2707 2687 2708 field_declaration_list_opt: 2688 // empty 2709 // empty => struct S { /* no fields */ }; 2689 2710 { $$ = nullptr; } 2690 | field_declaration_list_opt field_declaration2691 { $$ = $1 ? $1->set_last( $2 ) : $2; }2711 | field_declaration_list_opt attribute_list_opt field_declaration 2712 { distAttr( $2, $3 ); $$ = $1 ? $1->set_last( $3 ) : $3; } 2692 2713 ; 2693 2714 2694 2715 field_declaration: 2695 2716 type_specifier field_declaring_list_opt ';' 2696 { 2697 $$ = fieldDecl( $1, $2 ); 2698 } 2717 { $$ = fieldDecl( $1, $2 ); } 2699 2718 | type_specifier field_declaring_list_opt '}' // invalid syntax rule 2700 2719 { … … 2706 2725 | STATIC type_specifier field_declaring_list_opt ';' // CFA 2707 2726 { SemanticError( yylloc, "STATIC aggregate field qualifier currently unimplemented." ); $$ = nullptr; } 2708 | INLINE type_specifier field_abstract_list_opt ';' // CFA2709 { 2710 if ( ! $ 3) { // field declarator ?2711 $ 3= DeclarationNode::newName( nullptr );2727 | INLINE attribute_list_opt type_specifier field_abstract_list_opt ';' // CFA 2728 { 2729 if ( ! $4 ) { // field declarator ? 2730 $4 = DeclarationNode::newName( nullptr ); 2712 2731 } // if 2713 $ 3->inLine = true;2714 $$ = dist Attr( $2, $3 );// mark all fields in list2715 distInl( $ 3);2716 } 2717 | INLINE a ggregate_control ';' // CFA2732 $4->inLine = true; 2733 $$ = distTypeSpec( $3, $4 ); // mark all fields in list 2734 distInl( $4 ); 2735 } 2736 | INLINE attribute_list_opt aggregate_control ';' // CFA 2718 2737 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; } 2719 2738 | typedef_declaration ';' // CFA … … 2721 2740 | EXTENSION cfa_field_declaring_list ';' // GCC 2722 2741 { distExt( $2 ); $$ = $2; } // mark all fields in list 2723 | INLINE cfa_field_abstract_list ';'// CFA, new style field declaration2724 { $$ = $ 2; }// mark all fields in list2742 | INLINE attribute_list_opt cfa_field_abstract_list ';' // CFA, new style field declaration 2743 { $$ = $3->addQualifiers( $2 ); } // mark all fields in list 2725 2744 | cfa_typedef_declaration ';' // CFA 2726 2745 | static_assert ';' // C11 … … 2762 2781 2763 2782 field_abstract: 2764 // no bit fields 2765 variable_abstract_declarator 2783 variable_abstract_declarator // no bit fields 2766 2784 ; 2767 2785 … … 2796 2814 enum_type: 2797 2815 // anonymous, no type name 2798 ENUM attribute_list_opt hide_opt '{' enumerator_list comma_opt '}' 2816 ENUM attribute_list_opt hide_opt '{' enumerator_list comma_opt '}' attribute_list_opt 2799 2817 { 2800 2818 if ( $3 == EnumHiding::Hide ) { 2801 2819 SemanticError( yylloc, "illegal syntax, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; 2802 2820 } // if 2803 $$ = DeclarationNode::newEnum( nullptr, $5, true, false )->addQualifiers( $2 ) ;2804 } 2805 | ENUM enumerator_type attribute_list_opt hide_opt '{' enumerator_list comma_opt '}' 2821 $$ = DeclarationNode::newEnum( nullptr, $5, true, false )->addQualifiers( $2 )->addQualifiers( $8 ); 2822 } 2823 | ENUM enumerator_type attribute_list_opt hide_opt '{' enumerator_list comma_opt '}' attribute_list_opt 2806 2824 { 2807 2825 if ( $2 && ($2->storageClasses.val != 0 || $2->type->qualifiers.any()) ) { … … 2811 2829 SemanticError( yylloc, "illegal syntax, hiding ('!') the enumerator names of an anonymous enumeration means the names are inaccessible." ); $$ = nullptr; 2812 2830 } // if 2813 $$ = DeclarationNode::newEnum( nullptr, $6, true, true, $2 )->addQualifiers( $3 ) ;2831 $$ = DeclarationNode::newEnum( nullptr, $6, true, true, $2 )->addQualifiers( $3 )->addQualifiers( $9 ); 2814 2832 } 2815 2833 2816 2834 // named type 2817 | ENUM attribute_list_opt identifier 2835 | ENUM attribute_list_opt identifier attribute_list_opt 2818 2836 { typedefTable.makeTypedef( *$3, "enum_type 1" ); } 2819 hide_opt '{' enumerator_list comma_opt '}' 2820 { $$ = DeclarationNode::newEnum( $3, $ 7, true, false, nullptr, $5 )->addQualifiers( $2); }2821 | ENUM attribute_list_opt typedef_name hide_opt '{' enumerator_list comma_opt '}'// unqualified type name2822 { $$ = DeclarationNode::newEnum( $3->name, $ 6, true, false, nullptr, $4 )->addQualifiers( $2); }2837 hide_opt '{' enumerator_list comma_opt '}' attribute_list_opt 2838 { $$ = DeclarationNode::newEnum( $3, $8, true, false, nullptr, $6 )->addQualifiers( $2 ->addQualifiers( $4 ))->addQualifiers( $11 ); } 2839 | ENUM attribute_list_opt typedef_name attribute_list_opt hide_opt '{' enumerator_list comma_opt '}' attribute_list_opt // unqualified type name 2840 { $$ = DeclarationNode::newEnum( $3->name, $7, true, false, nullptr, $5 )->addQualifiers( $2 )->addQualifiers( $4 )->addQualifiers( $10 ); } 2823 2841 | ENUM enumerator_type attribute_list_opt identifier attribute_list_opt 2824 2842 { … … 2828 2846 typedefTable.makeTypedef( *$4, "enum_type 2" ); 2829 2847 } 2830 hide_opt '{' enumerator_list comma_opt '}' 2831 { $$ = DeclarationNode::newEnum( $4, $9, true, true, $2, $7 )->addQualifiers( $3 )->addQualifiers( $5 ) ; }2832 | ENUM enumerator_type attribute_list_opt typedef_name attribute_list_opt hide_opt '{' enumerator_list comma_opt '}' 2833 { $$ = DeclarationNode::newEnum( $4->name, $8, true, true, $2, $6 )->addQualifiers( $3 )->addQualifiers( $5 ) ; }2848 hide_opt '{' enumerator_list comma_opt '}' attribute_list_opt 2849 { $$ = DeclarationNode::newEnum( $4, $9, true, true, $2, $7 )->addQualifiers( $3 )->addQualifiers( $5 )->addQualifiers( $12 ); } 2850 | ENUM enumerator_type attribute_list_opt typedef_name attribute_list_opt hide_opt '{' enumerator_list comma_opt '}' attribute_list_opt 2851 { $$ = DeclarationNode::newEnum( $4->name, $8, true, true, $2, $6 )->addQualifiers( $3 )->addQualifiers( $5 )->addQualifiers( $11 ); } 2834 2852 2835 2853 // forward declaration … … 2910 2928 parameter_list: // abstract + real 2911 2929 parameter_declaration 2930 | attribute_list parameter_declaration 2931 { $$ = $2->addQualifiers( $1 ); } 2912 2932 | abstract_parameter_declaration 2913 | parameter_list ',' parameter_declaration 2914 { $$ = $1->set_last( $3 ); } 2915 | parameter_list ',' abstract_parameter_declaration 2916 { $$ = $1->set_last( $3 ); } 2933 | attribute_list abstract_parameter_declaration 2934 { $$ = $2->addQualifiers( $1 ); } 2935 | parameter_list ',' attribute_list_opt parameter_declaration 2936 { $4->addQualifiers( $3 ); $$ = $1->set_last( $4 ); } 2937 | parameter_list ',' attribute_list_opt abstract_parameter_declaration 2938 { $4->addQualifiers( $3 ); $$ = $1->set_last( $4 ); } 2917 2939 ; 2918 2940 … … 3002 3024 3003 3025 type_no_function: // sizeof, alignof, cast (constructor) 3004 cfa_abstract_declarator_tuple // CFA 3005 | type_specifier // cannot be type_specifier_nobody, e.g., (struct S {}){} is a thing 3026 type_specifier // cannot be type_specifier_nobody, e.g., (struct S {}){} is a thing 3006 3027 | type_specifier abstract_declarator 3007 3028 { $$ = $2->addType( $1 ); } 3029 | cfa_abstract_declarator_tuple // CFA 3008 3030 ; 3009 3031 3010 3032 type: // typeof, assertion 3011 3033 type_no_function 3034 | attribute_list type_no_function 3035 { $$ = $2->addQualifiers( $1 ); } 3012 3036 | cfa_abstract_function // CFA 3037 | attribute_list cfa_abstract_function // CFA 3038 { $$ = $2->addQualifiers( $1 ); } 3013 3039 ; 3014 3040 … … 3268 3294 ; 3269 3295 3270 external_definition_list:3271 push external_definition pop3272 { $$ = $2; }3273 | external_definition_list push external_definition pop3274 { $$ = $1 ? $1->set_last( $3 ) : $3; }3275 ;3276 3277 3296 external_definition_list_opt: 3278 3297 // empty 3279 3298 { $$ = nullptr; } 3280 3299 | external_definition_list 3300 ; 3301 3302 external_definition_list: 3303 attribute_list_opt push external_definition pop 3304 { distAttr( $1, $3 ); $$ = $3; } 3305 | external_definition_list attribute_list_opt push external_definition pop 3306 { distAttr( $2, $4 ); $$ = $1 ? $1->set_last( $4 ) : $4->addQualifiers( $2 ); } 3281 3307 ; 3282 3308 … … 3587 3613 ptrref_operator variable_declarator 3588 3614 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3615 | ptrref_operator attribute_list variable_declarator 3616 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 3589 3617 | ptrref_operator type_qualifier_list variable_declarator 3590 3618 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3651 3679 ptrref_operator function_declarator 3652 3680 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3681 | ptrref_operator attribute_list function_declarator 3682 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 3653 3683 | ptrref_operator type_qualifier_list function_declarator 3654 3684 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3703 3733 ptrref_operator KR_function_declarator 3704 3734 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3735 | ptrref_operator attribute_list KR_function_declarator 3736 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 3705 3737 | ptrref_operator type_qualifier_list KR_function_declarator 3706 3738 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3756 3788 ptrref_operator variable_type_redeclarator 3757 3789 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3790 | ptrref_operator attribute_list variable_type_redeclarator 3791 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 3758 3792 | ptrref_operator type_qualifier_list variable_type_redeclarator 3759 3793 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3820 3854 ptrref_operator function_type_redeclarator 3821 3855 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3856 | ptrref_operator attribute_list function_type_redeclarator 3857 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 3822 3858 | ptrref_operator type_qualifier_list function_type_redeclarator 3823 3859 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3864 3900 ptrref_operator identifier_parameter_declarator 3865 3901 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3902 | ptrref_operator attribute_list identifier_parameter_declarator 3903 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 3866 3904 | ptrref_operator type_qualifier_list identifier_parameter_declarator 3867 3905 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3922 3960 ptrref_operator type_parameter_redeclarator 3923 3961 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 3962 | ptrref_operator attribute_list type_parameter_redeclarator 3963 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 3924 3964 | ptrref_operator type_qualifier_list type_parameter_redeclarator 3925 3965 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 3963 4003 3964 4004 abstract_ptr: 3965 ptrref_operator 3966 { $$ = DeclarationNode::newPointer( nullptr, $1 ) ; }4005 ptrref_operator attribute_list_opt 4006 { $$ = DeclarationNode::newPointer( nullptr, $1 )->addQualifiers( $2 ); } 3967 4007 | ptrref_operator type_qualifier_list 3968 4008 { $$ = DeclarationNode::newPointer( $2, $1 ); } 3969 4009 | ptrref_operator abstract_declarator 3970 4010 { $$ = $2->addPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 4011 | ptrref_operator attribute_list abstract_declarator 4012 { $$ = $3->addPointer( DeclarationNode::newPointer( nullptr, $1 )->addQualifiers( $2 ) ); } 3971 4013 | ptrref_operator type_qualifier_list abstract_declarator 3972 4014 { $$ = $3->addPointer( DeclarationNode::newPointer( $2, $1 ) ); } … … 4096 4138 4097 4139 abstract_parameter_ptr: 4098 ptrref_operator 4099 { $$ = DeclarationNode::newPointer( nullptr, $1 ) ; }4140 ptrref_operator attribute_list_opt 4141 { $$ = DeclarationNode::newPointer( nullptr, $1 )->addQualifiers( $2 ); } 4100 4142 | ptrref_operator type_qualifier_list 4101 4143 { $$ = DeclarationNode::newPointer( $2, $1 ); } … … 4175 4217 4176 4218 variable_abstract_ptr: 4177 ptrref_operator 4178 { $$ = DeclarationNode::newPointer( nullptr, $1 ) ; }4219 ptrref_operator attribute_list_opt 4220 { $$ = DeclarationNode::newPointer( nullptr, $1 )->addQualifiers( $2 ); } 4179 4221 | ptrref_operator type_qualifier_list 4180 4222 { $$ = DeclarationNode::newPointer( $2, $1 ); } … … 4223 4265 cfa_identifier_parameter_ptr: // CFA 4224 4266 // No SUE declaration in parameter list. 4225 ptrref_operator type_specifier_nobody4267 ptrref_operator type_specifier_nobody 4226 4268 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 4269 | ptrref_operator attribute_list type_specifier_nobody 4270 { $$ = $3->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 4227 4271 | type_qualifier_list ptrref_operator type_specifier_nobody 4228 4272 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); } … … 4323 4367 ptrref_operator type_specifier 4324 4368 { $$ = $2->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) ); } 4369 | ptrref_operator attribute_list type_specifier 4370 { $$ = $3->addNewPointer( DeclarationNode::newPointer( nullptr, $1 ) )->addQualifiers( $2 ); } 4325 4371 | type_qualifier_list ptrref_operator type_specifier 4326 4372 { $$ = $3->addNewPointer( DeclarationNode::newPointer( $1, $2 ) ); }
Note:
See TracChangeset
for help on using the changeset viewer.