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 | // CommonType.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Sun May 17 06:59:27 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Thu Mar 16 16:24:31 2017 |
---|
13 | // Update Count : 7 |
---|
14 | // |
---|
15 | |
---|
16 | #include "typeops.h" |
---|
17 | #include "SynTree/Type.h" |
---|
18 | #include "Unify.h" |
---|
19 | |
---|
20 | |
---|
21 | /// #define DEBUG |
---|
22 | |
---|
23 | namespace ResolvExpr { |
---|
24 | class CommonType : public Visitor { |
---|
25 | public: |
---|
26 | CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ); |
---|
27 | Type *get_result() const { return result; } |
---|
28 | private: |
---|
29 | virtual void visit( VoidType *voidType ); |
---|
30 | virtual void visit( BasicType *basicType ); |
---|
31 | virtual void visit( PointerType *pointerType ); |
---|
32 | virtual void visit( ArrayType *arrayType ); |
---|
33 | virtual void visit( FunctionType *functionType ); |
---|
34 | virtual void visit( StructInstType *aggregateUseType ); |
---|
35 | virtual void visit( UnionInstType *aggregateUseType ); |
---|
36 | virtual void visit( EnumInstType *aggregateUseType ); |
---|
37 | virtual void visit( TraitInstType *aggregateUseType ); |
---|
38 | virtual void visit( TypeInstType *aggregateUseType ); |
---|
39 | virtual void visit( TupleType *tupleType ); |
---|
40 | virtual void visit( VarArgsType *varArgsType ); |
---|
41 | virtual void visit( ZeroType *zeroType ); |
---|
42 | virtual void visit( OneType *oneType ); |
---|
43 | |
---|
44 | void getCommonWithVoidPointer( PointerType* voidPointer, PointerType* otherPointer ); |
---|
45 | |
---|
46 | Type *result; |
---|
47 | Type *type2; // inherited |
---|
48 | bool widenFirst, widenSecond; |
---|
49 | const SymTab::Indexer &indexer; |
---|
50 | TypeEnvironment &env; |
---|
51 | const OpenVarSet &openVars; |
---|
52 | }; |
---|
53 | |
---|
54 | Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) { |
---|
55 | CommonType visitor( type2, widenFirst, widenSecond, indexer, env, openVars ); |
---|
56 | type1->accept( visitor ); |
---|
57 | Type *result = visitor.get_result(); |
---|
58 | if ( ! result ) { |
---|
59 | // this appears to be handling for opaque type declarations |
---|
60 | if ( widenSecond ) { |
---|
61 | if ( TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ) ) { |
---|
62 | if ( NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ) ) { |
---|
63 | TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt ); |
---|
64 | if ( type->get_base() ) { |
---|
65 | Type::Qualifiers tq1 = type1->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
66 | AssertionSet have, need; |
---|
67 | OpenVarSet newOpen( openVars ); |
---|
68 | type1->get_qualifiers() = Type::Qualifiers(); |
---|
69 | type->get_base()->get_qualifiers() = tq1; |
---|
70 | if ( unifyExact( type1, type->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
71 | result = type1->clone(); |
---|
72 | result->get_qualifiers() = tq1 | tq2; |
---|
73 | } // if |
---|
74 | type1->get_qualifiers() = tq1; |
---|
75 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
76 | } // if |
---|
77 | } // if |
---|
78 | } // if |
---|
79 | } // if |
---|
80 | } // if |
---|
81 | #ifdef DEBUG |
---|
82 | std::cout << "============= commonType" << std::endl << "type1 is "; |
---|
83 | type1->print( std::cout ); |
---|
84 | std::cout << " type2 is "; |
---|
85 | type2->print( std::cout ); |
---|
86 | if ( result ) { |
---|
87 | std::cout << " common type is "; |
---|
88 | result->print( std::cout ); |
---|
89 | } else { |
---|
90 | std::cout << " no common type"; |
---|
91 | } // if |
---|
92 | std::cout << std::endl; |
---|
93 | #endif |
---|
94 | return result; |
---|
95 | } |
---|
96 | |
---|
97 | static const BasicType::Kind combinedType[ BasicType::NUMBER_OF_BASIC_TYPES ][ BasicType::NUMBER_OF_BASIC_TYPES ] = |
---|
98 | { |
---|
99 | /* Bool Char SignedChar UnsignedChar ShortSignedInt ShortUnsignedInt SignedInt UnsignedInt LongSignedInt LongUnsignedInt LongLongSignedInt LongLongUnsignedInt Float Double LongDouble FloatComplex DoubleComplex LongDoubleComplex FloatImaginary DoubleImaginary LongDoubleImaginary */ |
---|
100 | /* Bool */ { BasicType::Bool, BasicType::Char, BasicType::SignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
101 | /* Char */ { BasicType::Char, BasicType::Char, BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
102 | /* SignedChar */ { BasicType::SignedChar, BasicType::UnsignedChar, BasicType::SignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
103 | /* UnsignedChar */ { BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
104 | /* ShortSignedInt */ { BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
105 | /* ShortUnsignedInt */ { BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
106 | /* SignedInt */ { BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
107 | /* UnsignedInt */ { BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
108 | /* LongSignedInt */ { BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
109 | /* LongUnsignedInt */ { BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
110 | /* LongLongSignedInt */ { BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
111 | /* LongLongUnsignedInt */ { BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
112 | /* Float */ { BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
113 | /* Double */ { BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::LongDouble, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
114 | /* LongDouble */ { BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex }, |
---|
115 | /* FloatComplex */ { BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
116 | /* DoubleComplex */ { BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
117 | /* LongDoubleComplex */ { BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex }, |
---|
118 | /* FloatImaginary */ { BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary }, |
---|
119 | /* DoubleImaginary */ { BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary }, |
---|
120 | /* LongDoubleImaginary */ { BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleImaginary, BasicType::LongDoubleImaginary, BasicType::LongDoubleImaginary } |
---|
121 | }; |
---|
122 | |
---|
123 | CommonType::CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) |
---|
124 | : result( 0 ), type2( type2 ), widenFirst( widenFirst ), widenSecond( widenSecond ), indexer( indexer ), env( env ), openVars( openVars ) { |
---|
125 | } |
---|
126 | |
---|
127 | void CommonType::visit( __attribute((unused)) VoidType *voidType ) {} |
---|
128 | |
---|
129 | void CommonType::visit( BasicType *basicType ) { |
---|
130 | if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) { |
---|
131 | BasicType::Kind newType = combinedType[ basicType->get_kind() ][ otherBasic->get_kind() ]; |
---|
132 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= otherBasic->get_qualifiers() ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->get_qualifiers() <= otherBasic->get_qualifiers() ) || widenSecond ) ) { |
---|
133 | result = new BasicType( basicType->get_qualifiers() | otherBasic->get_qualifiers(), newType ); |
---|
134 | } // if |
---|
135 | } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
136 | // use signed int in lieu of the enum/zero/one type |
---|
137 | BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ]; |
---|
138 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) { |
---|
139 | result = new BasicType( basicType->get_qualifiers() | type2->get_qualifiers(), newType ); |
---|
140 | } // if |
---|
141 | } // if |
---|
142 | } |
---|
143 | |
---|
144 | void CommonType::getCommonWithVoidPointer( PointerType* voidPointer, PointerType* otherPointer ) { |
---|
145 | if ( TypeInstType* var = dynamic_cast< TypeInstType* >( otherPointer->get_base() ) ) { |
---|
146 | OpenVarSet::const_iterator entry = openVars.find( var->get_name() ); |
---|
147 | if ( entry != openVars.end() ) { |
---|
148 | AssertionSet need, have; |
---|
149 | WidenMode widen( widenFirst, widenSecond ); |
---|
150 | if ( entry != openVars.end() && ! bindVar(var, voidPointer->get_base(), entry->second, env, need, have, openVars, widen, indexer ) ) return; |
---|
151 | } |
---|
152 | } |
---|
153 | result = voidPointer->clone(); |
---|
154 | result->get_qualifiers() |= otherPointer->get_qualifiers(); |
---|
155 | } |
---|
156 | |
---|
157 | void CommonType::visit( PointerType *pointerType ) { |
---|
158 | if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) { |
---|
159 | if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base()) ) { |
---|
160 | getCommonWithVoidPointer( otherPointer, pointerType ); |
---|
161 | } else if ( widenSecond && dynamic_cast< VoidType* >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base()) ) { |
---|
162 | getCommonWithVoidPointer( pointerType, otherPointer ); |
---|
163 | } else if ( ( pointerType->get_base()->get_qualifiers() >= otherPointer->get_base()->get_qualifiers() || widenFirst ) |
---|
164 | && ( pointerType->get_base()->get_qualifiers() <= otherPointer->get_base()->get_qualifiers() || widenSecond ) ) { |
---|
165 | Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers(), tq2 = otherPointer->get_base()->get_qualifiers(); |
---|
166 | pointerType->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
167 | otherPointer->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
168 | AssertionSet have, need; |
---|
169 | OpenVarSet newOpen( openVars ); |
---|
170 | if ( unifyExact( pointerType->get_base(), otherPointer->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
171 | if ( tq1 < tq2 ) { |
---|
172 | result = pointerType->clone(); |
---|
173 | } else { |
---|
174 | result = otherPointer->clone(); |
---|
175 | } // if |
---|
176 | result->get_qualifiers() = tq1 | tq2; |
---|
177 | } else { |
---|
178 | /// std::cout << "place for ptr-to-type" << std::endl; |
---|
179 | } // if |
---|
180 | pointerType->get_base()->get_qualifiers() = tq1; |
---|
181 | otherPointer->get_base()->get_qualifiers() = tq2; |
---|
182 | } // if |
---|
183 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
184 | result = pointerType->clone(); |
---|
185 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
186 | } // if |
---|
187 | } |
---|
188 | |
---|
189 | void CommonType::visit( __attribute((unused)) ArrayType *arrayType ) {} |
---|
190 | void CommonType::visit( __attribute((unused)) FunctionType *functionType ) {} |
---|
191 | void CommonType::visit( __attribute((unused)) StructInstType *aggregateUseType ) {} |
---|
192 | void CommonType::visit( __attribute((unused)) UnionInstType *aggregateUseType ) {} |
---|
193 | |
---|
194 | void CommonType::visit( EnumInstType *enumInstType ) { |
---|
195 | if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
196 | // reuse BasicType, EnumInstType code by swapping type2 with enumInstType |
---|
197 | Type * temp = type2; |
---|
198 | type2 = enumInstType; |
---|
199 | temp->accept( *this ); |
---|
200 | type2 = temp; |
---|
201 | } // if |
---|
202 | } |
---|
203 | |
---|
204 | void CommonType::visit( __attribute((unused)) TraitInstType *aggregateUseType ) { |
---|
205 | } |
---|
206 | |
---|
207 | void CommonType::visit( TypeInstType *inst ) { |
---|
208 | if ( widenFirst ) { |
---|
209 | NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ); |
---|
210 | if ( nt ) { |
---|
211 | TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt ); |
---|
212 | if ( type->get_base() ) { |
---|
213 | Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
214 | AssertionSet have, need; |
---|
215 | OpenVarSet newOpen( openVars ); |
---|
216 | type2->get_qualifiers() = Type::Qualifiers(); |
---|
217 | type->get_base()->get_qualifiers() = tq1; |
---|
218 | if ( unifyExact( type->get_base(), type2, env, have, need, newOpen, indexer ) ) { |
---|
219 | result = type2->clone(); |
---|
220 | result->get_qualifiers() = tq1 | tq2; |
---|
221 | } // if |
---|
222 | type2->get_qualifiers() = tq2; |
---|
223 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
224 | } // if |
---|
225 | } // if |
---|
226 | } // if |
---|
227 | } |
---|
228 | |
---|
229 | void CommonType::visit( __attribute((unused)) TupleType *tupleType ) {} |
---|
230 | void CommonType::visit( __attribute((unused)) VarArgsType *varArgsType ) {} |
---|
231 | |
---|
232 | void CommonType::visit( ZeroType *zeroType ) { |
---|
233 | if ( widenFirst ) { |
---|
234 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
235 | if ( widenSecond || zeroType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
236 | result = type2->clone(); |
---|
237 | result->get_qualifiers() |= zeroType->get_qualifiers(); |
---|
238 | } |
---|
239 | } else if ( widenSecond && dynamic_cast< OneType* >( type2 ) ) { |
---|
240 | result = new BasicType( zeroType->get_qualifiers(), BasicType::SignedInt ); |
---|
241 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
242 | } |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | void CommonType::visit( OneType *oneType ) { |
---|
247 | if ( widenFirst ) { |
---|
248 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
249 | if ( widenSecond || oneType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
250 | result = type2->clone(); |
---|
251 | result->get_qualifiers() |= oneType->get_qualifiers(); |
---|
252 | } |
---|
253 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
254 | result = new BasicType( oneType->get_qualifiers(), BasicType::SignedInt ); |
---|
255 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
256 | } |
---|
257 | } |
---|
258 | } |
---|
259 | } // namespace ResolvExpr |
---|
260 | |
---|
261 | // Local Variables: // |
---|
262 | // tab-width: 4 // |
---|
263 | // mode: c++ // |
---|
264 | // compile-command: "make install" // |
---|
265 | // End: // |
---|