Changes in / [0fe4e62:b7f8cb44]
- Location:
- src/InitTweak
- Files:
-
- 3 edited
-
FixInit.cc (modified) (4 diffs)
-
InitTweak.cc (modified) (2 diffs)
-
InitTweak.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r0fe4e62 rb7f8cb44 393 393 if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types 394 394 395 // type may involve type variables, so apply type substitution to get temporary variable's actual type, 396 // since result type may not be substituted (e.g., if the type does not appear in the parameter list) 395 // type may involve type variables, so apply type substitution to get temporary variable's actual type. 397 396 // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T). 397 result = result->clone(); 398 398 env->applyFree( result ); 399 399 ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr ); … … 570 570 571 571 if ( returnDecl ) { 572 ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr ); 572 UntypedExpr * assign = new UntypedExpr( new NameExpr( "?=?" ) ); 573 assign->get_args().push_back( new VariableExpr( returnDecl ) ); 574 assign->get_args().push_back( callExpr ); 575 // know the result type of the assignment is the type of the LHS (minus the pointer), so 576 // add that onto the assignment expression so that later steps have the necessary information 577 assign->set_result( returnDecl->get_type()->clone() ); 578 573 579 Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) ); 574 580 // move env from callExpr to retExpr … … 1155 1161 assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 ); 1156 1162 1163 // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary. 1164 ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr ); 1165 declsToAddBefore.push_back( tmp ); 1166 1157 1167 // xxx - this can be TupleAssignExpr now. Need to properly handle this case. 1158 1168 ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() ); … … 1160 1170 ctorExpr->set_callExpr( nullptr ); 1161 1171 ctorExpr->set_env( nullptr ); 1162 1163 // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.1164 ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr );1165 declsToAddBefore.push_back( tmp );1166 1172 delete ctorExpr; 1167 1173 -
src/InitTweak/InitTweak.cc
r0fe4e62 rb7f8cb44 12 12 #include "Parser/LinkageSpec.h" // for Spec, isBuiltin, Intrinsic 13 13 #include "ResolvExpr/typeops.h" // for typesCompatibleIgnoreQualifiers 14 #include "SymTab/Autogen.h"15 14 #include "SymTab/Indexer.h" // for Indexer 16 15 #include "SynTree/Attribute.h" // for Attribute … … 525 524 } 526 525 527 ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src ) {528 static FunctionDecl * assign = nullptr;529 if ( ! assign ) {530 // temporary? Generate a fake assignment operator to represent bitwise assignments.531 // This operator could easily exist as a real function, but it's tricky because nothing should resolve to this function.532 TypeDecl * td = new TypeDecl( "T", noStorageClasses, nullptr, TypeDecl::Dtype, true );533 assign = new FunctionDecl( "?=?", noStorageClasses, LinkageSpec::Intrinsic, SymTab::genAssignType( new TypeInstType( noQualifiers, td->name, td ) ), nullptr );534 }535 if ( dynamic_cast< ReferenceType * >( dst->result ) ) {536 dst = new AddressExpr( dst );537 } else {538 dst = new CastExpr( dst, new ReferenceType( noQualifiers, dst->result->clone() ) );539 }540 if ( dynamic_cast< ReferenceType * >( src->result ) ) {541 src = new CastExpr( src, new ReferenceType( noQualifiers, src->result->stripReferences()->clone() ) );542 }543 return new ApplicationExpr( VariableExpr::functionPointer( assign ), { dst, src } );544 }545 546 526 class ConstExprChecker : public Visitor { 547 527 public: -
src/InitTweak/InitTweak.h
r0fe4e62 rb7f8cb44 35 35 /// returns the first parameter of a constructor/destructor/assignment function 36 36 ObjectDecl * getParamThis( FunctionType * ftype ); 37 38 /// generate a bitwise assignment operation.39 ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src );40 37 41 38 /// transform Initializer into an argument list that can be passed to a call expression
Note:
See TracChangeset
for help on using the changeset viewer.