Changes in src/InitTweak/InitTweak.cc [490fb92e:954c954]
- File:
-
- 1 edited
-
src/InitTweak/InitTweak.cc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/InitTweak.cc
r490fb92e r954c954 498 498 } 499 499 500 const ast::ObjectDecl * getParamThis(const ast::FunctionDecl * func) {501 assertf( func, "getParamThis: nullptr ftype" );502 auto & params = func->params;503 assertf( ! params.empty(), "getParamThis: ftype with 0 parameters: %s", toString( func ).c_str());504 return params.front().strict_as<ast::ObjectDecl>();505 }506 507 500 bool tryConstruct( DeclarationWithType * dwt ) { 508 501 ObjectDecl * objDecl = dynamic_cast< ObjectDecl * >( dwt ); … … 518 511 } 519 512 520 bool tryConstruct( const ast::DeclWithType * dwt ) {521 auto objDecl = dynamic_cast< const ast::ObjectDecl * >( dwt );522 if ( ! objDecl ) return false;523 return (objDecl->init == nullptr ||524 ( objDecl->init != nullptr && objDecl->init->maybeConstructed ))525 && ! objDecl->storage.is_extern526 && isConstructable( objDecl->type );527 }528 529 bool isConstructable( const ast::Type * type ) {530 return ! dynamic_cast< const ast::VarArgsType * >( type ) && ! dynamic_cast< const ast::ReferenceType * >( type )531 && ! dynamic_cast< const ast::FunctionType * >( type ) && ! Tuples::isTtype( type );532 }533 534 513 struct CallFinder_old { 535 514 CallFinder_old( const std::list< std::string > & names ) : names( names ) {} … … 557 536 558 537 struct CallFinder_new final { 559 std::vector< const ast::Expr *> matches;538 std::vector< ast::ptr< ast::Expr > > matches; 560 539 const std::vector< std::string > names; 561 540 … … 579 558 } 580 559 581 std::vector< const ast::Expr *> collectCtorDtorCalls( const ast::Stmt * stmt ) {560 std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt ) { 582 561 ast::Pass< CallFinder_new > finder{ std::vector< std::string >{ "?{}", "^?{}" } }; 583 562 maybe_accept( stmt, finder ); … … 717 696 template <typename Predicate> 718 697 bool allofCtorDtor( const ast::Stmt * stmt, const Predicate & pred ) { 719 std::vector< const ast::Expr *> callExprs = collectCtorDtorCalls( stmt );698 std::vector< ast::ptr< ast::Expr > > callExprs = collectCtorDtorCalls( stmt ); 720 699 return std::all_of( callExprs.begin(), callExprs.end(), pred ); 721 700 } … … 960 939 } 961 940 962 // looks like some other such codegen uses UntypedExpr and does not create fake function. should revisit afterwards963 // following passes may accidentally resolve this expression if returned as untyped...964 ast::Expr * createBitwiseAssignment (const ast::Expr * dst, const ast::Expr * src) {965 static ast::ptr<ast::FunctionDecl> assign = nullptr;966 if (!assign) {967 auto td = new ast::TypeDecl({}, "T", {}, nullptr, ast::TypeDecl::Dtype, true);968 assign = new ast::FunctionDecl({}, "?=?", {},969 { new ast::ObjectDecl({}, "_dst", new ast::ReferenceType(new ast::TypeInstType("T", td))),970 new ast::ObjectDecl({}, "_src", new ast::TypeInstType("T", td))},971 { new ast::ObjectDecl({}, "_ret", new ast::TypeInstType("T", td))}, nullptr, {}, ast::Linkage::Intrinsic);972 }973 if (dst->result.as<ast::ReferenceType>()) {974 for (int depth = dst->result->referenceDepth(); depth > 0; depth--) {975 dst = new ast::AddressExpr(dst);976 }977 }978 else {979 dst = new ast::CastExpr(dst, new ast::ReferenceType(dst->result, {}));980 }981 if (src->result.as<ast::ReferenceType>()) {982 for (int depth = src->result->referenceDepth(); depth > 0; depth--) {983 src = new ast::AddressExpr(src);984 }985 }986 return new ast::ApplicationExpr(dst->location, ast::VariableExpr::functionPointer(dst->location, assign), {dst, src});987 }988 989 941 struct ConstExprChecker : public WithShortCircuiting { 990 942 // most expressions are not const expr
Note:
See TracChangeset
for help on using the changeset viewer.