Changeset a7c90d4 for src/InitTweak


Ignore:
Timestamp:
Mar 7, 2017, 8:33:43 AM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
64cb860, c3396e0
Parents:
7fe2498
Message:

change StorageClass to bitset, support _Thread_local as separate storage-class

Location:
src/InitTweak
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r7fe2498 ra7c90d4  
    1010// Created On       : Mon May 04 15:14:56 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar  3 21:55:33 2017
    13 // Update Count     : 9
     12// Last Modified On : Mon Mar  6 23:14:19 2017
     13// Update Count     : 14
    1414//
    1515
     
    8787                        dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) );
    8888                }
    89                 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
     89                initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::StorageClasses( DeclarationNode::StaticClass ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    9090                initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) );
    91                 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
     91                destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::StorageClasses( DeclarationNode::StaticClass ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    9292                destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) );
    9393        }
  • src/InitTweak/FixInit.cc

    r7fe2498 ra7c90d4  
    1010// Created On       : Wed Jan 13 16:29:30 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar  3 21:56:11 2017
    13 // Update Count     : 39
     12// Last Modified On : Tue Mar  7 07:51:40 2017
     13// Update Count     : 59
    1414//
    1515
     
    437437                        result = result->clone();
    438438                        env->apply( result );
    439                         ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result, 0 );
     439                        ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::StorageClasses(), LinkageSpec::C, 0, result, 0 );
    440440                        tmp->get_type()->set_isConst( false );
    441441
     
    483483                                result = result->clone();
    484484                                env->apply( result );
    485                                 ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result, 0 );
     485                                ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::StorageClasses(), LinkageSpec::C, 0, result, 0 );
    486486                                ret->get_type()->set_isConst( false );
    487487                                impCpCtorExpr->get_returnDecls().push_back( ret );
     
    506506                                result = result->clone();
    507507                                env->apply( result );
    508                                 ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result, 0 );
     508                                ObjectDecl * ret = new ObjectDecl( retNamer.newName(), DeclarationNode::StorageClasses(), LinkageSpec::C, 0, result, 0 );
    509509                                ret->get_type()->set_isConst( false );
    510510                                stmtExpr->get_returnDecls().push_front( ret );
     
    538538                        } else {
    539539                                // expr isn't a call expr, so create a new temporary variable to use to hold the value of the unique expression
    540                                 unqExpr->set_object( new ObjectDecl( toString("_unq_expr_", unqExpr->get_id()), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, unqExpr->get_result()->clone(), nullptr ) );
     540                                unqExpr->set_object( new ObjectDecl( toString("_unq_expr_", unqExpr->get_id()), DeclarationNode::StorageClasses(), LinkageSpec::C, nullptr, unqExpr->get_result()->clone(), nullptr ) );
    541541                                unqExpr->set_var( new VariableExpr( unqExpr->get_object() ) );
    542542                        }
     
    678678                                assert( ! ctorInit->get_ctor() || ! ctorInit->get_init() );
    679679                                if ( Statement * ctor = ctorInit->get_ctor() ) {
    680                                         if ( objDecl->get_storageClass() == DeclarationNode::Static ) {
     680                                        if ( objDecl->get_storageClasses()[ DeclarationNode::Static ] ) {
    681681                                                // originally wanted to take advantage of gcc nested functions, but
    682682                                                // we get memory errors with this approach. To remedy this, the static
     
    704704                                                BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool );
    705705                                                SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant( boolType->clone(), "1" ) ), noDesignators );
    706                                                 ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", DeclarationNode::Static, LinkageSpec::Cforall, 0, boolType, boolInitExpr );
     706                                                ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", DeclarationNode::StorageClasses( DeclarationNode::StaticClass ), LinkageSpec::Cforall, 0, boolType, boolInitExpr );
    707707                                                isUninitializedVar->fixUniqueId();
    708708
     
    731731
    732732                                                        // void __objName_dtor_atexitN(...) {...}
    733                                                         FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
     733                                                        FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), DeclarationNode::StorageClasses( DeclarationNode::StaticClass ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    734734                                                        dtorCaller->fixUniqueId();
    735735                                                        dtorCaller->get_statements()->push_back( dtorStmt );
     
    764764                                                        // create a new object which is never used
    765765                                                        static UniqueName dummyNamer( "_dummy" );
    766                                                         ObjectDecl * dummy = new ObjectDecl( dummyNamer.newName(), DeclarationNode::Static, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ), 0, std::list< Attribute * >{ new Attribute("unused") } );
     766                                                        ObjectDecl * dummy = new ObjectDecl( dummyNamer.newName(), DeclarationNode::StorageClasses( DeclarationNode::StaticClass ), LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ), 0, std::list< Attribute * >{ new Attribute("unused") } );
    767767                                                        return dummy;
    768768                                                }
     
    821821                void InsertDtors::visit( ObjectDecl * objDecl ) {
    822822                        // remember non-static destructed objects so that their destructors can be inserted later
    823                         if ( objDecl->get_storageClass() != DeclarationNode::Static ) {
     823                        if ( ! objDecl->get_storageClasses()[ DeclarationNode::Static ] ) {
    824824                                if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) {
    825825                                        // a decision should have been made by the resolver, so ctor and init are not both non-NULL
     
    11181118
    11191119                        // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
    1120                         ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, ctorExpr->get_result()->clone(), nullptr );
     1120                        ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::StorageClasses(), LinkageSpec::C, nullptr, ctorExpr->get_result()->clone(), nullptr );
    11211121                        addDeclaration( tmp );
    11221122
  • src/InitTweak/GenInit.cc

    r7fe2498 ra7c90d4  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 16 14:57:53 2017
    13 // Update Count     : 167
     12// Last Modified On : Tue Mar  7 07:51:38 2017
     13// Update Count     : 179
    1414//
    1515
     
    120120                void hoist( Type * type );
    121121
    122                 DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass;
     122                DeclarationNode::StorageClasses storageClasses;
    123123                bool inFunction = false;
    124124        };
     
    174174
    175175        DeclarationWithType * HoistArrayDimension::mutate( ObjectDecl * objectDecl ) {
    176                 storageclass = objectDecl->get_storageClass();
     176                storageClasses = objectDecl->get_storageClasses();
    177177                DeclarationWithType * temp = Parent::mutate( objectDecl );
    178178                hoist( objectDecl->get_type() );
    179                 storageclass = DeclarationNode::NoStorageClass;
    180179                return temp;
    181180        }
     
    185184                static UniqueName dimensionName( "_array_dim" );
    186185
    187                 // C doesn't allow variable sized arrays at global scope or for static variables,
    188                 // so don't hoist dimension.
     186                // C doesn't allow variable sized arrays at global scope or for static variables, so don't hoist dimension.
    189187                if ( ! inFunction ) return;
    190                 if ( storageclass == DeclarationNode::Static ) return;
     188                if ( storageClasses[ DeclarationNode::StaticClass] ) return;
    191189
    192190                if ( ArrayType * arrayType = dynamic_cast< ArrayType * >( type ) ) {
    193191                        if ( ! arrayType->get_dimension() ) return; // xxx - recursive call to hoist?
    194192
    195                         // don't need to hoist dimension if it's a constexpr - only need to if there's potential
    196                         // for side effects.
     193                        // don't need to hoist dimension if it's a constexpr - only need to if there's potential for side effects.
    197194                        if ( isConstExpr( arrayType->get_dimension() ) ) return;
    198195
    199                         ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageclass, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
     196                        ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
    200197                        arrayDimension->get_type()->set_isConst( true );
    201198
  • src/InitTweak/InitTweak.cc

    r7fe2498 ra7c90d4  
    260260                        (objDecl->get_init() == NULL ||
    261261                                ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() ))
    262                         && objDecl->get_storageClass() != DeclarationNode::Extern;
     262                        && ! objDecl->get_storageClasses()[ DeclarationNode::Extern ];
    263263        }
    264264
Note: See TracChangeset for help on using the changeset viewer.