xtc.parser
Class Inliner

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.parser.GrammarVisitor
          extended by xtc.parser.Inliner

public class Inliner
extends GrammarVisitor

Visitor to inline productions. If cost-based inlining is enabled, this visitor inlines productions with a cost estimate less or equal to the maximum cost. However, to avoid changing a production's semantic value, cost-based inlining is limited to void, text-only, and token-level productions. Independent of whether cost-based inlining is enabled or not, this visitor inlines productions that are referenced from a production consisting solely of a nonterminal (which, optionally, may be bound to CodeGenerator.VALUE). Note that generic productions are never inlined; neither are productions with the state attribute.

Note that, to be effective, this visitor requires that text-only productions have been marked as such. Similarly, token-level productions need to have beeen marked as such. Further note that, if this visitor inlines productions, the resulting grammar needs to be simplified before further processing. Also note that this visitor may create new opportunities for the elimination of dead productions. This visitor assumes that the entire grammar is contained in a single module.

Version:
$Revision: 1.53 $
Author:
Robert Grimm

Field Summary
protected  boolean attributeState
          Flag for whether the grammar has the state attribute.
static boolean INLINE_PERSISTENT
          The flag for whether to inline non-transient productions.
protected  boolean inlined
          Flag for whether this production inliner has inlined a production.
static int MAX_COST
          The maximum cost for inlining productions at arbitrary positions.
 
Fields inherited from class xtc.parser.GrammarVisitor
analyzer, isBound, isLastElement, isPredicate, isRepeatedOnce, isTopLevel, isVoided, needsSequence, runtime, transformInPlace
 
Constructor Summary
Inliner(Runtime runtime, Analyzer analyzer)
          Create a new production inliner.
 
Method Summary
protected  void inlined(Production p)
          Record that the specified production has been inlined and, if necessary, print a message to the console.
protected  boolean isBasic(Production p)
          Determine whether the specified production is void, text-only, or token-level.
 java.lang.Object visit(Module m)
          Process the specified grammar.
 Element visit(NonTerminal nt)
          Visit the specified nonterminal.
 
Methods inherited from class xtc.parser.GrammarVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
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

MAX_COST

public static final int MAX_COST
The maximum cost for inlining productions at arbitrary positions.

See Also:
Constant Field Values

INLINE_PERSISTENT

public static final boolean INLINE_PERSISTENT
The flag for whether to inline non-transient productions.

See Also:
Constant Field Values

attributeState

protected boolean attributeState
Flag for whether the grammar has the state attribute.


inlined

protected boolean inlined
Flag for whether this production inliner has inlined a production.

Constructor Detail

Inliner

public Inliner(Runtime runtime,
               Analyzer analyzer)
Create a new production inliner.

Parameters:
runtime - The runtime.
analyzer - The analyzer utility.
Method Detail

isBasic

protected boolean isBasic(Production p)
Determine whether the specified production is void, text-only, or token-level.

Parameters:
p - The production.
Returns:
true if the production is either text-only or void.

inlined

protected void inlined(Production p)
Record that the specified production has been inlined and, if necessary, print a message to the console.

Parameters:
p - The production.

visit

public java.lang.Object visit(Module m)
Process the specified grammar.

Overrides:
visit in class GrammarVisitor
Parameters:
m - The grammar module.
Returns:
Boolean.TRUE if the grammar has been modified, otherwise Boolean.FALSE.

visit

public Element visit(NonTerminal nt)
Visit the specified nonterminal.



Copyright © 2012. All Rights Reserved.