changeset 15775:4293efaaab76

Add description and language to the NodeInfo annotation
author Christian Wirth <christian.wirth@oracle.com>
date Mon, 19 May 2014 18:52:39 +0200
parents 402a74c6bc14
children 111bf82514ca
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ast/CodeElement.java
diffstat 3 files changed, 48 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Mon May 19 17:21:35 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Mon May 19 18:52:39 2014 +0200
@@ -506,4 +506,31 @@
             throw new RuntimeException(e);
         }
     }
+
+    /**
+     * Returns a user-readable description of the purpose of the Node, or "" if no description is
+     * available.
+     */
+    public String getDescription() {
+        NodeInfo info = getClass().getAnnotation(NodeInfo.class);
+        if (info != null) {
+            return info.description();
+        }
+        return "";
+    }
+
+    /**
+     * Returns a string representing the language this node has been implemented for. If the
+     * language is unknown, returns "".
+     */
+    public String getLanguage() {
+        NodeInfo info = getClass().getAnnotation(NodeInfo.class);
+        if (info != null && info.language() != null && info.language().length() > 0) {
+            return info.language();
+        }
+        if (parent != null) {
+            return parent.getLanguage();
+        }
+        return "";
+    }
 }
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java	Mon May 19 17:21:35 2014 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeInfo.java	Mon May 19 18:52:39 2014 +0200
@@ -35,7 +35,7 @@
 
     /**
      * Short name representing the node that can be used for debugging.
-     * 
+     *
      * @return the short name
      */
     String shortName() default "";
@@ -43,10 +43,26 @@
     /**
      * Provides a rough estimate for the cost of the annotated {@link Node}. This estimate can be
      * used by runtime systems or guest languages to implement heuristics based on Truffle ASTs.
-     * 
+     *
      * @see Node#getCost()
      * @see NodeCost
      */
     NodeCost cost() default NodeCost.MONOMORPHIC;
 
+    /**
+     * A human readable explanation of the purpose of the annotated {@link Node}. Can be used e.g.
+     * for debugging or visualization purposes.
+     *
+     * @return the description
+     */
+    String description() default "";
+
+    /**
+     * A description, providing a user-readable explanation of the source language of the annotated
+     * {@link Node}. Can be used e.g. for debugging or visualization purposes. Typically this
+     * information is set only in an abstract base node for the language implementation.
+     *
+     * @return the description
+     */
+    String language() default "";
 }
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ast/CodeElement.java	Mon May 19 17:21:35 2014 +0200
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ast/CodeElement.java	Mon May 19 18:52:39 2014 +0200
@@ -112,7 +112,7 @@
 
     /**
      * Support JDK8 langtools.
-     * 
+     *
      * @param annotationType
      */
     public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
@@ -121,7 +121,7 @@
 
     /**
      * Support for some JDK8 builds. (remove after jdk8 is released)
-     * 
+     *
      * @param annotationType
      */
     public <A extends Annotation> A[] getAnnotations(Class<A> annotationType) {
@@ -130,7 +130,7 @@
 
     /**
      * Support for some JDK8 builds. (remove after jdk8 is released)
-     * 
+     *
      * @param annotationType
      */
     public <A extends Annotation> A getAnnotation(Class<A> annotationType) {