source: src/ResolvExpr/CommonType.cc @ ea6332d

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 ea6332d was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 22.8 KB
RevLine 
[a32b204]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//
[a436947]7// CommonType.cc --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 06:59:27 2015
11// Last Modified By : Peter A. Buhr
[6f95000]12// Last Modified On : Thu Mar 16 16:24:31 2017
13// Update Count     : 7
[a32b204]14//
[51b7345]15
[ea6332d]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
[51b7345]27
28
29/// #define DEBUG
30
31namespace ResolvExpr {
[a32b204]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 );
[4040425]45                virtual void visit( TraitInstType *aggregateUseType );
[a32b204]46                virtual void visit( TypeInstType *aggregateUseType );
47                virtual void visit( TupleType *tupleType );
[44b7088]48                virtual void visit( VarArgsType *varArgsType );
[89e6ffc]49                virtual void visit( ZeroType *zeroType );
50                virtual void visit( OneType *oneType );
[a32b204]51
[a2a77af]52                void getCommonWithVoidPointer( PointerType* voidPointer, PointerType* otherPointer );
[a32b204]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 ) {
[2c57025]67                        // this appears to be handling for opaque type declarations
[a32b204]68                        if ( widenSecond ) {
[2c57025]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 );
[a32b204]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();
[6f95000]80                                                                result->get_qualifiers() = tq1 | tq2;
[a32b204]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
[51b7345]89#ifdef DEBUG
[a32b204]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;
[51b7345]101#endif
[a32b204]102                return result;
103        }
[51b7345]104
[a32b204]105        static const BasicType::Kind combinedType[ BasicType::NUMBER_OF_BASIC_TYPES ][ BasicType::NUMBER_OF_BASIC_TYPES ] =
106        {
[51b7345]107/*              Bool            Char    SignedChar      UnsignedChar    ShortSignedInt  ShortUnsignedInt        SignedInt       UnsignedInt     LongSignedInt   LongUnsignedInt LongLongSignedInt       LongLongUnsignedInt     Float   Double  LongDouble      FloatComplex    DoubleComplex   LongDoubleComplex       FloatImaginary  DoubleImaginary LongDoubleImaginary */
[a32b204]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
[7e003011]135        void CommonType::visit( __attribute((unused)) VoidType *voidType ) {}
[a32b204]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 ) ) {
[6f95000]141                                result = new BasicType( basicType->get_qualifiers() | otherBasic->get_qualifiers(), newType );
[a32b204]142                        } // if
[89e6ffc]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
[a436947]145                        BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ];
[89e6ffc]146                        if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) {
[6f95000]147                                result = new BasicType( basicType->get_qualifiers() | type2->get_qualifiers(), newType );
[a436947]148                        } // if
[a32b204]149                } // if
150        }
151
[a2a77af]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                        }
[2c57025]160                }
[a2a77af]161                result = voidPointer->clone();
[6f95000]162                result->get_qualifiers() |= otherPointer->get_qualifiers();
[2c57025]163        }
164
[a32b204]165        void CommonType::visit( PointerType *pointerType ) {
166                if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) {
[d7dc824]167                        if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base()) ) {
[a2a77af]168                                getCommonWithVoidPointer( otherPointer, pointerType );
[d7dc824]169                        } else if ( widenSecond && dynamic_cast< VoidType* >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base()) ) {
[a2a77af]170                                getCommonWithVoidPointer( pointerType, otherPointer );
[a32b204]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
[6f95000]184                                        result->get_qualifiers() = tq1 | tq2;
[a32b204]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
[89e6ffc]191                } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) {
192                        result = pointerType->clone();
[6f95000]193                        result->get_qualifiers() |= type2->get_qualifiers();
[a32b204]194                } // if
195        }
196
[7e003011]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 ) {}
[a32b204]201
[a436947]202        void CommonType::visit( EnumInstType *enumInstType ) {
[89e6ffc]203                if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) {
[a436947]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
[a32b204]210        }
211
[7e003011]212        void CommonType::visit( __attribute((unused)) TraitInstType *aggregateUseType ) {
[a32b204]213        }
214
215        void CommonType::visit( TypeInstType *inst ) {
216                if ( widenFirst ) {
217                        NamedTypeDecl *nt = indexer.lookupType( inst->get_name() );
218                        if ( nt ) {
[2c57025]219                                TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt );
[a32b204]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();
[6f95000]228                                                result->get_qualifiers() = tq1 | tq2;
[a32b204]229                                        } // if
230                                        type2->get_qualifiers() = tq2;
231                                        type->get_base()->get_qualifiers() = Type::Qualifiers();
232                                } // if
233                        } // if
234                } // if
235        }
236
[7e003011]237        void CommonType::visit( __attribute((unused)) TupleType *tupleType ) {}
238        void CommonType::visit( __attribute((unused)) VarArgsType *varArgsType ) {}
[89e6ffc]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();
[6f95000]245                                        result->get_qualifiers() |= zeroType->get_qualifiers();
[89e6ffc]246                                }
[4cb935e]247                        } else if ( widenSecond && dynamic_cast< OneType* >( type2 ) ) {
248                                result = new BasicType( zeroType->get_qualifiers(), BasicType::SignedInt );
[6f95000]249                                result->get_qualifiers() |= type2->get_qualifiers();
[89e6ffc]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();
[6f95000]259                                        result->get_qualifiers() |= oneType->get_qualifiers();
[89e6ffc]260                                }
[4cb935e]261                        } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) {
262                                result = new BasicType( oneType->get_qualifiers(), BasicType::SignedInt );
[6f95000]263                                result->get_qualifiers() |= type2->get_qualifiers();
[89e6ffc]264                        }
265                }
266        }
[51b7345]267} // namespace ResolvExpr
[a32b204]268
269// Local Variables: //
270// tab-width: 4 //
271// mode: c++ //
272// compile-command: "make install" //
273// End: //
Note: See TracBrowser for help on using the repository browser.