Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    r490fb92e r954c954  
    498498        }
    499499
    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 
    507500        bool tryConstruct( DeclarationWithType * dwt ) {
    508501                ObjectDecl * objDecl = dynamic_cast< ObjectDecl * >( dwt );
     
    518511        }
    519512
    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_extern
    526                         && 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 
    534513        struct CallFinder_old {
    535514                CallFinder_old( const std::list< std::string > & names ) : names( names ) {}
     
    557536
    558537        struct CallFinder_new final {
    559                 std::vector< const ast::Expr * > matches;
     538                std::vector< ast::ptr< ast::Expr > > matches;
    560539                const std::vector< std::string > names;
    561540
     
    579558        }
    580559
    581         std::vector< const ast::Expr * > collectCtorDtorCalls( const ast::Stmt * stmt ) {
     560        std::vector< ast::ptr< ast::Expr > > collectCtorDtorCalls( const ast::Stmt * stmt ) {
    582561                ast::Pass< CallFinder_new > finder{ std::vector< std::string >{ "?{}", "^?{}" } };
    583562                maybe_accept( stmt, finder );
     
    717696                template <typename Predicate>
    718697                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 );
    720699                        return std::all_of( callExprs.begin(), callExprs.end(), pred );
    721700                }
     
    960939        }
    961940
    962         // looks like some other such codegen uses UntypedExpr and does not create fake function. should revisit afterwards
    963         // 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 
    989941        struct ConstExprChecker : public WithShortCircuiting {
    990942                // most expressions are not const expr
Note: See TracChangeset for help on using the changeset viewer.