Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r7b3f66b rec79847  
    1010// Created On       : Mon May 04 15:14:56 2016
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 13 11:37:30 2016
     12// Last Modified On : Mon May 09 11:44:29 2016
    1313// Update Count     : 2
    1414//
    1515
    1616#include "FixGlobalInit.h"
    17 #include "InitTweak.h"
     17#include "GenInit.h"
    1818#include "SynTree/Declaration.h"
    1919#include "SynTree/Type.h"
     
    125125                std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids();
    126126
    127                 // if ( objDecl->get_init() == NULL ) return;
     127                if ( objDecl->get_init() == NULL ) return;
    128128                if ( ! tryConstruct( objDecl ) ) return; // don't construct @= or designated objects
    129129                if ( objDecl->get_type()->get_isConst() ) return; // temporary: can't assign to a const variable
    130                 if ( objDecl->get_storageClass() == DeclarationNode::Extern ) return;
    131130                // C allows you to initialize objects with constant expressions
    132131                // xxx - this is an optimization. Need to first resolve constructors before we decide
     
    134133                // if ( isConstExpr( objDecl->get_init() ) ) return;
    135134
    136                 if ( ArrayType * at = dynamic_cast< ArrayType * > ( objDecl->get_type() ) ) {
    137                         // xxx - initialize each element of the array
    138                 } else {
    139                         // steal initializer from object and attach it to a new temporary
    140                         ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, objDecl->get_type()->clone(), objDecl->get_init() );
    141                         objDecl->set_init( NULL );
    142                         initStatements.push_back( new DeclStmt( noLabels, newObj ) );
     135                // steal initializer from object and attach it to a new temporary
     136                ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, objDecl->get_type()->clone(), objDecl->get_init() );
     137                objDecl->set_init( NULL );
     138                initStatements.push_back( new DeclStmt( noLabels, newObj ) );
    143139
    144                         // copy construct objDecl using temporary
    145                         UntypedExpr * init = new UntypedExpr( new NameExpr( "?{}" ) );
    146                         init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
    147                         init->get_args().push_back( new VariableExpr( newObj ) );
    148                         initStatements.push_back( new ExprStmt( noLabels, init ) );
     140                // copy construct objDecl using temporary
     141                UntypedExpr * init = new UntypedExpr( new NameExpr( "?{}" ) );
     142                init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
     143                init->get_args().push_back( new VariableExpr( newObj ) );
     144                initStatements.push_back( new ExprStmt( noLabels, init ) );
    149145
    150                         // add destructor calls to global destroy function
    151                         UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) );
    152                         destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
    153                         destroyStatements.push_front( new ExprStmt( noLabels, destroy ) );
    154                 }
     146                // add destructor calls to global destroy function
     147                UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) );
     148                destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
     149                destroyStatements.push_front( new ExprStmt( noLabels, destroy ) );
    155150        }
    156151
Note: See TracChangeset for help on using the changeset viewer.