source: src/ResolvExpr/AdjustExprType.cc @ 0bd3faf

Last change on this file since 0bd3faf was 0bd3faf, checked in by Andrew Beach <ajbeach@…>, 8 months ago

Removed forward declarations missed in the BaseSyntaxNode? removal. Removed code and modified names to support two versions of the ast.

  • Property mode set to 100644
File size: 3.0 KB
Line 
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//
7// AdjustExprType_old.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Sat May 16 23:41:42 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Dec 11 21:43:56 2019
13// Update Count     : 6
14//
15
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"
21
22namespace ResolvExpr {
23
24namespace {
25        class AdjustExprType final : public ast::WithShortCircuiting {
26                const ast::SymbolTable & symtab;
27        public:
28                const ast::TypeEnvironment & tenv;
29
30                AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )
31                : symtab( syms ), tenv( e ) {}
32
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; }
47
48                const ast::Type * postvisit( const ast::ArrayType * at ) {
49                        return new ast::PointerType{ at->base, at->qualifiers };
50                }
51
52                const ast::Type * postvisit( const ast::FunctionType * ft ) {
53                        return new ast::PointerType{ ft };
54                }
55
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                                        }
67                                }
68                        }
69                        return inst;
70                }
71        };
72} // anonymous namespace
73
74const ast::Type * adjustExprType(
75        const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab
76) {
77        ast::Pass<AdjustExprType> adjuster{ env, symtab };
78        return type->accept( adjuster );
79}
80
81} // namespace ResolvExpr
82
83// Local Variables: //
84// tab-width: 4 //
85// mode: c++ //
86// compile-command: "make install" //
87// End: //
Note: See TracBrowser for help on using the repository browser.