Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AdjustExprType.cc

    r0bd3faf r2908f08  
    2323
    2424namespace {
    25         class AdjustExprType final : public ast::WithShortCircuiting {
    26                 const ast::SymbolTable & symtab;
    27         public:
    28                 const ast::TypeEnvironment & tenv;
    2925
    30                 AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )
    31                 : symtab( syms ), tenv( e ) {}
     26class AdjustExprType final : public ast::WithShortCircuiting {
     27        const ast::SymbolTable & symtab;
     28public:
     29        const ast::TypeEnvironment & tenv;
    3230
    33                 void previsit( const ast::VoidType * ) { visit_children = false; }
    34                 void previsit( const ast::BasicType * ) { visit_children = false; }
    35                 void previsit( const ast::PointerType * ) { visit_children = false; }
    36                 void previsit( const ast::ArrayType * ) { visit_children = false; }
    37                 void previsit( const ast::FunctionType * ) { visit_children = false; }
    38                 void previsit( const ast::StructInstType * ) { visit_children = false; }
    39                 void previsit( const ast::UnionInstType * ) { visit_children = false; }
    40                 void previsit( const ast::EnumInstType * ) { visit_children = false; }
    41                 void previsit( const ast::TraitInstType * ) { visit_children = false; }
    42                 void previsit( const ast::TypeInstType * ) { visit_children = false; }
    43                 void previsit( const ast::TupleType * ) { visit_children = false; }
    44                 void previsit( const ast::VarArgsType * ) { visit_children = false; }
    45                 void previsit( const ast::ZeroType * ) { visit_children = false; }
    46                 void previsit( const ast::OneType * ) { visit_children = false; }
     31        AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )
     32        : symtab( syms ), tenv( e ) {}
    4733
    48                 const ast::Type * postvisit( const ast::ArrayType * at ) {
    49                         return new ast::PointerType{ at->base, at->qualifiers };
    50                 }
     34        void previsit( const ast::VoidType * ) { visit_children = false; }
     35        void previsit( const ast::BasicType * ) { visit_children = false; }
     36        void previsit( const ast::PointerType * ) { visit_children = false; }
     37        void previsit( const ast::ArrayType * ) { visit_children = false; }
     38        void previsit( const ast::FunctionType * ) { visit_children = false; }
     39        void previsit( const ast::StructInstType * ) { visit_children = false; }
     40        void previsit( const ast::UnionInstType * ) { visit_children = false; }
     41        void previsit( const ast::EnumInstType * ) { visit_children = false; }
     42        void previsit( const ast::TraitInstType * ) { visit_children = false; }
     43        void previsit( const ast::TypeInstType * ) { visit_children = false; }
     44        void previsit( const ast::TupleType * ) { visit_children = false; }
     45        void previsit( const ast::VarArgsType * ) { visit_children = false; }
     46        void previsit( const ast::ZeroType * ) { visit_children = false; }
     47        void previsit( const ast::OneType * ) { visit_children = false; }
    5148
    52                 const ast::Type * postvisit( const ast::FunctionType * ft ) {
    53                         return new ast::PointerType{ ft };
    54                 }
     49        const ast::Type * postvisit( const ast::ArrayType * at ) {
     50                return new ast::PointerType( at->base, at->qualifiers );
     51        }
    5552
    56                 const ast::Type * postvisit( const ast::TypeInstType * inst ) {
    57                         // replace known function-type-variables with pointer-to-function
    58                         if ( const ast::EqvClass * eqvClass = tenv.lookup( *inst ) ) {
    59                                 if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) {
    60                                         return new ast::PointerType{ inst };
    61                                 }
    62                         } else if ( const ast::NamedTypeDecl * ntDecl = symtab.lookupType( inst->name ) ) {
    63                                 if ( auto tyDecl = dynamic_cast< const ast::TypeDecl * >( ntDecl ) ) {
    64                                         if ( tyDecl->kind == ast::TypeDecl::Ftype ) {
    65                                                 return new ast::PointerType{ inst };
    66                                         }
     53        const ast::Type * postvisit( const ast::FunctionType * ft ) {
     54                return new ast::PointerType( ft );
     55        }
     56
     57        const ast::Type * postvisit( const ast::TypeInstType * inst ) {
     58                // replace known function-type-variables with pointer-to-function
     59                if ( const ast::EqvClass * eqvClass = tenv.lookup( *inst ) ) {
     60                        if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) {
     61                                return new ast::PointerType( inst );
     62                        }
     63                } else if ( const ast::NamedTypeDecl * ntDecl = symtab.lookupType( inst->name ) ) {
     64                        if ( auto tyDecl = dynamic_cast< const ast::TypeDecl * >( ntDecl ) ) {
     65                                if ( tyDecl->kind == ast::TypeDecl::Ftype ) {
     66                                        return new ast::PointerType( inst );
    6767                                }
    6868                        }
    69                         return inst;
    7069                }
    71         };
     70                return inst;
     71        }
     72};
     73
    7274} // anonymous namespace
    7375
Note: See TracChangeset for help on using the changeset viewer.