Changeset 848ce71


Ignore:
Timestamp:
Oct 13, 2016, 2:46: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:
bf32bb8
Parents:
7756647
Message:

resolve untyped member exprs for tuples

Location:
src/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r7756647 r848ce71  
    229229                        assertf( false, "reached unexpected case of addAggMembers" );
    230230                }
     231        }
     232
     233        void AlternativeFinder::addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) {
     234                if ( ConstantExpr * constantExpr = dynamic_cast< ConstantExpr * >( member ) ) {
     235                        // get the value of the constant expression as an int, must be between 0 and the length of the tuple type to have meaning
     236                        // xxx - this should be improved by memoizing the value of constant exprs
     237                        // during parsing and reusing that information here.
     238                        std::stringstream ss( constantExpr->get_constant()->get_value() );
     239                        int val;
     240                        std::string tmp;
     241                        if ( ss >> val && ! (ss >> tmp) ) {
     242                                if ( val >= 0 && (unsigned int)val < tupleType->size() ) {
     243                                        alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
     244                                } // if
     245                        } // if
     246                } // if
    231247        }
    232248
     
    785801                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( agg->expr->get_result() ) ) {
    786802                                addAggMembers( unionInst, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
     803                        } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( agg->expr->get_result() ) ) {
     804                                addTupleMembers( tupleType, agg->expr, agg->cost, agg->env, memberExpr->get_member() );
    787805                        } // if
    788806                } // for
  • src/ResolvExpr/AlternativeFinder.h

    r7756647 r848ce71  
    7676                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
    7777                template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
     78                /// Adds alternatives for member expressions where the left side has tuple type
     79                void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
    7880                /// Adds alternatives for offsetof expressions, given the base type and name of the member
    7981                template< typename StructOrUnionType > void addOffsetof( StructOrUnionType *aggInst, const std::string &name );
Note: See TracChangeset for help on using the changeset viewer.