Changeset 85b2300 for src/GenPoly/Lvalue.cc
- Timestamp:
- Jun 11, 2018, 1:48:57 PM (5 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, 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, with_gc
- Children:
- 1057e3d
- Parents:
- 61accc5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
r61accc5 r85b2300 146 146 147 147 namespace { 148 // true for intrinsic function calls that return a reference148 // true for intrinsic function calls that return an lvalue in C 149 149 bool isIntrinsicReference( Expression * expr ) { 150 // known intrinsic-reference prelude functions 151 static std::set<std::string> lvalueFunctions = { "*?", "?[?]" }; 150 152 if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * >( expr ) ) { 151 153 std::string fname = InitTweak::getFunctionName( untyped ); 152 // known intrinsic-reference prelude functions 153 return fname == "*?" || fname == "?[?]"; 154 return lvalueFunctions.count(fname); 154 155 } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) { 155 156 if ( DeclarationWithType * func = InitTweak::getFunction( appExpr ) ) { 156 // use type of return variable rather than expr result type, since it may have been changed to a pointer type 157 FunctionType * ftype = GenPoly::getFunctionType( func->get_type() ); 158 Type * ret = ftype->returnVals.empty() ? nullptr : ftype->returnVals.front()->get_type(); 159 return func->linkage == LinkageSpec::Intrinsic && dynamic_cast<ReferenceType *>( ret ); 157 return func->linkage == LinkageSpec::Intrinsic && lvalueFunctions.count(func->name); 160 158 } 161 159 } … … 212 210 // TODO: it's likely that the second condition should be ... && ! isIntrinsicReference( arg ), but this requires investigation. 213 211 214 if ( function-> get_linkage()!= LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) {212 if ( function->linkage != LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) { 215 213 // needed for definition of prelude functions, etc. 216 214 // if argument is dereference or array subscript, the result isn't REALLY a reference, but non-intrinsic functions expect a reference: take address … … 228 226 arg = new AddressExpr( arg ); 229 227 // } else if ( function->get_linkage() == LinkageSpec::Intrinsic && InitTweak::getPointerBase( arg->result ) ) { 230 } else if ( function-> get_linkage()== LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) {228 } else if ( function->linkage == LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) { 231 229 // argument is a 'real' reference, but function expects a C lvalue: add a dereference to the reference-typed argument 232 230 PRINT(
Note: See TracChangeset
for help on using the changeset viewer.