Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Lvalue.cc

    rb6fd751 rbaba5d8  
    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                 };
    6657        } // namespace
    6758
     
    6960                Pass1 p1;
    7061                Pass2 p2;
    71                 GeneralizedLvalue genLval;
    7262                mutateAll( translationUnit, p1 );
    7363                acceptAll( translationUnit, p2 );
    74                 mutateAll( translationUnit, genLval );
    7564        }
    7665
     
    11099                        appExpr->get_function()->acceptMutator( *this );
    111100                        mutateAll( appExpr->get_args(), *this );
     101 
     102                        assert( ! appExpr->get_function()->get_results().empty() );
    112103
    113                         PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
    114                         FunctionType *function = safe_dynamic_cast< FunctionType* >( pointer->get_base() );
     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 );
    115108
    116109                        Type *funType = isLvalueRet( function );
    117110                        if ( funType && ! isIntrinsicApp( appExpr ) ) {
    118111                                Expression *expr = appExpr;
    119                                 Type *appType = appExpr->get_result();
     112                                Type *appType = appExpr->get_results().front();
    120113                                if ( isPolyType( funType ) && ! isPolyType( appType ) ) {
    121114                                        // make sure cast for polymorphic type is inside dereference
     
    123116                                }
    124117                                UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    125                                 deref->set_result( appType->clone() );
    126                                 appExpr->set_result( new PointerType( Type::Qualifiers(), appType ) );
     118                                deref->get_results().push_back( appType->clone() );
     119                                appExpr->get_results().front() = new PointerType( Type::Qualifiers(), appType );
    127120                                deref->get_args().push_back( expr );
    128121                                return deref;
     
    134127                Statement * Pass1::mutate(ReturnStmt *retStmt) {
    135128                        if ( retval && retStmt->get_expr() ) {
    136                                 if ( retStmt->get_expr()->get_result()->get_isLvalue() ) {
     129                                assert( ! retStmt->get_expr()->get_results().empty() );
     130                                if ( retStmt->get_expr()->get_results().front()->get_isLvalue() ) {
    137131                                        // ***** Code Removal ***** because casts may be stripped already
    138132
     
    161155                                retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) );
    162156                        } // if
    163 
     157 
    164158                        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;
    182159                }
    183160        } // namespace
Note: See TracChangeset for help on using the changeset viewer.