Changeset b3b2077


Ignore:
Timestamp:
Nov 9, 2016, 2:05:09 PM (7 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:
23bb1b9
Parents:
8780e30
Message:

refactor some code that generates dereference and assignment calls

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Specialize.cc

    r8780e30 rb3b2077  
    147147
    148148        Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) {
    149                 assert( actual->has_result() );
     149                assertf( actual->has_result(), "attempting to specialize an untyped expression" );
    150150                if ( needsSpecialization( formalType, actual->get_result(), env ) ) {
    151151                        FunctionType *funType;
  • src/InitTweak/FixInit.cc

    r8780e30 rb3b2077  
    509509                                        // an AddressExpr.  Effectively, this turns
    510510                                        //   lvalue T f();
    511                                         //   &*f()
     511                                        //   &*f();
    512512                                        // into
     513                                        //   T * f();
    513514                                        //   T * tmp_cp_retN;
    514                                         //   tmp_cp_ret_N = &*(tmp_cp_ret_N = &*f(), tmp_cp_ret);
     515                                        //   &*(tmp_cp_retN = &*f(), tmp_cp_retN);              // the first * and second & are generated here
    515516                                        // which work out in terms of types, but is pretty messy. It would be nice to find a better way.
    516517                                        assign->get_args().back() = new AddressExpr( assign->get_args().back() );
    517518
    518                                         Type * resultType = returnDecl->get_type()->clone();
    519519                                        returnDecl->set_type( new PointerType( Type::Qualifiers(), returnDecl->get_type() ) );
    520                                         UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    521                                         deref->get_args().push_back( retExpr );
    522                                         deref->set_result( resultType );
    523                                         retExpr = deref;
     520                                        retExpr->set_result( new PointerType( Type::Qualifiers(), retExpr->get_result() ) );
     521                                        retExpr = UntypedExpr::createDeref( retExpr );
    524522                                } // if
    525523                                retExpr->set_env( env->clone() );
  • src/SymTab/Validate.cc

    r8780e30 rb3b2077  
    241241                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
    242242        }
    243 
     243        // xxx - shouldn't this be declsToAddBefore?
    244244        template< typename AggDecl >
    245245        void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
  • src/SynTree/Expression.cc

    r8780e30 rb3b2077  
    380380}
    381381
     382UntypedExpr * UntypedExpr::createDeref( Expression * expr ) {
     383        UntypedExpr * ret = new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ expr } );
     384        if ( Type * type = expr->get_result() ) {
     385                Type * base = InitTweak::getPointerBase( type );
     386                if ( ! base ) {
     387                        std::cerr << type << std::endl;
     388                }
     389                assertf( base, "expected pointer type in dereference\n" );
     390                ret->set_result( maybeClone( base ) );
     391        }
     392        return ret;
     393}
     394
     395UntypedExpr * UntypedExpr::createAssign( Expression * arg1, Expression * arg2 ) {
     396        assert( arg1 && arg2 );
     397        UntypedExpr * ret = new UntypedExpr( new NameExpr( "?=?" ), std::list< Expression * >{ arg1, arg2 } );
     398        if ( arg1->get_result() && arg2->get_result() ) {
     399                // if both expressions are typed, assumes that this assignment is a C bitwise assignment,
     400                // so the result is the type of the RHS
     401                ret->set_result( arg2->get_result()->clone() );
     402        }
     403        return ret;
     404}
     405
     406
    382407void UntypedExpr::print( std::ostream &os, int indent ) const {
    383408        os << "Applying untyped: " << std::endl;
     
    446471
    447472void ConditionalExpr::print( std::ostream &os, int indent ) const {
    448         os << std::string( indent, ' ' ) << "Conditional expression on: " << std::endl;
     473        os << "Conditional expression on: " << std::endl;
     474        os << std::string( indent+2, ' ' );
    449475        arg1->print( os, indent+2 );
    450476        os << std::string( indent, ' ' ) << "First alternative:" << std::endl;
     477        os << std::string( indent+2, ' ' );
    451478        arg2->print( os, indent+2 );
    452479        os << std::string( indent, ' ' ) << "Second alternative:" << std::endl;
     480        os << std::string( indent+2, ' ' );
    453481        arg3->print( os, indent+2 );
    454482        os << std::endl;
  • src/SynTree/Expression.h

    r8780e30 rb3b2077  
    111111        std::list<Expression*>& get_args() { return args; }
    112112
     113        static UntypedExpr * createDeref( Expression * arg );
     114        static UntypedExpr * createAssign( Expression * arg1, Expression * arg2 );
     115
    113116        virtual UntypedExpr *clone() const { return new UntypedExpr( *this ); }
    114117        virtual void accept( Visitor &v ) { v.visit( this ); }
  • src/Tuples/TupleAssignment.cc

    r8780e30 rb3b2077  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May 18 15:02:53 2015
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Nov 9 13:48:42 2016
    1313// Update Count     : 2
    1414//
     
    180180                // explode the lhs so that each field of the tuple-valued-expr is assigned.
    181181                explode( lhsAlt, spotter.currentFinder.get_indexer(), back_inserter(lhs) );
     182
    182183                // and finally, re-add the cast to each lhs expr, so that qualified tuple fields can be constructed
    183184                if ( isCast ) {
     
    192193                        }
    193194                }
    194                 // }
    195         }
    196 
    197         TupleAssignSpotter::MassAssignMatcher::MassAssignMatcher( TupleAssignSpotter &spotter,const ResolvExpr::AltList & alts ) : Matcher( spotter, alts ) {
     195        }
     196
     197        TupleAssignSpotter::MassAssignMatcher::MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList & alts ) : Matcher( spotter, alts ) {
    198198                assert( alts.size() == 1 || alts.size() == 2 );
    199199                if ( alts.size() == 2 ) {
     
    210210                assert( left );
    211211                std::list< Expression * > args;
    212                 args.push_back( new AddressExpr( new UntypedExpr( new NameExpr("*?"), std::list< Expression * >{ new VariableExpr( left ) } ) ) );
     212                args.push_back( new AddressExpr( UntypedExpr::createDeref( new VariableExpr( left ) ) ) );
    213213                // args.push_back( new AddressExpr( new VariableExpr( left ) ) );
    214214                if ( right ) args.push_back( new VariableExpr( right ) );
     
    238238                static UniqueName lhsNamer( "__multassign_L" );
    239239                static UniqueName rhsNamer( "__multassign_R" );
     240
    240241                // xxx - need more complicated matching?
    241242                if ( lhs.size() == rhs.size() ) {
Note: See TracChangeset for help on using the changeset viewer.