You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2014/10/03 11:46:05 UTC
git commit: [flex-falcon] [refs/heads/falcon-antlr4] - - Continued
migrating the jbg to jburg 2.0 format
Repository: flex-falcon
Updated Branches:
refs/heads/falcon-antlr4 0e6389187 -> 1908d8ca2
- Continued migrating the jbg to jburg 2.0 format
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/1908d8ca
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/1908d8ca
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/1908d8ca
Branch: refs/heads/falcon-antlr4
Commit: 1908d8ca2a9820544398a681038be5db59736547
Parents: 0e63891
Author: cdutz <ch...@c-ware.de>
Authored: Fri Oct 3 11:45:38 2014 +0200
Committer: cdutz <ch...@c-ware.de>
Committed: Fri Oct 3 11:45:38 2014 +0200
----------------------------------------------------------------------
.../java/jburg/burg/AnnotationAccessor.java | 44 -
.../java/jburg/burg/JBurgPatternMatcher.java | 955 -------------------
compiler/src/main/java/jburg/burg/Multimap.java | 90 --
.../java/jburg/burg/inode/InodeAdapter.java | 30 -
.../java/jburg/burg/ir/FormalParameter.java | 42 -
.../main/java/jburg/burg/ir/GetNthChild.java | 22 -
.../src/main/java/jburg/emitter/EmitLang.java | 342 -------
.../as/codegen/ABCGeneratingReducer.java | 21 +-
.../internal/as/codegen/IASNodeAdapter.java | 73 --
.../compiler/internal/tree/as/NodeBase.java | 17 +
.../apache/flex/compiler/tree/as/IASNode.java | 17 +
.../compiler/internal/as/codegen/CmcEmitter.jbg | 2 +-
12 files changed, 45 insertions(+), 1610 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/jburg/burg/AnnotationAccessor.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/jburg/burg/AnnotationAccessor.java b/compiler/src/main/java/jburg/burg/AnnotationAccessor.java
deleted file mode 100644
index 2cec09f..0000000
--- a/compiler/src/main/java/jburg/burg/AnnotationAccessor.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package jburg.burg;
-
-/**
- * An AnnotationAccessor describes the get/set
- * sequences used by an i-node to manage its
- * JBurg annotation. Note that if not annotation
- * management sequences are specified, JBurg will
- * manage the annotations.
- */
-public class AnnotationAccessor
-{
- public final String getParameterName;
- public final String getAccessor;
- public final String setINodeName;
- public final String setParameterName;
- public final String setAccessor;
-
- public AnnotationAccessor(
- String getParameterName,
- String getAccessor,
- String setINodeName,
- String setParameterName,
- String setAccessor
- )
- {
- this.getParameterName = getParameterName;
- this.getAccessor = getAccessor;
- this.setINodeName = setINodeName;
- this.setParameterName = setParameterName;
- this.setAccessor = setAccessor;
- }
-
- public String toString()
- {
- return String.format(
- "AnnotationAccessor(%s,%s: %s\n%s: %s\n)",
- getParameterName,
- getAccessor,
- setINodeName,
- setAccessor
- );
-
- }
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/jburg/burg/JBurgPatternMatcher.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/jburg/burg/JBurgPatternMatcher.java b/compiler/src/main/java/jburg/burg/JBurgPatternMatcher.java
deleted file mode 100644
index aebed93..0000000
--- a/compiler/src/main/java/jburg/burg/JBurgPatternMatcher.java
+++ /dev/null
@@ -1,955 +0,0 @@
-package jburg.burg;
-
-import jburg.burg.inode.InodeAdapter;
-import jburg.burg.ir.GetNthChild;
-import jburg.emitter.EmitLang;
-
-import java.util.Comparator;
-import java.util.Vector;
-
-/**
- * JBurgPatternMatcher encodes a pattern match
- * recognizer for a subtree.
- */
-
-@SuppressWarnings("nls")
-public
-class JBurgPatternMatcher implements Comparable<JBurgPatternMatcher>
-{
- /**
- * The pattern's arity.
- * @warning only present for n-ary patterns;
- * Fixed-arity patterns get arity from the number
- * of sub-patterns.
- */
- private Arity arity = null;
-
- /**
- * A pattern that matches an operator,
- * i.e. a specific node type in the
- * matching subtree.
- */
- private String operator = null;
-
-
- /**
- * Subpatterns of this node.
- */
- private Vector<JBurgPatternMatcher> subPatterns = new Vector<JBurgPatternMatcher>();
-
- /**
- * A pattern node that matches any finite cost
- * for a particular goal state. This pattern
- * generates a subgoal.
- */
- private String finiteCostMatch = null;
-
- /**
- * Cost factored out by the pattern-match optimizer.
- */
- String factoredCost = null;
-
- /**
- * Path factored out by the pattern-match optimizer.
- */
- String factoredPath = null;
-
- /**
- * Parent of this node; used to traverse the tree
- * from a leaf back to the root.
- */
- private JBurgPatternMatcher parent = null;
-
- /**
- * This node's position in the parent's subpatterns vector.
- */
- Integer positionInParent = null;
-
- /**
- * The goal state of a non-terminal parameter to a parent pattern.
- * @see setParameterData(), which sets this when
- * the pattern-matching BURM sees a parameter declaration.
- */
- String paramState = null;
-
- /**
- * The name of a non-terminal parameter to a parent pattern.
- * @see setParameterData(), which sets this when
- * the pattern-matching BURM sees a parameter declaration.
- */
- String paramName = null;
-
- /**
- * A top-level patter matcher may have parameterized subtrees,
- * for example, in ADD(expr lhs, expr rhs) lhs and rhs are paramterized
- * subtrees. These subtrees play several parts in the computation of the
- * locally-optimal reduction:
- * - They contribute to the rule's computed cost.
- * - The reduction's action code may refer to these elements by name.
- * - If the rule is of the form OP(nttype1 a [, nttype2 b]), then the rule
- * must enforce this reduce-time goal state on its subtrees' reductions.
- */
- private Vector<JBurgPatternMatcher> parameterizedSubtrees;
-
- /**
- * Named subtrees that are not parameterized non-terminals;
- * record their names as a convenience so the reduction action
- * can refer to them by name.
- */
- private Vector<JBurgPatternMatcher> namedSubtrees;
-
- /**
- * The BURG sets this when it determines that this
- * pattern is in a context where its fixed-arity
- * checks can be elided.
- */
- private boolean elideFixedArityChecks = false;
-
- /**
- * Construct a pattern matching node.
- * @see factory methods that generate matcher nodes.
- */
- private JBurgPatternMatcher()
- {
- }
-
- /**
- * Construct a matcher that matches a specific operator.
- * @param pattern_op - the operator to match.
- * @return a pattern matcher that matches this operator.
- */
- public static JBurgPatternMatcher matchOperator(String pattern_op)
- {
- JBurgPatternMatcher result = new JBurgPatternMatcher();
- result.operator = pattern_op;
- return result;
- }
-
- /**
- * Construct a matcher that matches a subgoal that's present
- * at least a minimum number of times.
- * @param minimum - the minimum number of instances to accept.
- * almost always 1, may be zero.
- * @return a pattern matcher that matches the n-ary aggregation.
- */
- public static JBurgPatternMatcher matchOperandAtLeastNTimes(int minimum)
- {
- JBurgPatternMatcher result = new JBurgPatternMatcher();
- result.arity = new Arity(minimum);
- return result;
- }
-
- /**
- * Construct a matcher that matches when a subgoal has a finite
- * cost (i.e., when the labeler found a solution).
- * @param state - the subgoal's goal state.
- * @return a pattern matcher that matches when the reducer
- * can reduce the subgoal.
- */
- public static JBurgPatternMatcher matchFiniteCost( String state)
- {
- JBurgPatternMatcher result = new JBurgPatternMatcher();
- result.finiteCostMatch = state;
- return result;
- }
-
-
- /**
- * @return true if the pattern matches against an operator.
- */
- public boolean matchesOperator()
- {
- return null != this.operator;
- }
-
- /**
- * @return an operator-matching node's operator.
- */
- public String getOperator()
- {
- checkPrecondition ( matchesOperator(), "Node has no operator" );
- return this.operator;
- }
-
- /**
- * @return The minimum number of child nodes required to match this pattern.
- */
- public int getNominalArity()
- {
- if ( hasNaryTail() )
- {
- int arity_of_fixed_operands = this.subPatterns.size() - 1;
- return arity_of_fixed_operands + getMinimumNaryChildCount();
- }
- else
- {
- return this.subPatterns.size();
- }
- }
-
- /**
- * @return the minimum number of n-ary children required to match.
- */
- public int getMinimumNaryChildCount()
- {
- checkPrecondition( this.hasNaryTail(), "n-ary child count requires an n-ary pattern");
- return this.subPatterns.lastElement().arity.m_minimum;
- }
-
- /**
- * Add a child node.
- */
- void addChild( JBurgPatternMatcher child )
- {
- checkPrecondition ( ! this.hasNaryTail(), "Cannot add a subpattern after an n-ary subpattern.");
- checkPrecondition ( null == child.parent, "Child " + child.toString() + " already has a parent.");
-
- child.positionInParent = new Integer(this.subPatterns.size());
- child.parent = this;
- this.subPatterns.add(child);
- }
-
- /**
- * Assume ownership of a Vector of subpatterns.
- * @param patterns - this node's Vector of subpatterns.
- */
- public void addAll(Vector<JBurgPatternMatcher> patterns)
- {
- for ( JBurgPatternMatcher child: patterns)
- addChild(child);
- }
-
- /**
- * @return the pattern recognizer for this node and its children.
- * @param emitter - the code emitter to use to generate the path.
- * @param stem - the path generated by the parent (or external caller).
- */
- public Object generatePatternRecognizer( EmitLang emitter, String stem)
- {
- if ( finiteCostMatch != null || isNary() ) {
- // Costs are checked by a specialized routine.
- return null;
-
- } else {
- return generatePatternAndSubpatterns(emitter, stem);
- }
- }
-
- /**
- * @param emitter - the active code emitter.
- * @param stem - the a priori expression at the root of this node's path from root.
- * @return a snippet that gets the matched node's cost.
- */
- public Object generateCost( EmitLang emitter, String stem )
- {
- if ( factoredCost != null ) {
- return factoredCost;
-
- } else if ( finiteCostMatch != null ) {
- return generateGetFiniteCost(emitter, stem);
-
- } else if ( this.isNary() ) {
- return getNaryCost( emitter, stem );
-
- } else {
- // the node doesn't cost anything.
- return null;
- }
- }
-
- /**
- * @return true if the last sub-pattern is n-ary.
- */
- public boolean hasNaryTail()
- {
- return this.subPatterns.size() > 0 && this.subPatterns.lastElement().isNary();
- }
-
- /**
- * @param emitter - the active code emitter.
- * @param stem - the a priori expression at the root of this node's path from root.
- * @return a snippet that compares the candidate node to this matcher's constraints.
- */
- private Object generatePatternAndSubpatterns( EmitLang emitter, String stem)
- {
- checkPrecondition(operator != null, "Pattern node must have an operator");
-
- Object result_pattern = null;
-
- if ( this.hasNaryTail() ) {
-
- if ( this.getNominalArity() > 0 ) {
- result_pattern = emitter.genCmpGtEq(
- emitter.genCallMethod( generatePathToRoot(emitter, stem), "getArity"),
- Integer.toString(getNominalArity())
- );
- }
- } else {
- result_pattern = generateFixedArityCheck(emitter, stem);
- }
-
- // The check against opcode is redundant at the root;
- // that's just been tested as the switch expression.
- if ( !this.isRoot() ) {
- result_pattern =
- emitter.genLogicalAnd(
- result_pattern,
- generateOpCheck(emitter, stem)
- );
- }
-
- // AND in each pattern-matching child's recognizer.
- // Note: this could result in an arbitrarily deep
- // parenthetical structure, but in practice patterns
- // aren't nested very deeply.
- for ( JBurgPatternMatcher currentChild: this.subPatterns ) {
- result_pattern = emitter.genLogicalAnd(result_pattern, currentChild.generatePatternRecognizer(emitter, stem));
- }
-
- return result_pattern;
- }
-
- /**
- * @param emitter - the active code emitter.
- * @param stem - the a priori expression at the root of this node's path from root.
- * @return a snippet that calls the candidate node's getNaryCost() routine.
- */
- private Object getNaryCost(EmitLang emitter, String stem)
- {
- checkPrecondition(isNary(), "getNaryCost called on fixed-arity pattern");
-
- return emitter.genCallMethod(
- null,
- "getNaryCost",
- generatePathToRoot(emitter, stem),
- emitter.genGetGoalState(getSubgoal()),
- this.positionInParent.toString()
- );
- }
-
-
- /**
- * Generate a code snippet to access this pattern's node.
- * @param emitter - the active code emitter.
- * @param stem - the a priori name of the root node.
- * @return the path from the root node to this node.
- */
- public Object generatePathToRoot(EmitLang emitter, String stem)
- {
- Object result;
-
- if ( this.factoredPath != null ) {
- result = this.factoredPath;
-
- } else {
-
- // Build the path iteratively.
- result = stem;
-
- for ( PathElement idx: generateAccessPath() ) {
- result = emitter.genCallMethod(
- result,
- "getNthChild",
- Integer.toString(idx.index));
- }
- }
-
- return result;
- }
-
- /**
- * Generate the sequence of getNthChild calls necessary to access
- * the node that matched this pattern.
- * @return a Vector getNthChild indexes.
- */
- public Vector<PathElement> generateAccessPath()
- {
- if ( null == this.parent )
- {
- return new Vector<PathElement>();
- }
- else if ( this.isNary() )
- {
- checkPrecondition(this.parent != null, "N-ary node with no parent");
- return this.parent.generateAccessPath();
- }
- else
- {
- Vector<PathElement> path = parent.generateAccessPath();
- PathElement own_element = new PathElement(this.operator, this.paramState, this.positionInParent);
- path.add(own_element);
- return path;
- }
- }
-
- /**
- * Get the subgoal (non-terminal) state this pattern produces.
- * @return the subgoal state.
- */
- public String getSubgoal()
- {
- if ( this.isNary() )
- {
- checkPrecondition(this.paramState != null, "n-ary goal has no parameter state");
- return this.paramState;
- }
- else
- {
- checkPrecondition(finiteCostMatch != null, "pattern has no subgoal");
- return this.finiteCostMatch;
- }
- }
-
- /**
- * Is this an n-ary pattern?
- * @return true if this is an n-ary pattern.
- */
- public boolean isNary()
- {
- return this.arity != null;
- }
-
- /**
- * Wrap an isNary() call with standard naming conventions
- * so the StringTemplate renderer can find it.
- * @return true if this is a n-ary pattern.
- */
- public Object getIsNary()
- {
- return Boolean.valueOf(isNary());
- }
-
- /**
- * @return true if this pattern or any subpattern is n-ary.
- */
- public boolean hasNaryness()
- {
- boolean result = isNary();
-
- if ( this.subPatterns != null )
- {
- for ( JBurgPatternMatcher subpattern: this.subPatterns )
- result |= subpattern.hasNaryness();
- }
- return result;
- }
-
- /**
- * @param emitter - the active code emitter.
- * @param stem - the a priori expression at the root of this node's path from root.
- * @return a snippet that compares the candidate node's arity to this matcher's fixed arity,
- * or null if the arity has been checked here as a compiler-compile time constant.
- */
- private Object generateFixedArityCheck( EmitLang emitter, String stem)
- {
- if ( this.elideFixedArityChecks ) {
- return null;
- } else {
- // This calls the JBurgAnnotation's getArity() method,
- // indirectly calling the i-node's getArity implementation
- // Thus it's hardcoded.
-
- return emitter.genCmpEquality(
- emitter.genCallMethod(generatePathToRoot(emitter, stem), "getArity"),
- Integer.toString(getNominalArity()),
- EmitLang.TEST_EQUALITY
- );
- }
- }
-
- /**
- * @param emitter - the active code emitter.
- * @param stem - the a priori expression at the root of this node's path from root.
- * @return a snippet that compares the candidate node's operator to this matcher's specified operator.
- */
- private Object generateOpCheck( EmitLang codeEmitter, String stem )
- {
- return codeEmitter.genCmpEquality(
- codeEmitter.genCallMethod( generatePathToRoot(codeEmitter, stem), "getOperator"),
- operator,
- EmitLang.TEST_EQUALITY
- );
- }
-
- /**
- * @param emitter - the active code emitter.
- * @param stem - the a priori expression at the root of this node's path from root.
- * @return a call to the matched node's getCost() method.
- */
- private Object generateGetFiniteCost(EmitLang emitter, String stem)
- {
- return emitter.genCallMethod(
- generatePathToRoot(emitter, stem),
- "getCost",
- emitter.genGetGoalState(finiteCostMatch)
- );
- }
-
- /**
- * The BURM sees a parameterized subtree to a parent pattern, e.g.,
- * <xmp>operand = NON_TERMINAL_PARAMETER( simple_identifier state, simple_identifier paramName )</xmp>
- * @param param_state - the non-terminal state the subtree must derive.
- * @param param_name - the name to give to the reduced subtree result.
- */
- void setParameterData(String param_state, String param_name)
- {
- this.paramState = param_state;
- this.paramName = param_name;
- }
-
- /**
- * Get the name this parameterized subtree is to be given
- * in the parent pattern matcher's reduction action.
- * @return the name of this parameter.
- */
- public String getParameterName()
- {
- checkPrecondition(hasParameterName(), "no parameter name");
- return this.paramName;
- }
-
- /**
- * Does this pattern matcher have a parameter name?
- * @return true => the pattern is a parameter type matcher with a name.
- */
- public boolean hasParameterName()
- {
- return this.paramName != null;
- }
-
- /**
- * Get a pattern matcher's parameterized subtrees, e.g.
- * lhs and rhs in the pattern ADD(expr lhs, expr rhs).
- * @return this matcher's vector of subtrees.
- * @warn only top-level pattern matchers have these.
- */
- public Vector<JBurgPatternMatcher> getParameterizedSubtrees()
- {
- checkPrecondition (this.parameterizedSubtrees != null, "no parameterized subtrees");
- return this.parameterizedSubtrees;
- }
-
- /**
- * Set this pattern matcher's parameterized subtrees; the BURM harvests
- * these subtrees from the pattern matcher's AST and the BURM's caller
- * transfers them to the top-level pattern matcher.
- * @param subtrees - the subtrees identified by the BURM.
- */
- public void setParameterizedSubtrees(Vector<JBurgPatternMatcher> subtrees)
- {
- this.parameterizedSubtrees = subtrees;
- }
-
- /**
- * @return non-parameterized subtrees that were given names,
- * mostly embedded terminal nodes.
- */
- public Vector<JBurgPatternMatcher> getNamedSubtrees()
- {
- return this.namedSubtrees;
- }
-
- /**
- * Set a top-level pattern matcher's list of named subtrees.
- * @param named_subtrees - named subtrees identified by the BURM.
- */
- public void setNamedSubtrees(Vector<JBurgPatternMatcher> named_subtrees)
- {
- this.namedSubtrees = named_subtrees;
- }
-
- /**
- * Panic if the precondition isn't satisfied.
- * @param pre_condition - the condition that must be true.
- * @param diagnostic - detail message for the panic exception
- * @throws IllegalStateException if panic ensues.
- */
- private void checkPrecondition(boolean pre_condition, String diagnostic)
- {
- if ( !pre_condition )
- {
- System.err.println("!checkPrecondition(" + toString() + "): " + diagnostic );
- throw new IllegalStateException(diagnostic);
- }
- }
-
-
- @Override
- public String toString()
- {
- StringBuffer buffer = new StringBuffer();
- toStringHelper(buffer,0);
- return buffer.toString();
- }
-
- /**
- * Traverse a tree of pattern matchers and build
- * a string representation.
- * @param buffer - the StringBuffer used to build the result
- * @param level - recursion level, used to indent lines.
- */
- private void toStringHelper(StringBuffer buffer, int level)
- {
- for ( int i = 0; i < level; i++ )
- buffer.append(" ");
-
- if ( this.operator != null )
- buffer.append("opcode:" + this.operator + " ");
-
- if ( this.arity != null )
- buffer.append("Arity: " + this.arity.m_minimum + ":" + this.arity.m_maximum + " ");
-
- if ( finiteCostMatch != null )
- buffer.append("cost:" + finiteCostMatch + " ");
-
- for ( JBurgPatternMatcher matcher: this.subPatterns )
- {
- buffer.append("\n");
- matcher.toStringHelper(buffer, level+1);
- }
-
- buffer.append("\n");
-
- }
-
- /**
- * The minimum and maximum number of subtrees an n-ary pattern may match.
- */
- private static class Arity
- {
- int m_minimum;
- int m_maximum;
-
- Arity(int minimum)
- {
- m_minimum = minimum;
- m_maximum = Integer.MAX_VALUE;
- }
- }
-
- public static Comparator<JBurgPatternMatcher> getPatternComparator(final EmitLang e)
- {
- return new Comparator<JBurgPatternMatcher>()
- {
- EmitLang emitter;
- {
- this.emitter = e;
- }
- public int compare(JBurgPatternMatcher arg0, JBurgPatternMatcher arg1)
- {
- String path0 = arg0.generatePathToRoot(this.emitter, "node").toString();
- String path1 = arg1.generatePathToRoot(this.emitter, "node").toString();
-
- if (path0.compareTo(path1) != 0)
- return path0.compareTo(path1);
-
- if ( arg0.arity != null && arg1.arity != null ) {
- if ( arg0.arity.m_maximum - arg1.arity.m_maximum != 0 )
- return arg0.arity.m_maximum - arg1.arity.m_maximum;
- else if ( arg0.arity.m_minimum - arg1.arity.m_minimum != 0 )
- return arg0.arity.m_minimum - arg1.arity.m_minimum;
-
- } else if ( arg0.arity != null ) {
- return 1;
-
- } else if ( arg1.arity != null ) {
- return -1;
- }
-
- if ( arg0.matchesOperator() && arg1.matchesOperator() ) {
- if ( arg0.operator.compareTo(arg1.operator) != 0 )
- return arg0.operator.compareTo(arg1.operator);
-
- } else if ( arg0.matchesOperator() ) {
- return 1;
-
- } else if ( arg1.matchesOperator() ) {
- return -1;
- }
-
-
- if ( arg0.subPatterns.size() != arg1.subPatterns.size() )
- return arg0.subPatterns.size() - arg1.subPatterns.size();
-
- for ( int i = 0; i < arg0.subPatterns.size(); i++ ) {
-
- int sub_result = compare(arg0.subPatterns.elementAt(i), arg1.subPatterns.elementAt(i));
- if ( sub_result != 0 )
- return sub_result;
- }
-
- return 0;
- }
- };
- }
-
- public static Comparator<JBurgPatternMatcher> getCostComparator(final EmitLang e)
- {
- return new Comparator<JBurgPatternMatcher>()
- {
- EmitLang emitter;
- {
- this.emitter = e;
- }
-
- public int compare(JBurgPatternMatcher arg0, JBurgPatternMatcher arg1)
- {
- if ( arg0.finiteCostMatch != null && arg1.finiteCostMatch != null )
- {
- if ( arg0.finiteCostMatch.compareTo(arg1.finiteCostMatch) != 0 )
- return arg0.finiteCostMatch.compareTo(arg1.finiteCostMatch);
- }
- else
- throw new IllegalArgumentException("Cost comparator called on non-cost pattern");
-
- String path0 = arg0.generatePathToRoot(this.emitter, "node").toString();
- String path1 = arg1.generatePathToRoot(this.emitter, "node").toString();
-
- return path0.compareTo(path1);
- }
- };
- }
-
-
- /**
- * @return the minimum number of nodes this pattern requires for a match.
- * @pre the pattern must be n-ary.
- */
- public int getMinimumArity()
- {
- return this.arity.m_minimum;
- }
-
-
- /**
- * @return this pattern's position in its parent.
- */
- public int getPositionInParent()
- {
- return this.positionInParent;
- }
-
- /**
- * Generate a path to this pattern recognizer's node in the tree being parsed,
- * i.e., a path that can be used at reduce time. This is used to find named
- * terminals, or other parts of the subtree being reduced.
- * @param emitter - the language-specific emitter in use.
- * @param stem - the path to this subtree.
- * @param adapter - the i-node specific adapter in use.
- * @return the path to this subtree.
- */
- public Object generateReduceTimePath(EmitLang emitter, String stem, InodeAdapter adapter)
- {
- Object result = stem;
-
- for ( PathElement idx: generateAccessPath() ) {
-
- if ( adapter != null ) {
- result = new GetNthChild(result, Integer.toString(idx.index));
-
- } else {
- result = emitter.genAccessMember(
- result,
- emitter.genCallMethod(
- null,
- "getNthChild",
- Integer.toString(idx.index)) );
- }
- }
-
- return result;
- }
-
- /**
- * Information about one element of a path to a subtree.
- */
- public static class PathElement implements Comparable<PathElement>
- {
- /**
- * The operator of this subtree. Null if the subtree represents a nonterminal.
- */
- public final String operator;
-
- /**
- * This subtree's nonterminal state. Null if the subtree represents a pattern match.
- * One of operator or nonterminal must be set or the subtree is invalid.
- */
- public final String nonterminal;
-
- /**
- * This subtree's index in its parent.
- */
- public final int index;
-
- private PathElement(String operator, String nonterminal, int index)
- {
- this.operator = operator;
- this.nonterminal = nonterminal;
- this.index = index;
- }
-
- /**
- * @return true if this PathElement represents a pattern match.
- */
- public boolean isPatternMatch()
- {
- return this.operator != null;
- }
-
- /**
- * Compare PathElements based on their position in their parent.
- * {@inheritDoc}
- */
- @Override
- public int compareTo(PathElement other)
- {
- return this.index - other.index;
- }
- }
-
- /**
- * Compare two JBurgPatternMatchers. Semantics of comparison are:
- * <ol>
- * <li> Shorter path to root is lesser
- * <li> For each position in access path, if not equal then lesser position in parent is lesser
- * </ol>
- * @param other - the
- * @return
- */
- @Override
- public int compareTo(JBurgPatternMatcher other)
- {
- Vector<PathElement> this_path = this.generateAccessPath();
- Vector<PathElement> other_path = other.generateAccessPath();
-
- int result = this_path.size() - other_path.size();
-
- for ( int i = 0; i < this_path.size() && result == 0; i++ )
- result = this_path.elementAt(i).compareTo(other_path.elementAt(i));
-
- return result;
- }
-
- /**
- * Aggregate all the paths in this pattern matcher by a prototype path.
- * @param aggregated_matchers - the aggregated matchers.
- */
- void aggregatePaths(Multimap<JBurgPatternMatcher,JBurgPatternMatcher> aggregated_matchers)
- {
- aggregated_matchers.addToSet(this,this);
- if ( this.subPatterns != null )
- for (JBurgPatternMatcher kid: this.subPatterns)
- kid.aggregatePaths(aggregated_matchers);
- }
-
- /**
- * Find all (potentially) common subexpressions in a pattern matcher's path.
- * @param factors - a map from a prototype pattern matcher to the collection
- * of pattern matchers with that match that path prefix.
- */
- void findFactors(Multimap<JBurgPatternMatcher, JBurgPatternMatcher> factors)
- {
- if ( isRoot() || parentIsRoot() || isNary() )
- {
- // The first two levels of the tree are a priori present so
- // they don't need to be factored, and n-ary patterns are
- // leaf nodes with their own arity checking so they don't
- // need to be factored, either.
- }
- else
- {
- factors.addToSet(this,this);
- }
-
- if ( this.subPatterns != null )
- for (JBurgPatternMatcher kid: this.subPatterns)
- kid.findFactors(factors);
- }
-
- /**
- * Is this node at the root of a pattern?
- * @return true if this node is the root of a pattern.
- */
- boolean isRoot()
- {
- return this.parent == null;
- }
-
- /**
- * Is this node's parent the root of a pattern?
- * @return true if this node's parent is the root of a pattern.
- */
- boolean parentIsRoot()
- {
- return this.parent != null && this.parent.isRoot();
- }
-
-
- /**
- * Generate the initializer expression for a factored path variable.
- * @param codeEmitter - the active code emitter.
- * @return the correct initializer.
- */
- String generateFactoredReference(EmitLang codeEmitter)
- {
- Object result;
-
- if ( this.factoredPath != null )
- {
- result = this.factoredPath;
- }
- else if ( this.isRoot() )
- {
- result = "this";
- }
- else if ( this.parent.isRoot() )
- {
- result = codeEmitter.genCallMethod("this", "getNthChild", this.positionInParent);
- }
- else
- {
- Object parent = this.parent.generateFactoredReference(codeEmitter);
-
- result = codeEmitter.getTemplate(
- "factoredReferenceGuard",
- "parent", parent,
- "positionInParent", this.positionInParent
- );
- }
-
- return result.toString();
- }
-
- /**
- * The BURG has determined that this pattern (which is a root)
- * will only be matched in a context where its arity is already known.
- * @param elideFixedArityChecks - new setting for this.elideFixedArityChecks.
- */
- public void setFixedArityContext(boolean elideFixedArityChecks)
- {
- checkPrecondition( !this.hasNaryTail(), "Can't set fixed arity context on a n-ary pattern.");
- checkPrecondition( this.isRoot(), "Can't set fixed arity context on a non-root pattern.");
- this.elideFixedArityChecks = elideFixedArityChecks;
- }
-
- /**
- * Does this pattern use the given factored variable?
- * @param factoredVariable - the factored variable of interest.
- * @return true if this pattern uses the factored variable.
- */
- public boolean usesFactoredVariable(String factoredVariable)
- {
- if ( this.factoredPath != null && factoredVariable.contains(this.factoredPath) )
- {
- return true;
- }
- else
- {
- for ( JBurgPatternMatcher subpattern: this.subPatterns )
- if ( subpattern.usesFactoredVariable(factoredVariable) )
- return true;
- }
-
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/jburg/burg/Multimap.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/jburg/burg/Multimap.java b/compiler/src/main/java/jburg/burg/Multimap.java
deleted file mode 100644
index 3d61d3d..0000000
--- a/compiler/src/main/java/jburg/burg/Multimap.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package jburg.burg;
-
-import java.util.*;
-
-/**
- * Multimap maps a list of objects to a Comparable key.
- * @author tharwood
- *
- * @param <code><V></code> - the class of the objects to be mapped.
- */
-class Multimap<K extends Comparable<K>, V extends Object>
-{
- private Map<K, ArrayList<V>> contents = new TreeMap<K, ArrayList<V>>();
-
- /**
- * Add a value to its container.
- * @param key - the container's key.
- * @param value - the value.
- */
- public void addToSet(K key, V value)
- {
- getSet(key).add(value);
- }
-
- /**
- * Add all values in a Collection to their container.
- * @param key - the container's key.
- * @param values - the Collection of values.
- */
- public void addAllToSet(K key, Collection<V> values)
- {
- getSet(key).addAll(values);
- }
-
- /**
- * Fetch the container for the given key,
- * creating it if necessary.
- * @param key - the container's key.
- * @return the container associated with the key.
- * @see {@link #get(K)}, which delegates to this method.
- */
- public ArrayList<V> getSet(K key)
- {
- if ( !contents.containsKey(key))
- contents.put(key, new ArrayList<V>());
- return contents.get(key);
- }
-
- /**
- * Expose {@link #getSet} with a more map-like API.
- */
- public ArrayList<V> get(K key)
- {
- return getSet(key);
- }
-
- /**
- * Expose the underlying map's keySet() method.
- */
- public Set<K> keySet()
- {
- return contents.keySet();
- }
-
- /**
- * Expose the underlying map's values() method.
- */
- public Collection<ArrayList<V>> values()
- {
- return contents.values();
- }
-
- /**
- * Expose the underlying map's entrySet() method.
- */
- public Iterable<Map.Entry<K, ArrayList<V>>> entrySet()
- {
- return contents.entrySet();
- }
-
- /**
- * Expose the underlying map's containsKey() method.
- * @param key - the key of interest.
- */
- public boolean containsKey(K key)
- {
- return contents.containsKey(key);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/jburg/burg/inode/InodeAdapter.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/jburg/burg/inode/InodeAdapter.java b/compiler/src/main/java/jburg/burg/inode/InodeAdapter.java
deleted file mode 100644
index bc7808e..0000000
--- a/compiler/src/main/java/jburg/burg/inode/InodeAdapter.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package jburg.burg.inode;
-
-/**
- * INodeAdapter defines the interface the BURG uses to
- * write code that interacts with the input intermediate
- * representation, a.k.a. "i-nodes."
- */
-public interface InodeAdapter
-{
- /**
- * @return true if the adapter can handle this type of inode.
- */
- public boolean accept(String inodeClassName);
-
- /**
- * @return an expression that computes an inode's number of children.
- */
- public Object genGetArity(Object stem, jburg.emitter.EmitLang emitter);
-
- /**
- * @return an expression that fetches a child node at the specified index.
- */
- public Object genGetNthChild(Object stem, Object index, jburg.emitter.EmitLang emitter);
-
- /**
- * @return an expression that fetches the i-node's operator code
- * for pattern matching.
- */
- public Object genGetOperator(Object node, jburg.emitter.EmitLang emitter);
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/jburg/burg/ir/FormalParameter.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/jburg/burg/ir/FormalParameter.java b/compiler/src/main/java/jburg/burg/ir/FormalParameter.java
deleted file mode 100644
index 7e1e1ed..0000000
--- a/compiler/src/main/java/jburg/burg/ir/FormalParameter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package jburg.burg.ir;
-
-/**
- * FormalParameter describes a (type, name) formal parameter pair.
- */
-public class FormalParameter
-{
- private FormalParameter(Object type, Object name)
- {
- this.type = type;
- this.name = name;
- }
-
- public final Object type;
- public final Object name;
-
- /**
- * Build a formal parameter array.
- * @param rawParameters a variadic list of type/name pairs.
- * @return the raw parameters, organized into an array of formals.
- */
- public static FormalParameter[] buildFormals(Object... rawParameters)
- {
- if (rawParameters.length % 2 != 0) {
- throw new IllegalArgumentException("Internal error: formal parameters must be specified in type/name pairs.");
- }
-
- FormalParameter[] result = new FormalParameter[rawParameters.length/2];
-
- for (int i = 0; i < result.length; i++) {
- int rawIdx = i*2;
- result[i] = new FormalParameter(rawParameters[rawIdx], rawParameters[rawIdx+1]);
- }
-
- return result;
- }
-
- public String toString()
- {
- return String.format("[%s,%s]", this.type, this.name);
- }
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/jburg/burg/ir/GetNthChild.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/jburg/burg/ir/GetNthChild.java b/compiler/src/main/java/jburg/burg/ir/GetNthChild.java
deleted file mode 100644
index 1b36bb9..0000000
--- a/compiler/src/main/java/jburg/burg/ir/GetNthChild.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package jburg.burg.ir;
-
-/**
- * GetNthChild carries the information necessary to build a getNthChild call,
- * and signals the code generator (via its class) that such a call is
- * to be generated.
- */
-public class GetNthChild
-{
- /**
- * @param memberExpression an expression to access the root inode.
- * @param indexExpression an expression that designates which child to access.
- */
- public GetNthChild(Object memberExpression, Object indexExpression)
- {
- this.memberExpression = memberExpression;
- this.indexExpression = indexExpression;
- }
-
- public final Object memberExpression;
- public final Object indexExpression;
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/jburg/emitter/EmitLang.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/jburg/emitter/EmitLang.java b/compiler/src/main/java/jburg/emitter/EmitLang.java
deleted file mode 100644
index 0994491..0000000
--- a/compiler/src/main/java/jburg/emitter/EmitLang.java
+++ /dev/null
@@ -1,342 +0,0 @@
-package jburg.emitter;
-
-import jburg.burg.AnnotationAccessor;
-import jburg.burg.JBurgPatternMatcher;
-import jburg.burg.ir.FormalParameter;
-import org.stringtemplate.v4.*;
-
-import java.io.PrintStream;
-import java.util.Map;
-import java.util.Set;
-import java.util.Vector;
-
-/*
- * EmitLang defines the code emitter's interface.
- */
-
-public interface EmitLang
-{
- /**
- * Return true if based on the language and iNode class, this emitter can process the specification.
- * @param languageName Name specifed by the 'Language' qualifier in the spec
- * @return true if emitter handles this language (nb: on null or zero length EmitJava will trigger true)
- */
- abstract public boolean accept(String languageName);
-
- /**
- * Set the i-node adapter so the emitter can generate
- * code to access its relevant members.
- */
- abstract public void setInodeAdapter(jburg.burg.inode.InodeAdapter adapter);
-
- /**
- * Set the name of the class which will contain the BURM.
- * @param className the class name.
- */
- abstract public void setClassName(String className);
-
- /**
- * Set the opcode type.
- */
- abstract public void setOpcodeType(String opcode_type);
-
- /**
- * @return the opcode type.
- */
- abstract public String getOpcodeType();
-
- /**
- * Set the i-node type.
- */
- abstract public void setINodeType(String inode_type);
-
- /**
- * @return the i-node type.
- */
- abstract public String getINodeType();
-
- /**
- * Set the nonterminals' type.
- */
- abstract public void setNtType(String nt_type);
-
- /**
- * Set the annotation accessor.
- * @param accessor the annotation accessor. May be null.
- */
- abstract public void setAnnotationAccessor(AnnotationAccessor accessor);
-
- /**
- * Set or reset debug mode.
- * @param debugMode when set, the emitter may generate debugging logic.
- */
- abstract public void setDebugMode(Boolean debugMode);
-
- /**
- * Select a template by name, with optional attributes.
- * @param name the template's name.
- * @param attrValue pairs of attrName, attrValue.
- * @return an instance of the ST.
- */
- abstract public ST getTemplate(String name, Object... attrValue);
-
- /**
- * Set a default attribute in the template manager.
- * @param key the attribute's name.
- * @param value the attribute's value.
- */
- abstract public void setDefaultAttribute(String key, Object value);
-
- /**
- * Emit the file/class header information.
- * @param packageName the name of the package or namespace, or null if no package/namespace is to be generated.
- * @param headerBlock Code to be copied as-is into the header section of a Java file.
- * @param baseClassName the name of the base class, or null if no base class is to be specified.
- * @param InterfaceNames names of interfaces a Java class implements.
- * @param output
- */
- abstract public void emitHeader(String packageName, String headerBlock, String baseClassName, Vector<String> InterfaceNames, PrintStream output);
-
- /**
- * Emit static tables of subgoals.
- */
- abstract public void emitSubgoalLookupTables(int max_action, Map<Integer, Vector<JBurgPatternMatcher>> rules_by_action, PrintStream output);
-
- /**
- * Emit verbatim code blocks that are intended to be part of the class definition.
- * @param inclassBlocks A Vector of strings to be copied in verbatim.
- * @param output the stream that's writing the generated code.
- */
- abstract public void emitInclass(Vector<? extends Object> inclassBlocks, PrintStream output);
-
- /**
- * Emit the reducer and finish the class definition.
- * @param strClassName the name of the class being generated.
- * @param iNodeClass the name of the class that represents the i-code DAG.
- * @param subgoals the states that this BURM may transition through.
- * @param burm_properties any properties (private fields and public get/set methods)
- * @param output the stream that's writing the generated code.
- */
- abstract public void emitTrailer(Set<String> subgoals, Map<String, Object> burm_properties, Object default_error_handler, Map<Integer, Object> prologue_blocks, PrintStream output);
-
- /**
- * @return a code snippet that represents the code in the target language that declares
- * a variable and initializes it from the value stack, thus emulating a parameter declaration.
- * @param stackName - name of the stack.
- * @param paramType - the "parameter" type.
- * @param paramName - the "parameter's" name.
- */
- abstract public Object genActionRoutineParameter(Object stackName, Object paramType, Object paramName);
-
- /**
- * @return a code snippet that represents the code in the target language that will
- * get the top value of a stack and decrement the size of the stack
- * @param stackName variable name of the stack
- * @param valueType type of the value.
- */
- abstract public Object genPopFromStack(Object stackName, Object valueType);
-
- /**
- * @return a code snippet that pushes a value onto a stack of reduced values.
- * @param stackName the name of the stack variable. Type of the stack is assumed to be
- * reasonably generic, e.g., java.util.Stack on Java implementations, std::stack<void*> in C++.
- * @param value a code snippet that generates the value to be pushed.
- */
- abstract public Object genPushToStack(Object stackName, Object value);
-
- /**
- * @return a snippet that gives the code to check if a reference is null
- * @param paramName parameter to be checked
- * @param checkForNull if true, check for a null pointer, if false check is true if not null
- * @return object containing relevant code fragment
- */
- abstract public Object genCheckPtr(Object paramName, boolean checkForNull);
-
- /**
- * Generate code for direct access to an object's member
- * @param parentName name of the parent object
- * @param memberName name of the parameter to access
- * @return snippet containing the code fragment to use
- */
- abstract public Object genAccessMember(Object parentName, Object memberName);
-
- /**
- * Generate a clip that calls a method contained within an object.
- * @param parentName name of the parent object
- * @param methodName name of the method to call
- * @param params list of the paramters for the call
- * @return the relevent code fragment
- */
- abstract public Object genCallMethod(Object parentName, Object methodName, Object... params);
-
- /**
- * Generate a clip that compares two expressions.
- * @param lhs Expression to be placed on the left-hand side of the compare
- * @param rhs Expression to be placed on the right-hand side of the compare
- * @param bEquality set to true to compare for equality, false for non-equality
- * @return the applicable code fragment
- */
- abstract public Object genCmpEquality(Object lhs, Object rhs, boolean bEquality);
-
- /** Manifest constant for genCmpEquality -- test for equality. */
- public static final boolean TEST_EQUALITY = true;
-
- /** Manifest constant for genCmpEquality -- test for inequality. */
- public static final boolean TEST_INEQUALITY = false;
-
- /**
- * Generate a snippet that combines 2 expressions with a logical and
- * @param lhs Expression to be placed on the left-hand side of the and
- * @param rhs Expression to be placed on the right-hand side of the and
- * @return the applicable code fragment
- */
- abstract public Object genLogicalAnd(Object lhs, Object rhs);
-
- /**
- * @return a code snippet that returns true if rhs is less than lhs.
- */
- abstract public Object genCmpLess(Object lhs, Object rhs);
-
- /**
- * @return a code snippet that returns true if lhs is greater than
- * or equal to rhs.
- */
- abstract public Object genCmpGtEq(Object lhs, Object rhs);
-
- /**
- * @param operand
- * @return a code snippet that negates the operand.
- */
- abstract public Object genNot(Object operand);
-
- /**
- * @return a code snippet that adds two values.
- */
- abstract public Object genAddition(Object addend1, Object addend2);
-
- /**
- * @return a code snippet that defines a local variable in a method.
- * @param type the variable's type.
- * @param name the name of the variable.
- * @param initializer the variable's initial value. May be null, in which case no initialization code is generated.
- */
- abstract public Object genLocalVar(Object type, Object name, Object initializer);
-
- /**
- * @return a code snippet that defines an instance field.
- * @param modifiers values of java.lang.reflect.Modifier that work here are PUBLIC|PRIVATE|PROTECTED, FINAL, STATIC
- * @param type the field's type.
- * @param name the name of the field.
- * @param initializer the field's initial value. May be null, in which case no initialization code is generated.
- */
- abstract public Object genInstanceField(int modifiers, Object type, Object name, Object initializer);
-
- /**
- * @return a code snippet that creates a new object.
- * @param type the new object's class.
- * @param parameters an array of values (code snippets) to pass to the new object's constructor.
- */
- abstract public Object genNewObject(Object type, Object... parameters);
-
- /**
- * @return a code snippet that assigns a value to a variable.
- * @param lvar the variable into which the value is stored.
- * @param rvalue the value to store in the variable.
- */
- abstract public Object genAssignment(Object lvar, Object rvalue);
-
- /**
- * @return a code snippet that casts a target expression to a new type.
- * @param newType the type to cast to.
- * @param target the expression whose value is to assume the new type.
- */
- abstract public Object genCast(Object newType, Object target);
-
- /**
- * @return a code snippet that generates a comment.
- * @param text the comment text.
- */
- abstract public Object genComment (Object text);
-
- /**
- * @return a code snippet that gets the goal state of an i-node.
- * @param p the i-node.
- */
- abstract public Object genGetGoalState (Object p);
-
- /**
- * @return a code snippet that gets the undecorated goal state
- * of an i-node, which can be used as a case label.
- * @param p the i-node.
- */
- abstract public Object genGetUndecoratedGoalState (Object p);
-
- /**
- * @return a code snippet that signals a runtime error.
- * @param diagnostic the diagnostic content associated with the signal.
- */
- abstract public Object genThrow (Object diagnostic);
-
- /**
- * @return a code snippet that declares a method.
- * @param modifiers values of java.lang.reflect.Modifier that work are PUBLIC, PRIVATE.
- * @param returnClass the method's return type.
- * @param name the method's name.
- * @param formals formal parameter declarations.
- * @param exceptions an array of exceptions that the method may throw.
- * @note this method may change to emit the method header.
- */
- @SuppressWarnings("rawtypes")
- abstract public Object declareMethod(int modifiers, Object returnClass, Object name, FormalParameter[] formals, Class[] exceptions);
-
- /**
- * @return a code snippet that returns a value from a method.
- * @param value the value to return.
- */
- abstract public Object genReturnValue(Object value);
-
- /**
- * @return a code snippet that represents the target's maximum integer value, the "infinite" cost.
- */
- abstract public Object genMaxIntValue();
-
- /**
- * @return a code snippet that represents the target's null pointer value.
- */
- abstract public Object genNullPointer();
-
- /**
- * @return a code snippet that generates a pre-test (while) loop.
- */
- abstract public Object genWhileLoop(Object test_condition);
-
- /**
- * @return a code snippet that represents the target's generalized
- * container type, e.g., java.util.Vector or std::vector<void*>
- */
- abstract public Object genNaryContainerType(Object base_type);
-
- /**
- * @return a code snippet that adds two (integer) values without overflow.
- */
- abstract public Object genOverflowSafeAdd(Object expr1, Object expr2);
-
- /**
- * @return the type of the target's annotation object
- */
- abstract public Object getAnnotationType();
-
- /**
- * @return a constructor template.
- */
- abstract public ST getConstructorBody(Object decl, Object baseClass, Object... superParameters);
-
- /**
- * @return the name of the routine that appends to an n-ary list.
- */
- abstract public ST getNarySubtreeAdd();
-
- abstract public void setAllocator(Object allocator);
-
- abstract public void addSingletonAnnotationClass(String singletonClassName);
-}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/ABCGeneratingReducer.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/ABCGeneratingReducer.java b/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/ABCGeneratingReducer.java
index f26a59f..3bbba93 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/ABCGeneratingReducer.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/ABCGeneratingReducer.java
@@ -313,7 +313,7 @@ public class ABCGeneratingReducer
/**
* Construct a RTQnameL-type runtime name.
* @param qualifier - the runtime qualifier.
- * @param name - the runtime name.
+ * @param runtime_name - the runtime name.
*/
RuntimeMultiname(InstructionList qualifier, InstructionList runtime_name)
{
@@ -1087,7 +1087,7 @@ public class ABCGeneratingReducer
/**
* Generate access to a named entity.
- * @param name - the entity's name.
+ * @param binding - the entity's name.
* @param result - the instruction sequence to generate into.
*/
void generateAccess(Binding binding, InstructionList result)
@@ -1097,7 +1097,7 @@ public class ABCGeneratingReducer
/**
* Generate access to a named entity.
- * @param name - the entity's name.
+ * @param binding - the binding.
* @param accessType - one of Lenient or Strict.
* @param result - the instruction sequence to generate into.
*/
@@ -1800,7 +1800,7 @@ public class ABCGeneratingReducer
* Generate a compound logical assignment expression to a foo.bar type lvalue
* @param iNode - the assignment operator (root of the subtree).
* @param stem - the expression that generates the lvalue's stem, e.g., a in a[i]
- * @param index - the index expression.
+ * @param member - the member.
* @param expr - the expression to assign.
* @param is_and - true if the expression is &&=, false if it's ||=.
* @param need_value - true if the expression's not used in a void context.
@@ -1858,7 +1858,7 @@ public class ABCGeneratingReducer
/**
* Generate boilerplate function prolog/epilog code.
- * @param block - the actual CFG.
+ * @param iNode - the actual CFG.
* @param return_type - the function's return type.
* @return the function body.
*/
@@ -2141,10 +2141,9 @@ public class ABCGeneratingReducer
* Generate the instruction sequence that designates
* the parameter of a parameterized type, e.g.,
* String in Vector.<String> or * in Vector.<*>.
- * @param param_node - the type parameter's node.
- * @param param_name - the type parameter's name.
+ * @param param - the type parameter's node.
+ * @param result - the result.
* May be null in the * case.
- * @param result - the instruction sequence to generate into.
*/
private void generateTypeNameParameter(Binding param, InstructionList result)
{
@@ -2184,7 +2183,7 @@ public class ABCGeneratingReducer
}
/**
- * @param Label name in a break statement with a label.
+ * @param label name in a break statement with a label.
* @return A
* {@link ControlFlowContextManager.ControlFlowContextSearchCriteria} that
* will find the control context that a break statement with a label in the
@@ -2197,7 +2196,7 @@ public class ABCGeneratingReducer
}
/**
- * @param Label name in a continue statement with a label.
+ * @param label name in a continue statement with a label.
* @return A
* {@link ControlFlowContextManager.ControlFlowContextSearchCriteria} that
* will find the control context that a continue statement with a label
@@ -2210,7 +2209,7 @@ public class ABCGeneratingReducer
}
/**
- * @param Label name in a goto statement.
+ * @param label name in a goto statement.
* @return A
* {@link ControlFlowContextManager.ControlFlowContextSearchCriteria} that
* will find the control context that a goto statement in the
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/IASNodeAdapter.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/IASNodeAdapter.java b/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/IASNodeAdapter.java
deleted file mode 100644
index 2aa57ec..0000000
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/as/codegen/IASNodeAdapter.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.flex.compiler.internal.as.codegen;
-
-import jburg.emitter.EmitLang;
-import jburg.burg.inode.InodeAdapter;
-
-/**
- * IASNodeAdapter generates method calls into
- * a BURM to access properties of an IASNode.
- */
-public class IASNodeAdapter implements InodeAdapter
-{
- /**
- * @return true if the adapter can handle this type of inode.
- */
- public boolean accept(String inodeClassName)
- {
- return "IASNode".equals(inodeClassName);
- }
-
- /**
- * Generate an expression to fetch a node's child count.
- * @param node_path - the code generator's path to the node.
- * @param emitter - the compiler-compiler's code emitter.
- * @return said expression.
- */
- public Object genGetArity(Object node_path, EmitLang emitter)
- {
- return emitter.genCallMethod("SemanticUtils", "getChildCount", node_path);
- }
-
- /**
- * Generate an expression to fetch a node's Nth child.
- * @param node_path - the code generator's path to the node.
- * @param index - the index expression.
- * @param emitter - the compiler-compiler's code emitter.
- * @return said expression.
- */
- public Object genGetNthChild(Object node_path, Object index, EmitLang emitter)
- {
- return emitter.genCallMethod("SemanticUtils", "getNthChild", node_path, index);
- }
-
- /**
- * Generate an expression to fetch a node's node ID.
- * @param node_path - the code generator's path to the node.
- * @param emitter - the compiler-compiler's code emitter.
- * @return said expression.
- */
- public Object genGetOperator(Object node_path, EmitLang emitter)
- {
- return emitter.genCallMethod(node_path, "getNodeID");
- }
-}
-
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/NodeBase.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/NodeBase.java b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/NodeBase.java
index c648aac..a54e438 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/NodeBase.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/NodeBase.java
@@ -36,6 +36,7 @@ import org.apache.flex.compiler.internal.scopes.ASFileScope;
import org.apache.flex.compiler.internal.scopes.ASScope;
import org.apache.flex.compiler.internal.scopes.TypeScope;
import org.apache.flex.compiler.internal.semantics.PostProcessStep;
+import org.apache.flex.compiler.internal.semantics.SemanticUtils;
import org.apache.flex.compiler.problems.ICompilerProblem;
import org.apache.flex.compiler.scopes.IASScope;
import org.apache.flex.compiler.tree.ASTNodeID;
@@ -1031,4 +1032,20 @@ public abstract class NodeBase extends SourceLocation implements IASNode
counter.incrementCount(getClass().getSimpleName());
counter.incrementCount("nodes");
}
+
+ @Override
+ public int getArity() {
+ return SemanticUtils.getChildCount(this);
+ }
+
+ @Override
+ public IASNode getNthChild(int index) {
+ return SemanticUtils.getNthChild(this, index);
+ }
+
+ @Override
+ public ASTNodeID getOperator() {
+ return this.getNodeID();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/java/org/apache/flex/compiler/tree/as/IASNode.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/tree/as/IASNode.java b/compiler/src/main/java/org/apache/flex/compiler/tree/as/IASNode.java
index 5901dc2..79ac478 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/tree/as/IASNode.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/tree/as/IASNode.java
@@ -130,4 +130,21 @@ public interface IASNode extends ISourceLocation /* extends IAdaptable */
* @return true if this node is terminal
*/
boolean isTerminal();
+
+ /**
+ * @return the number of child nodes.
+ */
+ int getArity();
+
+ /**
+ *
+ * @param index index
+ * @return a child from position 0..getArity()-1
+ */
+ IASNode getNthChild(int index);
+
+ /**
+ * @return the node's operator type
+ */
+ ASTNodeID getOperator();
}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1908d8ca/compiler/src/main/jburg/org/apache/flex/compiler/internal/as/codegen/CmcEmitter.jbg
----------------------------------------------------------------------
diff --git a/compiler/src/main/jburg/org/apache/flex/compiler/internal/as/codegen/CmcEmitter.jbg b/compiler/src/main/jburg/org/apache/flex/compiler/internal/as/codegen/CmcEmitter.jbg
index 61f8ea7..fd01a52 100644
--- a/compiler/src/main/jburg/org/apache/flex/compiler/internal/as/codegen/CmcEmitter.jbg
+++ b/compiler/src/main/jburg/org/apache/flex/compiler/internal/as/codegen/CmcEmitter.jbg
@@ -51,7 +51,7 @@
/*
* The I-node type is IASNode, and it has its own adapter.
*/
-@INodeAdapter org.apache.flex.compiler.internal.as.codegen.IASNodeAdapter;
+@INodeAdapter jburg.burg.inode.DefaultAdapter;
// Generate Java output.
@Language java;