Changeset 66f8528 for src/InitTweak


Ignore:
Timestamp:
Dec 15, 2016, 5:16:42 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
43385ca, f7ff3fb
Parents:
5802a4f (diff), 596f987b (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' into tuples

Conflicts:

src/ResolvExpr/CommonType.cc
src/tests/.expect/32/extension.txt
src/tests/.expect/32/gccExtensions.txt
src/tests/.expect/64/declarationSpecifier.txt
src/tests/.expect/64/extension.txt
src/tests/.expect/64/gccExtensions.txt
src/tests/.expect/castError.txt
src/tests/Makefile.am

Location:
src/InitTweak
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r5802a4f r66f8528  
    346346
    347347                        if ( VariableExpr * function = dynamic_cast< VariableExpr * > ( appExpr->get_function() ) ) {
    348                                 if ( function->get_var()->get_linkage() == LinkageSpec::Intrinsic ) {
     348                                if ( LinkageSpec::isBuiltin( function->get_var()->get_linkage() ) ) {
    349349                                        // optimization: don't need to copy construct in order to call intrinsic functions
    350350                                        return appExpr;
  • src/InitTweak/InitTweak.cc

    r5802a4f r66f8528  
    304304
    305305        namespace {
     306                DeclarationWithType * getCalledFunction( Expression * expr );
     307
     308                template<typename CallExpr>
     309                DeclarationWithType * handleDerefCalledFunction( CallExpr * expr ) {
     310                        // (*f)(x) => should get "f"
     311                        std::string name = getFunctionName( expr );
     312                        assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() );
     313                        assertf( ! expr->get_args().empty(), "Can't get called function from dereference with no arguments" );
     314                        return getCalledFunction( expr->get_args().front() );
     315                }
     316
    306317                DeclarationWithType * getCalledFunction( Expression * expr ) {
    307318                        assert( expr );
     
    312323                        } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
    313324                                return getCalledFunction( castExpr->get_arg() );
     325                        } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( expr ) ) {
     326                                return handleDerefCalledFunction( untypedExpr );
     327                        } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) {
     328                                return handleDerefCalledFunction( appExpr );
    314329                        }
    315330                        return nullptr;
     
    377392
    378393        namespace {
     394                std::string funcName( Expression * func );
     395
     396                template<typename CallExpr>
     397                std::string handleDerefName( CallExpr * expr ) {
     398                        // (*f)(x) => should get name "f"
     399                        std::string name = getFunctionName( expr );
     400                        assertf( name == "*?", "Unexpected untyped expression: %s", name.c_str() );
     401                        assertf( ! expr->get_args().empty(), "Can't get function name from dereference with no arguments" );
     402                        return funcName( expr->get_args().front() );
     403                }
     404
    379405                std::string funcName( Expression * func ) {
    380406                        if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( func ) ) {
     
    388414                        } else if ( UntypedMemberExpr * memberExpr = dynamic_cast< UntypedMemberExpr * > ( func ) ) {
    389415                                return funcName( memberExpr->get_member() );
     416                        } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( func ) ) {
     417                                return handleDerefName( untypedExpr );
     418                        } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( func ) ) {
     419                                return handleDerefName( appExpr );
    390420                        } else {
    391421                                assertf( false, "Unexpected expression type being called as a function in call expression" );
     
    395425
    396426        std::string getFunctionName( Expression * expr ) {
     427                // there's some unforunate overlap here with getCalledFunction. Ideally this would be able to use getCalledFunction and
     428                // return the name of the DeclarationWithType, but this needs to work for NameExpr and UntypedMemberExpr, where getCalledFunction
     429                // can't possibly do anything reasonable.
    397430                if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ) ) {
    398431                        return funcName( appExpr->get_function() );
Note: See TracChangeset for help on using the changeset viewer.