Changeset bc61563


Ignore:
Timestamp:
Feb 27, 2024, 10:19:19 AM (10 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
4c0b674
Parents:
f1149ac
Message:

Factored out a very complex condition into a helper function and documented it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    rf1149ac rbc61563  
    412412
    413413        void resolveWithExprs(std::vector<ast::ptr<ast::Expr>> & exprs, std::list<ast::ptr<ast::Stmt>> & stmtsToAdd);
     414        bool shouldGenCtorInit( const ast::ObjectDecl * ) const;
    414415
    415416        void beginScope() { managedTypes.beginScope(); }
     
    581582}
    582583
     584bool Resolver::shouldGenCtorInit( ast::ObjectDecl const * decl ) const {
     585        // If we shouldn't try to construct it, then don't.
     586        if ( !InitTweak::tryConstruct( decl ) ) return false;
     587        // Otherwise, if it is a managed type, we may construct it.
     588        if ( managedTypes.isManaged( decl ) ) return true;
     589        // Skip construction if it is trivial at compile-time.
     590        if ( InitTweak::isConstExpr( decl->init ) ) return false;
     591        // Skip construction for local declarations.
     592        return ( !isInFunction() || decl->storage.is_static );
     593}
     594
    583595const ast::ObjectDecl * Resolver::previsit( const ast::ObjectDecl * objectDecl ) {
    584596        // To handle initialization of routine pointers [e.g. int (*fp)(int) = foo()],
     
    615627                        // this object in visitor pass, thus disabling CtorInit codegen.
    616628                        // this happens on aggregate members and function parameters.
    617                         if ( InitTweak::tryConstruct( mutDecl ) && ( managedTypes.isManaged( mutDecl ) || ((! isInFunction() || mutDecl->storage.is_static ) && ! InitTweak::isConstExpr( mutDecl->init ) ) ) ) {
     629                        if ( shouldGenCtorInit( mutDecl ) ) {
    618630                                // constructed objects cannot be designated
    619631                                if ( InitTweak::isDesignated( mutDecl->init ) ) {
Note: See TracChangeset for help on using the changeset viewer.