FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/r/RCntxt.cpp at master · pearsonca/rstudio · GitHub
pearsonca
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
r
/
RCntxt.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
223 lines (191 loc) · 5.65 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
r
/
RCntxt.cpp
Copy path
File metadata and controls
223 lines (191 loc) · 5.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* RCntxt.cpp
*
* Copyright (C) 2009-19 by RStudio, PBC
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
r/RCntxt.hpp
>
#
include
<
r/RExec.hpp
>
#
include
<
r/RIntCntxt.hpp
>
#
include
<
r/RCntxtUtils.hpp
>
#
include
<
r/RInterface.hpp
>
#
include
<
boost/make_shared.hpp
>
#
include
<
shared_core/Error.hpp
>
using
namespace
rstudio
::core
;
namespace
rstudio
{
namespace
r
{
namespace
context
{
RCntxt::RCntxt
()
{ }
//
constructs an RCntxt object from a raw RNTCXT* pointer; this is where the
//
we set up the appropriate interface pointer based on the R version
RCntxt::RCntxt
(
void
*rawCntxt)
{
if
(rawCntxt ==
nullptr
)
return
;
else
if
(
contextVersion
() == RVersion40)
pCntxt_ = boost::make_shared<RIntCntxt<
RCNTXT_40
> >(
static_cast
<
RCNTXT_40
*>(rawCntxt));
else
if
(
contextVersion
() == RVersion34)
pCntxt_ = boost::make_shared<RIntCntxt<
RCNTXT_34
> >(
static_cast
<
RCNTXT_34
*>(rawCntxt));
else
if
(
contextVersion
() == RVersion33)
pCntxt_ = boost::make_shared<RIntCntxt<
RCNTXT_33
> >(
static_cast
<
RCNTXT_33
*>(rawCntxt));
else
pCntxt_ = boost::make_shared<RIntCntxt<
RCNTXT_32
> >(
static_cast
<
RCNTXT_32
*>(rawCntxt));
}
Error
RCntxt::callSummary
(std::string* pCallSummary)
const
{
return
invokeFunctionOnCall
(
"
.rs.callSummary
"
, pCallSummary);
}
Error
RCntxt::functionName
(std::string* pFunctionName)
const
{
return
invokeFunctionOnCall
(
"
.rs.functionNameFromCall
"
, pFunctionName);
}
bool
RCntxt::isDebugHidden
()
const
{
SEXP
hideFlag =
r::sexp::getAttrib
(
callfun
(),
"
hideFromDebugger
"
);
return
TYPEOF
(hideFlag) !=
NILSXP
&&
r::sexp::asLogical
(hideFlag);
}
bool
RCntxt::isErrorHandler
()
const
{
SEXP
errFlag =
r::sexp::getAttrib
(
callfun
(),
"
errorHandlerType
"
);
return
TYPEOF
(errFlag) ==
INTSXP
;
}
bool
RCntxt::hasSourceRefs
()
const
{
SEXP
refs =
sourceRefs
();
return
refs &&
TYPEOF
(refs) !=
NILSXP
;
}
SEXP
RCntxt::sourceRefs
()
const
{
return
r::sexp::getAttrib
(
originalFunctionCall
(),
"
srcref
"
);
}
std::string
RCntxt::shinyFunctionLabel
()
const
{
std::string label;
SEXP
s =
r::sexp::getAttrib
(
originalFunctionCall
() ,
"
_rs_shinyDebugLabel
"
);
if
(s !=
nullptr
&&
TYPEOF
(s) !=
NILSXP
)
{
r::sexp::extract
(s, &label);
}
return
label;
}
//
enabling tracing on a function turns it into an S4 object with an 'original'
//
slot that includes the function's original contents. use this instead if
//
it's set up. (consider: is it safe to assume that S4 objects here are always
//
traced functions, or do we need to compare classes to be safe?)
SEXP
RCntxt::originalFunctionCall
()
const
{
SEXP
callObject =
callfun
();
if
(
Rf_isS4
(callObject))
{
callObject =
r::sexp::getAttrib
(callObject,
"
original
"
);
}
return
callObject;
}
Error
RCntxt::fileName
(std::string* pFileName)
const
{
//
skip over bytecode srcrefs
RCntxt context = *
this
;
SEXP
ref = context.
srcref
();
while
(ref &&
isByteCodeSrcRef
(ref))
{
context = context.
nextcontext
();
if
(context.
isNull
())
break
;
ref = context.
srcref
();
}
if
(ref &&
TYPEOF
(ref) !=
NILSXP
)
{
r::sexp::Protect protect;
SEXP
fileName;
Error error =
r::exec::RFunction
(
"
.rs.sourceFileFromRef
"
)
.
addParam
(ref)
.
call
(&fileName, &protect);
if
(error)
return
error;
return
r::sexp::extract
(fileName, pFileName,
true
);
}
else
{
//
If no source references, that's OK--just set an empty filename.
pFileName->
clear
();
return
Success
();
}
}
//
call objects can't be passed as primary values through our R interface
//
(early evaluation can be triggered) so we wrap them in an attribute attached
//
to a dummy value when we need to pass them through
Error
RCntxt::invokeFunctionOnCall
(
const
char
* rFunction,
std::string* pResult)
const
{
SEXP
result;
r::sexp::Protect protect;
SEXP
val =
r::sexp::create
(
"
_rs_callval
"
, &protect);
r::sexp::setAttrib
(val,
"
_rs_call
"
,
call
());
Error error =
r::exec::RFunction
(rFunction, val)
.
call
(&result, &protect);
if
(!error &&
r::sexp::length
(result) >
0
)
{
error =
r::sexp::extract
(result, pResult,
true
);
}
else
{
pResult->
clear
();
}
return
error;
}
bool
RCntxt::
operator
==(
const
RCntxt& other)
const
{
return
other.
pCntxt_
== pCntxt_;
}
RCntxt::iterator
RCntxt::begin
()
{
return
RCntxt::iterator
(
globalContext
());
}
RCntxt::iterator
RCntxt::end
()
{
return
RCntxt::iterator
(
RCntxt
());
}
bool
RCntxt::isNull
()
const
{
return
pCntxt_ ==
nullptr
;
}
SEXP
RCntxt::callfun
()
const
{
return
pCntxt_ ? pCntxt_->
callfun
() : R_NilValue;
}
int
RCntxt::callflag
()
const
{
return
pCntxt_ ? pCntxt_->
callflag
() :
0
;
}
SEXP
RCntxt::call
()
const
{
return
pCntxt_ ? pCntxt_->
call
() : R_NilValue;
}
SEXP
RCntxt::srcref
()
const
{
return
pCntxt_ ? pCntxt_->
srcref
() : R_NilValue;
}
SEXP
RCntxt::cloenv
()
const
{
return
pCntxt_ ? pCntxt_->
cloenv
() : R_NilValue;
}
RCntxt
RCntxt::nextcontext
()
const
{
return
pCntxt_ ? pCntxt_->
nextcontext
() :
RCntxt
(
nullptr
);
}
}
//
namespace context
}
//
namespace r
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL