Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r7baed7d r7b3f66b  
    2222#include "SynTree/Initializer.h"
    2323#include "SynTree/Visitor.h"
    24 #include "SynTree/Attribute.h"
    2524#include <algorithm>
    2625
     
    117116        GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) {
    118117                std::string fixedName = globalFunctionName( name );
    119                 std::list< Expression * > ctorParameters;
    120                 std::list< Expression * > dtorParameters;
    121                 if ( inLibrary ) {
    122                         // Constructor/destructor attributes take a single parameter which
    123                         // is the priority, with lower numbers meaning higher priority.
    124                         // Functions specified with priority are guaranteed to run before
    125                         // functions without a priority. To ensure that constructors and destructors
    126                         // for library code are run before constructors and destructors for user code,
    127                         // specify a priority when building the library. Priorities 0-100 are reserved by gcc.
    128                         ctorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) );
    129                         dtorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) );
    130                 }
    131                 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
    132                 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) );
    133                 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
    134                 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) );
     118                initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Constructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) );
     119
     120                destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Destructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) );
    135121        }
    136122
     
    139125                std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids();
    140126
     127                // if ( objDecl->get_init() == NULL ) return;
    141128                if ( ! tryConstruct( objDecl ) ) return; // don't construct @= or designated objects
     129                if ( objDecl->get_type()->get_isConst() ) return; // temporary: can't assign to a const variable
    142130                if ( objDecl->get_storageClass() == DeclarationNode::Extern ) return;
    143131                // C allows you to initialize objects with constant expressions
     
    158146                        init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
    159147                        init->get_args().push_back( new VariableExpr( newObj ) );
    160                         initStatements.push_back( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, init ) ) );
     148                        initStatements.push_back( new ExprStmt( noLabels, init ) );
    161149
    162150                        // add destructor calls to global destroy function
    163151                        UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) );
    164152                        destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
    165                         destroyStatements.push_front( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, destroy ) ) );
     153                        destroyStatements.push_front( new ExprStmt( noLabels, destroy ) );
    166154                }
    167155        }
Note: See TracChangeset for help on using the changeset viewer.