Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/GenericParameter.cpp

    rcaf06aa r0b0a285  
    120120}
    121121
    122 bool isSizedPolymorphic( const ast::AggregateDecl * decl ) {
    123         for ( const auto & param : decl->params ) {
    124                 if ( param->sized ) return true;
    125         }
    126         return false;
    127 }
    128 
    129 struct ValidateGenericParamsCore :
    130                 public ast::WithCodeLocation, public ast::WithGuards {
    131         // Generic parameter filling and checks:
     122struct ValidateGenericParamsCore : public ast::WithCodeLocation {
    132123        const ast::StructInstType * previsit( const ast::StructInstType * type ) {
    133124                assert( location );
     
    138129                assert( location );
    139130                return validateGeneric( *location, type );
    140         }
    141 
    142         // Check parameter and bitfield combinations:
    143         bool insideSized = false;
    144         void previsit( const ast::StructDecl * decl ) {
    145                 if ( isSizedPolymorphic( decl ) && !insideSized ) {
    146                         GuardValue( insideSized ) = true;
    147                 }
    148         }
    149 
    150         void previsit( const ast::UnionDecl * decl ) {
    151                 if ( isSizedPolymorphic( decl ) && !insideSized ) {
    152                         GuardValue( insideSized ) = true;
    153                 }
    154         }
    155 
    156         void previsit( const ast::ObjectDecl * decl ) {
    157                 if ( insideSized && decl->bitfieldWidth ) {
    158                         SemanticError( decl->location, decl,
    159                                 "Cannot have bitfields inside a sized polymorphic structure." );
    160                 }
    161131        }
    162132};
     
    277247const ast::Expr * TranslateDimensionCore::postvisit(
    278248                const ast::TypeExpr * expr ) {
    279         // Does nothing, except prevents matching ast::Expr (above).
     249        if ( auto instType = dynamic_cast<const ast::EnumInstType *>( expr->type.get() ) ) {
     250                const ast::EnumDecl * baseEnum = instType->base.get();
     251                return ast::ConstantExpr::from_int( expr->location, baseEnum->members.size() );
     252        }
    280253        return expr;
    281254}
Note: See TracChangeset for help on using the changeset viewer.