ROSE 0.11.145.147
sageFunctors.h
Go to the documentation of this file.
1
2#ifndef _SAGEFUNCTORS_H
3#define _SAGEFUNCTORS_H
4
11
12#include "sageInterface.h"
13#include "sageBuilder.h"
14
15// namespace sg // no longer used -> move to legacy for removal
16namespace legacy
17{
20 template <class SageNode>
21 static inline
22 SageNode* cloneNode(const SageNode* n)
23 {
24 if (!n) return 0;
25
27 }
28
31 static inline
32 void _append(SgExprListExp& container, SgExpression* elem)
33 {
34 SageInterface::appendExpression(&container, elem);
35 }
36
38 static inline
39 void _append(SgFunctionParameterList& container, SgInitializedName* elem)
40 {
41 SageInterface::appendArg(&container, elem);
42 }
43
46 {
47 explicit
49 : scope(the_scope)
50 {}
51
52 template <class ScopedSageNode>
53 void handle(ScopedSageNode* scopeElem) const
54 {
55 ROSE_ASSERT(scopeElem);
56
57 scopeElem->set_scope(&scope);
58 }
59
60 void operator()(SgStatement* scopeElem) const { handle(scopeElem); }
61 void operator()(SgInitializedName* scopeElem) const { handle(scopeElem); }
62
63 private:
64 SgScopeStatement& scope;
65 };
66
69 {
70 explicit
72 : scope(the_scope)
73 {}
74
75 SgVarRefExp* operator()(SgInitializedName* initName) const
76 {
77 return SageBuilder::buildVarRefExp(initName, &scope);
78 }
79
80 private:
81 SgScopeStatement& scope;
82 };
83
86 {
88 // DQ (3/25/2017): Remove to avoid Clang warning about unused private variable.
89 // : decl(declaration),
90 : scope(enclosing_scope)
91 {}
92
93 SgInitializedName* operator()(const SgInitializedName* orig) const
94 {
95 SgInitializer* copy_init = cloneNode(orig->get_initializer());
96 SgInitializedName* res = SageBuilder::buildInitializedName(orig->get_name(), orig->get_type(), copy_init);
97
98 res->set_scope(scope);
99
100 return res;
101 }
102
103 private:
104 // DQ (3/25/2017): Remove to avoid Clang warning about unused private variable.
105 // SgDeclarationStatement& decl;
106 SgScopeStatement* scope;
107 };
108
112 template <class SageSequenceContainer>
113 struct SageInserter : std::iterator<std::output_iterator_tag, void, void, void, void>
114 {
115 typedef SageSequenceContainer Container;
116
117 Container& container;
118
119 explicit
120 SageInserter(Container& cont)
121 : container(cont)
122 {}
123
124 // \todo SageElem should be derived form the container type
125 template <class SageElem>
126 SageInserter& operator=(SageElem* elem)
127 {
128 _append(container, elem);
129 return *this;
130 }
131
132 SageInserter& operator*() { return *this; }
133 SageInserter& operator++() { return *this; }
134 SageInserter& operator++(int) { return *this; }
135 };
136
139 template <class SageSequenceContainer>
141 sage_inserter(SageSequenceContainer& cont)
142 {
144 }
145}
146
147#endif /* _SAGEFUNCTORS_H */
This class represents the concept of a declaration statement.
This class represents the concept of a C and C++ expression list.
This class represents the notion of an expression. Expressions are derived from SgLocatedNodes,...
This class represents the concept of a declaration list.
This class represents the notion of a declared variable.
This class represents the notion of an initializer for a variable declaration or expression in a func...
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents the notion of a statement.
This class represents the variable refernece in expressions.
ROSE_DLL_API SgInitializedName * buildInitializedName(const SgName &name, SgType *type, SgInitializer *init=NULL)
Initialized names are tricky, their scope vary depending on context, so scope and symbol information ...
ROSE_DLL_API SgVarRefExp * buildVarRefExp(const SgName &name, SgScopeStatement *scope=NULL)
Build SgVarRefExp based on a variable's Sage name. It will lookup the name in the symbol table intern...
ROSE_DLL_API void appendExpression(SgExprListExp *, SgExpression *)
Append an expression to a SgExprListExp, set the parent pointer also.
NodeType * deepCopy(const NodeType *subtree)
A template function for deep copying a subtree. It is also used to create deepcopy functions with spe...
ROSE_DLL_API SgVariableSymbol * appendArg(SgFunctionParameterList *, SgInitializedName *)
Append an argument to SgFunctionParameterList, transparently set parent,scope, and symbols for argume...
SageInserter< SageSequenceContainer > sage_inserter(SageSequenceContainer &cont)
generates a SageInserter, adding elements at the end of a sequence
Functor copying an initialized name into a different scope.
Generic inserter for sage containers.
Functor setting the scope of a sage node to a specified (at Functor construction time) scope.
Functor building a variable reference from an initialized name.