- Timestamp:
- Feb 3, 2025, 11:46:55 AM (8 weeks ago)
- Branches:
- master
- Children:
- 54f70c6
- Parents:
- bbbff10
- Location:
- src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/AST/Decl.cpp ¶
rbbbff10 r90e683b 169 169 } 170 170 171 bool EnumDecl::isTyped() const { return base; }172 173 bool EnumDecl::isOpaque() const { return isCfa && !isTyped(); }174 175 171 } 176 172 -
TabularUnified src/AST/Decl.hpp ¶
rbbbff10 r90e683b 306 306 enum class EnumAttribute{ Value, Posn, Label }; 307 307 308 /// enum declaration `enum Foo { ... };` 308 /// enum declaration `enum Foo { ... };` or `enum(...) Foo { ... };` 309 309 class EnumDecl final : public AggregateDecl { 310 310 public: … … 317 317 std::vector< ast::ptr<ast::EnumInstType>> inlinedDecl; // child enums 318 318 319 bool is_c_enum () const { return !isCfa; } 320 bool is_opaque_enum() const { return isCfa && nullptr == base; } 321 bool is_typed_enum () const { return isCfa && nullptr != base; } 322 319 323 EnumDecl( const CodeLocation& loc, const std::string& name, bool isCfa = false, 320 324 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, … … 331 335 const char * typeString() const override { return aggrString( Enum ); } 332 336 333 bool isTyped() const;334 bool isOpaque() const;335 337 private: 336 338 EnumDecl * clone() const override { return new EnumDecl{ *this }; } -
TabularUnified src/AST/Util.cpp ¶
rbbbff10 r90e683b 85 85 // Check that `type->returns` corresponds with `decl->returns`. 86 86 assert( type->returns.size() == decl->returns.size() ); 87 } 88 89 /// Check that an enumeration has not been made with an inconsistent spec. 90 void isEnumerationConsistent( const EnumDecl * node ) { 91 if ( node->is_c_enum() ) { 92 assert( nullptr == node->base ); 93 } 87 94 } 88 95 … … 135 142 previsit( (const ParseNode *)node ); 136 143 functionDeclMatchesType( node ); 144 } 145 146 void previsit( const EnumDecl * node ) { 147 previsit( (const ParseNode *)node ); 148 isEnumerationConsistent( node ); 137 149 } 138 150 -
TabularUnified src/InitTweak/GenInit.cpp ¶
rbbbff10 r90e683b 164 164 ast::ObjectDecl * arrayDimension = nullptr; 165 165 166 const ast::TypeExpr * ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() ); 167 if ( ty ) { 166 if ( auto ty = dynamic_cast< const ast::TypeExpr * >( arrayType->dimension.get() ) ) { 168 167 auto inst = ty->type.as<ast::EnumInstType>(); 169 if ( inst ) { 170 if ( inst->base->isCfa ) { 171 arrayDimension = new ast::ObjectDecl( 168 if ( inst && !inst->base->is_c_enum() ) { 169 arrayDimension = new ast::ObjectDecl( 170 arrayType->dimension->location, 171 dimensionName.newName(), 172 new ast::BasicType( ast::BasicKind::UnsignedChar ), 173 new ast::SingleInit( 172 174 arrayType->dimension->location, 173 dimensionName.newName(), 174 new ast::BasicType( ast::BasicKind::UnsignedChar ), 175 new ast::SingleInit( 176 arrayType->dimension->location, 177 ast::ConstantExpr::from_int( arrayType->dimension->location, inst->base->members.size() ) 178 ) 179 ); 180 // return arrayType; 181 } 175 ast::ConstantExpr::from_int( arrayType->dimension->location, inst->base->members.size() ) 176 ) 177 ); 182 178 } 183 179 } -
TabularUnified src/Parser/TypeData.cpp ¶
rbbbff10 r90e683b 1482 1482 object->isHidden = ast::EnumDecl::EnumHiding::Hide == ret->hide; 1483 1483 object->isMember = true; 1484 if ( ret->is Opaque() && cur->has_enumeratorValue() ) {1484 if ( ret->is_opaque_enum() && cur->has_enumeratorValue() ) { 1485 1485 SemanticError( td->location, "Opague cannot have an explicit initializer value." ); 1486 1486 } else if ( cur->has_enumeratorValue() ) { 1487 1487 ast::Expr * initValue; 1488 if ( ret->is Cfa && ret->base) {1488 if ( ret->is_typed_enum() ) { 1489 1489 CodeLocation location = cur->enumeratorValue->location; 1490 1490 initValue = new ast::CastExpr( location, maybeMoveBuild( cur->consume_enumeratorValue() ), ret->base ); -
TabularUnified src/ResolvExpr/CastCost.cpp ¶
rbbbff10 r90e683b 53 53 void postvisit( const ast::EnumInstType * enumInst ) { 54 54 cost = conversionCost( enumInst, dst, srcIsLvalue, symtab, env ); 55 if ( enumInst->base->is Typed() ) {56 auto baseConversionCost = 55 if ( enumInst->base->is_typed_enum() ) { 56 auto baseConversionCost = 57 57 castCost( enumInst->base->base, dst, srcIsLvalue, symtab, env ); 58 cost = baseConversionCost < cost ? baseConversionCost: cost;58 cost = baseConversionCost < cost ? baseConversionCost : cost; 59 59 } 60 60 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 61 61 Cost intCost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 62 62 intCost.incSafe(); 63 cost = intCost < cost ? intCost: cost;63 cost = intCost < cost ? intCost : cost; 64 64 } 65 65 -
TabularUnified src/ResolvExpr/CommonType.cpp ¶
rbbbff10 r90e683b 386 386 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 387 387 const ast::EnumDecl* enumDecl = enumInst->base; 388 if ( !enumDecl->isCfa) {388 if ( enumDecl->is_c_enum() ) { 389 389 ast::BasicKind kind = commonTypes[ basic->kind ][ ast::BasicKind::SignedInt ]; 390 390 if ( … … 654 654 result = param; 655 655 } 656 } else if ( param->base && !param->base->isCfa) {656 } else if ( param->base && param->base->is_c_enum() ) { 657 657 auto basicType = new ast::BasicType( ast::BasicKind::UnsignedInt ); 658 658 result = commonType( basicType, type2, tenv, need, have, open, widen); -
TabularUnified src/ResolvExpr/ConversionCost.cpp ¶
rbbbff10 r90e683b 246 246 } 247 247 if (const ast::EnumInstType * srcAsInst = dynamic_cast< const ast::EnumInstType * >( src )) { 248 if ( srcAsInst->base && !srcAsInst->base->isCfa) {248 if ( srcAsInst->base && srcAsInst->base->is_c_enum() ) { 249 249 static const ast::BasicType* integer = new ast::BasicType( ast::BasicKind::UnsignedInt ); 250 250 return ast::Pass<ConversionCost>::read( integer, dst, srcIsLvalue, symtab, env, conversionCost ); … … 324 324 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 325 325 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 326 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa) {326 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) { 327 327 cost = Cost::safe; 328 328 } … … 405 405 if ( auto dstInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 406 406 cost = enumCastCost(inst, dstInst, symtab, env); 407 } else if ( !inst->base->isCfa) {407 } else if ( inst->base->is_c_enum() ) { 408 408 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) }; 409 409 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); … … 455 455 } 456 456 457 void ConversionCost::postvisit( const ast::VarArgsType * varArgsType ) { 458 (void)varArgsType; 457 void ConversionCost::postvisit( const ast::VarArgsType * ) { 459 458 if ( dynamic_cast< const ast::VarArgsType * >( dst ) ) { 460 459 cost = Cost::zero; … … 462 461 } 463 462 464 void ConversionCost::postvisit( const ast::ZeroType * zeroType ) { 465 (void)zeroType; 463 void ConversionCost::postvisit( const ast::ZeroType * ) { 466 464 if ( dynamic_cast< const ast::ZeroType * >( dst ) ) { 467 465 cost = Cost::zero; … … 487 485 // assuming 0p is supposed to be used for pointers? 488 486 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 489 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa) {487 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) { 490 488 cost = Cost::safe; 491 489 } … … 493 491 } 494 492 495 void ConversionCost::postvisit( const ast::OneType * oneType ) { 496 (void)oneType; 493 void ConversionCost::postvisit( const ast::OneType * ) { 497 494 if ( dynamic_cast< const ast::OneType * >( dst ) ) { 498 495 cost = Cost::zero; … … 508 505 } 509 506 } else if ( auto dstAsEnumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 510 if ( dstAsEnumInst->base && !dstAsEnumInst->base->isCfa) {507 if ( dstAsEnumInst->base && dstAsEnumInst->base->is_c_enum() ) { 511 508 cost = Cost::safe; 512 509 } -
TabularUnified src/ResolvExpr/ResolveTypeof.cpp ¶
rbbbff10 r90e683b 62 62 // replace basetypeof(<enum>) by int 63 63 auto enumInst = newType.as< ast::EnumInstType >(); 64 if ( enumInst && (!enumInst->base || !enumInst->base->isCfa) ) {64 if ( enumInst && (!enumInst->base || enumInst->base->is_c_enum() ) ) { 65 65 newType = new ast::BasicType( 66 66 ast::BasicKind::SignedInt, newType->qualifiers, copy(newType->attributes) ); … … 144 144 145 145 auto enumInst = decl->type.as<ast::EnumInstType>(); 146 if ( enumInst && enumInst->base->isCfa) {146 if ( enumInst && !enumInst->base->is_c_enum() ) { 147 147 if ( auto init = decl->init.as<ast::SingleInit>() ) { 148 148 if ( auto initExpr = init->value.as<ast::ConstantExpr>() ) { 149 149 if ( initExpr->result.as<ast::ZeroType>() ) { 150 auto newInit = new ast::SingleInit( init->location, 150 auto newInit = new ast::SingleInit( init->location, 151 151 ast::UntypedExpr::createCall( init->location, "lowerBound", {} ) 152 152 ); -
TabularUnified src/Validate/ImplementEnumFunc.cpp ¶
rbbbff10 r90e683b 61 61 ast::FunctionDecl* genLabelProto() const; 62 62 ast::FunctionDecl* genValueProto() const; 63 ast::FunctionDecl* genQuasiValueProto() const;64 63 ast::FunctionDecl* genTypeNameProto() const; 65 64 … … 206 205 207 206 ast::FunctionDecl* EnumAttrFuncGenerator::genValueProto() const { 208 assert (decl->isTyped());207 assert( decl->is_typed_enum() ); 209 208 return genProto( 210 209 "value", … … 414 413 void EnumAttrFuncGenerator::genTypedEnumFunction(const ast::EnumAttribute attr) { 415 414 if (attr == ast::EnumAttribute::Value) { 416 if ( !decl->is Typed() ) return;415 if ( !decl->is_typed_enum() ) return; 417 416 std::vector<ast::ptr<ast::Init>> inits = genValueInit(); 418 417 ast::ObjectDecl* arrayProto = … … 483 482 484 483 void ImplementEnumFunc::previsit(const ast::EnumDecl* enumDecl) { 485 if ( !enumDecl->body || !enumDecl->isCfa) return;484 if ( !enumDecl->body || enumDecl->is_c_enum() ) return; 486 485 ast::EnumInstType enumInst(enumDecl->name); 487 486 enumInst.base = enumDecl;
Note: See TracChangeset
for help on using the changeset viewer.