source: src/ResolvExpr/AdjustExprType.cc @ 4040425

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 4040425 was 4040425, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

change keyword type to otype and context to trait

  • Property mode set to 100644
File size: 3.7 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.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 Mar  2 17:34:53 2016
13// Update Count     : 4
14//
15
16#include "typeops.h"
17#include "SynTree/Type.h"
18#include "TypeEnvironment.h"
19#include "SymTab/Indexer.h"
20
21namespace ResolvExpr {
22        class AdjustExprType : public Mutator {
23                typedef Mutator Parent;
24          public:
25                AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer );
26          private:
27                virtual Type* mutate( VoidType *voidType );
28                virtual Type* mutate( BasicType *basicType );
29                virtual Type* mutate( PointerType *pointerType );
30                virtual Type* mutate( ArrayType *arrayType );
31                virtual Type* mutate( FunctionType *functionType );
32                virtual Type* mutate( StructInstType *aggregateUseType );
33                virtual Type* mutate( UnionInstType *aggregateUseType );
34                virtual Type* mutate( EnumInstType *aggregateUseType );
35                virtual Type* mutate( TraitInstType *aggregateUseType );
36                virtual Type* mutate( TypeInstType *aggregateUseType );
37                virtual Type* mutate( TupleType *tupleType );
38                virtual Type* mutate( VarArgsType *varArgsType );
39
40                const TypeEnvironment &env;
41                const SymTab::Indexer &indexer;
42        };
43
44        void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
45                AdjustExprType adjuster( env, indexer );
46                Type *newType = type->acceptMutator( adjuster );
47                type = newType;
48        }
49
50        AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer )
51                : env( env ), indexer( indexer ) {
52        }
53
54        Type *AdjustExprType::mutate( VoidType *voidType ) {
55                return voidType;
56        }
57
58        Type *AdjustExprType::mutate( BasicType *basicType ) {
59                return basicType;
60        }
61
62        Type *AdjustExprType::mutate( PointerType *pointerType ) {
63                return pointerType;
64        }
65
66        Type *AdjustExprType::mutate( ArrayType *arrayType ) {
67                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone() );
68                delete arrayType;
69                return pointerType;
70        }
71
72        Type *AdjustExprType::mutate( FunctionType *functionType ) {
73                PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType );
74                return pointerType;
75        }
76
77        Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) {
78                return aggregateUseType;
79        }
80
81        Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) {
82                return aggregateUseType;
83        }
84
85        Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) {
86                return aggregateUseType;
87        }
88
89        Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) {
90                return aggregateUseType;
91        }
92
93        Type *AdjustExprType::mutate( TypeInstType *typeInst ) {
94                EqvClass eqvClass;
95                if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
96                        if ( eqvClass.kind == TypeDecl::Ftype ) {
97                                PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
98                                return pointerType;
99                        }
100                } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) {
101                        if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) {
102                                if ( tyDecl->get_kind() == TypeDecl::Ftype ) {
103                                        PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst );
104                                        return pointerType;
105                                } // if
106                        } // if
107                } // if
108                return typeInst;
109        }
110
111        Type *AdjustExprType::mutate( TupleType *tupleType ) {
112                return tupleType;
113        }
114
115        Type *AdjustExprType::mutate( VarArgsType *varArgsType ) {
116                return varArgsType;
117        }
118} // namespace ResolvExpr
119
120// Local Variables: //
121// tab-width: 4 //
122// mode: c++ //
123// compile-command: "make install" //
124// End: //
Note: See TracBrowser for help on using the repository browser.