Changeset d964c39 for src/Parser
- Timestamp:
- Feb 25, 2023, 6:45:44 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 601bd9e
- Parents:
- ce44c5f (diff), 2d028003 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 3 edited
-
DeclarationNode.cc (modified) (4 diffs)
-
TypeData.h (modified) (2 diffs)
-
parser.yy (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
rce44c5f rd964c39 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 16 14:12:03202313 // Update Count : 1 38812 // Last Modified On : Sat Feb 25 12:15:40 2023 13 // Update Count : 1404 14 14 // 15 15 … … 254 254 newnode->type->enumeration.typed = typed; 255 255 newnode->type->enumeration.hiding = hiding; 256 if ( base && base->type ) {256 if ( base && base->type ) { 257 257 newnode->type->base = base->type; 258 258 } // if … … 567 567 568 568 checkQualifiers( type, q->type ); 569 if ( (builtin == Zero || builtin == One) && q->type->qualifiers. val != 0&& error.length() == 0 ) {570 SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, Type::QualifiersNames[ilog2( q->type->qualifiers.val )],builtinTypeNames[builtin] );569 if ( (builtin == Zero || builtin == One) && q->type->qualifiers.any() && error.length() == 0 ) { 570 SemanticWarning( yylloc, Warning::BadQualifiersZeroOne, builtinTypeNames[builtin] ); 571 571 } // if 572 572 addQualifiersToType( q->type, type ); … … 984 984 985 985 if ( DeclarationNode * extr = cur->extractAggregate() ) { 986 // handle the case where a structure declaration is contained within an object or type declaration 986 // Handle the case where a SUE declaration is contained within an object or type declaration. 987 988 assert( cur->type ); 989 // Replace anonymous SUE name with typedef name to prevent anonymous naming problems across translation units. 990 if ( cur->type->kind == TypeData::Symbolic && cur->type->symbolic.isTypedef ) { 991 assert( extr->type ); 992 // Handle anonymous aggregates: typedef struct { int i; } foo 993 extr->type->qualifiers.reset(); // clear any CVs associated with the aggregate 994 if ( extr->type->kind == TypeData::Aggregate && extr->type->aggregate.anon ) { 995 delete extr->type->aggregate.name; 996 extr->type->aggregate.name = new string( "__anonymous_" + *cur->name ); 997 extr->type->aggregate.anon = false; 998 assert( cur->type->base ); 999 if ( cur->type->base ) { 1000 delete cur->type->base->aggInst.aggregate->aggregate.name; 1001 cur->type->base->aggInst.aggregate->aggregate.name = new string( "__anonymous_" + *cur->name ); 1002 cur->type->base->aggInst.aggregate->aggregate.anon = false; 1003 cur->type->base->aggInst.aggregate->qualifiers.reset(); 1004 } // if 1005 } // if 1006 // Handle anonymous enumeration: typedef enum { A, B, C } foo 1007 if ( extr->type->kind == TypeData::Enum && extr->type->enumeration.anon ) { 1008 delete extr->type->enumeration.name; 1009 extr->type->enumeration.name = new string( "__anonymous_" + *cur->name ); 1010 extr->type->enumeration.anon = false; 1011 assert( cur->type->base ); 1012 if ( cur->type->base ) { 1013 delete cur->type->base->aggInst.aggregate->enumeration.name; 1014 cur->type->base->aggInst.aggregate->enumeration.name = new string( "__anonymous_" + *cur->name ); 1015 cur->type->base->aggInst.aggregate->enumeration.anon = false; 1016 } // if 1017 } // if 1018 } // if 987 1019 988 1020 Declaration * decl = extr->build(); -
src/Parser/TypeData.h
rce44c5f rd964c39 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 19 09:09:39202313 // Update Count : 20 412 // Last Modified On : Fri Feb 24 14:25:02 2023 13 // Update Count : 205 14 14 // 15 15 … … 41 41 }; 42 42 43 struct AggInst_t { 43 struct AggInst_t { // handles SUE 44 44 TypeData * aggregate = nullptr; 45 45 ExpressionNode * params = nullptr; -
src/Parser/parser.yy
rce44c5f rd964c39 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Feb 20 11:31:26 202313 // Update Count : 5 89612 // Last Modified On : Sat Feb 25 13:23:16 2023 13 // Update Count : 5989 14 14 // 15 15 … … 1173 1173 comma_expression_opt ';' 1174 1174 { $$ = new StatementNode( build_expr( $1 ) ); } 1175 | MUTEX '(' ')' comma_expression ';'1176 { $$ = new StatementNode( build_mutex( nullptr, new StatementNode( build_expr( $4 ) ) ) ); }1177 1175 ; 1178 1176 … … 1282 1280 { 1283 1281 $$ = new StatementNode( build_while( new CondCtl( nullptr, NEW_ONE ), maybe_build_compound( $4 ) ) ); 1284 SemanticWarning( yylloc, Warning::SuperfluousElse , "");1282 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1285 1283 } 1286 1284 | WHILE '(' conditional_declaration ')' statement %prec THEN … … 1293 1291 { 1294 1292 $$ = new StatementNode( build_do_while( NEW_ONE, maybe_build_compound( $2 ) ) ); 1295 SemanticWarning( yylloc, Warning::SuperfluousElse , "");1293 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1296 1294 } 1297 1295 | DO statement WHILE '(' comma_expression ')' ';' … … 1304 1302 { 1305 1303 $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); 1306 SemanticWarning( yylloc, Warning::SuperfluousElse , "");1304 SemanticWarning( yylloc, Warning::SuperfluousElse ); 1307 1305 } 1308 1306 | FOR '(' for_control_expression_list ')' statement %prec THEN … … 1584 1582 ; 1585 1583 1586 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".1584 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so possibly change syntax to "with mutex". 1587 1585 mutex_statement: 1588 MUTEX '(' argument_expression_list ')' statement 1589 { $$ = new StatementNode( build_mutex( $3, $5 ) ); } 1586 MUTEX '(' argument_expression_list_opt ')' statement 1587 { 1588 if ( ! $3 ) { SemanticError( yylloc, "mutex argument list cannot be empty." ); $$ = nullptr; } 1589 $$ = new StatementNode( build_mutex( $3, $5 ) ); 1590 } 1590 1591 ; 1591 1592 … … 1941 1942 // if type_specifier is an anon aggregate => name 1942 1943 typedefTable.addToEnclosingScope( *$3->name, TYPEDEFname, "4" ); 1943 $$ = $3->addType( $2 )->addTypedef(); 1944 $$ = $3->addType( $2 )->addTypedef(); // watchout frees $2 and $3 1944 1945 } 1945 1946 | typedef_declaration pop ',' push declarator … … 1985 1986 { 1986 1987 assert( $1->type ); 1987 if ( $1->type->qualifiers.val != 0 ) { 1988 SemanticError( yylloc, "Useless type qualifier in empty declaration." ); $$ = nullptr; 1988 if ( $1->type->qualifiers.any() ) { // CV qualifiers ? 1989 SemanticError( yylloc, "Useless type qualifier(s) in empty declaration." ); $$ = nullptr; 1990 } 1991 // enums are never empty declarations because there must have at least one enumeration. 1992 if ( $1->type->kind == TypeData::AggregateInst && $1->storageClasses.any() ) { // storage class ? 1993 SemanticError( yylloc, "Useless storage qualifier(s) in empty aggregate declaration." ); $$ = nullptr; 1989 1994 } 1990 1995 } … … 2006 2011 | sue_declaration_specifier invalid_types 2007 2012 { 2008 SemanticError( yylloc, 2009 ::toString( "Missing ';' after end of ", 2010 $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ), 2011 " declaration" ) ); 2013 SemanticError( yylloc, ::toString( "Missing ';' after end of ", 2014 $1->type->enumeration.name ? "enum" : AggregateDecl::aggrString( $1->type->aggregate.kind ), 2015 " declaration" ) ); 2012 2016 $$ = nullptr; 2013 2017 } … … 2588 2592 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2589 2593 { 2590 if ( $3->storageClasses.val != 0 || $3->type->qualifiers. val != 0)2594 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.any() ) 2591 2595 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2592 2596 … … 2599 2603 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2600 2604 { 2601 if ( $3->storageClasses. val != 0|| $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); }2605 if ( $3->storageClasses.any() || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2602 2606 typedefTable.makeTypedef( *$6 ); 2603 2607 } … … 2986 2990 TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' '}' 2987 2991 { 2988 SemanticWarning( yylloc, Warning::DeprecTraitSyntax , "");2992 SemanticWarning( yylloc, Warning::DeprecTraitSyntax ); 2989 2993 $$ = DeclarationNode::newTrait( $2, $4, nullptr ); 2990 2994 } … … 2993 2997 | TRAIT identifier_or_type_name '(' type_parameter_list ')' '{' push trait_declaration_list pop '}' 2994 2998 { 2995 SemanticWarning( yylloc, Warning::DeprecTraitSyntax , "");2999 SemanticWarning( yylloc, Warning::DeprecTraitSyntax ); 2996 3000 $$ = DeclarationNode::newTrait( $2, $4, $8 ); 2997 3001 } … … 3058 3062 { $$ = DeclarationNode::newDirectiveStmt( new StatementNode( build_directive( $1 ) ) ); } 3059 3063 | declaration 3064 { 3065 // Variable declarations of anonymous types requires creating a unique type-name across multiple translation 3066 // unit, which is a dubious task, especially because C uses name rather than structural typing; hence it is 3067 // disallowed at the moment. 3068 if ( $1->linkage == LinkageSpec::Cforall && ! $1->storageClasses.is_static && $1->type && $1->type->kind == TypeData::AggregateInst ) { 3069 if ( $1->type->aggInst.aggregate->kind == TypeData::Enum && $1->type->aggInst.aggregate->enumeration.anon ) { 3070 SemanticError( yylloc, "extern anonymous enumeration is currently unimplemented." ); $$ = nullptr; 3071 } else if ( $1->type->aggInst.aggregate->aggregate.anon ) { // handles struct or union 3072 SemanticError( yylloc, "extern anonymous struct/union is currently unimplemented." ); $$ = nullptr; 3073 } 3074 } 3075 } 3060 3076 | IDENTIFIER IDENTIFIER 3061 3077 { IdentifierBeforeIdentifier( *$1.str, *$2.str, " declaration" ); $$ = nullptr; } … … 3103 3119 | type_qualifier_list 3104 3120 { 3105 if ( $1->type->qualifiers. val) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }3121 if ( $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3106 3122 if ( $1->type->forall ) forall = true; // remember generic type 3107 3123 } … … 3114 3130 | declaration_qualifier_list 3115 3131 { 3116 if ( $1->type && $1->type->qualifiers. val) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }3132 if ( $1->type && $1->type->qualifiers.any() ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3117 3133 if ( $1->type && $1->type->forall ) forall = true; // remember generic type 3118 3134 } … … 3125 3141 | declaration_qualifier_list type_qualifier_list 3126 3142 { 3127 if ( ($1->type && $1->type->qualifiers. val) || ($2->type && $2->type->qualifiers.val) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); }3143 if ( ($1->type && $1->type->qualifiers.any()) || ($2->type && $2->type->qualifiers.any()) ) { SemanticError( yylloc, "CV qualifiers cannot be distributed; only storage-class and forall qualifiers." ); } 3128 3144 if ( ($1->type && $1->type->forall) || ($2->type && $2->type->forall) ) forall = true; // remember generic type 3129 3145 }
Note:
See TracChangeset
for help on using the changeset viewer.