Changes in src/GenPoly/Lvalue.cc [8ca3a72:ce8c12f]
- File:
-
- 1 edited
-
src/GenPoly/Lvalue.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
r8ca3a72 rce8c12f 32 32 #include "Common/UniqueName.h" 33 33 #include "Common/utility.h" 34 #include "InitTweak/InitTweak.h" 34 35 35 36 namespace GenPoly { 36 37 namespace { 38 const std::list<Label> noLabels; 39 37 40 /// Replace uses of lvalue returns with appropriate pointers 38 41 class Pass1 : public Mutator { 39 42 public: 43 typedef Mutator Parent; 40 44 Pass1(); 41 45 46 // xxx - should this happen to every expression with reference result type? probably just appexpr and varexpr? 47 virtual Type *mutate( ReferenceType * refType ); 48 virtual Expression *mutate( VariableExpr *varExpr ); 42 49 virtual Expression *mutate( ApplicationExpr *appExpr ); 43 50 virtual Statement *mutate( ReturnStmt *appExpr ); … … 103 110 } // if 104 111 return funcDecl; 112 } 113 114 Type * Pass1::mutate( ReferenceType * refType ) { 115 Type * base = refType->get_base(); 116 refType->set_base( nullptr ); 117 delete refType; 118 return new PointerType( Type::Qualifiers(), base ); 119 } 120 121 Expression * Pass1::mutate( VariableExpr *varExpr ) { 122 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( varExpr->get_result() ) ) { 123 varExpr->set_result( refType->acceptMutator( *this ) ); 124 return UntypedExpr::createDeref( varExpr ); 125 } 126 return Parent::mutate( varExpr ); 105 127 } 106 128 … … 163 185 } 164 186 187 bool isDeref( Expression * expr ) { 188 if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * >( expr ) ) { 189 return InitTweak::getFunctionName( untyped ) == "*?"; 190 } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) { 191 return InitTweak::getFunctionName( appExpr ) == "*?"; 192 } else { 193 return false; 194 } 195 } 196 165 197 Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) { 166 198 addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) ); … … 176 208 delete addrExpr; 177 209 return new ConditionalExpr( arg1, new AddressExpr( arg2 ), new AddressExpr( arg3 ) ); 210 } else if ( isDeref( addrExpr->get_arg() ) ) { 211 // xxx - this doesn't belong here -- move it somewhere else 212 Expression *& arg = InitTweak::getCallArg( addrExpr->get_arg(), 0 ); 213 Expression * inner = arg; 214 arg = nullptr; 215 delete addrExpr; 216 return inner; 178 217 } 179 218 return addrExpr;
Note:
See TracChangeset
for help on using the changeset viewer.