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 : Sat May 16 23:54:02 2015 |
---|
13 | // Update Count : 3 |
---|
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 | 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( ContextInstType *aggregateUseType ); |
---|
36 | virtual Type* mutate( TypeInstType *aggregateUseType ); |
---|
37 | virtual Type* mutate( TupleType *tupleType ); |
---|
38 | |
---|
39 | const TypeEnvironment &env; |
---|
40 | const SymTab::Indexer &indexer; |
---|
41 | }; |
---|
42 | |
---|
43 | void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { |
---|
44 | AdjustExprType adjuster( env, indexer ); |
---|
45 | Type *newType = type->acceptMutator( adjuster ); |
---|
46 | type = newType; |
---|
47 | } |
---|
48 | |
---|
49 | AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer ) |
---|
50 | : env( env ), indexer( indexer ) { |
---|
51 | } |
---|
52 | |
---|
53 | Type *AdjustExprType::mutate( VoidType *voidType ) { |
---|
54 | return voidType; |
---|
55 | } |
---|
56 | |
---|
57 | Type *AdjustExprType::mutate( BasicType *basicType ) { |
---|
58 | return basicType; |
---|
59 | } |
---|
60 | |
---|
61 | Type *AdjustExprType::mutate( PointerType *pointerType ) { |
---|
62 | return pointerType; |
---|
63 | } |
---|
64 | |
---|
65 | Type *AdjustExprType::mutate( ArrayType *arrayType ) { |
---|
66 | PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone() ); |
---|
67 | delete arrayType; |
---|
68 | return pointerType; |
---|
69 | } |
---|
70 | |
---|
71 | Type *AdjustExprType::mutate( FunctionType *functionType ) { |
---|
72 | PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType ); |
---|
73 | return pointerType; |
---|
74 | } |
---|
75 | |
---|
76 | Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) { |
---|
77 | return aggregateUseType; |
---|
78 | } |
---|
79 | |
---|
80 | Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) { |
---|
81 | return aggregateUseType; |
---|
82 | } |
---|
83 | |
---|
84 | Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) { |
---|
85 | return aggregateUseType; |
---|
86 | } |
---|
87 | |
---|
88 | Type *AdjustExprType::mutate( ContextInstType *aggregateUseType ) { |
---|
89 | return aggregateUseType; |
---|
90 | } |
---|
91 | |
---|
92 | Type *AdjustExprType::mutate( TypeInstType *typeInst ) { |
---|
93 | EqvClass eqvClass; |
---|
94 | if ( env.lookup( typeInst->get_name(), eqvClass ) ) { |
---|
95 | if ( eqvClass.kind == TypeDecl::Ftype ) { |
---|
96 | PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); |
---|
97 | return pointerType; |
---|
98 | } |
---|
99 | } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { |
---|
100 | if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { |
---|
101 | if ( tyDecl->get_kind() == TypeDecl::Ftype ) { |
---|
102 | PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); |
---|
103 | return pointerType; |
---|
104 | } // if |
---|
105 | } // if |
---|
106 | } // if |
---|
107 | return typeInst; |
---|
108 | } |
---|
109 | |
---|
110 | Type *AdjustExprType::mutate( TupleType *tupleType ) { |
---|
111 | return tupleType; |
---|
112 | } |
---|
113 | } // namespace ResolvExpr |
---|
114 | |
---|
115 | // Local Variables: // |
---|
116 | // tab-width: 4 // |
---|
117 | // mode: c++ // |
---|
118 | // compile-command: "make install" // |
---|
119 | // End: // |
---|