changeset 18762:0ef23ff7d5a1

SL: make lookup of NodeInfo annotation more rebust.
author Christian Humer <christian.humer@gmail.com>
date Mon, 29 Dec 2014 23:38:59 +0100
parents a665483c3881
children 301fea50e42e
files graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Mon Dec 29 23:38:54 2014 +0100
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Mon Dec 29 23:38:59 2014 +0100
@@ -244,8 +244,11 @@
             }
         }
         result.append(": operation");
-        if (ex.getNode() != null && ex.getNode().getClass().getAnnotation(NodeInfo.class) != null) {
-            result.append(" \"").append(ex.getNode().getClass().getAnnotation(NodeInfo.class).shortName()).append("\"");
+        if (ex.getNode() != null) {
+            NodeInfo nodeInfo = SLContext.lookupNodeInfo(ex.getNode().getClass());
+            if (nodeInfo != null) {
+                result.append(" \"").append(nodeInfo.shortName()).append("\"");
+            }
         }
         result.append(" not defined for");
 
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java	Mon Dec 29 23:38:54 2014 +0100
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java	Mon Dec 29 23:38:59 2014 +0100
@@ -126,7 +126,7 @@
         /* Instantiate the builtin node. This node performs the actual functionality. */
         SLBuiltinNode builtinBodyNode = factory.createNode(argumentNodes, this);
         /* The name of the builtin function is specified via an annotation on the node class. */
-        String name = builtinBodyNode.getClass().getAnnotation(NodeInfo.class).shortName();
+        String name = lookupNodeInfo(builtinBodyNode.getClass()).shortName();
         /* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */
         SLRootNode rootNode = new SLRootNode(this, new FrameDescriptor(), builtinBodyNode, name);
 
@@ -134,6 +134,18 @@
         getFunctionRegistry().register(name, rootNode);
     }
 
+    public static NodeInfo lookupNodeInfo(Class<?> clazz) {
+        if (clazz == null) {
+            return null;
+        }
+        NodeInfo info = clazz.getAnnotation(NodeInfo.class);
+        if (info != null) {
+            return info;
+        } else {
+            return lookupNodeInfo(clazz.getSuperclass());
+        }
+    }
+
     /**
      * This function will parse the given source code, parse the code using the {@link Parser}, and
      * then execute the function named main. To use this method with instrumentation,