Ignore:
Timestamp:
Nov 29, 2016, 3:30:59 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
8e5724e
Parents:
3a2128f (diff), 9129a84 (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 plg2:software/cfa/cfa-cc

Conflicts:

src/Parser/parser.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Lvalue.cc

    r3a2128f r1f44196  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Lvalue.cc -- 
     7// Lvalue.cc --
    88//
    99// Author           : Richard C. Bilson
     
    4141                  public:
    4242                        Pass1();
    43  
     43
    4444                        virtual Expression *mutate( ApplicationExpr *appExpr );
    4545                        virtual Statement *mutate( ReturnStmt *appExpr );
     
    5555                  private:
    5656                };
     57
     58                /// GCC-like Generalized Lvalues (which have since been removed from GCC)
     59                /// https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Lvalues.html#Lvalues
     60                /// Replaces &(a,b) with (a, &b), &(a ? b : c) with (a ? &b : &c)
     61                class GeneralizedLvalue : public Mutator {
     62                        typedef Mutator Parent;
     63
     64                        virtual Expression * mutate( AddressExpr * addressExpr );
     65                };
    5766        } // namespace
    5867
     
    6069                Pass1 p1;
    6170                Pass2 p2;
     71                GeneralizedLvalue genLval;
    6272                mutateAll( translationUnit, p1 );
    6373                acceptAll( translationUnit, p2 );
     74                mutateAll( translationUnit, genLval );
    6475        }
    6576
     
    99110                        appExpr->get_function()->acceptMutator( *this );
    100111                        mutateAll( appExpr->get_args(), *this );
    101  
    102                         assert( ! appExpr->get_function()->get_results().empty() );
    103112
    104                         PointerType *pointer = dynamic_cast< PointerType* >( appExpr->get_function()->get_results().front() );
    105                         assert( pointer );
    106                         FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() );
    107                         assert( function );
     113                        PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     114                        FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
    108115
    109116                        Type *funType = isLvalueRet( function );
    110117                        if ( funType && ! isIntrinsicApp( appExpr ) ) {
    111118                                Expression *expr = appExpr;
    112                                 Type *appType = appExpr->get_results().front();
     119                                Type *appType = appExpr->get_result();
    113120                                if ( isPolyType( funType ) && ! isPolyType( appType ) ) {
    114121                                        // make sure cast for polymorphic type is inside dereference
     
    116123                                }
    117124                                UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    118                                 deref->get_results().push_back( appType->clone() );
    119                                 appExpr->get_results().front() = new PointerType( Type::Qualifiers(), appType );
     125                                deref->set_result( appType->clone() );
     126                                appExpr->set_result( new PointerType( Type::Qualifiers(), appType ) );
    120127                                deref->get_args().push_back( expr );
    121128                                return deref;
     
    127134                Statement * Pass1::mutate(ReturnStmt *retStmt) {
    128135                        if ( retval && retStmt->get_expr() ) {
    129                                 assert( ! retStmt->get_expr()->get_results().empty() );
    130                                 if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
     136                                if ( retStmt->get_expr()->get_result()->get_isLvalue() ) {
    131137                                        // ***** Code Removal ***** because casts may be stripped already
    132138
     
    155161                                retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) );
    156162                        } // if
    157  
     163
    158164                        Visitor::visit( funType );
     165                }
     166
     167                Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {
     168                        addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );
     169                        if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( addrExpr->get_arg() ) ) {
     170                                Expression * arg1 = commaExpr->get_arg1()->clone();
     171                                Expression * arg2 = commaExpr->get_arg2()->clone();
     172                                delete addrExpr;
     173                                return new CommaExpr( arg1, new AddressExpr( arg2 ) );
     174                        } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( addrExpr->get_arg() ) ) {
     175                                Expression * arg1 = condExpr->get_arg1()->clone();
     176                                Expression * arg2 = condExpr->get_arg2()->clone();
     177                                Expression * arg3 = condExpr->get_arg3()->clone();
     178                                delete addrExpr;
     179                                return new ConditionalExpr( arg1, new AddressExpr( arg2 ), new AddressExpr( arg3 ) );
     180                        }
     181                        return addrExpr;
    159182                }
    160183        } // namespace
Note: See TracChangeset for help on using the changeset viewer.