Changeset 39d8950 for src/InitTweak
- Timestamp:
- Mar 16, 2022, 4:41:01 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- f7496c5
- Parents:
- 9d8124f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInitNew.cpp
r9d8124f r39d8950 86 86 /// generate/resolve copy construction expressions for each, and generate/resolve destructors for both 87 87 /// arguments and return value temporaries 88 struct ResolveCopyCtors final : public ast::WithGuards, public ast::WithStmtsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting, public ast::WithVisitorRef<ResolveCopyCtors> {88 struct ResolveCopyCtors final : public ast::WithGuards, public ast::WithStmtsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting, public ast::WithVisitorRef<ResolveCopyCtors>, public ast::WithConstTranslationUnit { 89 89 const ast::Expr * postvisit( const ast::ImplicitCopyCtorExpr * impCpCtorExpr ); 90 90 const ast::StmtExpr * previsit( const ast::StmtExpr * stmtExpr ); … … 190 190 /// for any member that is missing a corresponding ctor/dtor call. 191 191 /// error if a member is used before constructed 192 struct GenStructMemberCalls final : public ast::WithGuards, public ast::WithShortCircuiting, public ast::WithSymbolTable, public ast::WithVisitorRef<GenStructMemberCalls> {192 struct GenStructMemberCalls final : public ast::WithGuards, public ast::WithShortCircuiting, public ast::WithSymbolTable, public ast::WithVisitorRef<GenStructMemberCalls>, public ast::WithConstTranslationUnit { 193 193 void previsit( const ast::FunctionDecl * funcDecl ); 194 194 const ast::DeclWithType * postvisit( const ast::FunctionDecl * funcDecl ); … … 215 215 216 216 /// expands ConstructorExpr nodes into comma expressions, using a temporary for the first argument 217 struct FixCtorExprs final : public ast::WithDeclsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting {217 struct FixCtorExprs final : public ast::WithDeclsToAdd<>, public ast::WithSymbolTable, public ast::WithShortCircuiting, public ast::WithConstTranslationUnit { 218 218 const ast::Expr * postvisit( const ast::ConstructorExpr * ctorExpr ); 219 219 }; … … 510 510 // (VariableExpr and already resolved expression) 511 511 CP_CTOR_PRINT( std::cerr << "ResolvingCtorDtor " << untyped << std::endl; ) 512 ast::ptr<ast::Expr> resolved = ResolvExpr::findVoidExpression(untyped, symtab);512 ast::ptr<ast::Expr> resolved = ResolvExpr::findVoidExpression(untyped, { symtab, transUnit().global } ); 513 513 assert( resolved ); 514 514 if ( resolved->env ) { … … 588 588 589 589 ast::Expr * ResolveCopyCtors::destructRet( const ast::ObjectDecl * ret, const ast::Expr * arg ) { 590 auto global = transUnit().global; 590 591 // TODO: refactor code for generating cleanup attribute, since it's common and reused in ~3-4 places 591 592 // check for existing cleanup attribute before adding another(?) 592 593 // need to add __Destructor for _tmp_cp variables as well 593 594 594 assertf( ast::dtorStruct, "Destructor generation requires __Destructor definition." );595 assertf( ast::dtorStruct->members.size() == 2, "__Destructor definition does not have expected fields." );596 assertf( ast::dtorStructDestroy, "Destructor generation requires __destroy_Destructor." );595 assertf( global.dtorStruct, "Destructor generation requires __Destructor definition." ); 596 assertf( global.dtorStruct->members.size() == 2, "__Destructor definition does not have expected fields." ); 597 assertf( global.dtorDestroy, "Destructor generation requires __destroy_Destructor." ); 597 598 598 599 const CodeLocation loc = ret->location; … … 611 612 auto dtorFunc = getDtorFunc( ret, new ast::ExprStmt(loc, dtor ), stmtsToAddBefore ); 612 613 613 auto dtorStructType = new ast::StructInstType( ast::dtorStruct);614 auto dtorStructType = new ast::StructInstType( global.dtorStruct ); 614 615 615 616 // what does this do??? … … 623 624 static UniqueName namer( "_ret_dtor" ); 624 625 auto retDtor = new ast::ObjectDecl(loc, namer.newName(), dtorStructType, new ast::ListInit(loc, { new ast::SingleInit(loc, ast::ConstantExpr::null(loc) ), new ast::SingleInit(loc, new ast::CastExpr( new ast::VariableExpr(loc, dtorFunc ), dtorType ) ) } ) ); 625 retDtor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr(loc, ast::dtorStructDestroy ) } ) );626 retDtor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr(loc, global.dtorDestroy ) } ) ); 626 627 stmtsToAddBefore.push_back( new ast::DeclStmt(loc, retDtor ) ); 627 628 628 629 if ( arg ) { 629 auto member = new ast::MemberExpr(loc, ast::dtorStruct->members.front().strict_as<ast::DeclWithType>(), new ast::VariableExpr(loc, retDtor ) );630 auto member = new ast::MemberExpr(loc, global.dtorStruct->members.front().strict_as<ast::DeclWithType>(), new ast::VariableExpr(loc, retDtor ) ); 630 631 auto object = new ast::CastExpr( new ast::AddressExpr( new ast::VariableExpr(loc, ret ) ), new ast::PointerType(new ast::VoidType() ) ); 631 632 ast::Expr * assign = createBitwiseAssignment( member, object ); … … 1179 1180 auto guard = makeFuncGuard( [this]() { symtab.enterScope(); }, [this]() { symtab.leaveScope(); } ); 1180 1181 symtab.addFunction( function ); 1182 auto global = transUnit().global; 1181 1183 1182 1184 // need to iterate through members in reverse in order for … … 1224 1226 1225 1227 static UniqueName memberDtorNamer = { "__memberDtor" }; 1226 assertf( ast::dtorStruct, "builtin __Destructor not found." );1227 assertf( ast::dtorStructDestroy, "builtin __destroy_Destructor not found." );1228 assertf( global.dtorStruct, "builtin __Destructor not found." ); 1229 assertf( global.dtorDestroy, "builtin __destroy_Destructor not found." ); 1228 1230 1229 1231 ast::Expr * thisExpr = new ast::CastExpr( new ast::AddressExpr( new ast::VariableExpr(loc, thisParam ) ), new ast::PointerType( new ast::VoidType(), ast::CV::Qualifiers() ) ); … … 1235 1237 auto dtorType = new ast::PointerType( dtorFtype ); 1236 1238 1237 auto destructor = new ast::ObjectDecl(loc, memberDtorNamer.newName(), new ast::StructInstType( ast::dtorStruct ), new ast::ListInit(loc, { new ast::SingleInit(loc, thisExpr ), new ast::SingleInit(loc, new ast::CastExpr( dtorExpr, dtorType ) ) } ) );1238 destructor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr( loc, ast::dtorStructDestroy ) } ) );1239 auto destructor = new ast::ObjectDecl(loc, memberDtorNamer.newName(), new ast::StructInstType( global.dtorStruct ), new ast::ListInit(loc, { new ast::SingleInit(loc, thisExpr ), new ast::SingleInit(loc, new ast::CastExpr( dtorExpr, dtorType ) ) } ) ); 1240 destructor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr( loc, global.dtorDestroy ) } ) ); 1239 1241 mutStmts->push_front( new ast::DeclStmt(loc, destructor ) ); 1240 1242 mutStmts->kids.splice( mutStmts->kids.begin(), stmtsToAdd ); … … 1331 1333 const ast::Expr * GenStructMemberCalls::postvisit( const ast::UntypedExpr * untypedExpr ) { 1332 1334 // xxx - functions returning ast::ptr seems wrong... 1333 auto res = ResolvExpr::findVoidExpression( untypedExpr, symtab);1335 auto res = ResolvExpr::findVoidExpression( untypedExpr, { symtab, transUnit().global } ); 1334 1336 // Fix CodeLocation (at least until resolver is fixed). 1335 1337 auto fix = localFillCodeLocations( untypedExpr->location, res.release() ); … … 1368 1370 1369 1371 // resolve assignment and dispose of new env 1370 auto resolved = ResolvExpr::findVoidExpression( assign, symtab);1372 auto resolved = ResolvExpr::findVoidExpression( assign, { symtab, transUnit().global } ); 1371 1373 auto mut = resolved.get_and_mutate(); 1372 1374 assertf(resolved.get() == mut, "newly resolved expression must be unique");
Note: See TracChangeset
for help on using the changeset viewer.