Changeset b7778c1 for src/ResolvExpr


Ignore:
Timestamp:
Oct 4, 2017, 3:31:43 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
3364962
Parents:
3628765 (diff), bb9d8e8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/ResolvExpr
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AdjustExprType.cc

    r3628765 rb7778c1  
    1414//
    1515
     16#include "Common/PassVisitor.h"
    1617#include "SymTab/Indexer.h"       // for Indexer
    1718#include "SynTree/Declaration.h"  // for TypeDecl, TypeDecl::Kind::Ftype
     
    2122
    2223namespace ResolvExpr {
    23         class AdjustExprType : public Mutator {
    24                 typedef Mutator Parent;
    25                 using Parent::mutate;
     24        class AdjustExprType : public WithShortCircuiting {
    2625          public:
    2726                AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer );
     27                void premutate( VoidType * ) { visit_children = false; }
     28                void premutate( BasicType * ) { visit_children = false; }
     29                void premutate( PointerType * ) { visit_children = false; }
     30                void premutate( FunctionType * ) { visit_children = false; }
     31                void premutate( StructInstType * ) { visit_children = false; }
     32                void premutate( UnionInstType * ) { visit_children = false; }
     33                void premutate( EnumInstType * ) { visit_children = false; }
     34                void premutate( TraitInstType * ) { visit_children = false; }
     35                void premutate( TypeInstType * ) { visit_children = false; }
     36                void premutate( TupleType * ) { visit_children = false; }
     37                void premutate( VarArgsType * ) { visit_children = false; }
     38                void premutate( ZeroType * ) { visit_children = false; }
     39                void premutate( OneType * ) { visit_children = false; }
     40
     41                Type * postmutate( ArrayType *arrayType );
     42                Type * postmutate( FunctionType *functionType );
     43                Type * postmutate( TypeInstType *aggregateUseType );
     44
    2845          private:
    29                 virtual Type* mutate( VoidType *voidType );
    30                 virtual Type* mutate( BasicType *basicType );
    31                 virtual Type* mutate( PointerType *pointerType );
    32                 virtual Type* mutate( ArrayType *arrayType );
    33                 virtual Type* mutate( FunctionType *functionType );
    34                 virtual Type* mutate( StructInstType *aggregateUseType );
    35                 virtual Type* mutate( UnionInstType *aggregateUseType );
    36                 virtual Type* mutate( EnumInstType *aggregateUseType );
    37                 virtual Type* mutate( TraitInstType *aggregateUseType );
    38                 virtual Type* mutate( TypeInstType *aggregateUseType );
    39                 virtual Type* mutate( TupleType *tupleType );
    40                 virtual Type* mutate( VarArgsType *varArgsType );
    41                 virtual Type* mutate( ZeroType *zeroType );
    42                 virtual Type* mutate( OneType *oneType );
    43 
    4446                const TypeEnvironment &env;
    4547                const SymTab::Indexer &indexer;
     
    4749
    4850        void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
    49                 AdjustExprType adjuster( env, indexer );
     51                PassVisitor<AdjustExprType> adjuster( env, indexer );
    5052                Type *newType = type->acceptMutator( adjuster );
    5153                type = newType;
     
    5658        }
    5759
    58         Type *AdjustExprType::mutate( VoidType *voidType ) {
    59                 return voidType;
    60         }
    61 
    62         Type *AdjustExprType::mutate( BasicType *basicType ) {
    63                 return basicType;
    64         }
    65 
    66         Type *AdjustExprType::mutate( PointerType *pointerType ) {
    67                 return pointerType;
    68         }
    69 
    70         Type *AdjustExprType::mutate( ArrayType *arrayType ) {
     60        Type * AdjustExprType::postmutate( ArrayType * arrayType ) {
    7161                // need to recursively mutate the base type in order for multi-dimensional arrays to work.
    72                 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ) );
     62                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base );
     63                arrayType->base = nullptr;
    7364                delete arrayType;
    7465                return pointerType;
    7566        }
    7667
    77         Type *AdjustExprType::mutate( FunctionType *functionType ) {
    78                 PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType );
    79                 return pointerType;
     68        Type * AdjustExprType::postmutate( FunctionType * functionType ) {
     69                return new PointerType( Type::Qualifiers(), functionType );
    8070        }
    8171
    82         Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) {
    83                 return aggregateUseType;
    84         }
    85 
    86         Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) {
    87                 return aggregateUseType;
    88         }
    89 
    90         Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) {
    91                 return aggregateUseType;
    92         }
    93 
    94         Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) {
    95                 return aggregateUseType;
    96         }
    97 
    98         Type *AdjustExprType::mutate( TypeInstType *typeInst ) {
     72        Type * AdjustExprType::postmutate( TypeInstType * typeInst ) {
    9973                EqvClass eqvClass;
    10074                if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
     
    11387                return typeInst;
    11488        }
    115 
    116         Type *AdjustExprType::mutate( TupleType *tupleType ) {
    117                 return tupleType;
    118         }
    119 
    120         Type *AdjustExprType::mutate( VarArgsType *varArgsType ) {
    121                 return varArgsType;
    122         }
    123 
    124         Type *AdjustExprType::mutate( ZeroType *zeroType ) {
    125                 return zeroType;
    126         }
    127 
    128         Type *AdjustExprType::mutate( OneType *oneType ) {
    129                 return oneType;
    130         }
    13189} // namespace ResolvExpr
    13290
  • src/ResolvExpr/Alternative.cc

    r3628765 rb7778c1  
    6666        }
    6767
    68         void Alternative::print( std::ostream &os, int indent ) const {
    69                 os << std::string( indent, ' ' ) << "Cost " << cost << ": ";
     68        void Alternative::print( std::ostream &os, Indenter indent ) const {
     69                os << "Cost " << cost << ": ";
    7070                if ( expr ) {
    71                         expr->print( os, indent );
    72                         os << "(types:" << std::endl;
    73                         os << std::string( indent+4, ' ' );
    74                         expr->get_result()->print( os, indent + 4 );
    75                         os << std::endl << ")" << std::endl;
     71                        expr->print( os, indent+1 );
     72                        os << std::endl << indent << "(types:" << std::endl;
     73                        os << indent+1;
     74                        expr->result->print( os, indent+1 );
     75                        os << std::endl << indent << ")" << std::endl;
    7676                } else {
    7777                        os << "Null expression!" << std::endl;
    7878                } // if
    79                 os << std::string( indent, ' ' ) << "Environment: ";
    80                 env.print( os, indent+2 );
     79                os << indent << "Environment: ";
     80                env.print( os, indent+1 );
    8181                os << std::endl;
    8282        }
  • src/ResolvExpr/Alternative.h

    r3628765 rb7778c1  
    3939                ~Alternative();
    4040
    41                 void print( std::ostream &os, int indent = 0 ) const;
     41                void print( std::ostream &os, Indenter indent = {} ) const;
    4242
    4343                Cost cost;
  • src/ResolvExpr/AlternativeFinder.cc

    r3628765 rb7778c1  
    7575
    7676        namespace {
    77                 void printAlts( const AltList &list, std::ostream &os, int indent = 0 ) {
     77                void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt = 0 ) {
     78                        Indenter indent = { Indenter::tabsize, indentAmt };
    7879                        for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) {
    7980                                i->print( os, indent );
     
    195196                                AltList winners;
    196197                                findMinCost( alternatives.begin(), alternatives.end(), back_inserter( winners ) );
    197                                 stream << "Cannot choose between " << winners.size() << " alternatives for expression ";
     198                                stream << "Cannot choose between " << winners.size() << " alternatives for expression\n";
    198199                                expr->print( stream );
    199                                 stream << "Alternatives are:";
    200                                 printAlts( winners, stream, 8 );
     200                                stream << "Alternatives are:\n";
     201                                printAlts( winners, stream, 1 );
    201202                                throw SemanticError( stream.str() );
    202203                        }
     
    728729                PRINT(
    729730                        std::cerr << "known function ops:" << std::endl;
    730                         printAlts( funcOpFinder.alternatives, std::cerr, 8 );
     731                        printAlts( funcOpFinder.alternatives, std::cerr, 1 );
    731732                )
    732733
     
    838839        bool isLvalue( Expression *expr ) {
    839840                // xxx - recurse into tuples?
    840                 return expr->has_result() && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );
     841                return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );
    841842        }
    842843
     
    972973                PRINT( std::cerr << "nameExpr is " << nameExpr->get_name() << std::endl; )
    973974                for ( std::list< DeclarationWithType* >::iterator i = declList.begin(); i != declList.end(); ++i ) {
    974                         VariableExpr newExpr( *i, nameExpr->get_argName() );
     975                        VariableExpr newExpr( *i );
    975976                        alternatives.push_back( Alternative( newExpr.clone(), env, Cost::zero ) );
    976977                        PRINT(
  • src/ResolvExpr/ResolveTypeof.cc

    r3628765 rb7778c1  
    1818#include <cassert>               // for assert
    1919
     20#include "Common/PassVisitor.h"  // for PassVisitor
    2021#include "Resolver.h"            // for resolveInVoidContext
    2122#include "SynTree/Expression.h"  // for Expression
     
    4142        }
    4243
    43         class ResolveTypeof : public Mutator {
     44        class ResolveTypeof : public WithShortCircuiting {
    4445          public:
    4546                ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {}
    46                 Type *mutate( TypeofType *typeofType );
     47                void premutate( TypeofType *typeofType );
     48                Type * postmutate( TypeofType *typeofType );
    4749
    4850          private:
     
    5052        };
    5153
    52         Type *resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {
    53                 ResolveTypeof mutator( indexer );
     54        Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {
     55                PassVisitor<ResolveTypeof> mutator( indexer );
    5456                return type->acceptMutator( mutator );
    5557        }
    5658
    57         Type *ResolveTypeof::mutate( TypeofType *typeofType ) {
     59        void ResolveTypeof::premutate( TypeofType * ) {
     60                visit_children = false;
     61        }
     62
     63        Type * ResolveTypeof::postmutate( TypeofType *typeofType ) {
    5864#if 0
    59                 std::cout << "resolving typeof: ";
    60                 typeofType->print( std::cout );
    61                 std::cout << std::endl;
     65                std::cerr << "resolving typeof: ";
     66                typeofType->print( std::cerr );
     67                std::cerr << std::endl;
    6268#endif
    63                 if ( typeofType->get_expr() ) {
    64                         Expression *newExpr = resolveInVoidContext( typeofType->get_expr(), indexer );
    65                         assert( newExpr->has_result() && ! newExpr->get_result()->isVoid() );
    66                         Type *newType = newExpr->get_result();
    67                         newExpr->set_result( nullptr );
     69                if ( typeofType->expr ) {
     70                        Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer );
     71                        assert( newExpr->result && ! newExpr->result->isVoid() );
     72                        Type * newType = newExpr->result;
     73                        newExpr->result = nullptr;
    6874                        delete typeofType;
    6975                        delete newExpr;
  • src/ResolvExpr/TypeEnvironment.cc

    r3628765 rb7778c1  
    6868        }
    6969
    70         void EqvClass::print( std::ostream &os, int indent ) const {
    71                 os << std::string( indent, ' ' ) << "( ";
     70        void EqvClass::print( std::ostream &os, Indenter indent ) const {
     71                os << "( ";
    7272                std::copy( vars.begin(), vars.end(), std::ostream_iterator< std::string >( os, " " ) );
    7373                os << ")";
    7474                if ( type ) {
    7575                        os << " -> ";
    76                         type->print( os, indent );
     76                        type->print( os, indent+1 );
    7777                } // if
    7878                if ( ! allowWidening ) {
     
    144144        }
    145145
    146         void TypeEnvironment::print( std::ostream &os, int indent ) const {
     146        void TypeEnvironment::print( std::ostream &os, Indenter indent ) const {
    147147                for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) {
    148148                        i->print( os, indent );
  • src/ResolvExpr/TypeEnvironment.h

    r3628765 rb7778c1  
    6868                EqvClass &operator=( const EqvClass &other );
    6969                ~EqvClass();
    70                 void print( std::ostream &os, int indent = 0 ) const;
     70                void print( std::ostream &os, Indenter indent = {} ) const;
    7171        };
    7272
     
    8080                void makeSubstitution( TypeSubstitution &result ) const;
    8181                bool isEmpty() const { return env.empty(); }
    82                 void print( std::ostream &os, int indent = 0 ) const;
     82                void print( std::ostream &os, Indenter indent = {} ) const;
    8383                void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );
    8484                void simpleCombine( const TypeEnvironment &second );
  • src/ResolvExpr/Unify.cc

    r3628765 rb7778c1  
    2222#include <utility>                // for pair
    2323
     24#include "Common/PassVisitor.h"   // for PassVisitor
    2425#include "FindOpenVars.h"         // for findOpenVars
    2526#include "Parser/LinkageSpec.h"   // for C
     
    537538        /// If this isn't done then argument lists can have wildly different
    538539        /// size and structure, when they should be compatible.
    539         struct TtypeExpander : public Mutator {
    540                 TypeEnvironment & env;
    541                 TtypeExpander( TypeEnvironment & env ) : env( env ) {}
    542                 Type * mutate( TypeInstType * typeInst ) {
     540        struct TtypeExpander : public WithShortCircuiting {
     541                TypeEnvironment & tenv;
     542                TtypeExpander( TypeEnvironment & tenv ) : tenv( tenv ) {}
     543                void premutate( TypeInstType * ) { visit_children = false; }
     544                Type * postmutate( TypeInstType * typeInst ) {
    543545                        EqvClass eqvClass;
    544                         if ( env.lookup( typeInst->get_name(), eqvClass ) ) {
     546                        if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) {
    545547                                if ( eqvClass.data.kind == TypeDecl::Ttype ) {
    546548                                        // expand ttype parameter into its actual type
     
    560562                dst.clear();
    561563                for ( DeclarationWithType * dcl : src ) {
    562                         TtypeExpander expander( env );
     564                        PassVisitor<TtypeExpander> expander( env );
    563565                        dcl->acceptMutator( expander );
    564566                        std::list< Type * > types;
     
    750752                        std::list<Type *> types1, types2;
    751753
    752                         TtypeExpander expander( env );
     754                        PassVisitor<TtypeExpander> expander( env );
    753755                        flat1->acceptMutator( expander );
    754756                        flat2->acceptMutator( expander );
Note: See TracChangeset for help on using the changeset viewer.