Changes in src/GenPoly/Lvalue.cc [b6fd751:baba5d8]
- File:
-
- 1 edited
-
src/GenPoly/Lvalue.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
rb6fd751 rbaba5d8 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Lvalue.cc -- 7 // Lvalue.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 41 41 public: 42 42 Pass1(); 43 43 44 44 virtual Expression *mutate( ApplicationExpr *appExpr ); 45 45 virtual Statement *mutate( ReturnStmt *appExpr ); … … 55 55 private: 56 56 }; 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#Lvalues60 /// 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 };66 57 } // namespace 67 58 … … 69 60 Pass1 p1; 70 61 Pass2 p2; 71 GeneralizedLvalue genLval;72 62 mutateAll( translationUnit, p1 ); 73 63 acceptAll( translationUnit, p2 ); 74 mutateAll( translationUnit, genLval );75 64 } 76 65 … … 110 99 appExpr->get_function()->acceptMutator( *this ); 111 100 mutateAll( appExpr->get_args(), *this ); 101 102 assert( ! appExpr->get_function()->get_results().empty() ); 112 103 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 ); 115 108 116 109 Type *funType = isLvalueRet( function ); 117 110 if ( funType && ! isIntrinsicApp( appExpr ) ) { 118 111 Expression *expr = appExpr; 119 Type *appType = appExpr->get_result ();112 Type *appType = appExpr->get_results().front(); 120 113 if ( isPolyType( funType ) && ! isPolyType( appType ) ) { 121 114 // make sure cast for polymorphic type is inside dereference … … 123 116 } 124 117 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 ); 127 120 deref->get_args().push_back( expr ); 128 121 return deref; … … 134 127 Statement * Pass1::mutate(ReturnStmt *retStmt) { 135 128 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() ) { 137 131 // ***** Code Removal ***** because casts may be stripped already 138 132 … … 161 155 retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) ); 162 156 } // if 163 157 164 158 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;182 159 } 183 160 } // namespace
Note:
See TracChangeset
for help on using the changeset viewer.