Changeset 33b7d49 for src/InitTweak/FixInitNew.cpp
- Timestamp:
- Mar 15, 2022, 10:14:05 AM (2 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 48a91e2
- Parents:
- d824715
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.