Class AcceptInliner
- java.lang.Object
-
- EDU.purdue.jtb.parser.visitor.DepthFirstVoidVisitor
-
- EDU.purdue.jtb.generate.AcceptInliner
-
- All Implemented Interfaces:
IVoidVisitor
public class AcceptInliner extends DepthFirstVoidVisitor
TheAcceptInliner
visitor (an extension ofvisitor
) is called byVisitorsGenerator
(which callsgenAcceptMethods(StringBuilder, Spacing, UserClassInfo, VisitorInfo)
to "inline" the accept methods on the user classes nodes.
This facilitates the user customization work by preparing all the lines of code the user wants to keep or to modify. CODEJAVAIntermediate variables are generated within the visit methods to walk into the syntax tree of the production each method visits.
They are of the proper type (always for theNodeList
,NodeListOptional
,NodeOptional
,NodeSequence
,Token
types, or the production type if at the first level), or of theINode
type for a production type below the first level.
They are generated (through theLONGNAMES
build constant flag) in a long format (reflecting all the types and levels of the parent variables) or in a short one (reflecting only their types).This visitor maintains state (for a grammar), is supposed to be run once and not supposed to be run in parallel threads (on the same grammar).
TESTCASE some to add
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class EDU.purdue.jtb.parser.visitor.DepthFirstVoidVisitor
DepthFirstVoidVisitor.ShouldNotOccurException
-
-
Field Summary
Fields Modifier and Type Field Description protected int
bnfLvl
The "BNF" nesting level: incremented/decremented:
for each new nestedExpansionChoices
(so starts at 0 (inDepthFirstVoidVisitor.visit(BNFProduction)
)), and for each new nestedExpansion
except in anExpansionChoices
with no choices Used to control spaces / new lines.protected CommonCodeGenerator
ccg
protected GlobalDataBuilder
gdbv
TheGlobalDataBuilder
visitorprotected java.lang.String
gvaStr
The generated variable assignment string to be insertedprotected JavaBranchPrinter
jbp
TheJavaBranchPrinter
printer to print a java node and its subtreeprotected java.lang.StringBuilder
sb
The (current) buffer to print intoprotected Spacing
spc
The indentation object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringBuilder
genJavaBranch(INode n)
Generates a java node and its subtree with a JavaPrinter.protected java.lang.String
nodeClassComment(INode n)
Returns a node class comment (a //jcp followed by the node class short name if global flag set, nothing otherwise).protected java.lang.String
nodeClassComment(INode n, java.lang.String str)
Returns a node class comment with an extra comment (a //jcp followed by the node class short name plus the extra comment if global flag set, nothing otherwise).int
saveToFile(java.lang.String outFile)
Saves the current buffer to an output file.void
visit(AccessModifier n)
Visits aAccessModifier
node, whose child is the following :void
visit(BNFProduction n)
Visits aBNFProduction
node, whose children are the following :void
visit(CharacterDescriptor n)
Visits aCharacterDescriptor
node, whose children are the following :void
visit(CharacterList n)
Visits aCharacterList
node, whose children are the following :void
visit(ComplexRegularExpression n)
Visits aComplexRegularExpression
node, whose child is the following :void
visit(ComplexRegularExpressionChoices n)
Visits aComplexRegularExpressionChoices
node, whose children are the following :void
visit(ComplexRegularExpressionUnit n)
Visits aComplexRegularExpressionUnit
node, whose child is the following :void
visit(Expansion n)
Visits aExpansion
node, whose children are the following :void
visit(ExpansionChoices n)
Visits aExpansionChoices
node, whose children are the following :void
visit(ExpansionUnit n)
Visits aExpansionUnit
node, whose child is the following :void
visit(ExpansionUnitTCF n)
Visits aExpansionUnitTCF
node, whose children are the following :void
visit(IdentifierAsString n)
Visits aIdentifierAsString
node, whose child is the following :void
visit(IntegerLiteral n)
Visits aIntegerLiteral
node, whose child is the following :void
visit(JavaCCOptions n)
Visits aJavaCCOptions
node, whose child is the following :void
visit(JavaCodeProduction n)
Visits aJavaCodeProduction
node, whose children are the following :void
visit(LocalLookahead n)
Visits aLocalLookahead
node, whose children are the following :void
visit(OptionBinding n)
Visits aOptionBinding
node, whose children are the following :void
visit(Production n)
Visits aProduction
node, whose child is the following :void
visit(RegExprKind n)
Visits aRegExprKind
node, whose child is the following :void
visit(RegExprSpec n)
Visits aRegExprSpec
node, whose children are the following :void
visit(RegularExpression n)
Visits aRegularExpression
node, whose child is the following :void
visit(RegularExprProduction n)
Visits aRegularExprProduction
node, whose children are the following :void
visit(StringLiteral n)
Visits aStringLiteral
node, whose child is the following :void
visit(TokenManagerDecls n)
Visits aTokenManagerDecls
node, whose children are the following :void
visit(Token n)
Prints into the current buffer a Token image and its specials before if global flag set.-
Methods inherited from class EDU.purdue.jtb.parser.visitor.DepthFirstVoidVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
-
-
-
-
Field Detail
-
gdbv
protected final GlobalDataBuilder gdbv
TheGlobalDataBuilder
visitor
-
ccg
protected final CommonCodeGenerator ccg
-
sb
protected java.lang.StringBuilder sb
The (current) buffer to print into
-
spc
protected Spacing spc
The indentation object
-
jbp
protected JavaBranchPrinter jbp
TheJavaBranchPrinter
printer to print a java node and its subtree
-
gvaStr
protected java.lang.String gvaStr
The generated variable assignment string to be inserted
-
bnfLvl
protected int bnfLvl
The "BNF" nesting level: incremented/decremented:
- for each new nested
ExpansionChoices
(so starts at 0 (inDepthFirstVoidVisitor.visit(BNFProduction)
)), and - for each new nested
Expansion
except in anExpansionChoices
with no choices
- for each new nested
-
-
Method Detail
-
visit
public void visit(ExpansionChoices n)
Visits aExpansionChoices
node, whose children are the following :f0 -> Expansion()
f1 -> ( #0 "|" #1 Expansion() )*
s: -1726831935- Specified by:
visit
in interfaceIVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(Expansion n)
Visits aExpansion
node, whose children are the following :f0 -> ( #0 "LOOKAHEAD" #1 "(" #2 LocalLookahead() #3 ")" )?
f1 -> ( ExpansionUnit() )+
s: -2134365682- Specified by:
visit
in interfaceIVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ExpansionUnit n)
Visits aExpansionUnit
node, whose child is the following :f0 -> . %0 #0 "LOOKAHEAD" #1 "(" #2 LocalLookahead() #3 ")"
.. .. | %1 Block()
.. .. | %2 #0 "[" #1 ExpansionChoices() #2 "]"
.. .. | %3 ExpansionUnitTCF()
.. .. | %4 #0 [ $0 PrimaryExpression() $1 "=" ]
.. .. . .. #1 ( &0 $0 IdentifierAsString() $1 Arguments()
.. .. . .. .. . .. $2 [ "!" ]
.. .. . .. .. | &1 $0 RegularExpression()
.. .. . .. .. . .. $1 [ ?0 "." ?1 < IDENTIFIER > ]
.. .. . .. .. . .. $2 [ "!" ] )
.. .. | %5 #0 "(" #1 ExpansionChoices() #2 ")"
.. .. . .. #3 ( &0 "+"
.. .. . .. .. | &1 "*"
.. .. . .. .. | &2 "?" )?
s: 1116287061- Specified by:
visit
in interfaceIVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ExpansionUnitTCF n)
Visits aExpansionUnitTCF
node, whose children are the following :f0 -> "try"
f1 -> "{"
f2 -> ExpansionChoices()
f3 -> "}"
f4 -> ( #0 "catch" #1 "("
.. .. . #2 ( Annotation() )*
.. .. . #3 [ "final" ]
.. .. . #4 Name() #5 < IDENTIFIER > #6 ")" #7 Block() )*
f5 -> [ #0 "finally" #1 Block() ]
s: 1601707097- Specified by:
visit
in interfaceIVoidVisitor
- Parameters:
n
- - the node to visit
-
nodeClassComment
protected java.lang.String nodeClassComment(INode n, java.lang.String str)
Returns a node class comment with an extra comment (a //jcp followed by the node class short name plus the extra comment if global flag set, nothing otherwise).- Parameters:
n
- - the node for the node class commentstr
- - the extra comment- Returns:
- the node class comment
-
nodeClassComment
protected java.lang.String nodeClassComment(INode n)
Returns a node class comment (a //jcp followed by the node class short name if global flag set, nothing otherwise).- Parameters:
n
- - the node for the node class comment- Returns:
- the node class comment
-
saveToFile
public final int saveToFile(java.lang.String outFile) throws java.io.IOException
Saves the current buffer to an output file.- Parameters:
outFile
- - the output file- Returns:
- OK_RC or FILE_EXISTS_RC
- Throws:
java.io.IOException
- if IO problem
-
genJavaBranch
protected final java.lang.StringBuilder genJavaBranch(INode n)
Generates a java node and its subtree with a JavaPrinter.- Parameters:
n
- - the node to process- Returns:
- a buffer with the generated source
-
visit
public void visit(Token n)
Prints into the current buffer a Token image and its specials before if global flag set.- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(JavaCCOptions n)
Visits aJavaCCOptions
node, whose child is the following :f0 -> [ #0 "options" #1 "{"
.. .. . #2 ( OptionBinding() )*
.. .. . #3 "}" ]
s: -1270729337- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(OptionBinding n)
Visits aOptionBinding
node, whose children are the following :f0 -> ( %0 < IDENTIFIER >
.. .. | %1 "LOOKAHEAD"
.. .. | %2 "IGNORE_CASE"
.. .. | %3 "static" )
f1 -> "="
f2 -> ( %0 IntegerLiteral()
.. .. | %1 BooleanLiteral()
.. .. | %2 StringLiteral() )
f3 -> ";"
s: -1998174573- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(Production n)
Visits aProduction
node, whose child is the following :f0 -> . %0 JavaCodeProduction()
.. .. | %1 RegularExprProduction()
.. .. | %2 TokenManagerDecls()
.. .. | %3 BNFProduction()
s: -120615333- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(JavaCodeProduction n)
Visits aJavaCodeProduction
node, whose children are the following :f0 -> "JAVACODE"
f1 -> AccessModifier()
f2 -> ResultType()
f3 -> IdentifierAsString()
f4 -> FormalParameters()
f5 -> [ #0 "throws" #1 Name()
.. .. . #2 ( $0 "," $1 Name() )* ]
f6 -> [ "%" ]
f7 -> Block()
s: -763138104- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(BNFProduction n)
Visits aBNFProduction
node, whose children are the following :f0 -> AccessModifier()
f1 -> ResultType()
f2 -> IdentifierAsString()
f3 -> FormalParameters()
f4 -> [ #0 "throws" #1 Name()
.. .. . #2 ( $0 "," $1 Name() )* ]
f5 -> [ "!" ]
f6 -> ":"
f7 -> Block()
f8 -> "{"
f9 -> ExpansionChoices()
f10 -> "}"
s: 1323482450- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(AccessModifier n)
Visits aAccessModifier
node, whose child is the following :f0 -> ( %0 "public"
.. .. | %1 "protected"
.. .. | %2 "private"
.. .. | %3 "final" )*
s: -1053437682- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(RegularExprProduction n)
Visits aRegularExprProduction
node, whose children are the following :f0 -> [ %0 #0 "<" #1 "*" #2 ">"
.. .. | %1 #0 "<" #1 < IDENTIFIER >
.. .. . .. #2 ( $0 "," $1 < IDENTIFIER > )*
.. .. . .. #3 ">" ]
f1 -> RegExprKind()
f2 -> [ #0 "[" #1 "IGNORE_CASE" #2 "]" ]
f3 -> ":"
f4 -> "{"
f5 -> RegExprSpec()
f6 -> ( #0 "|" #1 RegExprSpec() )*
f7 -> "}"
s: 484788342- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(TokenManagerDecls n)
Visits aTokenManagerDecls
node, whose children are the following :f0 -> "TOKEN_MGR_DECLS"
f1 -> ":"
f2 -> ClassOrInterfaceBody()
s: -1566997219- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(RegExprKind n)
Visits aRegExprKind
node, whose child is the following :f0 -> . %0 "TOKEN"
.. .. | %1 "SPECIAL_TOKEN"
.. .. | %2 "SKIP"
.. .. | %3 "MORE"
s: -1874441621- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(RegExprSpec n)
Visits aRegExprSpec
node, whose children are the following :f0 -> RegularExpression()
f1 -> [ "!" ]
f2 -> [ Block() ]
f3 -> [ #0 ":" #1 < IDENTIFIER > ]
s: -1949948808- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(LocalLookahead n)
Visits aLocalLookahead
node, whose children are the following :f0 -> [ IntegerLiteral() ]
f1 -> [ "," ]
f2 -> [ ExpansionChoices() ]
f3 -> [ "," ]
f4 -> [ #0 "{"
.. .. . #1 [ Expression() ]
.. .. . #2 "}" ]
s: -1879920786- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(RegularExpression n)
Visits aRegularExpression
node, whose child is the following :f0 -> . %0 StringLiteral()
.. .. | %1 #0 "<"
.. .. . .. #1 [ $0 [ "#" ]
.. .. . .. .. . $1 IdentifierAsString() $2 ":" ]
.. .. . .. #2 ComplexRegularExpressionChoices() #3 ">"
.. .. | %2 #0 "<" #1 IdentifierAsString() #2 ">"
.. .. | %3 #0 "<" #1 "EOF" #2 ">"
s: 1719627151- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ComplexRegularExpressionChoices n)
Visits aComplexRegularExpressionChoices
node, whose children are the following :f0 -> ComplexRegularExpression()
f1 -> ( #0 "|" #1 ComplexRegularExpression() )*
s: -1240933595- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ComplexRegularExpression n)
Visits aComplexRegularExpression
node, whose child is the following :f0 -> ( ComplexRegularExpressionUnit() )+
s: 896313544- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ComplexRegularExpressionUnit n)
Visits aComplexRegularExpressionUnit
node, whose child is the following :f0 -> . %0 StringLiteral()
.. .. | %1 #0 "<" #1 IdentifierAsString() #2 ">"
.. .. | %2 CharacterList()
.. .. | %3 #0 "(" #1 ComplexRegularExpressionChoices() #2 ")"
.. .. . .. #3 ( &0 "+"
.. .. . .. .. | &1 "*"
.. .. . .. .. | &2 "?"
.. .. . .. .. | &3 $0 "{" $1 IntegerLiteral()
.. .. . .. .. . .. $2 [ ?0 ","
.. .. . .. .. . .. .. . ?1 [ IntegerLiteral() ] ]
.. .. . .. .. . .. $3 "}" )?
s: -1507427530- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(CharacterList n)
Visits aCharacterList
node, whose children are the following :f0 -> [ "~" ]
f1 -> "["
f2 -> [ #0 CharacterDescriptor()
.. .. . #1 ( $0 "," $1 CharacterDescriptor() )* ]
f3 -> "]"
s: -966448889- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(CharacterDescriptor n)
Visits aCharacterDescriptor
node, whose children are the following :f0 -> StringLiteral()
f1 -> [ #0 "-" #1 StringLiteral() ]
s: 895087809- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(IdentifierAsString n)
Visits aIdentifierAsString
node, whose child is the following :f0 -> < IDENTIFIER >
s: -1580059612- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(IntegerLiteral n)
Visits aIntegerLiteral
node, whose child is the following :f0 -> < INTEGER_LITERAL >
s: -1048223857- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(StringLiteral n)
Visits aStringLiteral
node, whose child is the following :f0 -> < STRING_LITERAL >
s: 241433948- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
-