All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jastadd.jastaddparser.ast.Grammar Maven / Gradle / Ivy

The newest version!
/* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13 */
package org.jastadd.jastaddparser.ast;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.*;
import java.util.Iterator;
import java.io.PrintStream;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
/**
 * @ast node
 * @declaredat /home/jesper/git/jastaddparser/src/jastadd/Grammar.ast:31
 * @production Grammar : {@link ASTNode} ::= {@link Clause}*;

 */
public class Grammar extends ASTNode implements Cloneable {
  /**
   * @aspect NameChecking
   * @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:44
   */
  protected void nameCheck() {
    if (explicitGoals().isEmpty()) {
      java.util.List rules = rule(firstGoal());
      if (!rules.isEmpty()) {
        Rule rule = rules.get(0);
        rule.warning("No explicit goals in grammar; will use \"" + firstGoal() + "\"");
      }
    }
    for (Goal goal : explicitGoals()) {
      if (rule(goal.getName()).isEmpty()) {
        goal.error("Goal " + goal.getName() + " is not defined");
      }
    }
  }
  /**
   * @aspect CodeGen
   * @declaredat /home/jesper/git/jastaddparser/src/jastadd/CodeGen.jrag:80
   */
  public void genCode(PrintStream out, boolean noBeaverSymbol, boolean useTokenlist) {
    ASTNode.out = out;
    ASTNode.noBeaverSymbol = noBeaverSymbol;
    ASTNode.useTokenlist = useTokenlist;
    for (Clause clause : getClauseList()) {
      if (clause instanceof Declaration) {
        clause.genCode();
      }
    }
    for (String terminal : terminals()) {
      format("%%terminals %s;\n", terminal);
    }
    for (String name : ruleNames()) {
      boolean genOpt = false;
      boolean genOptList = false;
      boolean genList = false;
      String typeName = "";
      for (Rule rule : rule(name)) {
        genOpt = genOpt || rule.genOpt();
        genOptList = genOptList || rule.genOptList();
        genList = genList || rule.genList();
        typeName = rule.type();
      }
      format("%%typeof %s = \"%s\";\n", name, typeName);
      if (genOpt) {
        Rule rule = nonTerminal(name);
        if (rule != null && rule.type().equals("List")) {
          format("%%typeof %s_opt = \"List\";\n", name);
        } else {
          format("%%typeof %s_opt = \"Opt\";\n", name);
        }
      }
      if (genOptList) {
        format("%%typeof %s_opt_list = \"List\";\n", name);
      }
      if (genList) {
        format("%%typeof %s_list = \"List\";\n", name);
      }
    }
    String defaultGoal = null;
    Collection goals = new ArrayList();
    for (Clause clause : getClauseList()) {
      if (defaultGoal == null && (clause instanceof Rule)) {
        defaultGoal = ((Rule) clause).name();
      }
      if (clause instanceof Goal) {
        goals.add(((Goal) clause).getName());
      }
    }
    if (goals.isEmpty()) {
      goals.add(defaultGoal);
    }
    for (String goal : goals) {
      format("%%goal %s;\n", goal);
    }
    for (Rule rule : rules()) {
      rule.genCode();
    }

    // Generate _opt, _opt_list, _list constructs.
    for (String name : ruleNames()) {
      boolean genOpt = false;
      boolean genOptList = false;
      boolean genList = false;
      String typeName = "";
      for (Rule rule : rule(name)) {
        if (rule.genOpt()) {
          genOpt = true;
        }
        if (rule.genOptList()) {
          genOptList = true;
        }
        if (rule.genList()) {
          genList = true;
        }
        typeName = rule.type();
      }
      if (genOpt) {
        Rule rule = rule(name).get(0);
        if (rule.type().equals("List")) {
          println(name + "_opt =");
          printReturn("new List()");
          println("  | " + name + ".n");
          printReturn("n", "n", "n");
          println("  ;");
        } else if (rule.type().equals("Opt")) {
          println(name + "_opt =");
          printReturn("new Opt()");
          println("  | " + name + ".n");
          printReturn("n", "n", "n");
          println("  ;");
        } else {
          println(name + "_opt =");
          printReturn("new Opt()");
          println("  | " + name + ".n");
          printReturn("new Opt(n)", "n", "n");
          println("  ;");
        }
      }
      if (genOptList) {
        println(name + "_opt_list =");
        printReturn("new List()");
        println("  | " + name + "_list.n");
        printReturn("n", "n", "n");
        println("  ;");
      }
      if (genList) {
        println(name + "_list =");
        println("  " + name + ".n");
        printReturn("new List().add(n)", "n", "n");
        println("  | " + name + "_list.l " + name + ".n");
        printReturn("l.add(n)", "l", "n");
        println("  ;");
      }
    }
  }
  /**
   * Generates the semantic action code for a single production.
   * @aspect CodeGen
   * @declaredat /home/jesper/git/jastaddparser/src/jastadd/CodeGen.jrag:200
   */
  private void printReturn(String returnVal, String alias1, String alias2) {
    if (noBeaverSymbol) {
      format("  {: ASTNode _node_ = %s;\n", returnVal);
		if(useTokenlist){
			println("	Object first = _symbol_" + alias1 + ".value;");
			println("	Object last = _symbol_" + alias2 + ".value;");
			println("  	if(first instanceof Token){");
			println("		_node_.setStartToken((Token) first);");
			println("  	} else {");
			println("  		ASTNode fn = (ASTNode) first;");
			println("  		_node_.setStartToken(fn.getStartToken());");
			println("  	}");
			println("  	if(last instanceof Token){");
			println("  		_node_.setEndToken((Token) last);");
			println("  	} else {");
			println(" 		ASTNode ln = (ASTNode) last;");
			println("  		_node_.setEndToken(ln.getEndToken());");
			println("  	}");
		}
      println("   _node_.setStart(Symbol.getLine(_symbol_" + alias1 +
          ".getStart()), (short) Symbol.getColumn(_symbol_" + alias1 +".getStart()));");
      println("   _node_.setEnd(Symbol.getLine(_symbol_" + alias2 +
          ".getEnd()), (short) Symbol.getColumn(_symbol_" + alias2 + ".getEnd()));");
      println("   return new Symbol(_node_); :}");
    } else {
      format("  {: return %s; :}\n", returnVal);
    }
  }
  /**
   * @aspect CodeGen
   * @declaredat /home/jesper/git/jastaddparser/src/jastadd/CodeGen.jrag:229
   */
  private void printReturn(String returnVal) {
    if (noBeaverSymbol) {
      format("    {: return new Symbol(%s); :}\n", returnVal);
    } else {
      format("  {: return %s; :}\n", returnVal);
    }
  }
  /**
   * @declaredat ASTNode:1
   */
  public Grammar() {
    super();
    is$Final(true);
  }
  /**
   * Initializes the child array to the correct size.
   * Initializes List and Opt nta children.
   * @apilevel internal
   * @ast method
   * @declaredat ASTNode:11
   */
  public void init$Children() {
    children = new ASTNode[1];
    setChild(new List(), 0);
  }
  /**
   * @declaredat ASTNode:15
   */
  public Grammar(List p0) {
    setChild(p0, 0);
    is$Final(true);
  }
  /**
   * @apilevel low-level
   * @declaredat ASTNode:22
   */
  protected int numChildren() {
    return 1;
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:28
   */
  public boolean mayHaveRewrite() {
    return false;
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:34
   */
  public void flushAttrCache() {
    super.flushAttrCache();
    firstGoal_reset();
    explicitGoals_reset();
    goal_String_reset();
    uses_reset();
    isNonTerminal_String_reset();
    nonTerminal_String_reset();
    terminals_reset();
    ruleNames_reset();
    rules_reset();
    rule_String_reset();
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:50
   */
  public void flushCollectionCache() {
    super.flushCollectionCache();
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:56
   */
  public void flushRewriteCache() {
    super.flushRewriteCache();
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:62
   */
  public Grammar clone() throws CloneNotSupportedException {
    Grammar node = (Grammar) super.clone();
    return node;
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:69
   */
  public Grammar copy() {
    try {
      Grammar node = (Grammar) clone();
      node.parent = null;
      if (children != null) {
        node.children = (ASTNode[]) children.clone();
      }
      return node;
    } catch (CloneNotSupportedException e) {
      throw new Error("Error: clone not supported for " + getClass().getName());
    }
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @deprecated Please use treeCopy or treeCopyNoTransform instead
   * @declaredat ASTNode:88
   */
  @Deprecated
  public Grammar fullCopy() {
    return treeCopyNoTransform();
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @declaredat ASTNode:98
   */
  public Grammar treeCopyNoTransform() {
    Grammar tree = (Grammar) copy();
    if (children != null) {
      for (int i = 0; i < children.length; ++i) {
        ASTNode child = (ASTNode) children[i];
        if (child != null) {
          child = child.treeCopyNoTransform();
          tree.setChild(child, i);
        }
      }
    }
    return tree;
  }
  /**
   * Create a deep copy of the AST subtree at this node.
   * The subtree of this node is traversed to trigger rewrites before copy.
   * The copy is dangling, i.e. has no parent.
   * @return dangling copy of the subtree at this node
   * @apilevel low-level
   * @declaredat ASTNode:118
   */
  public Grammar treeCopy() {
    doFullTraversal();
    return treeCopyNoTransform();
  }
  /**
   * @apilevel internal
   * @declaredat ASTNode:125
   */
  protected boolean is$Equal(ASTNode node) {
    return super.is$Equal(node);    
  }
  /**
   * Replaces the Clause list.
   * @param list The new list node to be used as the Clause list.
   * @apilevel high-level
   */
  public void setClauseList(List list) {
    setChild(list, 0);
  }
  /**
   * Retrieves the number of children in the Clause list.
   * @return Number of children in the Clause list.
   * @apilevel high-level
   */
  public int getNumClause() {
    return getClauseList().getNumChild();
  }
  /**
   * Retrieves the number of children in the Clause list.
   * Calling this method will not trigger rewrites.
   * @return Number of children in the Clause list.
   * @apilevel low-level
   */
  public int getNumClauseNoTransform() {
    return getClauseListNoTransform().getNumChildNoTransform();
  }
  /**
   * Retrieves the element at index {@code i} in the Clause list.
   * @param i Index of the element to return.
   * @return The element at position {@code i} in the Clause list.
   * @apilevel high-level
   */
  public Clause getClause(int i) {
    return (Clause) getClauseList().getChild(i);
  }
  /**
   * Check whether the Clause list has any children.
   * @return {@code true} if it has at least one child, {@code false} otherwise.
   * @apilevel high-level
   */
  public boolean hasClause() {
    return getClauseList().getNumChild() != 0;
  }
  /**
   * Append an element to the Clause list.
   * @param node The element to append to the Clause list.
   * @apilevel high-level
   */
  public void addClause(Clause node) {
    List list = (parent == null) ? getClauseListNoTransform() : getClauseList();
    list.addChild(node);
  }
  /**
   * @apilevel low-level
   */
  public void addClauseNoTransform(Clause node) {
    List list = getClauseListNoTransform();
    list.addChild(node);
  }
  /**
   * Replaces the Clause list element at index {@code i} with the new node {@code node}.
   * @param node The new node to replace the old list element.
   * @param i The list index of the node to be replaced.
   * @apilevel high-level
   */
  public void setClause(Clause node, int i) {
    List list = getClauseList();
    list.setChild(node, i);
  }
  /**
   * Retrieves the Clause list.
   * @return The node representing the Clause list.
   * @apilevel high-level
   */
  @ASTNodeAnnotation.ListChild(name="Clause")
  public List getClauseList() {
    List list = (List) getChild(0);
    return list;
  }
  /**
   * Retrieves the Clause list.
   * 

This method does not invoke AST transformations.

* @return The node representing the Clause list. * @apilevel low-level */ public List getClauseListNoTransform() { return (List) getChildNoTransform(0); } /** * Retrieves the Clause list. * @return The node representing the Clause list. * @apilevel high-level */ public List getClauses() { return getClauseList(); } /** * Retrieves the Clause list. *

This method does not invoke AST transformations.

* @return The node representing the Clause list. * @apilevel low-level */ public List getClausesNoTransform() { return getClauseListNoTransform(); } /** * @apilevel internal */ protected int firstGoal_visited = -1; /** * @apilevel internal */ protected boolean firstGoal_computed = false; /** * @apilevel internal */ protected String firstGoal_value; /** * @apilevel internal */ private void firstGoal_reset() { firstGoal_computed = false; firstGoal_value = null; firstGoal_visited = -1; } @ASTNodeAnnotation.Attribute public String firstGoal() { ASTNode$State state = state(); if (firstGoal_computed) { return firstGoal_value; } if (firstGoal_visited == state().boundariesCrossed) { throw new RuntimeException("Circular definition of attr: firstGoal in class: org.jastadd.ast.AST.SynDecl"); } firstGoal_visited = state().boundariesCrossed; boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); firstGoal_value = firstGoal_compute(); if (isFinal && num == state().boundariesCrossed) { firstGoal_computed = true; } else { } state.INTERMEDIATE_VALUE |= intermediate; firstGoal_visited = -1; return firstGoal_value; } /** * @apilevel internal */ private String firstGoal_compute() { for (int i = 0; i < getNumClause(); i++) { if (getClause(i) instanceof Rule) { return ((Rule) getClause(i)).name(); } } return null; } /** * @apilevel internal */ protected int explicitGoals_visited = -1; /** * @apilevel internal */ protected boolean explicitGoals_computed = false; /** * @apilevel internal */ protected Set explicitGoals_value; /** * @apilevel internal */ private void explicitGoals_reset() { explicitGoals_computed = false; explicitGoals_value = null; explicitGoals_visited = -1; } @ASTNodeAnnotation.Attribute public Set explicitGoals() { ASTNode$State state = state(); if (explicitGoals_computed) { return explicitGoals_value; } if (explicitGoals_visited == state().boundariesCrossed) { throw new RuntimeException("Circular definition of attr: explicitGoals in class: org.jastadd.ast.AST.SynDecl"); } explicitGoals_visited = state().boundariesCrossed; boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); explicitGoals_value = explicitGoals_compute(); if (isFinal && num == state().boundariesCrossed) { explicitGoals_computed = true; } else { } state.INTERMEDIATE_VALUE |= intermediate; explicitGoals_visited = -1; return explicitGoals_value; } /** * @apilevel internal */ private Set explicitGoals_compute() { Set set = new HashSet(); for (int i = 0; i < getNumClause(); i++) { if (getClause(i) instanceof Goal) { set.add((Goal) getClause(i)); } } return set; } /** * @apilevel internal */ protected java.util.Map goal_String_visited; /** * @apilevel internal */ protected java.util.Map goal_String_values; /** * @apilevel internal */ private void goal_String_reset() { goal_String_values = null; goal_String_visited = null; } @ASTNodeAnnotation.Attribute public Goal goal(String name) { Object _parameters = name; if (goal_String_visited == null) goal_String_visited = new java.util.HashMap(4); if (goal_String_values == null) goal_String_values = new java.util.HashMap(4); ASTNode$State state = state(); if (goal_String_values.containsKey(_parameters)) { return (Goal) goal_String_values.get(_parameters); } if (Integer.valueOf(state().boundariesCrossed).equals(goal_String_visited.get(_parameters))) { throw new RuntimeException("Circular definition of attr: goal in class: org.jastadd.ast.AST.SynDecl"); } goal_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed)); boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); Goal goal_String_value = goal_compute(name); if (isFinal && num == state().boundariesCrossed) { goal_String_values.put(_parameters, goal_String_value); } else { } state.INTERMEDIATE_VALUE |= intermediate; goal_String_visited.remove(_parameters); return goal_String_value; } /** * @apilevel internal */ private Goal goal_compute(String name) { for (Goal goal : explicitGoals()) { if (goal.getName().equals(name)) { return goal; } } return null; } /** * @apilevel internal */ protected int uses_visited = -1; /** * @apilevel internal */ protected boolean uses_computed = false; /** * @apilevel internal */ protected Map> uses_value; /** * @apilevel internal */ private void uses_reset() { uses_computed = false; uses_value = null; uses_visited = -1; } @ASTNodeAnnotation.Attribute public Map> uses() { ASTNode$State state = state(); if (uses_computed) { return uses_value; } if (uses_visited == state().boundariesCrossed) { throw new RuntimeException("Circular definition of attr: uses in class: org.jastadd.ast.AST.SynDecl"); } uses_visited = state().boundariesCrossed; boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); uses_value = uses_compute(); if (isFinal && num == state().boundariesCrossed) { uses_computed = true; } else { } state.INTERMEDIATE_VALUE |= intermediate; uses_visited = -1; return uses_value; } /** * @apilevel internal */ private Map> uses_compute() { Map> map = new HashMap>(); findUses(map); return map; } /** * @apilevel internal */ protected java.util.Map isNonTerminal_String_visited; /** * @apilevel internal */ protected java.util.Map isNonTerminal_String_values; /** * @apilevel internal */ private void isNonTerminal_String_reset() { isNonTerminal_String_values = null; isNonTerminal_String_visited = null; } @ASTNodeAnnotation.Attribute public boolean isNonTerminal(String name) { Object _parameters = name; if (isNonTerminal_String_visited == null) isNonTerminal_String_visited = new java.util.HashMap(4); if (isNonTerminal_String_values == null) isNonTerminal_String_values = new java.util.HashMap(4); ASTNode$State state = state(); if (isNonTerminal_String_values.containsKey(_parameters)) { return (Boolean) isNonTerminal_String_values.get(_parameters); } if (Integer.valueOf(state().boundariesCrossed).equals(isNonTerminal_String_visited.get(_parameters))) { throw new RuntimeException("Circular definition of attr: isNonTerminal in class: org.jastadd.ast.AST.SynDecl"); } isNonTerminal_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed)); boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); boolean isNonTerminal_String_value = isNonTerminal_compute(name); if (isFinal && num == state().boundariesCrossed) { isNonTerminal_String_values.put(_parameters, isNonTerminal_String_value); } else { } state.INTERMEDIATE_VALUE |= intermediate; isNonTerminal_String_visited.remove(_parameters); return isNonTerminal_String_value; } /** * @apilevel internal */ private boolean isNonTerminal_compute(String name) { for (Rule rule : rules()) { if (rule.name().equals(name)) { return true; } } return false; } /** * @apilevel internal */ protected java.util.Map nonTerminal_String_visited; /** * @apilevel internal */ protected java.util.Map nonTerminal_String_values; /** * @apilevel internal */ private void nonTerminal_String_reset() { nonTerminal_String_values = null; nonTerminal_String_visited = null; } @ASTNodeAnnotation.Attribute public Rule nonTerminal(String name) { Object _parameters = name; if (nonTerminal_String_visited == null) nonTerminal_String_visited = new java.util.HashMap(4); if (nonTerminal_String_values == null) nonTerminal_String_values = new java.util.HashMap(4); ASTNode$State state = state(); if (nonTerminal_String_values.containsKey(_parameters)) { return (Rule) nonTerminal_String_values.get(_parameters); } if (Integer.valueOf(state().boundariesCrossed).equals(nonTerminal_String_visited.get(_parameters))) { throw new RuntimeException("Circular definition of attr: nonTerminal in class: org.jastadd.ast.AST.SynDecl"); } nonTerminal_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed)); boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); Rule nonTerminal_String_value = nonTerminal_compute(name); if (isFinal && num == state().boundariesCrossed) { nonTerminal_String_values.put(_parameters, nonTerminal_String_value); } else { } state.INTERMEDIATE_VALUE |= intermediate; nonTerminal_String_visited.remove(_parameters); return nonTerminal_String_value; } /** * @apilevel internal */ private Rule nonTerminal_compute(String name) { for (Rule rule : rules()) { if (rule.name().equals(name)) { return rule; } } return null; } /** * @apilevel internal */ protected int terminals_visited = -1; /** * @apilevel internal */ protected boolean terminals_computed = false; /** * @apilevel internal */ protected Set terminals_value; /** * @apilevel internal */ private void terminals_reset() { terminals_computed = false; terminals_value = null; terminals_visited = -1; } @ASTNodeAnnotation.Attribute public Set terminals() { ASTNode$State state = state(); if (terminals_computed) { return terminals_value; } if (terminals_visited == state().boundariesCrossed) { throw new RuntimeException("Circular definition of attr: terminals in class: org.jastadd.ast.AST.SynDecl"); } terminals_visited = state().boundariesCrossed; boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); terminals_value = terminals_compute(); if (isFinal && num == state().boundariesCrossed) { terminals_computed = true; } else { } state.INTERMEDIATE_VALUE |= intermediate; terminals_visited = -1; return terminals_value; } /** * @apilevel internal */ private Set terminals_compute() { Set set = new LinkedHashSet(); findTerminals(set); return set; } /** * @apilevel internal */ protected int ruleNames_visited = -1; /** * @apilevel internal */ protected boolean ruleNames_computed = false; /** * @apilevel internal */ protected Set ruleNames_value; /** * @apilevel internal */ private void ruleNames_reset() { ruleNames_computed = false; ruleNames_value = null; ruleNames_visited = -1; } @ASTNodeAnnotation.Attribute public Set ruleNames() { ASTNode$State state = state(); if (ruleNames_computed) { return ruleNames_value; } if (ruleNames_visited == state().boundariesCrossed) { throw new RuntimeException("Circular definition of attr: ruleNames in class: org.jastadd.ast.AST.SynDecl"); } ruleNames_visited = state().boundariesCrossed; boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); ruleNames_value = ruleNames_compute(); if (isFinal && num == state().boundariesCrossed) { ruleNames_computed = true; } else { } state.INTERMEDIATE_VALUE |= intermediate; ruleNames_visited = -1; return ruleNames_value; } /** * @apilevel internal */ private Set ruleNames_compute() { Set set = new LinkedHashSet(); for (Rule rule : rules()) { set.add(rule.name()); } return set; } /** * @apilevel internal */ protected int rules_visited = -1; /** * @apilevel internal */ protected boolean rules_computed = false; /** * @apilevel internal */ protected Collection rules_value; /** * @apilevel internal */ private void rules_reset() { rules_computed = false; rules_value = null; rules_visited = -1; } @ASTNodeAnnotation.Attribute public Collection rules() { ASTNode$State state = state(); if (rules_computed) { return rules_value; } if (rules_visited == state().boundariesCrossed) { throw new RuntimeException("Circular definition of attr: rules in class: org.jastadd.ast.AST.SynDecl"); } rules_visited = state().boundariesCrossed; boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); rules_value = rules_compute(); if (isFinal && num == state().boundariesCrossed) { rules_computed = true; } else { } state.INTERMEDIATE_VALUE |= intermediate; rules_visited = -1; return rules_value; } /** * @apilevel internal */ private Collection rules_compute() { Collection c = new ArrayList(); for (Clause clause : getClauseList()) { if (clause instanceof Rule) { c.add((Rule) clause); } } return c; } /** * @apilevel internal */ protected java.util.Map rule_String_visited; /** * @apilevel internal */ protected java.util.Map rule_String_values; /** * @apilevel internal */ private void rule_String_reset() { rule_String_values = null; rule_String_visited = null; } @ASTNodeAnnotation.Attribute public java.util.List rule(String name) { Object _parameters = name; if (rule_String_visited == null) rule_String_visited = new java.util.HashMap(4); if (rule_String_values == null) rule_String_values = new java.util.HashMap(4); ASTNode$State state = state(); if (rule_String_values.containsKey(_parameters)) { return (java.util.List) rule_String_values.get(_parameters); } if (Integer.valueOf(state().boundariesCrossed).equals(rule_String_visited.get(_parameters))) { throw new RuntimeException("Circular definition of attr: rule in class: org.jastadd.ast.AST.SynDecl"); } rule_String_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed)); boolean intermediate = state.INTERMEDIATE_VALUE; state.INTERMEDIATE_VALUE = false; int num = state.boundariesCrossed; boolean isFinal = this.is$Final(); java.util.List rule_String_value = rule_compute(name); if (isFinal && num == state().boundariesCrossed) { rule_String_values.put(_parameters, rule_String_value); } else { } state.INTERMEDIATE_VALUE |= intermediate; rule_String_visited.remove(_parameters); return rule_String_value; } /** * @apilevel internal */ private java.util.List rule_compute(String name) { ArrayList list = new ArrayList(1); for (Rule rule : rules()) { if (rule.name().equals(name)) { list.add(rule); } } return list; } /** * @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:80 * @apilevel internal */ public boolean Define_isGoal(ASTNode caller, ASTNode child) { if (caller == getClauseListNoTransform()) { // @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:82 int index = caller.getIndexOfChild(child); { if (getClause(index) instanceof Rule) { Rule rule = (Rule) getClause(index); return goal(rule.name()) != null || rule.name().equals(firstGoal()); } return false; } } else { return getParent().Define_isGoal(this, caller); } } /** * @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:170 * @apilevel internal */ public Set Define_uses(ASTNode caller, ASTNode child, String name) { if (caller == getClauseListNoTransform()) { // @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:172 int childIndex = caller.getIndexOfChild(child); return uses().containsKey(name) ? uses().get(name) : Collections.emptySet(); } else { return getParent().Define_uses(this, caller, name); } } /** * @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:179 * @apilevel internal */ public boolean Define_isNonTerminal(ASTNode caller, ASTNode child, String name) { if (caller == getClauseListNoTransform()) { // @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:181 int childIndex = caller.getIndexOfChild(child); return isNonTerminal(name); } else { return getParent().Define_isNonTerminal(this, caller, name); } } /** * @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:194 * @apilevel internal */ public Rule Define_nonTerminal(ASTNode caller, ASTNode child, String name) { if (caller == getClauseListNoTransform()) { // @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:196 int childIndex = caller.getIndexOfChild(child); return nonTerminal(name); } else { return getParent().Define_nonTerminal(this, caller, name); } } /** * @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:265 * @apilevel internal */ public boolean Define_replaced(ASTNode caller, ASTNode child, String name) { if (caller == getClauseListNoTransform()) { // @declaredat /home/jesper/git/jastaddparser/src/jastadd/NameBinding.jrag:267 int index = caller.getIndexOfChild(child); { for (int i = index + 1; i < getNumClause(); i++) { if (getClause(i).replaces(name)) { return true; } } return false; } } else { return getParent().Define_replaced(this, caller, name); } } /** * @apilevel internal */ public ASTNode rewriteTo() { return super.rewriteTo(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy