Changeset 33b7d49 for src/InitTweak
- Timestamp:
- Mar 15, 2022, 10:14:05 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 48a91e2
- Parents:
- d824715
- Location:
- src/InitTweak
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/InitTweak/FixGlobalInit.cc ¶
rd824715 r33b7d49 113 113 accept_all(translationUnit, fixer); 114 114 115 // Say these magic declarations come at the end of the file. 116 CodeLocation const & location = translationUnit.decls.back()->location; 117 115 118 if ( !fixer.core.initStmts.empty() ) { 116 119 std::vector<ast::ptr<ast::Expr>> ctorParams; 117 if (inLibrary) ctorParams.emplace_back(ast::ConstantExpr::from_int({}, 200)); 118 auto initFunction = new ast::FunctionDecl({}, "__global_init__", {}, {}, {}, new ast::CompoundStmt({}, std::move(fixer.core.initStmts)), 119 ast::Storage::Static, ast::Linkage::C, {new ast::Attribute("constructor", std::move(ctorParams))}); 120 if (inLibrary) ctorParams.emplace_back(ast::ConstantExpr::from_int(location, 200)); 121 auto initFunction = new ast::FunctionDecl(location, 122 "__global_init__", {}, {}, {}, 123 new ast::CompoundStmt(location, std::move(fixer.core.initStmts)), 124 ast::Storage::Static, ast::Linkage::C, 125 {new ast::Attribute("constructor", std::move(ctorParams))}); 120 126 121 127 translationUnit.decls.emplace_back( initFunction ); … … 124 130 if ( !fixer.core.destroyStmts.empty() ) { 125 131 std::vector<ast::ptr<ast::Expr>> dtorParams; 126 if (inLibrary) dtorParams.emplace_back(ast::ConstantExpr::from_int({}, 200)); 127 auto destroyFunction = new ast::FunctionDecl({}, "__global_destroy__", {}, {}, {}, new ast::CompoundStmt({}, std::move(fixer.core.destroyStmts)), 128 ast::Storage::Static, ast::Linkage::C, {new ast::Attribute("destructor", std::move(dtorParams))}); 132 if (inLibrary) dtorParams.emplace_back(ast::ConstantExpr::from_int(location, 200)); 133 auto destroyFunction = new ast::FunctionDecl( location, 134 "__global_destroy__", {}, {}, {}, 135 new ast::CompoundStmt(location, std::move(fixer.core.destroyStmts)), 136 ast::Storage::Static, ast::Linkage::C, 137 {new ast::Attribute("destructor", std::move(dtorParams))}); 129 138 130 139 translationUnit.decls.emplace_back(destroyFunction); -
TabularUnified src/InitTweak/FixInitNew.cpp ¶
rd824715 r33b7d49 16 16 #include "CodeGen/GenType.h" // for genPrettyType 17 17 #include "CodeGen/OperatorTable.h" 18 #include "Common/CodeLocationTools.hpp" 18 19 #include "Common/PassVisitor.h" // for PassVisitor, WithStmtsToAdd 19 20 #include "Common/SemanticError.h" // for SemanticError … … 553 554 ast::ptr<ast::Expr> guard = mutArg; 554 555 555 ast::ptr<ast::ObjectDecl> tmp = new ast::ObjectDecl( {}, "__tmp", mutResult, nullptr );556 ast::ptr<ast::ObjectDecl> tmp = new ast::ObjectDecl(loc, "__tmp", mutResult, nullptr ); 556 557 557 558 // create and resolve copy constructor … … 799 800 // to prevent warnings ('_unq0' may be used uninitialized in this function), 800 801 // insert an appropriate zero initializer for UniqueExpr temporaries. 801 ast::Init * makeInit( const ast::Type * t ) {802 ast::Init * makeInit( const ast::Type * t, CodeLocation const & loc ) { 802 803 if ( auto inst = dynamic_cast< const ast::StructInstType * >( t ) ) { 803 804 // initizer for empty struct must be empty 804 if ( inst->base->members.empty() ) return new ast::ListInit({}, {}); 805 if ( inst->base->members.empty() ) { 806 return new ast::ListInit( loc, {} ); 807 } 805 808 } else if ( auto inst = dynamic_cast< const ast::UnionInstType * >( t ) ) { 806 809 // initizer for empty union must be empty 807 if ( inst->base->members.empty() ) return new ast::ListInit({}, {}); 808 } 809 810 return new ast::ListInit( {}, { new ast::SingleInit( {}, ast::ConstantExpr::from_int({}, 0) ) } ); 810 if ( inst->base->members.empty() ) { 811 return new ast::ListInit( loc, {} ); 812 } 813 } 814 815 return new ast::ListInit( loc, { 816 new ast::SingleInit( loc, ast::ConstantExpr::from_int( loc, 0 ) ) 817 } ); 811 818 } 812 819 … … 832 839 } else { 833 840 // expr isn't a call expr, so create a new temporary variable to use to hold the value of the unique expression 834 mutExpr->object = new ast::ObjectDecl( mutExpr->location, toString("_unq", mutExpr->id), mutExpr->result, makeInit( mutExpr->result ) );841 mutExpr->object = new ast::ObjectDecl( mutExpr->location, toString("_unq", mutExpr->id), mutExpr->result, makeInit( mutExpr->result, mutExpr->location ) ); 835 842 mutExpr->var = new ast::VariableExpr( mutExpr->location, mutExpr->object ); 836 843 } … … 1229 1236 1230 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 ) ) } ) ); 1231 destructor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr( {}, ast::dtorStructDestroy ) } ) );1238 destructor->attributes.push_back( new ast::Attribute( "cleanup", { new ast::VariableExpr( loc, ast::dtorStructDestroy ) } ) ); 1232 1239 mutStmts->push_front( new ast::DeclStmt(loc, destructor ) ); 1233 1240 mutStmts->kids.splice( mutStmts->kids.begin(), stmtsToAdd ); … … 1323 1330 1324 1331 const ast::Expr * GenStructMemberCalls::postvisit( const ast::UntypedExpr * untypedExpr ) { 1325 // Expression * newExpr = untypedExpr;1326 1332 // xxx - functions returning ast::ptr seems wrong... 1327 1333 auto res = ResolvExpr::findVoidExpression( untypedExpr, symtab ); 1328 return res.release(); 1329 // return newExpr; 1334 // Fix CodeLocation (at least until resolver is fixed). 1335 auto fix = localFillCodeLocations( untypedExpr->location, res.release() ); 1336 return strict_dynamic_cast<const ast::Expr *>( fix ); 1330 1337 } 1331 1338
Note: See TracChangeset
for help on using the changeset viewer.