Changeset 53452de


Ignore:
Timestamp:
Jan 17, 2018, 12:52:15 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
78754d7
Parents:
36a2367
Message:

Convert CommonType? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CommonType.cc

    r36a2367 r53452de  
    1818#include <utility>                       // for pair
    1919
     20#include "Common/PassVisitor.h"
    2021#include "ResolvExpr/TypeEnvironment.h"  // for OpenVarSet, AssertionSet
    2122#include "SymTab/Indexer.h"              // for Indexer
     
    2930
    3031namespace ResolvExpr {
    31         class CommonType : public Visitor {
    32           public:
     32        struct CommonType : public WithShortCircuiting {
    3333                CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
    3434                Type *get_result() const { return result; }
     35
     36                void previsit( BaseSyntaxNode * ) { visit_children = false; }
     37
     38                void postvisit( VoidType * voidType );
     39                void postvisit( BasicType * basicType );
     40                void postvisit( PointerType * pointerType );
     41                void postvisit( ArrayType * arrayType );
     42                void postvisit( ReferenceType * refType );
     43                void postvisit( FunctionType * functionType );
     44                void postvisit( StructInstType * aggregateUseType );
     45                void postvisit( UnionInstType * aggregateUseType );
     46                void postvisit( EnumInstType * aggregateUseType );
     47                void postvisit( TraitInstType * aggregateUseType );
     48                void postvisit( TypeInstType * aggregateUseType );
     49                void postvisit( TupleType * tupleType );
     50                void postvisit( VarArgsType * varArgsType );
     51                void postvisit( ZeroType * zeroType );
     52                void postvisit( OneType * oneType );
     53
    3554          private:
    36                 virtual void visit( VoidType *voidType );
    37                 virtual void visit( BasicType *basicType );
    38                 virtual void visit( PointerType *pointerType );
    39                 virtual void visit( ArrayType *arrayType );
    40                 virtual void visit( ReferenceType *refType );
    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 
    5255                template< typename Pointer > void getCommonWithVoidPointer( Pointer* voidPointer, Pointer* otherPointer );
    5356                template< typename RefType > void handleRefType( RefType *inst, Type *other );
     
    8083
    8184        Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) {
    82                 CommonType visitor( type2, widenFirst, widenSecond, indexer, env, openVars );
     85                PassVisitor<CommonType> visitor( type2, widenFirst, widenSecond, indexer, env, openVars );
    8386
    8487                int depth1 = type1->referenceDepth();
     
    116119
    117120                type1->accept( visitor );
    118                 Type *result = visitor.get_result();
     121                Type *result = visitor.pass.get_result();
    119122                if ( ! result ) {
    120123                        // this appears to be handling for opaque type declarations
     
    188191        }
    189192
    190         void CommonType::visit( VoidType * ) {}
    191 
    192         void CommonType::visit( BasicType *basicType ) {
     193        void CommonType::postvisit( VoidType * ) {}
     194
     195        void CommonType::postvisit( BasicType *basicType ) {
    193196                if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) {
    194197                        BasicType::Kind newType = combinedType[ basicType->get_kind() ][ otherBasic->get_kind() ];
     
    219222        }
    220223
    221         void CommonType::visit( PointerType *pointerType ) {
     224        void CommonType::postvisit( PointerType *pointerType ) {
    222225                if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) {
    223226                        // std::cerr << "commonType: two pointers: " << pointerType << " / " << otherPointer << std::endl;
     
    254257        }
    255258
    256         void CommonType::visit( ArrayType * ) {}
    257 
    258         void CommonType::visit( ReferenceType *refType ) {
     259        void CommonType::postvisit( ArrayType * ) {}
     260
     261        void CommonType::postvisit( ReferenceType *refType ) {
    259262                if ( ReferenceType *otherRef = dynamic_cast< ReferenceType* >( type2 ) ) {
    260263                        // std::cerr << "commonType: both references: " << refType << " / " << otherRef << std::endl;
     
    291294        }
    292295
    293         void CommonType::visit( FunctionType * ) {}
    294         void CommonType::visit( StructInstType * ) {}
    295         void CommonType::visit( UnionInstType * ) {}
    296 
    297         void CommonType::visit( EnumInstType *enumInstType ) {
     296        void CommonType::postvisit( FunctionType * ) {}
     297        void CommonType::postvisit( StructInstType * ) {}
     298        void CommonType::postvisit( UnionInstType * ) {}
     299
     300        void CommonType::postvisit( EnumInstType *enumInstType ) {
    298301                if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) {
    299302                        // reuse BasicType, EnumInstType code by swapping type2 with enumInstType
    300                         ValueGuard< Type * > temp( type2 );
    301                         type2 = enumInstType;
    302                         temp.old->accept( *this );
    303                 } // if
    304         }
    305 
    306         void CommonType::visit( TraitInstType * ) {
    307         }
    308 
    309         void CommonType::visit( TypeInstType *inst ) {
     303                        result = commonType( type2, enumInstType, widenSecond, widenFirst, indexer, env, openVars );
     304                } // if
     305        }
     306
     307        void CommonType::postvisit( TraitInstType * ) {
     308        }
     309
     310        void CommonType::postvisit( TypeInstType *inst ) {
    310311                if ( widenFirst ) {
    311312                        NamedTypeDecl *nt = indexer.lookupType( inst->get_name() );
     
    329330        }
    330331
    331         void CommonType::visit( TupleType * ) {}
    332         void CommonType::visit( VarArgsType * ) {}
    333 
    334         void CommonType::visit( ZeroType *zeroType ) {
     332        void CommonType::postvisit( TupleType * ) {}
     333        void CommonType::postvisit( VarArgsType * ) {}
     334
     335        void CommonType::postvisit( ZeroType *zeroType ) {
    335336                if ( widenFirst ) {
    336337                        if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) {
     
    346347        }
    347348
    348         void CommonType::visit( OneType *oneType ) {
     349        void CommonType::postvisit( OneType *oneType ) {
    349350                if ( widenFirst ) {
    350351                        if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) {
Note: See TracChangeset for help on using the changeset viewer.