ROSE
0.9.6a
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
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
16
{
19
template
<
class
SageNode>
20
static
inline
21
SageNode*
cloneNode
(
const
SageNode* n)
22
{
23
if
(!n)
return
0;
24
25
return
SageInterface::deepCopy
(n);
26
}
27
30
static
inline
31
void
_append
(
SgExprListExp
& container,
SgExpression
* elem)
32
{
33
SageInterface::appendExpression
(&container, elem);
34
}
35
37
static
inline
38
void
_append
(
SgFunctionParameterList
& container,
SgInitializedName
* elem)
39
{
40
SageInterface::appendArg
(&container, elem);
41
}
42
44
struct
ScopeSetter
45
{
46
explicit
47
ScopeSetter
(
SgScopeStatement
& the_scope)
48
:
scope
(the_scope)
49
{}
50
51
template
<
class
ScopedSageNode>
52
void
handle
(ScopedSageNode* scopeElem)
const
53
{
54
ROSE_ASSERT(scopeElem);
55
56
scopeElem->set_scope(&
scope
);
57
}
58
59
void
operator()
(
SgStatement
* scopeElem)
const
{
handle
(scopeElem); }
60
void
operator()
(
SgInitializedName
* scopeElem)
const
{
handle
(scopeElem); }
61
62
private
:
63
SgScopeStatement
&
scope
;
64
};
65
67
struct
VarRefBuilder
68
{
69
explicit
70
VarRefBuilder
(
SgScopeStatement
& the_scope)
71
:
scope
(the_scope)
72
{}
73
74
SgVarRefExp
*
operator()
(
SgInitializedName
* initName)
const
75
{
76
return
SageBuilder::buildVarRefExp
(initName, &
scope
);
77
}
78
79
private
:
80
SgScopeStatement
&
scope
;
81
};
82
84
struct
InitNameCloner
85
{
86
InitNameCloner
(
SgDeclarationStatement
& declaration,
SgScopeStatement
* enclosing_scope = 0)
87
:
decl
(declaration),
scope
(enclosing_scope)
88
{}
89
90
SgInitializedName
*
operator()
(
const
SgInitializedName
* orig)
const
91
{
92
SgInitializer
* copy_init =
cloneNode
(orig->
get_initializer
());
93
SgInitializedName
* res =
SageBuilder::buildInitializedName
(orig->
get_name
(), orig->
get_type
(), copy_init);
94
95
res->
set_scope
(
scope
);
96
97
return
res;
98
}
99
100
private
:
101
SgDeclarationStatement
&
decl
;
102
SgScopeStatement
*
scope
;
103
};
104
108
template
<
class
SageSequenceContainer>
109
struct
SageInserter
: std::iterator<std::output_iterator_tag, void, void, void, void>
110
{
111
typedef
SageSequenceContainer
Container
;
112
113
Container
&
container
;
114
115
explicit
116
SageInserter
(
Container
& cont)
117
:
container
(cont)
118
{}
119
120
// \todo SageElem should be derived form the container type
121
template
<
class
SageElem>
122
SageInserter
&
operator=
(SageElem* elem)
123
{
124
_append
(
container
, elem);
125
return
*
this
;
126
}
127
128
SageInserter
&
operator*
() {
return
*
this
; }
129
SageInserter
&
operator++
() {
return
*
this
; }
130
SageInserter
&
operator++
(
int
) {
return
*
this
; }
131
};
132
135
template
<
class
SageSequenceContainer>
136
SageInserter<SageSequenceContainer>
137
sage_inserter
(SageSequenceContainer& cont)
138
{
139
return
SageInserter<SageSequenceContainer>
(cont);
140
}
141
}
142
143
#endif
/* _SAGEFUNCTORS_H */
rose-edg4x
src
frontend
SageIII
sageInterface
sageFunctors.h
Generated on Mon May 5 2014 17:29:26 for ROSE by
1.8.4