source: src/ResolvExpr/CommonType.cc @ 596f987b

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 596f987b was a2a77af, checked in by Aaron Moss <a3moss@…>, 7 years ago

Fix void* to dtype* bindings

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