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