Changeset 0d70e0d for src/GenPoly/Lvalue.cc
- Timestamp:
- May 28, 2019, 3:35:00 PM (3 years ago)
- Branches:
- arm-eh, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
- Children:
- eba615c
- Parents:
- 2c04369
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cc
r2c04369 r0d70e0d 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Tue May 28 11:07:00 201913 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 17 09:11:18 2017 13 // Update Count : 5 14 14 // 15 15 … … 42 42 namespace GenPoly { 43 43 namespace { 44 /// Local helper for pass visitors that need to add reference operations. 45 struct WithDerefOp { 46 FunctionDecl * dereferenceOperator = nullptr; 47 48 // TODO: fold this into the general createDeref function?? 49 Expression * mkDeref( Expression * arg ) { 50 if ( dereferenceOperator ) { 51 // note: reference depth can be arbitrarily deep here, so peel off the 52 // outermost pointer/reference, not just pointer because they are effecitvely 53 // equivalent in this pass 54 VariableExpr * deref = new VariableExpr( dereferenceOperator ); 55 deref->result = new PointerType( Type::Qualifiers(), deref->result ); 56 Type * base = InitTweak::getPointerBase( arg->result ); 57 assertf( base, "expected pointer type in dereference (type was %s)", 58 toString( arg->result ).c_str() ); 59 ApplicationExpr * ret = new ApplicationExpr( deref, { arg } ); 60 delete ret->result; 61 ret->result = base->clone(); 62 ret->result->set_lvalue( true ); 63 return ret; 64 } else { 65 return UntypedExpr::createDeref( arg ); 66 } 67 } 68 69 void previsit( FunctionDecl * funcDecl ) { 70 if ( dereferenceOperator ) return; 71 if ( funcDecl->get_name() != "*?" ) return; 72 if ( funcDecl->get_linkage() == LinkageSpec::Intrinsic ) return; 73 FunctionType * ftype = funcDecl->get_functionType(); 74 if ( ftype->get_parameters().size() != 1 ) return; 75 DeclarationWithType * arg0 = ftype->get_parameters().front(); 76 if ( arg0->get_type()->get_qualifiers() == Type::Qualifiers() ) return; 77 dereferenceOperator = funcDecl; 78 } 79 }; 80 81 struct ReferenceConversions final : public WithStmtsToAdd, public WithDerefOp { 44 // TODO: fold this into the general createDeref function?? 45 Expression * mkDeref( Expression * arg ) { 46 if ( SymTab::dereferenceOperator ) { 47 // note: reference depth can be arbitrarily deep here, so peel off the outermost pointer/reference, not just pointer because they are effecitvely equivalent in this pass 48 VariableExpr * deref = new VariableExpr( SymTab::dereferenceOperator ); 49 deref->result = new PointerType( Type::Qualifiers(), deref->result ); 50 Type * base = InitTweak::getPointerBase( arg->result ); 51 assertf( base, "expected pointer type in dereference (type was %s)", toString( arg->result ).c_str() ); 52 ApplicationExpr * ret = new ApplicationExpr( deref, { arg } ); 53 delete ret->result; 54 ret->result = base->clone(); 55 ret->result->set_lvalue( true ); 56 return ret; 57 } else { 58 return UntypedExpr::createDeref( arg ); 59 } 60 } 61 62 struct ReferenceConversions final : public WithStmtsToAdd { 82 63 Expression * postmutate( CastExpr * castExpr ); 83 64 Expression * postmutate( AddressExpr * addrExpr ); … … 85 66 86 67 /// Intrinsic functions that take reference parameters don't REALLY take reference parameters -- their reference arguments must always be implicitly dereferenced. 87 struct FixIntrinsicArgs final : public WithDerefOp{68 struct FixIntrinsicArgs final { 88 69 Expression * postmutate( ApplicationExpr * appExpr ); 89 70 }; … … 117 98 }; 118 99 119 struct AddrRef final : public WithGuards, public WithVisitorRef<AddrRef>, 120 public WithShortCircuiting, public WithDerefOp { 100 struct AddrRef final : public WithGuards, public WithVisitorRef<AddrRef>, public WithShortCircuiting { 121 101 void premutate( AddressExpr * addrExpr ); 122 102 Expression * postmutate( AddressExpr * addrExpr );
Note: See TracChangeset
for help on using the changeset viewer.