Ignore:
Timestamp:
Nov 8, 2017, 5:43:33 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
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:
954908d
Parents:
78315272 (diff), e35f30a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.h

    r78315272 r3f7e12cb  
    1919#include <string>                 // for string
    2020
     21#include "CodeGen/OperatorTable.h"
    2122#include "Common/UniqueName.h"    // for UniqueName
    2223#include "InitTweak/InitTweak.h"  // for InitExpander
     
    4445        extern FunctionDecl * dereferenceOperator;
    4546
    46         // temporary
     47        // generate the type of an assignment function for paramType
    4748        FunctionType * genAssignType( Type * paramType );
     49
     50        // generate the type of a default constructor or destructor for paramType
     51        FunctionType * genDefaultType( Type * paramType );
     52
     53        // generate the type of a copy constructor for paramType
     54        FunctionType * genCopyType( Type * paramType );
    4855
    4956        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
     
    5461        /// optionally returns a statement which must be inserted prior to the containing loop, if there is one
    5562        template< typename OutputIterator >
    56         Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
     63        Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, bool addCast = false ) {
     64                bool isReferenceCtorDtor = false;
     65                if ( dynamic_cast< ReferenceType * >( type ) && CodeGen::isCtorDtor( fname ) ) {
     66                        // reference constructors are essentially application of the rebind operator.
     67                        // apply & to both arguments, do not need a cast
     68                        fname = "?=?";
     69                        dstParam = new AddressExpr( dstParam );
     70                        addCast = false;
     71                        isReferenceCtorDtor = true;
     72                }
     73
    5774                // want to be able to generate assignment, ctor, and dtor generically,
    5875                // so fname is either ?=?, ?{}, or ^?{}
    59                 UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
     76                UntypedExpr * fExpr = new UntypedExpr( new NameExpr( fname ) );
    6077
    6178                if ( addCast ) {
     
    7289                        dstParam = new CastExpr( dstParam, new ReferenceType( Type::Qualifiers(), castType ) );
    7390                }
    74                 fExpr->get_args().push_back( dstParam );
     91                fExpr->args.push_back( dstParam );
    7592
    7693                Statement * listInit = srcParam.buildListInit( fExpr );
    7794
    78                 std::list< Expression * > args = *++srcParam;
    79                 fExpr->get_args().splice( fExpr->get_args().end(), args );
     95                // fetch next set of arguments
     96                ++srcParam;
     97
     98                // return if adding reference fails - will happen on default constructor and destructor
     99                if ( isReferenceCtorDtor && ! srcParam.addReference() ) {
     100                        delete fExpr;
     101                        return listInit;
     102                }
     103
     104                std::list< Expression * > args = *srcParam;
     105                fExpr->args.splice( fExpr->args.end(), args );
    80106
    81107                *out++ = new ExprStmt( noLabels, fExpr );
     
    99125                        // generate: for ( int i = 0; i < N; ++i )
    100126                        begin = new ConstantExpr( Constant::from_int( 0 ) );
    101                         end = array->get_dimension()->clone();
     127                        end = array->dimension->clone();
    102128                        cmp = new NameExpr( "?<?" );
    103129                        update = new NameExpr( "++?" );
     
    105131                        // generate: for ( int i = N-1; i >= 0; --i )
    106132                        begin = new UntypedExpr( new NameExpr( "?-?" ) );
    107                         ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() );
    108                         ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) );
     133                        ((UntypedExpr*)begin)->args.push_back( array->dimension->clone() );
     134                        ((UntypedExpr*)begin)->args.push_back( new ConstantExpr( Constant::from_int( 1 ) ) );
    109135                        end = new ConstantExpr( Constant::from_int( 0 ) );
    110136                        cmp = new NameExpr( "?>=?" );
     
    115141
    116142                UntypedExpr *cond = new UntypedExpr( cmp );
    117                 cond->get_args().push_back( new VariableExpr( index ) );
    118                 cond->get_args().push_back( end );
     143                cond->args.push_back( new VariableExpr( index ) );
     144                cond->args.push_back( end );
    119145
    120146                UntypedExpr *inc = new UntypedExpr( update );
    121                 inc->get_args().push_back( new VariableExpr( index ) );
     147                inc->args.push_back( new VariableExpr( index ) );
    122148
    123149                UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
    124                 dstIndex->get_args().push_back( dstParam );
    125                 dstIndex->get_args().push_back( new VariableExpr( index ) );
     150                dstIndex->args.push_back( dstParam );
     151                dstIndex->args.push_back( new VariableExpr( index ) );
    126152                dstParam = dstIndex;
    127153
    128154                // srcParam must keep track of the array indices to build the
    129155                // source parameter and/or array list initializer
    130                 srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() );
     156                srcParam.addArrayIndex( new VariableExpr( index ), array->dimension->clone() );
    131157
    132158                // for stmt's body, eventually containing call
    133159                CompoundStmt * body = new CompoundStmt( noLabels );
    134                 Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
     160                Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->kids ), array->base, addCast, forward );
    135161
    136162                // block containing for stmt and index variable
    137163                std::list<Statement *> initList;
    138164                CompoundStmt * block = new CompoundStmt( noLabels );
    139                 block->get_kids().push_back( new DeclStmt( noLabels, index ) );
     165                block->push_back( new DeclStmt( noLabels, index ) );
    140166                if ( listInit ) block->get_kids().push_back( listInit );
    141                 block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
     167                block->push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
    142168
    143169                *out++ = block;
     
    145171
    146172        template< typename OutputIterator >
    147         Statement * genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
     173        Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
    148174                if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    149175                        genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
     
    159185        /// ImplicitCtorDtorStmt node.
    160186        template< typename OutputIterator >
    161         void genImplicitCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
     187        void genImplicitCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
    162188                ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl );
    163189                assert( obj );
     
    167193                bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) );
    168194                std::list< Statement * > stmts;
    169                 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward );
     195                genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward );
    170196
    171197                // 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
Note: See TracChangeset for help on using the changeset viewer.