Changeset 1f44196 for src/GenPoly/Lvalue.cc
- Timestamp:
- Nov 29, 2016, 3:30:59 PM (9 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
r3a2128f r1f44196 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#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 }; 57 66 } // namespace 58 67 … … 60 69 Pass1 p1; 61 70 Pass2 p2; 71 GeneralizedLvalue genLval; 62 72 mutateAll( translationUnit, p1 ); 63 73 acceptAll( translationUnit, p2 ); 74 mutateAll( translationUnit, genLval ); 64 75 } 65 76 … … 99 110 appExpr->get_function()->acceptMutator( *this ); 100 111 mutateAll( appExpr->get_args(), *this ); 101 102 assert( ! appExpr->get_function()->get_results().empty() );103 112 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() ); 108 115 109 116 Type *funType = isLvalueRet( function ); 110 117 if ( funType && ! isIntrinsicApp( appExpr ) ) { 111 118 Expression *expr = appExpr; 112 Type *appType = appExpr->get_result s().front();119 Type *appType = appExpr->get_result(); 113 120 if ( isPolyType( funType ) && ! isPolyType( appType ) ) { 114 121 // make sure cast for polymorphic type is inside dereference … … 116 123 } 117 124 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 ) ); 120 127 deref->get_args().push_back( expr ); 121 128 return deref; … … 127 134 Statement * Pass1::mutate(ReturnStmt *retStmt) { 128 135 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() ) { 131 137 // ***** Code Removal ***** because casts may be stripped already 132 138 … … 155 161 retParm->set_type( new PointerType( Type::Qualifiers(), retParm->get_type() ) ); 156 162 } // if 157 163 158 164 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; 159 182 } 160 183 } // namespace
Note:
See TracChangeset
for help on using the changeset viewer.