@Override @TruffleBoundary protected void printValue(RAbstractListVector s, PrintContext printCtx) throws IOException { RAbstractIntVector dims = Utils.<RAbstractIntVector>castTo(s.getAttr(RRuntime.DIM_ATTR_KEY)); if (dims != null && dims.getLength() > 1) { printDimList(s, printCtx); } else { // no dim() printNoDimList(s, printCtx); } }
@TruffleBoundary static void printNoDimList(RAbstractContainer s, PrintContext printCtx) throws IOException { final PrintParameters pp = printCtx.parameters(); final PrintWriter out = printCtx.output(); final StringBuilder tagbuf = printCtx.getOrCreateTagBuffer(); // save the original length so that we can restore the original value int taglen = tagbuf.length(); int ns = s.getLength(); RAbstractStringVector names; names = Utils.castTo(RRuntime.asAbstractVector(s.getNames(dummyAttrProfiles))); if (ns > 0) { int npr = (ns <= pp.getMax() + 1) ? ns : pp.getMax(); /* '...max +1' ==> will omit at least 2 ==> plural in msg below */ for (int i = 0; i < npr; i++) { if (i > 0) { out.println(); } String ss = names == null ? null : Utils.<String>getDataAt(names, i); if (ss != null && !ss.isEmpty()) { /* * Bug for L <- list(`a\\b` = 1, `a\\c` = 2) : const char *ss = * translateChar(STRING_ELT(names, i)); */ if (taglen + ss.length() > TAGBUFLEN) { if (taglen <= TAGBUFLEN) { tagbuf.append("$..."); } } else { /* * we need to distinguish character NA from "NA", which is a valid (if * non-syntactic) name */ if (ss == RRuntime.STRING_NA) { tagbuf.append("$<NA>"); } else if (RDeparse.isValidName(ss)) { tagbuf.append(String.format("$%s", ss)); } else { tagbuf.append(String.format("$`%s`", ss)); } } } else { if (taglen + indexWidth(i) > TAGBUFLEN) { if (taglen <= TAGBUFLEN) { tagbuf.append("$..."); } } else { tagbuf.append(String.format("[[%d]]", i + 1)); } } out.println(tagbuf); Object si = s.getDataAtAsObject(i); if (si instanceof RAttributable && ((RAttributable) si).isObject()) { RContext.getEngine().printResult(si); } else { ValuePrinters.INSTANCE.print(si, printCtx); ValuePrinters.printNewLine(printCtx); } tagbuf.setLength(taglen); // reset tag buffer to the original value } if (npr < ns) { out.printf("\n [ reached getOption(\"max.print\") -- omitted %d entries ]", ns - npr); } } else { /* ns = length(s) == 0 */ /* Formal classes are represented as empty lists */ String className = null; if (printCtx.printerNode().isObject(s) && printCtx.printerNode().isMethodDispatchOn()) { RAbstractStringVector klass = Utils.castTo(RRuntime.asAbstractVector(s.getAttr(RRuntime.CLASS_ATTR_KEY))); if (klass != null && klass.getLength() == 1) { String ss = klass.getDataAt(0); String str = snprintf(200, ".__C__%s", ss); Frame frame = com.oracle.truffle.r.runtime.Utils.getActualCurrentFrame(); if (ReadVariableNode.lookupAny(str, frame, false) != null) { className = ss; } } } if (className != null) { out.printf("An object of class \"%s\"", className); } else { if (names != null) { out.print("named "); } out.print("list()"); } } }