Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Validate/GenericParameter.cpp

    rf02f546 rbccd70a  
    1616#include "GenericParameter.hpp"
    1717
     18#include "AST/Copy.hpp"
    1819#include "AST/Decl.hpp"
    1920#include "AST/Expr.hpp"
     
    119120}
    120121
    121 bool isSizedPolymorphic( const ast::AggregateDecl * decl ) {
    122         for ( const auto & param : decl->params ) {
    123                 if ( param->sized ) return true;
    124         }
    125         return false;
    126 }
    127 
    128 struct ValidateGenericParamsCore :
    129                 public ast::WithCodeLocation, public ast::WithGuards {
    130         // Generic parameter filling and checks:
     122struct ValidateGenericParamsCore : public ast::WithCodeLocation {
    131123        const ast::StructInstType * previsit( const ast::StructInstType * type ) {
    132124                assert( location );
     
    138130                return validateGeneric( *location, type );
    139131        }
    140 
    141         // Check parameter and bitfield combinations:
    142         bool insideSized = false;
    143         void previsit( const ast::StructDecl * decl ) {
    144                 if ( isSizedPolymorphic( decl ) && !insideSized ) {
    145                         GuardValue( insideSized ) = true;
    146                 }
    147         }
    148 
    149         void previsit( const ast::UnionDecl * decl ) {
    150                 if ( isSizedPolymorphic( decl ) && !insideSized ) {
    151                         GuardValue( insideSized ) = true;
    152                 }
    153         }
    154 
    155         void previsit( const ast::ObjectDecl * decl ) {
    156                 if ( insideSized && decl->bitfieldWidth ) {
    157                         SemanticError( decl->location, decl,
    158                                 "Cannot have bitfields inside a sized polymorphic structure." );
    159                 }
    160         }
    161132};
    162133
     
    164135
    165136struct TranslateDimensionCore :
    166                 public WithNoIdSymbolTable, public ast::WithGuards,
    167                 public ast::WithVisitorRef<TranslateDimensionCore> {
     137                public WithNoIdSymbolTable, public ast::WithGuards {
    168138
    169139        // SUIT: Struct- or Union- InstType
     
    190160
    191161        const ast::TypeDecl * postvisit( const ast::TypeDecl * decl );
    192         const ast::Type * postvisit( const ast::FunctionType * type );
    193         const ast::Type * postvisit( const ast::TypeInstType * type );
    194 
    195162        const ast::Expr * postvisit( const ast::DimensionExpr * expr );
    196163        const ast::Expr * postvisit( const ast::Expr * expr );
     
    198165};
    199166
    200 // Declaration of type variable: forall( [N] )  ->  forall( N & | sized( N ) )
    201167const ast::TypeDecl * TranslateDimensionCore::postvisit(
    202168                const ast::TypeDecl * decl ) {
     
    210176        }
    211177        return decl;
    212 }
    213 
    214 // Makes postvisit( TypeInstType ) get called on the entries of the function declaration's type's forall list.
    215 // Pass.impl.hpp's visit( FunctionType ) does not consider the forall entries to be child nodes.
    216 // Workaround is: during the current TranslateDimension pass, manually visit down there.
    217 const ast::Type * TranslateDimensionCore::postvisit(
    218                 const ast::FunctionType * type ) {
    219         visitor->maybe_accept( type, &ast::FunctionType::forall );
    220         return type;
    221 }
    222 
    223 // Use of type variable, assuming `forall( [N] )` in scope:  void (*)( foo( /*dimension*/ N ) & )  ->  void (*)( foo( /*dtype*/ N ) & )
    224 const ast::Type * TranslateDimensionCore::postvisit(
    225                 const ast::TypeInstType * type ) {
    226         if ( type->kind == ast::TypeDecl::Dimension ) {
    227                 auto mutType = ast::mutate( type );
    228                 mutType->kind = ast::TypeDecl::Dtype;
    229                 return mutType;
    230         }
    231         return type;
    232178}
    233179
Note: See TracChangeset for help on using the changeset viewer.