Changeset 696bf6e for src/InitTweak
- Timestamp:
- Sep 25, 2017, 3:56:14 PM (7 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:
- b4bfa0a
- Parents:
- 3aeaecd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r3aeaecd r696bf6e 242 242 }; 243 243 244 class FixCtorExprs final : public GenPoly::DeclMutator { 245 public: 244 struct FixCtorExprs final : public WithDeclsToAdd, public WithIndexer { 246 245 /// expands ConstructorExpr nodes into comma expressions, using a temporary for the first argument 247 246 static void fix( std::list< Declaration * > & translationUnit ); 248 247 249 using GenPoly::DeclMutator::mutate; 250 virtual Expression * mutate( ConstructorExpr * ctorExpr ) override; 248 Expression * postmutate( ConstructorExpr * ctorExpr ); 251 249 }; 252 250 } // namespace … … 325 323 326 324 void FixCtorExprs::fix( std::list< Declaration * > & translationUnit ) { 327 FixCtorExprsfixer;328 fixer.mutateDeclarationList( translationUnit);325 PassVisitor<FixCtorExprs> fixer; 326 mutateAll( translationUnit, fixer ); 329 327 } 330 328 … … 1146 1144 } 1147 1145 1148 Expression * FixCtorExprs:: mutate( ConstructorExpr * ctorExpr ) {1146 Expression * FixCtorExprs::postmutate( ConstructorExpr * ctorExpr ) { 1149 1147 static UniqueName tempNamer( "_tmp_ctor_expr" ); 1150 1148 // xxx - is the size check necessary? … … 1153 1151 // 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. 1154 1152 ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr ); 1155 addDeclaration( tmp );1153 declsToAddBefore.push_back( tmp ); 1156 1154 1157 1155 // xxx - this can be TupleAssignExpr now. Need to properly handle this case. … … 1162 1160 delete ctorExpr; 1163 1161 1162 // build assignment and replace constructor's first argument with new temporary 1164 1163 Expression *& firstArg = callExpr->get_args().front(); 1165 1166 // xxx - hack in 'fake' assignment operator until resolver can easily be called in this pass. Once the resolver can be used in PassVisitor, this hack goes away. 1167 1168 // generate the type of assignment operator using the type of tmp minus any reference types 1169 Type * type = tmp->get_type()->stripReferences(); 1170 FunctionType * ftype = SymTab::genAssignType( type ); 1171 1172 // generate fake assignment decl and call it using &tmp and &firstArg 1173 // since tmp is guaranteed to be a reference and we want to assign pointers 1174 FunctionDecl * assignDecl = new FunctionDecl( "?=?", Type::StorageClasses(), LinkageSpec::Intrinsic, ftype, nullptr ); 1175 ApplicationExpr * assign = new ApplicationExpr( VariableExpr::functionPointer( assignDecl ) ); 1176 assign->get_args().push_back( new AddressExpr( new VariableExpr( tmp ) ) ); 1177 Expression * addrArg = new AddressExpr( firstArg ); 1178 // if firstArg has type T&&, then &firstArg has type T*&. 1179 // Cast away the reference to a value type so that the argument 1180 // matches the assignment's parameter types 1181 if ( dynamic_cast<ReferenceType *>( addrArg->get_result() ) ) { 1182 addrArg = new CastExpr( addrArg, addrArg->get_result()->stripReferences()->clone() ); 1183 } 1184 assign->get_args().push_back( addrArg ); 1164 Expression * assign = new UntypedExpr( new NameExpr( "?=?" ), { new AddressExpr( new VariableExpr( tmp ) ), new AddressExpr( firstArg ) } ); 1185 1165 firstArg = new VariableExpr( tmp ); 1166 1167 // resolve assignment and dispose of new env 1168 Expression * resolvedAssign = ResolvExpr::findVoidExpression( assign, indexer ); 1169 delete resolvedAssign->env; 1170 resolvedAssign->env = nullptr; 1171 delete assign; 1186 1172 1187 1173 // for constructor expr: … … 1192 1178 // T & tmp; 1193 1179 // &tmp = &x, ?{}(tmp), tmp 1194 CommaExpr * commaExpr = new CommaExpr( assign, new CommaExpr( callExpr, new VariableExpr( tmp ) ) );1180 CommaExpr * commaExpr = new CommaExpr( resolvedAssign, new CommaExpr( callExpr, new VariableExpr( tmp ) ) ); 1195 1181 commaExpr->set_env( env ); 1196 1182 return commaExpr;
Note: See TracChangeset
for help on using the changeset viewer.