Changeset bd0b6b62 for src/ResolvExpr


Ignore:
Timestamp:
Jan 11, 2018, 11:15:15 AM (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:
0690350
Parents:
721cd19f
Message:

Convert ConversionCost? and CastCost? to PassVisitor?

Location:
src/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CastCost.cc

    r721cd19f rbd0b6b62  
    3131
    3232namespace ResolvExpr {
    33         class CastCost : public ConversionCost {
     33        struct CastCost : public ConversionCost {
    3434          public:
    3535                CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
    3636
    37                 virtual void visit( BasicType *basicType );
    38                 virtual void visit( PointerType *pointerType );
     37                using ConversionCost::previsit;
     38                using ConversionCost::postvisit;
     39                void postvisit( BasicType * basicType );
     40                void postvisit( PointerType * pointerType );
    3941        };
    4042
     
    7880                        });
    7981                } else {
    80                         CastCost converter( dest, indexer, env, castCost );
     82                        PassVisitor<CastCost> converter( dest, indexer, env, castCost );
    8183                        src->accept( converter );
    82                         if ( converter.get_cost() == Cost::infinity ) {
     84                        if ( converter.pass.get_cost() == Cost::infinity ) {
    8385                                return Cost::infinity;
    8486                        } else {
    8587                                // xxx - why are we adding cost 0 here?
    86                                 return converter.get_cost() + Cost::zero;
     88                                return converter.pass.get_cost() + Cost::zero;
    8789                        } // if
    8890                } // if
     
    9395        }
    9496
    95         void CastCost::visit( BasicType *basicType ) {
     97        void CastCost::postvisit( BasicType *basicType ) {
    9698                PointerType *destAsPointer = dynamic_cast< PointerType* >( dest );
    9799                if ( destAsPointer && basicType->isInteger() ) {
     
    103105        }
    104106
    105         void CastCost::visit( PointerType *pointerType ) {
     107        void CastCost::postvisit( PointerType *pointerType ) {
    106108                if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) {
    107109                        if ( pointerType->get_qualifiers() <= destAsPtr->get_qualifiers() && typesCompatibleIgnoreQualifiers( pointerType->base, destAsPtr->base, indexer, env ) ) {
  • src/ResolvExpr/ConversionCost.cc

    r721cd19f rbd0b6b62  
    8181                        });
    8282                } else {
    83                         ConversionCost converter( dest, indexer, env, conversionCost );
     83                        PassVisitor<ConversionCost> converter( dest, indexer, env, conversionCost );
    8484                        src->accept( converter );
    85                         if ( converter.get_cost() == Cost::infinity ) {
     85                        if ( converter.pass.get_cost() == Cost::infinity ) {
    8686                                return Cost::infinity;
    8787                        } else {
    88                                 return converter.get_cost() + Cost::zero;
     88                                return converter.pass.get_cost() + Cost::zero;
    8989                        } // if
    9090                } // if
     
    130130                        } else {
    131131                                PRINT( std::cerr << "reference to rvalue conversion" << std::endl; )
    132                                 ConversionCost converter( dest, indexer, env, conversionCost );
     132                                PassVisitor<ConversionCost> converter( dest, indexer, env, conversionCost );
    133133                                src->accept( converter );
    134                                 return converter.get_cost();
     134                                return converter.pass.get_cost();
    135135                        } // if
    136136                } else {
     
    257257        };
    258258
    259         void ConversionCost::visit( VoidType * ) {
     259        void ConversionCost::postvisit( VoidType * ) {
    260260                cost = Cost::infinity;
    261261        }
    262262
    263         void ConversionCost::visit(BasicType *basicType) {
     263        void ConversionCost::postvisit(BasicType *basicType) {
    264264                if ( BasicType *destAsBasic = dynamic_cast< BasicType* >( dest ) ) {
    265265                        int tableResult = costMatrix[ basicType->get_kind() ][ destAsBasic->get_kind() ];
     
    278278        }
    279279
    280         void ConversionCost::visit( PointerType * pointerType ) {
     280        void ConversionCost::postvisit( PointerType * pointerType ) {
    281281                if ( PointerType *destAsPtr = dynamic_cast< PointerType* >( dest ) ) {
    282282                        PRINT( std::cerr << pointerType << " ===> " << destAsPtr << std::endl; )
     
    312312        }
    313313
    314         void ConversionCost::visit( ArrayType * ) {}
    315 
    316         void ConversionCost::visit( ReferenceType * refType ) {
     314        void ConversionCost::postvisit( ArrayType * ) {}
     315
     316        void ConversionCost::postvisit( ReferenceType * refType ) {
    317317                // Note: dest can never be a reference, since it would have been caught in an earlier check
    318318                assert( ! dynamic_cast< ReferenceType * >( dest ) );
     
    331331        }
    332332
    333         void ConversionCost::visit( FunctionType * ) {}
    334 
    335         void ConversionCost::visit( StructInstType * inst ) {
     333        void ConversionCost::postvisit( FunctionType * ) {}
     334
     335        void ConversionCost::postvisit( StructInstType * inst ) {
    336336                if ( StructInstType *destAsInst = dynamic_cast< StructInstType* >( dest ) ) {
    337337                        if ( inst->name == destAsInst->name ) {
     
    341341        }
    342342
    343         void ConversionCost::visit( UnionInstType * inst ) {
     343        void ConversionCost::postvisit( UnionInstType * inst ) {
    344344                if ( UnionInstType *destAsInst = dynamic_cast< UnionInstType* >( dest ) ) {
    345345                        if ( inst->name == destAsInst->name ) {
     
    349349        }
    350350
    351         void ConversionCost::visit( EnumInstType * ) {
     351        void ConversionCost::postvisit( EnumInstType * ) {
    352352                static Type::Qualifiers q;
    353353                static BasicType integer( q, BasicType::SignedInt );
     
    358358        }
    359359
    360         void ConversionCost::visit( TraitInstType * ) {}
    361 
    362         void ConversionCost::visit( TypeInstType *inst ) {
     360        void ConversionCost::postvisit( TraitInstType * ) {}
     361
     362        void ConversionCost::postvisit( TypeInstType *inst ) {
    363363                EqvClass eqvClass;
    364364                NamedTypeDecl *namedType;
     
    379379        }
    380380
    381         void ConversionCost::visit( TupleType * tupleType ) {
     381        void ConversionCost::postvisit( TupleType * tupleType ) {
    382382                Cost c = Cost::zero;
    383383                if ( TupleType * destAsTuple = dynamic_cast< TupleType * >( dest ) ) {
     
    399399        }
    400400
    401         void ConversionCost::visit( VarArgsType * ) {
     401        void ConversionCost::postvisit( VarArgsType * ) {
    402402                if ( dynamic_cast< VarArgsType* >( dest ) ) {
    403403                        cost = Cost::zero;
     
    405405        }
    406406
    407         void ConversionCost::visit( ZeroType * ) {
     407        void ConversionCost::postvisit( ZeroType * ) {
    408408                if ( dynamic_cast< ZeroType * >( dest ) ) {
    409409                        cost = Cost::zero;
     
    422422        }
    423423
    424         void ConversionCost::visit( OneType * ) {
     424        void ConversionCost::postvisit( OneType * ) {
    425425                if ( dynamic_cast< OneType * >( dest ) ) {
    426426                        cost = Cost::zero;
  • src/ResolvExpr/ConversionCost.h

    r721cd19f rbd0b6b62  
    1919
    2020#include "Cost.h"             // for Cost
     21
     22#include "Common/PassVisitor.h"
    2123#include "SynTree/Visitor.h"  // for Visitor
    2224#include "SynTree/SynTree.h"  // for Visitor Nodes
     
    3032
    3133        typedef std::function<Cost(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction;
    32         class ConversionCost : public Visitor {
     34        struct ConversionCost : public WithShortCircuiting {
    3335          public:
    3436                ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction );
     
    3638                Cost get_cost() const { return cost; }
    3739
    38                 virtual void visit(VoidType *voidType);
    39                 virtual void visit(BasicType *basicType);
    40                 virtual void visit(PointerType *pointerType);
    41                 virtual void visit(ArrayType *arrayType);
    42                 virtual void visit(ReferenceType *refType);
    43                 virtual void visit(FunctionType *functionType);
    44                 virtual void visit(StructInstType *aggregateUseType);
    45                 virtual void visit(UnionInstType *aggregateUseType);
    46                 virtual void visit(EnumInstType *aggregateUseType);
    47                 virtual void visit(TraitInstType *aggregateUseType);
    48                 virtual void visit(TypeInstType *aggregateUseType);
    49                 virtual void visit(TupleType *tupleType);
    50                 virtual void visit(VarArgsType *varArgsType);
    51                 virtual void visit(ZeroType *zeroType);
    52                 virtual void visit(OneType *oneType);
     40                void previsit( BaseSyntaxNode * ) { visit_children = false; }
     41
     42                void postvisit( VoidType * voidType );
     43                void postvisit( BasicType * basicType );
     44                void postvisit( PointerType * pointerType );
     45                void postvisit( ArrayType * arrayType );
     46                void postvisit( ReferenceType * refType );
     47                void postvisit( FunctionType * functionType );
     48                void postvisit( StructInstType * aggregateUseType );
     49                void postvisit( UnionInstType * aggregateUseType );
     50                void postvisit( EnumInstType * aggregateUseType );
     51                void postvisit( TraitInstType * aggregateUseType );
     52                void postvisit( TypeInstType * aggregateUseType );
     53                void postvisit( TupleType * tupleType );
     54                void postvisit( VarArgsType * varArgsType );
     55                void postvisit( ZeroType * zeroType );
     56                void postvisit( OneType * oneType );
    5357          protected:
    5458                Type *dest;
Note: See TracChangeset for help on using the changeset viewer.