Program Listing for File functionEvaluationOrderTraversal.h

Program Listing for File functionEvaluationOrderTraversal.h#

Return to documentation for file (src/midend/programTransformation/extractFunctionArgumentsNormalization/functionEvaluationOrderTraversal.h)

#pragma once

// DQ (10/5/2014): This is more strict now that we include rose_config.h in the sage3basic.h.
// #include "rose.h"
// rose.h and sage3basic.h should not be included in librose header files. [Robb P. Matzke 2014-10-15]
// #include "sage3basic.h"

struct FunctionCallInheritedAttribute
{
    SgNode* currentScope;

    SgStatement* lastStatement;

    enum
    {
        INSIDE_FOR_INIT, INSIDE_FOR_TEST, INSIDE_FOR_INCREMENT, INSIDE_WHILE_CONDITION,
        INSIDE_DO_WHILE_CONDITION, IN_SAFE_PLACE, INSIDE_CONDITIONAL_EXP_TRUE_ARM, INSIDE_CONDITIONAL_EXP_FALSE_ARM, INSIDE_SHORT_CIRCUIT_EXP_RHS
    }
    scopeStatus;

    FunctionCallInheritedAttribute() : currentScope(NULL), lastStatement(NULL), scopeStatus(IN_SAFE_PLACE) { }
};

struct FunctionCallInfo
{
    SgFunctionCallExp* functionCall;

    SgStatement* tempVarDeclarationLocation;

    enum InsertionMode
    {
        INSERT_BEFORE,
        APPEND_SCOPE,
        INVALID
    };

    InsertionMode tempVarDeclarationInsertionMode;

    FunctionCallInfo(SgFunctionCallExp * function) :
    functionCall(function),
    tempVarDeclarationLocation(NULL),
    tempVarDeclarationInsertionMode(INVALID) { }
};



class FunctionEvaluationOrderTraversal : public AstTopDownBottomUpProcessing<FunctionCallInheritedAttribute, bool>
{
public:
    static std::pair< std::vector<FunctionCallInfo>, std::vector<FunctionCallInfo> > GetFunctionCalls(SgNode* root);

    FunctionCallInheritedAttribute evaluateInheritedAttribute(SgNode* astNode, FunctionCallInheritedAttribute parentAttribute);

    bool evaluateSynthesizedAttribute(SgNode* astNode, FunctionCallInheritedAttribute parentAttribute, SynthesizedAttributesList);

    virtual bool IsFunctionCallSideEffectFree(SgFunctionCallExp* functionCall);

private:


    FunctionEvaluationOrderTraversal() { }

    std::vector<FunctionCallInfo> normalizableFunctionCalls;
    std::vector<FunctionCallInfo> nonNormalizableFunctionCalls;
};