source: src/ResolvExpr/AdjustExprType.cc @ 13de4478

Last change on this file since 13de4478 was 2908f08, checked in by Andrew Beach <ajbeach@…>, 7 months ago

Most of ResolvExpr? was written before the new style standard. Some files updated, focus on headers.

  • 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
26class AdjustExprType final : public ast::WithShortCircuiting {
27        const ast::SymbolTable & symtab;
28public:
29        const ast::TypeEnvironment & tenv;
30
31        AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )
32        : symtab( syms ), tenv( e ) {}
33
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; }
48
49        const ast::Type * postvisit( const ast::ArrayType * at ) {
50                return new ast::PointerType( at->base, at->qualifiers );
51        }
52
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 );
67                                }
68                        }
69                }
70                return inst;
71        }
72};
73
74} // anonymous namespace
75
76const ast::Type * adjustExprType(
77        const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab
78) {
79        ast::Pass<AdjustExprType> adjuster{ env, symtab };
80        return type->accept( adjuster );
81}
82
83} // namespace ResolvExpr
84
85// Local Variables: //
86// tab-width: 4 //
87// mode: c++ //
88// compile-command: "make install" //
89// End: //
Note: See TracBrowser for help on using the repository browser.