<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to INodeAdapter</title><link>https://sourceforge.net/p/jburg/wiki/INodeAdapter/</link><description>Recent changes to INodeAdapter</description><atom:link href="https://sourceforge.net/p/jburg/wiki/INodeAdapter/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 20 Mar 2013 00:00:02 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/jburg/wiki/INodeAdapter/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage INodeAdapter modified by Tom Harwood</title><link>https://sourceforge.net/p/jburg/wiki/INodeAdapter/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -1,4 +1,5 @@
 # Building a Custom `INodeAdapter`
+[TOC]

 An `INodeAdapter` implementation allows JBurg to work with your AST/i-node class.
 The logic in JBurg's core works with an abstract i-node model; the INodeAdapter
@@ -76,7 +77,7 @@
         return emitter.genCallMethod("SemanticUtils", "getChildCount", new String[] { node_path } );
     }

-[Falcon IASNodeAdapter](http://svn.apache.org/viewvc/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/IASNodeAdapter.java?view=markup)
+* See: [Falcon IASNodeAdapter](http://svn.apache.org/viewvc/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/IASNodeAdapter.java?view=markup)

 ## INodeAdapter2

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tom Harwood</dc:creator><pubDate>Wed, 20 Mar 2013 00:00:02 -0000</pubDate><guid>https://sourceforge.net7b84a269cd2e58e0f0a822f3d8c5a35441bac704</guid></item><item><title>WikiPage INodeAdapter modified by Tom Harwood</title><link>https://sourceforge.net/p/jburg/wiki/INodeAdapter/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="building-a-custom-inodeadapter"&gt;Building a Custom &lt;code&gt;INodeAdapter&lt;/code&gt;&lt;/h1&gt;
&lt;p&gt;An &lt;code&gt;INodeAdapter&lt;/code&gt; implementation allows JBurg to work with your AST/i-node class.&lt;br /&gt;
The logic in JBurg's core works with an abstract i-node model; the INodeAdapter&lt;br /&gt;
translates that abstract model into platform-specific code that calls the correct&lt;br /&gt;
methods, or accesses the correct fields, in your i-node class.&lt;/p&gt;
&lt;h2 id="inodeadapter-examples"&gt;&lt;code&gt;INodeAdapter&lt;/code&gt; examples&lt;/h2&gt;
&lt;h3 id="antlr3javaadapter"&gt;&lt;code&gt;Antlr3JavaAdapter&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The JBurg distribution includes several &lt;code&gt;INodeAdapter&lt;/code&gt; implementations. The &lt;code&gt;Antlr3JavaAdapter&lt;/code&gt; implementation is shown below.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;br /&gt;
package jburg.burg.inode;&lt;/p&gt;
&lt;p&gt;/*&lt;em&gt;&lt;br /&gt;
 * The Antlr3JavaAdapter is called by the JBurg code generator as it&lt;br /&gt;
 * generates the BURM; the adapter translates implementation and target&lt;br /&gt;
 * agnostic operations into code snippets appropriate for the ANTLR3&lt;br /&gt;
 * Tree class.&lt;br /&gt;
&lt;/em&gt;/&lt;br /&gt;
public class Antlr3JavaAdapter implements InodeAdapter {&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="cm"&gt;/**  The fully qualified name of the AST. */&lt;/span&gt;
&lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;s_iNodeType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;org.antlr.runtime.tree.Tree&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; * Is this the correct INodeAdapter for the INodeType in the specification?&lt;/span&gt;
&lt;span class="cm"&gt; * @param iNodeClass the qualified name of the AST/inode class being processed.&lt;/span&gt;
&lt;span class="cm"&gt; * @return true if iNodeClass matches the ANTLR3 class name.&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;accept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;iNodeClass&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;iNodeClass&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s_iNodeType&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; * Generate a call to get the number of children a node has (its arity).&lt;/span&gt;
&lt;span class="cm"&gt; * @param node an expression that will generate a path to the node.&lt;/span&gt;
&lt;span class="cm"&gt; * @param emitter the target-specific code emitter.&lt;/span&gt;
&lt;span class="cm"&gt; * @return a code snippet that calls node.getChildCount()&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;genGetArity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jburg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmitLang&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;genCallMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;getChildCount&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; * Generate a call to get the n'th child of a node.&lt;/span&gt;
&lt;span class="cm"&gt; * @param node an expression that will generate a path to the node.&lt;/span&gt;
&lt;span class="cm"&gt; * @param index an expression that computes the index of the desired child.&lt;/span&gt;
&lt;span class="cm"&gt; * @param emitter the target-specific code emitter.&lt;/span&gt;
&lt;span class="cm"&gt; * @return a code snippet that calls node.getChild(index)&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;genGetNthChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jburg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmitLang&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;genCallMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;getChild&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;span class="cm"&gt; * Generate a call to get the operator (the type) of a node.&lt;/span&gt;
&lt;span class="cm"&gt; * @param node an expression that will generate a path to the node.&lt;/span&gt;
&lt;span class="cm"&gt; * @param emitter the target-specific code emitter.&lt;/span&gt;
&lt;span class="cm"&gt; * @return a code snippet that calls node.getType()&lt;/span&gt;
&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;genGetOperator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;jburg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EmitLang&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;genCallMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;getType&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;}&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h3 id="falcons-iasnodeadapter"&gt;Falcon's &lt;code&gt;IASNodeAdapter&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Falcon's AST is quite complex, and the logic to access it is contained in static methods of Falcon's &lt;code&gt;SemanticUtils&lt;/code&gt; utility class.  This &lt;code&gt;INodeAdapter&lt;/code&gt; generates calls to the static methods and passes in the node path:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;genGetArity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;node_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;EmitLang&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;emitter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;genCallMethod&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&amp;quot;&lt;span class="n"&gt;SemanticUtils&lt;/span&gt;&amp;quot;&lt;span class="p"&gt;,&lt;/span&gt; &amp;quot;&lt;span class="n"&gt;getChildCount&lt;/span&gt;&amp;quot;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;node_path&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;a class="" href="http://svn.apache.org/viewvc/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/IASNodeAdapter.java?view=markup"&gt;Falcon IASNodeAdapter&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="inodeadapter2"&gt;INodeAdapter2&lt;/h2&gt;
&lt;p&gt;INodeAdapter2 has proved not as useful as hoped; in situations where the tree shape is so complex that a simple method call cannot return the correct result, we recommend using a static method and passing in the node path, as Falcon does. The resulting Java code is more maintainable than complex snippets generated on the fly.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tom Harwood</dc:creator><pubDate>Tue, 19 Mar 2013 23:59:17 -0000</pubDate><guid>https://sourceforge.net28841fbc6030f7a374e61b4febe48528726ae5ea</guid></item></channel></rss>