Skip to content

Commit 82a0fc2

Browse files
committed
logival value for string and double sequence
1 parent bde9b6c commit 82a0fc2

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

visualvm/heapviewer.truffle/src/org/graalvm/visualvm/heapviewer/truffle/lang/r/RDetailsProvider.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public class RDetailsProvider extends DetailsProvider.Basic {
5252
private static final String RCOMPLEX_VECTOR_FQN = "com.oracle.truffle.r.runtime.data.RComplexVector"; // NOI18N
5353
private static final String RINT_SEQUENCE_FQN = "com.oracle.truffle.r.runtime.data.RIntSequence"; // NOI18N
5454
private static final String RINT_SEQUENCE1_FQN = "com.oracle.truffle.r.runtime.data.RIntSeqVectorData"; // NOI18N
55+
private static final String RDOUBLE_SEQUENCE_FQN = "com.oracle.truffle.r.runtime.data.RDoubleSequence"; // NOI18N
56+
private static final String RDOUBLE_SEQUENCE1_FQN = "com.oracle.truffle.r.runtime.data.RDoubleSeqVectorData"; // NOI18N
57+
private static final String RSTRING_SEQUENCE_FQN = "com.oracle.truffle.r.runtime.data.RStringSequence"; // NOI18N
58+
private static final String RSTRING_SEQUENCE1_FQN = "com.oracle.truffle.r.runtime.data.RStringSeqVectorData"; // NOI18N
5559
private static final String REXPRESSION_FQN = "com.oracle.truffle.r.runtime.data.RExpression"; // NOI18N
5660
private static final String RWRAPPER_MASK = "com.oracle.truffle.r.runtime.data.RForeignWrapper+"; // NOI18N
5761
private static final String RSYMBOL_MASK = "com.oracle.truffle.r.runtime.data.RSymbol"; //NOI18N
@@ -67,8 +71,9 @@ public class RDetailsProvider extends DetailsProvider.Basic {
6771

6872
public RDetailsProvider() {
6973
super(RVECTOR_MASK, RABSTRACT_VECTOR_MASK, RSCALAR_VECTOR_MASK, RINT_SEQUENCE_FQN,
70-
RINT_SEQUENCE1_FQN, RWRAPPER_MASK, RSYMBOL_MASK, RFUNCTION_MASK,
71-
RS4OBJECT_MASK, RNULL_MASK, RENVIRONMENT_MASK, CHARSXPWRAPPER_FQN);
74+
RINT_SEQUENCE1_FQN, RDOUBLE_SEQUENCE_FQN, RDOUBLE_SEQUENCE1_FQN,
75+
RSTRING_SEQUENCE_FQN, RSTRING_SEQUENCE1_FQN, RWRAPPER_MASK, RSYMBOL_MASK,
76+
RFUNCTION_MASK, RS4OBJECT_MASK, RNULL_MASK, RENVIRONMENT_MASK, CHARSXPWRAPPER_FQN);
7277
}
7378

7479
public String getDetailsString(String className, Instance instance, Heap heap) {
@@ -164,18 +169,33 @@ public String getDetailsString(String className, Instance instance, Heap heap) {
164169
return getScalar(instance, heap);
165170
}
166171
if (RINT_SEQUENCE_FQN.equals(className) || RINT_SEQUENCE1_FQN.equals(className)) {
167-
Integer stride = (Integer) instance.getValueOfField("stride"); // NOI18N
168-
Integer start = (Integer) instance.getValueOfField("start"); // NOI18N
172+
String val = logicalValueForIntSeq(instance);
173+
if (val != null) {
174+
return val;
175+
}
176+
}
177+
if (RDOUBLE_SEQUENCE_FQN.equals(className) || RDOUBLE_SEQUENCE1_FQN.equals(className)) {
178+
Double stride = (Double) instance.getValueOfField("stride"); // NOI18N
179+
Double start = (Double) instance.getValueOfField("start"); // NOI18N
169180
Integer len = (Integer) instance.getValueOfField("length"); // NOI18N
170181

171182
if (stride != null && start != null & len != null) {
172183
int length = len.intValue();
173184
if (length == 0) { // empty vector
174-
return "[]";
185+
return "[]"; // NOI18N
175186
}
176-
if (stride.intValue() == 1) {
177-
int end = start.intValue() + length-1;
178-
return "["+start.intValue()+":"+end+"]";
187+
double end = start.doubleValue()+ (length-1) * stride.doubleValue();
188+
return "seq("+start+","+end+","+stride+")"; // NOI18N
189+
}
190+
}
191+
if (RSTRING_SEQUENCE_FQN.equals(className) || RSTRING_SEQUENCE1_FQN.equals(className)) {
192+
String val = logicalValueForIntSeq(instance);
193+
if (val != null) {
194+
String prefix = DetailsUtils.getInstanceFieldString(instance, "prefix", heap); // NOI18N
195+
String suffix = DetailsUtils.getInstanceFieldString(instance, "suffix", heap); // NOI18N
196+
197+
if (prefix != null && suffix != null) {
198+
return "paste0(\""+prefix+"\", "+val+", \""+suffix+"\")";
179199
}
180200
}
181201
}
@@ -217,6 +237,25 @@ public String getDetailsString(String className, Instance instance, Heap heap) {
217237
return null;
218238
}
219239

240+
private String logicalValueForIntSeq(Instance instance) {
241+
Integer stride = (Integer) instance.getValueOfField("stride"); // NOI18N
242+
Integer start = (Integer) instance.getValueOfField("start"); // NOI18N
243+
Integer len = (Integer) instance.getValueOfField("length"); // NOI18N
244+
245+
if (stride != null && start != null & len != null) {
246+
int length = len.intValue();
247+
if (length == 0) { // empty vector
248+
return "[]"; // NOI18N
249+
}
250+
int end = start.intValue() + (length-1) * stride.intValue();
251+
if (stride.intValue() == 1) {
252+
return "["+start.intValue()+":"+end+"]"; // NOI18N
253+
}
254+
return "seq("+start+","+end+","+stride+")"; // NOI18N
255+
}
256+
return null;
257+
}
258+
220259
private String getRClassName(Instance instance, Heap heap) {
221260
Instance attributesInst = (Instance) instance.getValueOfField("attributes"); // NOI18N
222261
if (attributesInst != null) {

0 commit comments

Comments
 (0)