Changeset 9e7236f4
- Timestamp:
- May 2, 2022, 3:18:32 AM (17 months ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 24ceace
- Parents:
- 2686bc7
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r2686bc7 r9e7236f4 1724 1724 } 1725 1725 1726 // Convert SynTree::EnumDecl to AST::EnumDecl 1726 1727 1727 virtual void visit( const EnumDecl * old ) override final { 1728 1728 if ( inCache( old ) ) return; -
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 -
src/ResolvExpr/Resolver.cc
r2686bc7 r9e7236f4 427 427 // enumerator initializers should not use the enum type to initialize, since 428 428 // the enum type is still incomplete at this point. Use signed int instead. 429 // TODO: BasicType::SignedInt may not longer be true 429 430 currentObject = CurrentObject( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 430 431 } … … 1477 1478 // enum type is still incomplete at this point. Use `int` instead. 1478 1479 1479 if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) { // const ast::PointerType & 1480 // const ast::Type * enumBase = (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get()); 1481 // const ast::PointerType * enumBaseAsPtr = dynamic_cast<const ast::PointerType *>(enumBase); 1482 1483 // if ( enumBaseAsPtr ) { 1484 // const ast::Type * pointerBase = enumBaseAsPtr->base.get(); 1485 // if ( dynamic_cast<const ast::BasicType *>(pointerBase) ) { 1486 // objectDecl = fixObjectType(objectDecl, context); 1487 // if (dynamic_cast<const ast::BasicType *>(pointerBase)->kind == ast::BasicType::Char) 1488 // currentObject = ast::CurrentObject{ 1489 // objectDecl->location, new ast::PointerType{ 1490 // new ast::BasicType{ ast::BasicType::Char } 1491 // } }; 1492 // } else { 1493 // objectDecl = fixObjectType(objectDecl, context); 1494 // currentObject = ast::CurrentObject{objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } }; 1495 // } 1496 // } 1480 if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) { 1497 1481 objectDecl = fixObjectType( objectDecl, context ); 1498 1482 const ast::Type * enumBase = (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get()); -
src/SymTab/Validate.cc
r2686bc7 r9e7236f4 760 760 } // if 761 761 } 762 763 762 void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) { 764 763 const StructDecl * st = local_indexer->lookupStruct( structInst->name ); … … 886 885 void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) { 887 886 // visit enum members first so that the types of self-referencing members are updated properly 887 // Replace the enum base; right now it works only for StructEnum 888 if ( enumDecl->base && dynamic_cast<TypeInstType*>(enumDecl->base) ) { 889 std::string baseName = static_cast<TypeInstType*>(enumDecl->base)->name; 890 const StructDecl * st = local_indexer->lookupStruct( baseName ); 891 if ( st ) { 892 enumDecl->base = new StructInstType(Type::Qualifiers(),const_cast<StructDecl *>(st)); // Just linking in the node 893 } 894 } 888 895 if ( enumDecl->body ) { 889 896 ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->name );
Note: See TracChangeset
for help on using the changeset viewer.