Changes in / [61accc5:f184ca3]


Ignore:
Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r61accc5 rf184ca3  
    836836                assertf( ! genC, "Deleted expressions should not reach code generation." );
    837837                expr->expr->accept( *visitor );
    838         }
    839 
    840         void CodeGenerator::postvisit( DefaultArgExpr * arg ) {
    841                 assertf( ! genC, "Default argument expressions should not reach code generation." );
    842                 arg->expr->accept( *visitor );
    843838        }
    844839
  • src/CodeGen/CodeGenerator.h

    r61accc5 rf184ca3  
    9494                void postvisit( ConstructorExpr * );
    9595                void postvisit( DeletedExpr * );
    96                 void postvisit( DefaultArgExpr * );
    9796                void postvisit( GenericExpr * );
    9897
  • src/Common/PassVisitor.h

    r61accc5 rf184ca3  
    125125        virtual void visit( InitExpr *  initExpr ) override final;
    126126        virtual void visit( DeletedExpr *  delExpr ) override final;
    127         virtual void visit( DefaultArgExpr * argExpr ) override final;
    128127        virtual void visit( GenericExpr * genExpr ) override final;
    129128
     
    225224        virtual Expression * mutate( InitExpr *  initExpr ) override final;
    226225        virtual Expression * mutate( DeletedExpr *  delExpr ) override final;
    227         virtual Expression * mutate( DefaultArgExpr * argExpr ) override final;
    228226        virtual Expression * mutate( GenericExpr * genExpr ) override final;
    229227
     
    260258
    261259private:
    262         bool inFunction = false;
    263 
    264260        template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
    265261        template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
  • src/Common/PassVisitor.impl.h

    r61accc5 rf184ca3  
    404404                        indexerAddId( &func );
    405405                        maybeAccept_impl( node->type, *this );
    406                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    407                         // a new scope if inFunction is true
    408                         ValueGuard< bool > oldInFunction( inFunction );
    409                         inFunction = true;
    410406                        maybeAccept_impl( node->statements, *this );
    411407                        maybeAccept_impl( node->attributes, *this );
     
    438434                        indexerAddId( &func );
    439435                        maybeMutate_impl( node->type, *this );
    440                         // function body needs to have the same scope as parameters - CompoundStmt will not enter
    441                         // a new scope if inFunction is true
    442                         ValueGuard< bool > oldInFunction( inFunction );
    443                         inFunction = true;
    444436                        maybeMutate_impl( node->statements, *this );
    445437                        maybeMutate_impl( node->attributes, *this );
     
    720712        VISIT_START( node );
    721713        {
    722                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    723                 ValueGuard< bool > oldInFunction( inFunction );
    724                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     714                auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    725715                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    726                 inFunction = false;
    727716                visitStatementList( node->kids );
    728717        }
     
    734723        MUTATE_START( node );
    735724        {
    736                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    737                 ValueGuard< bool > oldInFunction( inFunction );
    738                 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
     725                auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
    739726                auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
    740                 inFunction = false;
    741727                mutateStatementList( node->kids );
    742728        }
     
    20882074template< typename pass_type >
    20892075Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) {
    2090         MUTATE_START( node );
    2091 
    2092         indexerScopedMutate( node->env, *this );
    2093         indexerScopedMutate( node->result, *this );
    2094         maybeMutate_impl( node->expr, *this );
    2095 
    2096         MUTATE_END( Expression, node );
    2097 }
    2098 
    2099 //--------------------------------------------------------------------------
    2100 // DefaultArgExpr
    2101 template< typename pass_type >
    2102 void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) {
    2103         VISIT_START( node );
    2104 
    2105         indexerScopedAccept( node->result, *this );
    2106         maybeAccept_impl( node->expr, *this );
    2107 
    2108         VISIT_END( node );
    2109 }
    2110 
    2111 template< typename pass_type >
    2112 Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) {
    21132076        MUTATE_START( node );
    21142077
  • src/ResolvExpr/AlternativeFinder.cc

    r61accc5 rf184ca3  
    176176                                                selected[ mangleName ] = current;
    177177                                        } else if ( candidate->cost == mapPlace->second.candidate->cost ) {
    178                                                 // if one of the candidates contains a deleted identifier, can pick the other, since
    179                                                 // deleted expressions should not be ambiguous if there is another option that is at least as good
    180                                                 if ( findDeletedExpr( candidate->expr ) ) {
    181                                                         // do nothing
    182                                                         PRINT( std::cerr << "candidate is deleted" << std::endl; )
    183                                                 } else if ( findDeletedExpr( mapPlace->second.candidate->expr ) ) {
    184                                                         PRINT( std::cerr << "current is deleted" << std::endl; )
    185                                                         selected[ mangleName ] = current;
    186                                                 } else {
    187                                                         PRINT(
    188                                                                 std::cerr << "marking ambiguous" << std::endl;
    189                                                         )
    190                                                         mapPlace->second.isAmbiguous = true;
    191                                                 }
     178                                                PRINT(
     179                                                        std::cerr << "marking ambiguous" << std::endl;
     180                                                )
     181                                                mapPlace->second.isAmbiguous = true;
    192182                                        } else {
    193183                                                PRINT(
     
    345335                if ( ConstantExpr * constantExpr = dynamic_cast< ConstantExpr * >( member ) ) {
    346336                        // get the value of the constant expression as an int, must be between 0 and the length of the tuple type to have meaning
    347                         auto val = constantExpr->intValue();
     337                        // xxx - this should be improved by memoizing the value of constant exprs
     338                        // during parsing and reusing that information here.
     339                        std::stringstream ss( constantExpr->get_constant()->get_value() );
     340                        int val = 0;
    348341                        std::string tmp;
    349                         if ( val >= 0 && (unsigned long long)val < tupleType->size() ) {
     342                        if ( ss >> val && ! (ss >> tmp) ) {
     343                                if ( val >= 0 && (unsigned int)val < tupleType->size() ) {
     344                                        alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
     345                                } // if
     346                        } // if
     347                } else if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ) ) {
     348                        // xxx - temporary hack until 0/1 are int constants
     349                        if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {
     350                                std::stringstream ss( nameExpr->get_name() );
     351                                int val;
     352                                ss >> val;
    350353                                alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
    351                         } // if
     354                        }
    352355                } // if
    353356        }
     
    436439                                        return Cost::infinity;
    437440                                }
    438                         }
    439                         if ( DefaultArgExpr * def = dynamic_cast< DefaultArgExpr * >( *actualExpr ) ) {
    440                                 // default arguments should be free - don't include conversion cost.
    441                                 // Unwrap them here because they are not relevant to the rest of the system.
    442                                 *actualExpr = def->expr;
    443                                 ++formal;
    444                                 continue;
    445441                        }
    446442                        Type * formalType = (*formal)->get_type();
     
    615611        ConstantExpr* getDefaultValue( Initializer* init ) {
    616612                if ( SingleInit* si = dynamic_cast<SingleInit*>( init ) ) {
    617                         if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->value ) ) {
    618                                 return dynamic_cast<ConstantExpr*>( ce->arg );
    619                         } else {
    620                                 return dynamic_cast<ConstantExpr*>( si->value );
     613                        if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->get_value() ) ) {
     614                                return dynamic_cast<ConstantExpr*>( ce->get_arg() );
    621615                        }
    622616                }
     
    879873                                                                indexer ) ) {
    880874                                                        results.emplace_back(
    881                                                                 i, new DefaultArgExpr( cnstExpr ), move(env), move(need), move(have),
     875                                                                i, cnstExpr, move(env), move(need), move(have),
    882876                                                                move(openVars), nextArg, nTuples );
    883877                                                }
     
    10711065                funcFinder.findWithAdjustment( untypedExpr->function );
    10721066                // if there are no function alternatives, then proceeding is a waste of time.
    1073                 // xxx - findWithAdjustment throws, so this check and others like it shouldn't be necessary.
    10741067                if ( funcFinder.alternatives.empty() ) return;
    10751068
  • src/ResolvExpr/Resolver.h

    r61accc5 rf184ca3  
    3636        void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer );
    3737        void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer );
    38         /// Searches expr and returns the first DeletedExpr found, otherwise nullptr
    39         DeletedExpr * findDeletedExpr( Expression * expr );
    4038} // namespace ResolvExpr
    4139
  • src/SynTree/Expression.cc

    r61accc5 rf184ca3  
    746746        os << std::endl << indent+1 << "... deleted by: ";
    747747        deleteStmt->print( os, indent+1 );
    748 }
    749 
    750 
    751 DefaultArgExpr::DefaultArgExpr( Expression * expr ) : expr( expr ) {
    752         assert( expr->result );
    753         result = expr->result->clone();
    754 }
    755 DefaultArgExpr::DefaultArgExpr( const DefaultArgExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ) {}
    756 DefaultArgExpr::~DefaultArgExpr() {
    757         delete expr;
    758 }
    759 
    760 void DefaultArgExpr::print( std::ostream & os, Indenter indent ) const {
    761         os << "Default Argument Expression" << std::endl << indent+1;
    762         expr->print( os, indent+1 );
    763748}
    764749
  • src/SynTree/Expression.h

    r61accc5 rf184ca3  
    865865};
    866866
    867 /// expression wrapping the use of a default argument - should never make it past the resolver.
    868 class DefaultArgExpr : public Expression {
    869 public:
    870         Expression * expr;
    871 
    872         DefaultArgExpr( Expression * expr );
    873         DefaultArgExpr( const DefaultArgExpr & other );
    874         ~DefaultArgExpr();
    875 
    876         virtual DefaultArgExpr * clone() const { return new DefaultArgExpr( * this ); }
    877         virtual void accept( Visitor & v ) { v.visit( this ); }
    878         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    879         virtual void print( std::ostream & os, Indenter indent = {} ) const;
    880 };
    881 
    882867/// C11 _Generic expression
    883868class GenericExpr : public Expression {
  • src/SynTree/Mutator.h

    r61accc5 rf184ca3  
    9393        virtual Expression * mutate( InitExpr  * initExpr ) = 0;
    9494        virtual Expression * mutate( DeletedExpr * delExpr ) = 0;
    95         virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0;
    9695        virtual Expression * mutate( GenericExpr * genExpr ) = 0;
    9796
  • src/SynTree/SynTree.h

    r61accc5 rf184ca3  
    101101class InitExpr;
    102102class DeletedExpr;
    103 class DefaultArgExpr;
    104103class GenericExpr;
    105104
  • src/SynTree/Visitor.h

    r61accc5 rf184ca3  
    9595        virtual void visit( InitExpr *  initExpr ) = 0;
    9696        virtual void visit( DeletedExpr * delExpr ) = 0;
    97         virtual void visit( DefaultArgExpr * argExpr ) = 0;
    9897        virtual void visit( GenericExpr * genExpr ) = 0;
    9998
Note: See TracChangeset for help on using the changeset viewer.