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