Ignore:
Timestamp:
Jan 19, 2016, 1:28:25 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
ca1c11f
Parents:
71f4e4f
Message:

added intrinsic ctor/dtors to prelude, modified MakeLibCfa? to build prelude ctor/dtors, added ctor/dtor to polymorphic object type constraints, rudimentary fallback on initializer nodes if chosen ctor is intrinsic, remove intrinsic destructor statements to reduce output pollution

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/RemoveInit.cc

    r71f4e4f rf1e012b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jan 13 15:19:35 2016
    13 // Update Count     : 154
     12// Last Modified On : Tue Jan 19 11:12:49 2016
     13// Update Count     : 165
    1414//
    1515
     
    5959                static void generateCtorDtor( std::list< Declaration * > &translationUnit );
    6060
     61                CtorDtor() : inFunction( false ) {}
     62
    6163                virtual ObjectDecl * mutate( ObjectDecl * );
    6264                virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
     
    7173
    7274          protected:
     75                bool inFunction;
    7376
    7477                // to be added before block ends - use push_front so order is correct
     
    9396                if (objDecl->get_init() && dynamic_cast<TypeInstType*>(objDecl->get_type())) {
    9497                        if (SingleInit * single = dynamic_cast<SingleInit*>(objDecl->get_init())) {
    95                                 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
     98                                // xxx this can be more complicated - consider ListInit
     99                                UntypedExpr *assign = new UntypedExpr( new NameExpr( "?{}" ) );
    96100                                assign->get_args().push_back( new AddressExpr (new NameExpr( objDecl->get_name() ) ) );
    97101                                assign->get_args().push_back( single->get_value()->clone() );
     
    107111                // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address
    108112                // is being returned
     113                // xxx - this should construct rather than assign
    109114                if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue()  ) {
    110115                        ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 );
     
    186191                // hands off if designated or if @=
    187192                if ( tryConstruct( objDecl ) ) {
    188                         Expression * ctor = makeCtorDtorExpr( "?{}", objDecl, makeInitList( objDecl->get_init() ) );
    189                         Expression * dtor = makeCtorDtorExpr( "^?{}", objDecl, std::list< Expression * >() );
    190 
    191                         // need to remember init expression, in case no ctors exist
    192                         // if ctor does exist, want to use ctor expression instead of init
    193                         // push this decision to the resolver
    194                         objDecl->set_init( new ConstructorInit( ctor, objDecl->get_init() ) );
    195                         destructorStmts.push_front( new ExprStmt( noLabels, dtor ) );
     193                        if ( inFunction ) {
     194                                Expression * ctor = makeCtorDtorExpr( "?{}", objDecl, makeInitList( objDecl->get_init() ) );
     195                                Expression * dtor = makeCtorDtorExpr( "^?{}", objDecl, std::list< Expression * >() );
     196
     197                                // need to remember init expression, in case no ctors exist
     198                                // if ctor does exist, want to use ctor expression instead of init
     199                                // push this decision to the resolver
     200                                objDecl->set_init( new ConstructorInit( ctor, objDecl->get_init() ) );
     201                                destructorStmts.push_front( new ExprStmt( noLabels, dtor ) );
     202                        } else {
     203                                // xxx - find a way to construct/destruct globals
     204                                // hack: implicit "static" initialization routine for each struct type? or something similar?
     205                                // --ties into module system
     206                        }
    196207                }
    197208                return objDecl;
     
    200211        DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) {
    201212                // parameters should not be constructed and destructed, so don't mutate FunctionType
     213                bool oldInFunc = inFunction;
    202214                mutateAll( functionDecl->get_oldDecls(), *this );
     215                inFunction = true;
    203216                functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
     217                inFunction = oldInFunc;
    204218                return functionDecl;
    205219        }
Note: See TracChangeset for help on using the changeset viewer.