xtc.parser
Class MetaDataSetter

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.parser.MetaDataSetter

public class MetaDataSetter
extends Visitor

Visitor to fill in the production meta-data. Note that this visitor requires that a grammar's Properties.GENERIC and Properties.RECURSIVE have been appropriately set. Also note that this visitor does not create meta-data records; they must be created with the meta-data creator before applying this visitor. Further note that this visitor does not determine usage and self counts, as they need to be (repeatedly) determined during dead production elimination. Finally, note that this visitor assumes that the entire grammar is contained in a single module.

Version:
$Revision: 1.56 $
Author:
Robert Grimm

Field Summary
protected  Analyzer analyzer
          The analyzer utility.
protected  AST ast
          The type operations.
protected  java.util.List<Type> boundRepetitions
          The structure of bound repetitions.
protected  boolean createsNodeValue
          Flag for whether the current production may create a node value.
protected  boolean hasParseTree
          Flag for whether the grammar has the parseTree attribute.
static java.util.regex.Pattern IMPORT
          The regular expression for matching import declarations.
protected  boolean isBound
          Flag for whether the next element is bound.
protected  boolean isFirstElement
          Flag for whether the current element is the first element of a sequence.
protected  boolean isLastInPredicate
          Flag for whether the current element is the last element in a predicate.
protected  boolean isNotFollowedBy
          Flag for whether we are analyzing a not-followed-by predicate.
protected  boolean isOptional
          Flag for whether the current sequence is optional.
protected  boolean isPredicate
          Flag for whether we are analyzing a predicate.
protected  boolean isRepeated
          Flag for whether the current sequence is repeated.
protected  boolean isTopLevel
          Flag for whether the current element is the top-level element of a production.
protected  int optionLevel
          The current nesting level for options.
protected  java.util.List<Type> options
          The structure of options.
protected  int repetitionLevel
          The current nesting level for repetitions.
protected  java.util.List<java.lang.Boolean> repetitions
          The structure of repetitions.
protected  boolean requiresBaseIndex
          Flag for whether a production requires a base index variable.
protected  boolean requiresChar
          Flag for whether a production requires a character variable.
protected  boolean requiresIndex
          Flag for whether a production requires an index variable.
protected  boolean requiresLocatable
          Flag for whether the grammar requires Locatable.
protected  boolean requiresPredIndex
          Flag for whether a production requires a predicate index variable.
protected  boolean requiresPredMatch
          Flag for whether a production requires a predicate matched variable.
protected  boolean requiresPredResult
          Flag for whether a production requires a predicate result variable.
protected  boolean requiresResult
          Flag for whether a production requires a result variable.
protected  Runtime runtime
          The runtime.
protected  boolean withLocation
          Flag for whether the grammar has the withLocation attribute.
 
Constructor Summary
MetaDataSetter(Runtime runtime, Analyzer analyzer, AST ast)
          Create a new meta-data setter.
 
Method Summary
protected  boolean hasDirectLocation()
          Determine whether the current production can annotate a node with its location relative to CodeGenerator.VALUE.
protected  void importType(java.lang.String name)
          Import the specified fully qualified type.
protected  boolean isNotFollowedBy()
          Determine whether we are processing a not-followed-by predicate.
 void visit(Action a)
          Analyze the specified action.
 void visit(ActionBaseValue v)
          Analyze the specified action base value.
 void visit(AnyChar a)
          Analyze the specified any character element.
 void visit(Binding b)
          Analyze the specified binding.
 void visit(CharCase c)
          Analyze the specified character case.
 void visit(CharSwitch s)
          Analyzer the specified character switch.
 void visit(Element e)
          Analyze the specified element.
 void visit(FollowedBy p)
          Analyze the specified followed-by predicate.
 void visit(GenericActionValue v)
          Analyze the specified generic action value.
 void visit(GenericValue v)
          Analyze the specified generic value.
 void visit(Module m)
          Analyze the specified grammar.
 void visit(NonTerminal nt)
          Analyze the specified nonterminal.
 void visit(NotFollowedBy p)
          Analyze the specified not-followed-by predicate.
 void visit(Option o)
          Analyze the specified option.
 void visit(OrderedChoice c)
          Analyze the specified ordered choice.
 void visit(ParserAction pa)
          Analyze the specified parser action.
 void visit(Production p)
          Analyze the specified production.
 void visit(Repetition r)
          Analyze the specified repetition.
 void visit(SemanticPredicate p)
          Analyze the specified semantic predicate.
 void visit(Sequence s)
          Analyze the specified sequence.
 void visit(StringLiteral l)
          Analyze the specified string literal.
 void visit(StringMatch m)
          Analyze the specified string match.
 void visit(Terminal t)
          Analyze the specified terminal.
 void visit(TokenValue v)
          Analyze the specified token value.
 void visit(VoidedElement v)
          Analyze the specified voided element.
 
Methods inherited from class xtc.tree.Visitor
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMPORT

public static final java.util.regex.Pattern IMPORT
The regular expression for matching import declarations.


runtime

protected final Runtime runtime
The runtime.


analyzer

protected final Analyzer analyzer
The analyzer utility.


ast

protected final AST ast
The type operations.


withLocation

protected boolean withLocation
Flag for whether the grammar has the withLocation attribute.


hasParseTree

protected boolean hasParseTree
Flag for whether the grammar has the parseTree attribute.


requiresLocatable

protected boolean requiresLocatable
Flag for whether the grammar requires Locatable.


requiresChar

protected boolean requiresChar
Flag for whether a production requires a character variable.


requiresIndex

protected boolean requiresIndex
Flag for whether a production requires an index variable.


requiresResult

protected boolean requiresResult
Flag for whether a production requires a result variable.


requiresPredIndex

protected boolean requiresPredIndex
Flag for whether a production requires a predicate index variable.


requiresPredResult

protected boolean requiresPredResult
Flag for whether a production requires a predicate result variable.


requiresPredMatch

protected boolean requiresPredMatch
Flag for whether a production requires a predicate matched variable.


requiresBaseIndex

protected boolean requiresBaseIndex
Flag for whether a production requires a base index variable.


repetitions

protected java.util.List<java.lang.Boolean> repetitions
The structure of repetitions.


boundRepetitions

protected java.util.List<Type> boundRepetitions
The structure of bound repetitions.


options

protected java.util.List<Type> options
The structure of options.


createsNodeValue

protected boolean createsNodeValue
Flag for whether the current production may create a node value.


isTopLevel

protected boolean isTopLevel
Flag for whether the current element is the top-level element of a production.


isRepeated

protected boolean isRepeated
Flag for whether the current sequence is repeated.


isOptional

protected boolean isOptional
Flag for whether the current sequence is optional.


isFirstElement

protected boolean isFirstElement
Flag for whether the current element is the first element of a sequence.


isBound

protected boolean isBound
Flag for whether the next element is bound.


isPredicate

protected boolean isPredicate
Flag for whether we are analyzing a predicate.


isNotFollowedBy

protected boolean isNotFollowedBy
Flag for whether we are analyzing a not-followed-by predicate.


isLastInPredicate

protected boolean isLastInPredicate
Flag for whether the current element is the last element in a predicate.


repetitionLevel

protected int repetitionLevel
The current nesting level for repetitions.


optionLevel

protected int optionLevel
The current nesting level for options.

Constructor Detail

MetaDataSetter

public MetaDataSetter(Runtime runtime,
                      Analyzer analyzer,
                      AST ast)
Create a new meta-data setter.

Parameters:
runtime - The runtime.
analyzer - The analyzer utility.
ast - The type operations.
Method Detail

importType

protected void importType(java.lang.String name)
Import the specified fully qualified type.

Parameters:
name - The type name.

visit

public void visit(Module m)
Analyze the specified grammar.


visit

public void visit(Production p)
Analyze the specified production.


visit

public void visit(OrderedChoice c)
Analyze the specified ordered choice.


visit

public void visit(Repetition r)
Analyze the specified repetition.


visit

public void visit(Option o)
Analyze the specified option.


visit

public void visit(Sequence s)
Analyze the specified sequence.


visit

public void visit(FollowedBy p)
Analyze the specified followed-by predicate.


isNotFollowedBy

protected boolean isNotFollowedBy()
Determine whether we are processing a not-followed-by predicate.

Returns:
true if we are processing a not-followed-by predicate.

visit

public void visit(NotFollowedBy p)
Analyze the specified not-followed-by predicate.


visit

public void visit(SemanticPredicate p)
Analyze the specified semantic predicate.


visit

public void visit(VoidedElement v)
Analyze the specified voided element.


visit

public void visit(Binding b)
Analyze the specified binding.


visit

public void visit(StringMatch m)
Analyze the specified string match.


visit

public void visit(NonTerminal nt)
Analyze the specified nonterminal.


visit

public void visit(AnyChar a)
Analyze the specified any character element.


visit

public void visit(StringLiteral l)
Analyze the specified string literal.


visit

public void visit(CharCase c)
Analyze the specified character case.


visit

public void visit(CharSwitch s)
Analyzer the specified character switch.


visit

public void visit(Terminal t)
Analyze the specified terminal.


visit

public void visit(Action a)
Analyze the specified action.


visit

public void visit(ParserAction pa)
Analyze the specified parser action.


hasDirectLocation

protected boolean hasDirectLocation()
Determine whether the current production can annotate a node with its location relative to CodeGenerator.VALUE.

Returns:
true if the location annotation can be optimized.

visit

public void visit(TokenValue v)
Analyze the specified token value.


visit

public void visit(ActionBaseValue v)
Analyze the specified action base value.


visit

public void visit(GenericValue v)
Analyze the specified generic value.


visit

public void visit(GenericActionValue v)
Analyze the specified generic action value. Note that generic recursion values are also generic action values.


visit

public void visit(Element e)
Analyze the specified element. This method provides the default implementation for parse tree nodes, null literals, node markers, and value elements (besides token values, action base values, and generic values).



Copyright © 2012. All Rights Reserved.