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