[a32b204] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[d57e349] | 7 | // AdjustExprType_old.cc -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sat May 16 23:41:42 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[07de76b] | 12 | // Last Modified On : Wed Dec 11 21:43:56 2019 |
---|
| 13 | // Update Count : 6 |
---|
[834d4fc] | 14 | // |
---|
[a32b204] | 15 | |
---|
[d57e349] | 16 | #include "AST/Node.hpp" |
---|
| 17 | #include "AST/Pass.hpp" |
---|
| 18 | #include "AST/SymbolTable.hpp" |
---|
| 19 | #include "AST/Type.hpp" |
---|
| 20 | #include "AST/TypeEnvironment.hpp" |
---|
[51b7345] | 21 | |
---|
| 22 | namespace ResolvExpr { |
---|
[d57e349] | 23 | |
---|
| 24 | namespace { |
---|
| 25 | |
---|
[2908f08] | 26 | class AdjustExprType final : public ast::WithShortCircuiting { |
---|
| 27 | const ast::SymbolTable & symtab; |
---|
| 28 | public: |
---|
| 29 | const ast::TypeEnvironment & tenv; |
---|
[d57e349] | 30 | |
---|
[2908f08] | 31 | AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) |
---|
| 32 | : symtab( syms ), tenv( e ) {} |
---|
[6be3b7d6] | 33 | |
---|
[2908f08] | 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; } |
---|
[d57e349] | 48 | |
---|
[2908f08] | 49 | const ast::Type * postvisit( const ast::ArrayType * at ) { |
---|
| 50 | return new ast::PointerType( at->base, at->qualifiers ); |
---|
| 51 | } |
---|
[d57e349] | 52 | |
---|
[2908f08] | 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 ); |
---|
[d57e349] | 67 | } |
---|
| 68 | } |
---|
| 69 | } |
---|
[2908f08] | 70 | return inst; |
---|
| 71 | } |
---|
| 72 | }; |
---|
| 73 | |
---|
[d57e349] | 74 | } // anonymous namespace |
---|
| 75 | |
---|
[ef5b828] | 76 | const ast::Type * adjustExprType( |
---|
| 77 | const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab |
---|
[d57e349] | 78 | ) { |
---|
[0bd3faf] | 79 | ast::Pass<AdjustExprType> adjuster{ env, symtab }; |
---|
[d57e349] | 80 | return type->accept( adjuster ); |
---|
| 81 | } |
---|
| 82 | |
---|
[51b7345] | 83 | } // namespace ResolvExpr |
---|
[a32b204] | 84 | |
---|
| 85 | // Local Variables: // |
---|
| 86 | // tab-width: 4 // |
---|
| 87 | // mode: c++ // |
---|
| 88 | // compile-command: "make install" // |
---|
| 89 | // End: // |
---|