Skip to content
Snippets Groups Projects
Commit 4ee61403 authored by Mick Jordan's avatar Mick Jordan
Browse files

properly handle isTaggedWith for RSyntaxNodes used a internal children; clean up fastr.syntaxtree

parent 4bd4fe2f
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,9 @@ import com.oracle.truffle.r.nodes.access.variables.NamedRNode;
import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.nodes.builtin.RBuiltinRootNode;
import com.oracle.truffle.r.nodes.builtin.base.DoCall;
import com.oracle.truffle.r.nodes.builtin.base.Lapply;
import com.oracle.truffle.r.nodes.builtin.base.Mapply;
import com.oracle.truffle.r.nodes.builtin.helpers.DebugHandling;
import com.oracle.truffle.r.nodes.builtin.helpers.TraceHandling;
import com.oracle.truffle.r.nodes.control.AbstractLoopNode;
......@@ -79,6 +82,7 @@ import com.oracle.truffle.r.runtime.data.RUnboundValue;
import com.oracle.truffle.r.runtime.data.model.RAbstractContainer;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.gnur.SEXPTYPE;
import com.oracle.truffle.r.runtime.nodes.InternalRSyntaxNodeChildren;
import com.oracle.truffle.r.runtime.nodes.RBaseNode;
import com.oracle.truffle.r.runtime.nodes.RCodeBuilder;
import com.oracle.truffle.r.runtime.nodes.RCodeBuilder.Argument;
......@@ -601,6 +605,12 @@ class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
}
public boolean isTaggedWith(Node node, Class<?> tag) {
if (!(node instanceof RSyntaxNode)) {
return false;
}
if (isInternalChild(node)) {
return false;
}
String className = tag.getSimpleName();
switch (className) {
case "CallTag":
......@@ -634,4 +644,15 @@ class RRuntimeASTAccessImpl implements RRuntimeASTAccess {
}
}
private static boolean isInternalChild(Node node) {
Node parent = node.getParent();
while (parent != null) {
if (parent instanceof InternalRSyntaxNodeChildren) {
return true;
}
parent = parent.getParent();
}
return false;
}
}
......@@ -39,7 +39,6 @@ import com.oracle.truffle.r.runtime.conn.StdConnections;
import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
import com.oracle.truffle.r.runtime.nodes.RBaseNode;
import com.oracle.truffle.r.runtime.nodes.RNode;
import com.oracle.truffle.r.runtime.nodes.RSyntaxCall;
import com.oracle.truffle.r.runtime.nodes.RSyntaxConstant;
......@@ -57,7 +56,7 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxVisitor;
* Only nodes that return {@code true} to {@link RSyntaxNode#isSyntax()} are processed. N.B. This
* will reach nodes that implement {@link RSyntaxNode} but are used in {@link RSyntaxNode#INTERNAL}
* mode</li>
* <li><b>syntaxnode</b>: Use the {@link RSyntaxNodeVisitor}. The main difference from mode
* <li><b>rsyntaxnode</b>: Use the {@link RSyntaxNodeVisitor}. The main difference from mode
* {@code node} is that the children of non-syntax nodes are not visited at all.</li>
* <li><b<syntaxelement</b>: Use the {@link RSyntaxVisitor} to visit the "logical" syntax tree.</li>
* </ol>
......@@ -66,7 +65,7 @@ import com.oracle.truffle.r.runtime.nodes.RSyntaxVisitor;
public abstract class FastRSyntaxTree extends RExternalBuiltinNode.Arg4 {
@Specialization
@TruffleBoundary
protected RNull printTree(RFunction function, byte printSourceLogical, RAbstractStringVector visitMode, byte printTagsLogical) {
protected RNull printTree(RFunction function, RAbstractStringVector visitMode, byte printSourceLogical, byte printTagsLogical) {
boolean printSource = RRuntime.fromLogical(printSourceLogical);
boolean printTags = RRuntime.fromLogical(printTagsLogical);
FunctionDefinitionNode root = (FunctionDefinitionNode) function.getTarget().getRootNode();
......@@ -76,19 +75,18 @@ public abstract class FastRSyntaxTree extends RExternalBuiltinNode.Arg4 {
@Override
public boolean visit(Node node) {
if (RBaseNode.isRSyntaxNode(node)) {
writeString(node.getClass().getSimpleName(), false);
SourceSection ss = node.getSourceSection();
processSourceSection(ss, printSource, printTags);
printnl();
}
int depth = nodeDepth(node);
printIndent(depth);
writeString(node.getClass().getSimpleName(), false);
processNode(node, printSource, printTags);
printnl();
return true;
}
});
break;
case "syntaxnode":
case "rsyntaxnode":
RSyntaxNode.accept(root, 0, new RSyntaxNodeVisitor() {
@Override
......@@ -110,7 +108,7 @@ public abstract class FastRSyntaxTree extends RExternalBuiltinNode.Arg4 {
protected Void visit(RSyntaxCall element) {
printIndent(depth);
writeString(element.getClass().getSimpleName(), false);
processSourceSection(element.getSourceSection(), printSource, printTags);
processSourceSection(element.getSourceSection(), printSource);
printnl();
RSyntaxElement lhs = element.getSyntaxLHS();
RSyntaxElement[] arguments = element.getSyntaxArguments();
......@@ -127,7 +125,7 @@ public abstract class FastRSyntaxTree extends RExternalBuiltinNode.Arg4 {
protected Void visit(RSyntaxConstant element) {
printIndent(depth);
writeString(element.getClass().getSimpleName(), false);
processSourceSection(element.getSourceSection(), printSource, printTags);
processSourceSection(element.getSourceSection(), printSource);
printnl();
return null;
}
......@@ -144,7 +142,7 @@ public abstract class FastRSyntaxTree extends RExternalBuiltinNode.Arg4 {
protected Void visit(RSyntaxFunction element) {
printIndent(depth);
writeString(element.getClass().getSimpleName(), false);
processSourceSection(element.getSourceSection(), printSource, printTags);
processSourceSection(element.getSourceSection(), printSource);
printnl();
depth++;
accept(element.getSyntaxBody());
......@@ -160,6 +158,16 @@ public abstract class FastRSyntaxTree extends RExternalBuiltinNode.Arg4 {
return RNull.instance;
}
private static int nodeDepth(Node node) {
int result = 0;
Node parent = node.getParent();
while (parent != null) {
result++;
parent = parent.getParent();
}
return result;
}
@SuppressWarnings("unused")
@Fallback
protected Object fallback(Object a1, Object a2, Object a3, Object a4) {
......@@ -174,21 +182,21 @@ public abstract class FastRSyntaxTree extends RExternalBuiltinNode.Arg4 {
private static void processRSyntaxNode(RSyntaxNode node, boolean printSource, boolean printTags) {
SourceSection ss = node.getSourceSection();
if (ss == null) {
writeString(" *** null source section", false);
} else {
if (printSource) {
printSourceCode(ss);
}
if (printTags) {
if (node instanceof RNode) {
printTags(node.asRNode());
}
processSourceSection(ss, printSource);
if (printTags) {
if (node instanceof RNode) {
printTags(node.asRNode());
}
}
}
private static void processSourceSection(SourceSection ss, boolean printSource, @SuppressWarnings("unused") boolean printTags) {
private static void processNode(Node node, boolean printSource, @SuppressWarnings("unused") boolean printTags) {
if (node instanceof RSyntaxNode) {
processRSyntaxNode((RSyntaxNode) node, printSource, printTags);
}
}
private static void processSourceSection(SourceSection ss, boolean printSource) {
// All syntax nodes should have source sections
if (ss == null) {
writeString(" *** null source section", false);
......
......@@ -41,8 +41,8 @@ fastr.compile <- function(func, background=TRUE) .FastR(.NAME="compile", func, b
fastr.dumptrees <- function(func, igvDump=FALSE, verbose=FALSE) .FastR(.NAME="dumptrees", func, igvDump, verbose)
fastr.syntaxtree <- function(func, printSource=FALSE, visitMode=c("node", "syntaxnode", "syntaxelement"), printTags=FALSE) {
invisible(.FastR(.NAME="syntaxtree", func, printSource, match.arg(visitMode), printTags))
fastr.syntaxtree <- function(func, visitMode=c("rsyntaxnode", "syntaxelement", "node"), printSource=FALSE, printTags=FALSE) {
invisible(.FastR(.NAME="syntaxtree", func, match.arg(visitMode), printSource, printTags))
}
fastr.tree <- function(func, verbose=FALSE) invisible(.FastR(.NAME="tree", func, verbose))
......
......@@ -72,11 +72,12 @@ import com.oracle.truffle.r.runtime.data.RStringVector;
import com.oracle.truffle.r.runtime.data.RSymbol;
import com.oracle.truffle.r.runtime.data.model.RAbstractStringVector;
import com.oracle.truffle.r.runtime.env.REnvironment;
import com.oracle.truffle.r.runtime.nodes.InternalRSyntaxNodeChildren;
import com.oracle.truffle.r.runtime.nodes.RNode;
// TODO Implement properly, this is a simple implementation that works when the environment doesn't matter
@RBuiltin(name = "do.call", kind = INTERNAL, parameterNames = {"what", "args", "envir"})
public abstract class DoCall extends RBuiltinNode {
public abstract class DoCall extends RBuiltinNode implements InternalRSyntaxNodeChildren {
@Child private CallInlineCacheNode callCache = CallInlineCacheNodeGen.create();
@Child private GetFunctions.Get getNode;
......
......@@ -46,6 +46,7 @@ import com.oracle.truffle.r.runtime.data.RFunction;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RPromise;
import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
import com.oracle.truffle.r.runtime.nodes.InternalRSyntaxNodeChildren;
import com.oracle.truffle.r.runtime.nodes.RNode;
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
......@@ -73,7 +74,7 @@ public abstract class Lapply extends RBuiltinNode {
}
@NodeChildren({@NodeChild(type = RNode.class), @NodeChild(type = RNode.class), @NodeChild(type = RNode.class)})
protected abstract static class LapplyInternalNode extends RNode {
public abstract static class LapplyInternalNode extends RNode implements InternalRSyntaxNodeChildren {
private static final String INDEX_NAME = AnonymousFrameVariable.create("LAPPLY_ITER_INDEX");
private static final String VECTOR_ELEMENT = AnonymousFrameVariable.create("LAPPLY_VEC_ELEM");
......
......@@ -52,6 +52,7 @@ import com.oracle.truffle.r.runtime.data.RList;
import com.oracle.truffle.r.runtime.data.RLogicalVector;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.model.RAbstractContainer;
import com.oracle.truffle.r.runtime.nodes.InternalRSyntaxNodeChildren;
import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
/**
......@@ -95,7 +96,7 @@ public abstract class Mapply extends RBuiltinNode {
return mApply(frame, fun, dots, RDataFactory.createList());
}
protected abstract static class MapplyInternalNode extends Node {
public abstract static class MapplyInternalNode extends Node implements InternalRSyntaxNodeChildren {
private static final String VECTOR_ELEMENT_PREFIX = "MAPPLY_VEC_ELEM_";
private static final RLogicalVector DROP = RDataFactory.createLogicalVectorFromScalar(true);
......
/*
* Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.r.runtime.nodes;
import com.oracle.truffle.api.nodes.Node;
/**
* A tagging interface denoting that an internal, i.e. no syntax {@link Node} uses
* {@link RSyntaxNode}s in its children.
*/
public interface InternalRSyntaxNodeChildren {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment