ROSE  0.11.145.0
ExtractFunctionArguments.h
1 #pragma once
2 
3 // DQ (10/5/2014): This is more strict now that we include rose_config.h in the sage3basic.h.
4 // #include "rose.h"
5 #include "sage3basic.h"
6 
7 #include "functionEvaluationOrderTraversal.h"
8 
9 //class FunctionCallInfo;
10 
17 {
18 public:
19 
22  void NormalizeTree(SgNode* tree, bool doUnsafeNormalization = false);
23 
24  // returns a vector of newly introduced temporaries
25  std::vector<SgVariableDeclaration*> GetTemporariesIntroduced();
26 
27  /*
28  IsNormalized: Given a subtree, returns true if every argument of every function call is a trivial arguemnt.
29  */
30  bool IsNormalized(SgNode* tree);
31 
32  /*
33  IsNormalizable: Given a subtree, returns true if every argument of every function call is a either trivial arguemnt or
34  is present in a SAFE place from where lifting is possible.
35  */
36  bool IsNormalizable(SgNode* tree);
37 
38 
39 private:
40 
41  std::vector<SgVariableDeclaration*> temporariesIntroduced;
42  std::pair< std::vector<FunctionCallInfo>, std::vector<FunctionCallInfo> > functionCalls;
43 
48  bool FunctionArgumentNeedsNormalization(SgExpression* argument);
49 
52  bool FunctionArgsNeedNormalization(SgExprListExp* functionArgs);
53 
56  bool SubtreeNeedsNormalization(SgNode* top);
57 
60  void RewriteFunctionCallArguments(const FunctionCallInfo& functionCallInfo);
61 
64  void InsertStatement(SgStatement* newStatement, SgStatement* location, const FunctionCallInfo& insertionMode);
65 
66  bool FunctionArgumentCanBeNormalized(SgExpression* argument);
67 
68 
69  /* Given the expression which is the argument to a function call, returns true if that
70  expression is trivial. Trivial expressions are those which are simple variable references or constants.
71  */
72  bool IsFunctionArgumentTrivial(SgExpression* argument);
73 
74  /* Given a vector of function call sites returns true if every argument of every function call is a trivial expression
75  (IsFunctionArgumentTrivial). Such functions don't need to be normalized.
76  */
77  bool AreAllFunctionCallsTrivial(std::vector<FunctionCallInfo> functions);
78 
79  /* Given a vector of function call sites, returns true if every argument
80  at every function call site is either trivial (IsFunctionArgumentTrivial) or can be normalized (FunctionArgumentCanBeNormalized).
81  */
82  bool AreAllFunctionCallsNormalizable(std::vector<FunctionCallInfo> functions);
83 };
void NormalizeTree(SgNode *tree, bool doUnsafeNormalization=false)
Performs the function argument extraction on all function calls in the given subtree of the AST...
This class represents the concept of a C and C++ expression list.
This normalization makes sure each function call argument is a side-effect free expression of only on...
Stores a function call expression, along with associated information about its context.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code.
This class represents the base class for all IR nodes within Sage III.
Definition: Cxx_Grammar.h:9846
This class represents the notion of a statement.