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/InitTweak/InitTweak.cc

    r78315272 r3f7e12cb  
    1 #include <stddef.h>                // for NULL
    21#include <algorithm>               // for find, all_of
    32#include <cassert>                 // for assertf, assert, strict_dynamic_cast
     
    2322#include "SynTree/Type.h"          // for FunctionType, ArrayType, PointerType
    2423#include "SynTree/Visitor.h"       // for Visitor, maybeAccept
     24#include "Tuples/Tuples.h"         // for Tuples::isTtype
    2525
    2626class UntypedValofExpr;
     
    170170        }
    171171
     172        bool InitExpander::addReference() {
     173                bool added = false;
     174                for ( Expression *& expr : cur ) {
     175                        expr = new AddressExpr( expr );
     176                        added = true;
     177                }
     178                return added;
     179        }
     180
    172181        namespace {
    173182                /// given index i, dimension d, initializer init, and callExpr f, generates
     
    184193                        callExpr->get_args().splice( callExpr->get_args().end(), args );
    185194
    186                         *out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels, callExpr ), NULL );
     195                        *out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels, callExpr ), nullptr );
    187196
    188197                        UntypedExpr * increment = new UntypedExpr( new NameExpr( "++?" ) );
     
    250259        // To accomplish this, generate switch statement, consuming all of expander's elements
    251260        Statement * InitImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) {
    252                 if ( ! init ) return NULL;
     261                if ( ! init ) return nullptr;
    253262                CompoundStmt * block = new CompoundStmt( noLabels );
    254263                build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) );
    255264                if ( block->get_kids().empty() ) {
    256265                        delete block;
    257                         return NULL;
     266                        return nullptr;
    258267                } else {
    259                         init = NULL; // init was consumed in creating the list init
     268                        init = nullptr; // init was consumed in creating the list init
    260269                        return block;
    261270                }
    262271        }
    263272
    264         Statement * ExprImpl::buildListInit( __attribute((unused)) UntypedExpr * dst, __attribute((unused)) std::list< Expression * > & indices ) {
    265                 return NULL;
     273        Statement * ExprImpl::buildListInit( UntypedExpr *, std::list< Expression * > & ) {
     274                return nullptr;
    266275        }
    267276
     
    270279        }
    271280
    272         bool tryConstruct( ObjectDecl * objDecl ) {
     281        Type * getTypeofThis( FunctionType * ftype ) {
     282                assertf( ftype, "getTypeofThis: nullptr ftype" );
     283                ObjectDecl * thisParam = getParamThis( ftype );
     284                ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( thisParam->type );
     285                return refType->base;
     286        }
     287
     288        ObjectDecl * getParamThis( FunctionType * ftype ) {
     289                assertf( ftype, "getParamThis: nullptr ftype" );
     290                auto & params = ftype->parameters;
     291                assertf( ! params.empty(), "getParamThis: ftype with 0 parameters: %s", toString( ftype ).c_str() );
     292                return strict_dynamic_cast< ObjectDecl * >( params.front() );
     293        }
     294
     295        bool tryConstruct( DeclarationWithType * dwt ) {
     296                ObjectDecl * objDecl = dynamic_cast< ObjectDecl * >( dwt );
     297                if ( ! objDecl ) return false;
    273298                return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&
    274                         (objDecl->get_init() == NULL ||
    275                                 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() ))
    276                         && ! objDecl->get_storageClasses().is_extern;
     299                        (objDecl->get_init() == nullptr ||
     300                                ( objDecl->get_init() != nullptr && objDecl->get_init()->get_maybeConstructed() ))
     301                        && ! objDecl->get_storageClasses().is_extern
     302                        && isConstructable( objDecl->type );
     303        }
     304
     305        bool isConstructable( Type * type ) {
     306                return ! dynamic_cast< VarArgsType * >( type ) && ! dynamic_cast< ReferenceType * >( type ) && ! dynamic_cast< FunctionType * >( type ) && ! Tuples::isTtype( type );
    277307        }
    278308
     
    314344                collectCtorDtorCalls( stmt, matches );
    315345                assert( matches.size() <= 1 );
    316                 return matches.size() == 1 ? matches.front() : NULL;
     346                return matches.size() == 1 ? matches.front() : nullptr;
    317347        }
    318348
     
    332362                        assert( expr );
    333363                        if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) {
    334                                 return varExpr->get_var();
     364                                return varExpr->var;
    335365                        } else if ( MemberExpr * memberExpr = dynamic_cast< MemberExpr * >( expr ) ) {
    336                                 return memberExpr->get_member();
     366                                return memberExpr->member;
    337367                        } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
    338                                 return getCalledFunction( castExpr->get_arg() );
     368                                return getCalledFunction( castExpr->arg );
    339369                        } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( expr ) ) {
    340370                                return handleDerefCalledFunction( untypedExpr );
     
    342372                                return handleDerefCalledFunction( appExpr );
    343373                        } else if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {
    344                                 return getCalledFunction( addrExpr->get_arg() );
     374                                return getCalledFunction( addrExpr->arg );
     375                        } else if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( expr ) ) {
     376                                return getCalledFunction( commaExpr->arg2 );
    345377                        }
    346378                        return nullptr;
     
    359391        ApplicationExpr * isIntrinsicCallExpr( Expression * expr ) {
    360392                ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr );
    361                 if ( ! appExpr ) return NULL;
     393                if ( ! appExpr ) return nullptr;
    362394                DeclarationWithType * function = getCalledFunction( appExpr->get_function() );
    363395                assertf( function, "getCalledFunction returned nullptr: %s", toString( appExpr->get_function() ).c_str() );
    364396                // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor
    365397                // will call all member dtors, and some members may have a user defined dtor.
    366                 return function->get_linkage() == LinkageSpec::Intrinsic ? appExpr : NULL;
     398                return function->get_linkage() == LinkageSpec::Intrinsic ? appExpr : nullptr;
    367399        }
    368400
     
    482514                        return refType->get_base();
    483515                } else {
    484                         return NULL;
     516                        return nullptr;
    485517                }
    486518        }
     
    488520        Type * isPointerType( Type * type ) {
    489521                if ( getPointerBase( type ) ) return type;
    490                 else return NULL;
     522                else return nullptr;
    491523        }
    492524
     
    557589        FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname ) {
    558590                FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl );
    559                 if ( ! function ) return 0;
    560                 if ( function->get_name() != fname ) return 0;
    561                 FunctionType * ftype = function->get_functionType();
    562                 if ( ftype->get_parameters().size() != 2 ) return 0;
     591                if ( ! function ) return nullptr;
     592                if ( function->name != fname ) return nullptr;
     593                FunctionType * ftype = function->type;
     594                if ( ftype->parameters.size() != 2 ) return nullptr;
    563595
    564596                Type * t1 = getPointerBase( ftype->get_parameters().front()->get_type() );
    565                 Type * t2 = ftype->get_parameters().back()->get_type();
     597                Type * t2 = ftype->parameters.back()->get_type();
    566598                assert( t1 );
    567599
     
    583615        }
    584616        FunctionDecl * isDefaultConstructor( Declaration * decl ) {
    585                 if ( isConstructor( decl->get_name() ) ) {
     617                if ( isConstructor( decl->name ) ) {
    586618                        if ( FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ) ) {
    587                                 if ( func->get_functionType()->get_parameters().size() == 1 ) {
     619                                if ( func->type->parameters.size() == 1 ) {
    588620                                        return func;
    589621                                }
Note: See TracChangeset for help on using the changeset viewer.