Changeset 39f84a4 for src/SymTab


Ignore:
Timestamp:
Jul 29, 2016, 11:40:28 AM (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:
4d2434a
Parents:
29e8bf5
Message:

part-way through reorganizing ctor call generation so that it is more general

Location:
src/SymTab
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    r29e8bf5 r39f84a4  
    189189                }
    190190
     191                InitTweak::InitExpander srcParam( src );
     192
    191193                // assign to destination (and return value if generic)
    192194                UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
    193195                derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
    194196                Expression *dstselect = new MemberExpr( field, derefExpr );
    195                 genImplicitCall( src, dstselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
     197                genImplicitCall( srcParam, dstselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
    196198
    197199                if ( isGeneric && returnVal ) {
     
    199201                        derefRet->get_args().push_back( new VariableExpr( returnVal ) );
    200202                        Expression *retselect = new MemberExpr( field, derefRet );
    201                         genImplicitCall( src, retselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
     203                        genImplicitCall( srcParam, retselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
    202204                } // if
    203205        }
  • src/SymTab/Autogen.h

    r29e8bf5 r39f84a4  
    2222#include "SynTree/Declaration.h"
    2323#include "SynTree/Initializer.h"
     24#include "InitTweak/InitTweak.h"
    2425
    2526namespace SymTab {
     
    3637        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
    3738        template< typename OutputIterator >
    38         void genCall( Expression * srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward = true );
     39        void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward = true );
    3940
    4041        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types.
    4142        template< typename OutputIterator >
    42         void genScalarCall( Expression *srcParam, Expression *dstParam, const std::string & fname, OutputIterator out ) {
     43        void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out ) {
    4344                // want to be able to generate assignment, ctor, and dtor generically,
    4445                // so fname is either ?=?, ?{}, or ^?{}
     
    4849                fExpr->get_args().push_back( new AddressExpr( dstParam ) );
    4950
    50                 if ( srcParam ) {
     51    Statement * listInit = srcParam.buildListInit( fExpr );
     52    if ( listInit ) {
     53      *out++ = listInit;
     54    }
     55
     56    std::list< Expression * > args = *++srcParam;
     57    fExpr->get_args().splice( fExpr->get_args().end(), args );
     58/*              if ( srcParam ) {
     59                        // xxx -
     60                        // make srcParam more complicated
     61                        // if srcParam contains
    5162                        fExpr->get_args().push_back( srcParam );
    5263                }
    53 
     64*/
    5465                *out++ = new ExprStmt( noLabels, fExpr );
    5566        }
     
    5869        /// If forward is true, loop goes from 0 to N-1, else N-1 to 0
    5970        template< typename OutputIterator >
    60         void genArrayCall( Expression *srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool forward = true ) {
     71        void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool forward = true ) {
    6172                static UniqueName indexName( "_index" );
    6273
     
    100111                dstParam = dstIndex;
    101112
    102                 // srcParam is NULL for default ctor/dtor
    103                 if ( srcParam ) {
    104                         UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
    105                         srcIndex->get_args().push_back( srcParam );
    106                         srcIndex->get_args().push_back( new VariableExpr( index ) );
    107                         srcParam = srcIndex;
    108                 }
     113                // srcParam must keep track of the array indices to build the
     114                // source parameter and/or array list initializer
     115                srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() );
     116
     117                // if ( srcParam ) {
     118                //      UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
     119                //      srcIndex->get_args().push_back( srcParam );
     120                //      srcIndex->get_args().push_back( new VariableExpr( index ) );
     121                //      srcParam = srcIndex;
     122                // }
    109123
    110124                // for stmt's body, eventually containing call
     
    122136
    123137        template< typename OutputIterator >
    124         void genCall( Expression * srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward ) {
     138        void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool forward ) {
    125139                if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    126140                        genArrayCall( srcParam, dstParam, fname, out, at, forward );
     
    135149        /// ImplicitCtorDtorStmt node.
    136150        template< typename OutputIterator >
    137         void genImplicitCall( Expression * srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
     151        void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
    138152                ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl );
    139153                assert( obj );
Note: See TracChangeset for help on using the changeset viewer.