Changeset 284da8c for src/Parser
- Timestamp:
- Jul 6, 2018, 9:45:43 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- a1cfa0c, ac4ebc1
- Parents:
- 57fc7d8
- Location:
- src/Parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r57fc7d8 r284da8c 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 7 12:08:55201813 // Update Count : 10 7912 // Last Modified On : Fri Jul 6 06:56:08 2018 13 // Update Count : 1088 14 14 // 15 15 … … 504 504 505 505 static void addQualifiersToType( TypeData *&src, TypeData * dst ) { 506 if ( src->forall && dst->kind == TypeData::Function ) {507 if ( dst->forall ) {508 dst->forall->appendList( src->forall );509 } else {510 dst->forall = src->forall;511 } // if512 src->forall = nullptr;513 } // if514 506 if ( dst->base ) { 515 507 addQualifiersToType( src, dst->base ); … … 1065 1057 SemanticError( this, "invalid function specifier for " ); 1066 1058 } // if 1059 // Forall qualifier can only appear on a function/aggregate definition/declaration. 1060 // 1061 // forall int f(); // allowed 1062 // forall int g( int i ); // allowed 1063 // forall int i; // disallowed 1064 if ( type->kind != TypeData::Function && type->forall ) { 1065 SemanticError( this, "invalid type qualifier for " ); 1066 } // if 1067 1067 bool isDelete = initializer && initializer->get_isDelete(); 1068 1068 Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild< Initializer >(initializer), attributes )->set_extension( extension ); -
src/Parser/parser.yy
r57fc7d8 r284da8c 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 4 20:56:04201813 // Update Count : 3 61612 // Last Modified On : Fri Jul 6 08:02:38 2018 13 // Update Count : 3716 14 14 // 15 15 … … 116 116 117 117 void distQual( DeclarationNode * declaration, DeclarationNode * qualifiers ) { 118 // distribute qualifiers across all declarations in a distribution statemement118 // distribute qualifiers across all non-variable declarations in a distribution statemement 119 119 for ( DeclarationNode * iter = declaration; iter != nullptr; iter = (DeclarationNode *)iter->get_next() ) { 120 iter->addQualifiers( qualifiers->clone() ); 120 // SKULLDUGGERY: Distributions are parsed inside out, so qualifiers are added to declarations inside out. Since 121 // addQualifiers appends to the back of the list, the forall clauses are in the wrong order (right to left). To 122 // get the qualifiers in the correct order and still use addQualifiers (otherwise, 90% of addQualifiers has to 123 // be copied to add to front), the appropriate forall pointers are interchanged before calling addQualifiers. 124 DeclarationNode * clone = qualifiers->clone(); 125 if ( qualifiers->type ) { // forall clause ? (handles SC) 126 if ( iter->type->kind == TypeData::Aggregate ) { // struct/union ? 127 swap( clone->type->forall, iter->type->aggregate.params ); 128 iter->addQualifiers( clone ); 129 } else if ( iter->type->kind == TypeData::AggregateInst && iter->type->aggInst.aggregate->aggregate.body ) { // struct/union ? 130 // Create temporary node to hold aggregate, call addQualifiers as above, then put nodes back together. 131 DeclarationNode newnode; 132 swap( newnode.type, iter->type->aggInst.aggregate ); 133 swap( clone->type->forall, newnode.type->aggregate.params ); 134 newnode.addQualifiers( clone ); 135 swap( newnode.type, iter->type->aggInst.aggregate ); 136 } else if ( iter->type->kind == TypeData::Function ) { // routines ? 137 swap( clone->type->forall, iter->type->forall ); 138 iter->addQualifiers( clone ); 139 } // if 140 } else { // just SC qualifiers 141 iter->addQualifiers( clone ); 142 } // if 121 143 } // for 122 } // distExt 144 delete qualifiers; 145 } // distQual 123 146 124 147 // There is an ambiguity for inline generic-routine return-types and generic routines. … … 364 387 %type<decl> type_parameter type_parameter_list type_initializer_opt 365 388 366 %type<en> type_ list389 %type<en> type_parameters_opt type_list 367 390 368 391 %type<decl> type_qualifier type_qualifier_name forall type_qualifier_list_opt type_qualifier_list … … 404 427 // Order of these lines matters (low-to-high precedence). 405 428 %precedence TYPEGENname 429 %precedence '}' 406 430 %precedence '(' 407 431 … … 1751 1775 { $$ = $3->addQualifiers( $1 ); } 1752 1776 | sue_type_specifier type_qualifier 1753 { $$ = $1->addQualifiers( $2 ); } 1777 { 1778 if ( $2->type != nullptr && $2->type->forall ) forall = true; // remember generic type 1779 $$ = $1->addQualifiers( $2 ); 1780 } 1754 1781 ; 1755 1782 … … 1829 1856 1830 1857 aggregate_type: // struct, union 1831 aggregate_key attribute_list_opt '{' field_declaration_list_opt '}' 1832 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), nullptr, $4, true )->addQualifiers( $2 ); }1858 aggregate_key attribute_list_opt '{' field_declaration_list_opt '}' type_parameters_opt 1859 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $6, $4, true )->addQualifiers( $2 ); } 1833 1860 | aggregate_key attribute_list_opt no_attr_identifier fred 1834 1861 { … … 1836 1863 forall = false; // reset 1837 1864 } 1838 '{' field_declaration_list_opt '}' 1839 { $$ = DeclarationNode::newAggregate( $1, $3, nullptr, $7, true )->addQualifiers( $2 ); }1865 '{' field_declaration_list_opt '}' type_parameters_opt 1866 { $$ = DeclarationNode::newAggregate( $1, $3, $9, $7, true )->addQualifiers( $2 ); } 1840 1867 | aggregate_key attribute_list_opt type_name fred 1841 1868 { … … 1843 1870 forall = false; // reset 1844 1871 } 1845 '{' field_declaration_list_opt '}' 1846 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, nullptr, $7, true )->addQualifiers( $2 ); } 1847 | aggregate_key attribute_list_opt '(' type_list ')' '{' field_declaration_list_opt '}' // CFA 1848 { $$ = DeclarationNode::newAggregate( $1, new string( DeclarationNode::anonymous.newName() ), $4, $7, false )->addQualifiers( $2 ); } 1872 '{' field_declaration_list_opt '}' type_parameters_opt 1873 { $$ = DeclarationNode::newAggregate( $1, $3->type->symbolic.name, $9, $7, true )->addQualifiers( $2 ); } 1849 1874 | aggregate_type_nobody 1875 ; 1876 1877 type_parameters_opt: 1878 // empty 1879 { $$ = nullptr; } %prec '}' 1880 | '(' type_list ')' 1881 { $$ = $2; } 1850 1882 ; 1851 1883 … … 2386 2418 distQual( $5, $1 ); 2387 2419 xxx = false; 2388 delete $1;2389 2420 $$ = $5; 2390 2421 } … … 2398 2429 distQual( $5, $1 ); 2399 2430 xxx = false; 2400 delete $1;2401 2431 $$ = $5; 2402 2432 } … … 2408 2438 '{' up external_definition_list_opt down '}' // CFA, namespace 2409 2439 { 2410 distQual( $6, $2 ); 2411 distQual( $6, $1 ); 2440 distQual( $6, $1->addQualifiers( $2 ) ); 2412 2441 xxx = false; 2413 delete $1;2414 delete $2;2415 2442 $$ = $6; 2416 2443 }
Note: See TracChangeset
for help on using the changeset viewer.