Changeset 9e7236f4 for src/Parser
- Timestamp:
- May 2, 2022, 3:18:32 AM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 24ceace
- Parents:
- 2686bc7
- Location:
- src/Parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/DeclarationNode.cc
r2686bc7 r9e7236f4 253 253 } // DeclarationNode::newAggregate 254 254 255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body ) {255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, DeclarationNode * base) { 256 256 DeclarationNode * newnode = new DeclarationNode; 257 257 newnode->type = new TypeData( TypeData::Enum ); … … 260 260 newnode->type->enumeration.body = body; 261 261 newnode->type->enumeration.anon = name == nullptr; 262 if ( base && base->type) { 263 newnode->type->base = base->type; 264 } // if 265 266 // Check: if base has TypeData 262 267 return newnode; 263 268 } // DeclarationNode::newEnum … … 290 295 return newName( name ); // Not explicitly inited enum value; 291 296 } // if 292 } // DeclarationNode::newEnum Generic297 } // DeclarationNode::newEnumValueGeneric 293 298 294 299 DeclarationNode * DeclarationNode::newFromTypedef( const string * name ) { -
src/Parser/ParseNode.h
r2686bc7 r9e7236f4 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 );237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, DeclarationNode * base = nullptr ); 238 238 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 239 239 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init ); -
src/Parser/TypeData.cc
r2686bc7 r9e7236f4 388 388 if ( enumeration.body ) { 389 389 os << string( indent + 2, ' ' ) << " with body" << endl; 390 } // if 391 if ( base ) { 392 os << "for "; 393 base->print( os, indent + 2 ); 390 394 } // if 391 395 break; … … 926 930 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 927 931 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 928 } else {932 } else if ( !cur->initializer ) { 929 933 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) { 930 934 SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." ); 931 935 } 932 } // if 936 } 937 // else cur is a List Initializer and has been set as init in buildList() 938 // if 933 939 } // for 934 ret->set_body( td->enumeration.body ); // Boolean; if it has body940 ret->set_body( td->enumeration.body ); 935 941 return ret; 936 942 } // buildEnum -
src/Parser/parser.yy
r2686bc7 r9e7236f4 2303 2303 ; 2304 2304 2305 enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed ); // enum2305 enum_type: 2306 2306 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2307 2307 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); } … … 2318 2318 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2319 2319 2320 $$ = DeclarationNode::newEnum( nullptr, $7, true ) ->addQualifiers( $5 ) -> addEnumBase( $3);2321 } 2322 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier2320 $$ = DeclarationNode::newEnum( nullptr, $7, true, $3 ) ->addQualifiers( $5 ); 2321 } 2322 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2323 2323 { 2324 2324 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." ); } … … 2327 2327 '{' enumerator_list comma_opt '}' 2328 2328 { 2329 $$ = DeclarationNode::newEnum( $6, $10, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3);2329 $$ = DeclarationNode::newEnum( $6, $10, true, $3 ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2330 2330 } 2331 2331 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' … … 2333 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." ); } 2334 2334 typedefTable.makeTypedef( *$6->name ); 2335 $$ = DeclarationNode::newEnum( $6->name, $9, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3);2335 $$ = DeclarationNode::newEnum( $6->name, $9, true, $3 ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2336 2336 } 2337 2337 | enum_type_nobody
Note: See TracChangeset
for help on using the changeset viewer.