Changeset 6c3a988f for src/SynTree


Ignore:
Timestamp:
Jan 5, 2017, 3:47:36 PM (8 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:
f831177
Parents:
1e3d5b6
Message:

fix inferred parameter data structures to correctly associate parameters with the entity that requested them, modify tuple specialization and unification to work with self-recursive assertions

Location:
src/SynTree
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/SynTree/ApplicationExpr.cc

    r1e3d5b6 r6c3a988f  
    2424
    2525ParamEntry::ParamEntry( const ParamEntry &other ) :
    26                 decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ) {
     26                decl( other.decl ), actualType( maybeClone( other.actualType ) ), formalType( maybeClone( other.formalType ) ), expr( maybeClone( other.expr ) ), inferParams( new InferredParams( *other.inferParams ) ) {
    2727}
    2828
     
    3434        formalType = maybeClone( other.formalType );
    3535        expr = maybeClone( other.expr );
     36        *inferParams = *other.inferParams;
    3637        return *this;
    3738}
     
    6263}
    6364
     65void printInferParams( const InferredParams & inferParams, std::ostream &os, int indent, int level ) {
     66        if ( ! inferParams.empty() ) {
     67                os << std::string(indent, ' ') << "with inferred parameters " << level << ":" << std::endl;
     68                for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
     69                        os << std::string(indent+2, ' ');
     70                        Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
     71                        os << std::endl;
     72                        printInferParams( *i->second.inferParams, os, indent+2, level+1 );
     73                } // for
     74        } // if
     75}
     76
    6477void ApplicationExpr::print( std::ostream &os, int indent ) const {
    6578        os << "Application of" << std::endl << std::string(indent+2, ' ');
     
    6982                printAll( args, os, indent+2 );
    7083        } // if
    71         if ( ! inferParams.empty() ) {
    72                 os << std::string(indent, ' ') << "with inferred parameters:" << std::endl;
    73                 for ( InferredParams::const_iterator i = inferParams.begin(); i != inferParams.end(); ++i ) {
    74                         os << std::string(indent+2, ' ');
    75                         Declaration::declFromId( i->second.decl )->printShort( os, indent+2 );
    76                         os << std::endl;
    77                 } // for
    78         } // if
     84        printInferParams( inferParams, os, indent+2, 0 );
    7985        Expression::print( os, indent );
    8086}
  • TabularUnified src/SynTree/Expression.h

    r1e3d5b6 r6c3a988f  
    5454};
    5555
     56struct ParamEntry;
     57typedef std::map< UniqueId, ParamEntry > InferredParams;
     58
    5659/// ParamEntry contains the i.d. of a declaration and a type that is derived from that declaration,
    5760/// but subject to decay-to-pointer and type parameter renaming
    5861struct ParamEntry {
    59         ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ) {}
    60         ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ) {}
     62        ParamEntry(): decl( 0 ), actualType( 0 ), formalType( 0 ), expr( 0 ), inferParams( new InferredParams ) {}
     63        ParamEntry( UniqueId decl, Type *actualType, Type *formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {}
    6164        ParamEntry( const ParamEntry &other );
    6265        ~ParamEntry();
     
    6770        Type *formalType;
    6871        Expression* expr;
    69 };
    70 
    71 typedef std::map< UniqueId, ParamEntry > InferredParams;
     72        std::unique_ptr< InferredParams > inferParams;
     73};
    7274
    7375/// ApplicationExpr represents the application of a function to a set of parameters.  This is the result of running an
  • TabularUnified src/SynTree/TupleExpr.cc

    r1e3d5b6 r6c3a988f  
    5858TupleIndexExpr::TupleIndexExpr( Expression * tuple, unsigned int index ) : tuple( tuple ), index( index )  {
    5959        TupleType * type = safe_dynamic_cast< TupleType * >( tuple->get_result() );
    60         assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested index %d", type->size(), index );
     60        assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested index %d in expr %s", type->size(), index, toString( tuple ).c_str() );
    6161        set_result( (*std::next( type->get_types().begin(), index ))->clone() );
    6262        get_result()->set_isLvalue( type->get_isLvalue() );
Note: See TracChangeset for help on using the changeset viewer.