public class Inliner extends GrammarVisitor
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.| Modifier and Type | Field and Description |
|---|---|
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.
|
analyzer, isBound, isLastElement, isPredicate, isRepeatedOnce, isTopLevel, isVoided, needsSequence, runtime, transformInPlace| Constructor and Description |
|---|
Inliner(Runtime runtime,
Analyzer analyzer)
Create a new production inliner.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitdispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visitpublic static final int MAX_COST
public static final boolean INLINE_PERSISTENT
protected boolean attributeState
protected boolean inlined
protected boolean isBasic(Production p)
p - The production.true if the production is either text-only
or void.protected void inlined(Production p)
p - The production.public java.lang.Object visit(Module m)
visit in class GrammarVisitorm - The grammar module.Boolean.TRUE if the grammar has been modified,
otherwise Boolean.FALSE.public Element visit(NonTerminal nt)
Copyright © 2014. All Rights Reserved.