Changeset 374cb117 for src/Parser
- Timestamp:
- Apr 19, 2022, 3:53:53 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 2686bc7
- Parents:
- 75cd27b
- Location:
- src/Parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r75cd27b r374cb117 253 253 } // DeclarationNode::newAggregate 254 254 255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body , bool typed) {255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body) { 256 256 DeclarationNode * newnode = new DeclarationNode; 257 257 newnode->type = new TypeData( TypeData::Enum ); … … 272 272 } // DeclarationNode::newName 273 273 274 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { // Marker274 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { 275 275 DeclarationNode * newnode = newName( name ); 276 276 newnode->enumeratorValue.reset( constant ); 277 277 return newnode; 278 278 } // DeclarationNode::newEnumConstant 279 280 DeclarationNode * DeclarationNode::newEnumValueGeneric( const string * name, InitializerNode * init ) { 281 if ( init ) { // list init {} or a singleInit 282 if ( init->get_expression() ) { // singleInit 283 return newEnumConstant( name, init->get_expression() ); 284 } else { // TODO: listInit 285 DeclarationNode * newnode = newName( name ); 286 newnode->initializer = init; 287 return newnode; 288 } // if 289 } else { 290 return newName( name ); // Not explicitly inited enum value; 291 } // if 292 } // DeclarationNode::newEnumGeneric 279 293 280 294 DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) { -
src/Parser/InitializerNode.cc
r75cd27b r374cb117 101 101 } else { 102 102 if ( get_expression() ) { 103 assertf( get_expression()->expr, "The expression of initializer must have value" ); 103 104 return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed ); 104 105 } // if -
src/Parser/ParseNode.h
r75cd27b r374cb117 235 235 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 236 236 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body , bool typed);237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body ); 238 238 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 239 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init ); 239 240 static DeclarationNode * newName( const std::string * ); 240 241 static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params ); -
src/Parser/parser.yy
r75cd27b r374cb117 380 380 381 381 %type<decl> enumerator_list enum_type enum_type_nobody 382 %type< en> enumerator_value_opt382 %type<in> enumerator_value_opt 383 383 384 384 %type<decl> external_definition external_definition_list external_definition_list_opt … … 2305 2305 enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed ); // enum 2306 2306 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2307 { $$ = DeclarationNode::newEnum( nullptr, $4, true , false)->addQualifiers( $2 ); }2307 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } 2308 2308 | ENUM attribute_list_opt identifier 2309 2309 { typedefTable.makeTypedef( *$3 ); } 2310 2310 '{' enumerator_list comma_opt '}' 2311 { $$ = DeclarationNode::newEnum( $3, $6, true , false)->addQualifiers( $2 ); }2311 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); } 2312 2312 | ENUM attribute_list_opt typedef_name // unqualified type name 2313 2313 '{' enumerator_list comma_opt '}' 2314 { $$ = DeclarationNode::newEnum( $3->name, $5, true , false)->addQualifiers( $2 ); }2314 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); } 2315 2315 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2316 2316 { 2317 2317 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) 2318 2318 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2319 // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2320 2321 $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ) -> addEnumBase( $3 ); 2322 // $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ); 2319 2320 $$ = DeclarationNode::newEnum( nullptr, $7, true ) ->addQualifiers( $5 ) -> addEnumBase( $3 ); 2323 2321 } 2324 2322 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier … … 2329 2327 '{' enumerator_list comma_opt '}' 2330 2328 { 2331 $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2332 // $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2329 $$ = DeclarationNode::newEnum( $6, $10, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2333 2330 } 2334 2331 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' … … 2336 2333 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." ); } 2337 2334 typedefTable.makeTypedef( *$6->name ); 2338 $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2339 // $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2335 $$ = DeclarationNode::newEnum( $6->name, $9, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2340 2336 } 2341 2337 | enum_type_nobody … … 2344 2340 enum_type_nobody: // enum - {...} 2345 2341 ENUM attribute_list_opt identifier 2346 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false , false)->addQualifiers( $2 ); }2342 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); } 2347 2343 | ENUM attribute_list_opt type_name // qualified type name 2348 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false , false)->addQualifiers( $2 ); }2344 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); } 2349 2345 ; 2350 2346 2351 2347 enumerator_list: 2352 2348 identifier_or_type_name enumerator_value_opt 2353 { $$ = DeclarationNode::newEnum Constant( $1, $2 ); }2349 { $$ = DeclarationNode::newEnumValueGeneric( $1, $2 ); } 2354 2350 | INLINE type_name 2355 { $$ = DeclarationNode::newEnum Constant( new string("inline"), nullptr ); }2351 { $$ = DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ); } 2356 2352 | enumerator_list ',' identifier_or_type_name enumerator_value_opt 2357 { $$ = $1->appendList( DeclarationNode::newEnum Constant( $3, $4 ) ); }2353 { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( $3, $4 ) ); } 2358 2354 | enumerator_list ',' INLINE type_name enumerator_value_opt 2359 { $$ = $1->appendList( DeclarationNode::newEnum Constant( new string("inline"), nullptr ) ); }2355 { $$ = $1->appendList( DeclarationNode::newEnumValueGeneric( new string("inline"), nullptr ) ); } 2360 2356 ; 2361 2357 … … 2366 2362 // { $$ = $2; } 2367 2363 | simple_assignment_operator initializer 2368 { $$ = $ 2->get_expression(); } // FIX ME: enum only deals with constant_expression2364 { $$ = $1 == OperKinds::Assign ? $2 : $2->set_maybeConstructed( false ); } 2369 2365 ; 2370 2366
Note: See TracChangeset
for help on using the changeset viewer.