Changeset 2be1023 for src/InitTweak


Ignore:
Timestamp:
Jul 18, 2016, 4:13:51 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, 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:
5f98ce5
Parents:
956a9c77
Message:

rework ctor/dtor generation to work properly with multidimensional arrays

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    r956a9c77 r2be1023  
    145145                                if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) {
    146146                                        // call into makeArrayFunction from validate.cc to generate calls to ctor/dtor for each element of array
    147                                         // TODO: walk initializer and generate appropriate copy ctor if element has initializer
     147                                        // TODO: walk initializers and generate appropriate ctor if element has initializer.
     148                                        // Initializer could be nested (depends on the depth of the array type on the object)
     149
    148150                                        std::list< Expression * > args = makeInitList( objDecl->get_init() );
    149151                                        if ( args.empty() ) {
     
    151153                                                std::list< Statement * > dtor;
    152154
    153                                                 SymTab::makeArrayFunction( NULL, new VariableExpr( objDecl ), at, "?{}", back_inserter( ctor ) );
    154                                                 SymTab::makeArrayFunction( NULL, new VariableExpr( objDecl ), at, "^?{}", front_inserter( dtor ), false );
    155 
    156                                                 // Currently makeArrayFunction produces a single Statement - a CompoundStmt
     155                                                SymTab::genImplicitCall( NULL, new VariableExpr( objDecl ), "?{}", back_inserter( ctor ), objDecl );
     156                                                SymTab::genImplicitCall( NULL, new VariableExpr( objDecl ), "^?{}", front_inserter( dtor ), objDecl, false );
     157
     158                                                // Currently genArrayCall produces a single Statement - a CompoundStmt
    157159                                                // which  wraps everything that needs to happen. As such, it's technically
    158160                                                // possible to use a Statement ** in the above calls, but this is inherently
     
    160162                                                // immediately informed if somehow the above assumption is broken. In this case,
    161163                                                // we could always wrap the list of statements at this point with a CompoundStmt,
    162                                                 // but it seems reasonable at the moment for this to be done by makeArrayFunction
     164                                                // but it seems reasonable at the moment for this to be done by genArrayCall
    163165                                                // itself
    164166                                                assert( ctor.size() == 1 && dynamic_cast< ImplicitCtorDtorStmt * >( ctor.front() ) );
     
    170172                                                // we haven't exceeded size. This requires precomputing the size because it might be a side-effecting
    171173                                                // computation.
    172                                                 // may have fewer initializers than eleemnts in the array - need to default construct
     174                                                // may have fewer initializers than elements in the array - need to default construct
    173175                                                // remaining elements.
    174176                                                // might be able to merge this with the case above.
     177
    175178                                        }
    176179                                } else {
Note: See TracChangeset for help on using the changeset viewer.