Changeset f9cebb5 for src/SymTab


Ignore:
Timestamp:
Aug 4, 2016, 4:10:06 PM (8 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:
4819cac
Parents:
73bf8cf2
Message:

add gcc attributes to ObjectDecl?, hoist destructed static variables, add breaks to end of generated switch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    r73bf8cf2 rf9cebb5  
    3737        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
    3838        template< typename OutputIterator >
    39         void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
     39        Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
    4040
    4141        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types.
     42        /// optionally returns a statement which must be inserted prior to the containing loop, if there is one
    4243        template< typename OutputIterator >
    43         void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
     44        Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
    4445                // want to be able to generate assignment, ctor, and dtor generically,
    4546                // so fname is either ?=?, ?{}, or ^?{}
     
    6364                fExpr->get_args().push_back( dstParam );
    6465
    65     Statement * listInit = srcParam.buildListInit( fExpr );
    66     if ( listInit ) {
    67       *out++ = listInit;
    68     }
     66                Statement * listInit = srcParam.buildListInit( fExpr );
    6967
    70     std::list< Expression * > args = *++srcParam;
    71     fExpr->get_args().splice( fExpr->get_args().end(), args );
     68                std::list< Expression * > args = *++srcParam;
     69                fExpr->get_args().splice( fExpr->get_args().end(), args );
    7270
    7371                *out++ = new ExprStmt( noLabels, fExpr );
    7472
    75     srcParam.clearArrayIndices();
     73                srcParam.clearArrayIndices();
     74
     75                return listInit;
    7676        }
    7777
     
    125125                srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() );
    126126
    127                 // if ( srcParam ) {
    128                 //      UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
    129                 //      srcIndex->get_args().push_back( srcParam );
    130                 //      srcIndex->get_args().push_back( new VariableExpr( index ) );
    131                 //      srcParam = srcIndex;
    132                 // }
    133 
    134127                // for stmt's body, eventually containing call
    135128                CompoundStmt * body = new CompoundStmt( noLabels );
    136                 genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
     129                Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
    137130
    138131                // block containing for stmt and index variable
     
    140133                CompoundStmt * block = new CompoundStmt( noLabels );
    141134                block->get_kids().push_back( new DeclStmt( noLabels, index ) );
     135                if ( listInit ) block->get_kids().push_back( listInit );
    142136                block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
    143137
     
    146140
    147141        template< typename OutputIterator >
    148         void genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
     142        Statement * genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
    149143                if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    150144                        genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
     145                        return 0;
    151146                } else {
    152                         genScalarCall( srcParam, dstParam, fname, out, type, addCast );
     147                        return genScalarCall( srcParam, dstParam, fname, out, type, addCast );
    153148                }
    154149        }
     
    171166                // currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call
    172167                assert( stmts.size() <= 1 );
    173     if ( stmts.size() == 1 ) {
    174                 Statement * callStmt = stmts.front();
    175                 if ( addCast ) {
    176                         // implicitly generated ctor/dtor calls should be wrapped
    177                         // so that later passes are aware they were generated.
    178                         // xxx - don't mark as an implicit ctor/dtor if obj is a bitfield,
    179                         // because this causes the address to be taken at codegen, which is illegal in C.
    180                         callStmt = new ImplicitCtorDtorStmt( callStmt );
    181                 }
    182                 *out++ = callStmt;
    183     }
     168                if ( stmts.size() == 1 ) {
     169                        Statement * callStmt = stmts.front();
     170                        if ( addCast ) {
     171                                // implicitly generated ctor/dtor calls should be wrapped
     172                                // so that later passes are aware they were generated.
     173                                // xxx - don't mark as an implicit ctor/dtor if obj is a bitfield,
     174                                // because this causes the address to be taken at codegen, which is illegal in C.
     175                                callStmt = new ImplicitCtorDtorStmt( callStmt );
     176                        }
     177                        *out++ = callStmt;
     178                }
    184179        }
    185180} // namespace SymTab
Note: See TracChangeset for help on using the changeset viewer.