Class GlobalDataBuilder
- java.lang.Object
-
- EDU.purdue.jtb.parser.visitor.DepthFirstVoidVisitor
-
- EDU.purdue.jtb.analyse.GlobalDataBuilder
-
- All Implemented Interfaces:
IVoidVisitor
public class GlobalDataBuilder extends DepthFirstVoidVisitor
TheGlobalDataBuilder
visitor performs, at the beginning of the JTB processing, some error checking and builds and stores objects needed by other classes:- a HashMap (
notTbcNodesHM
) of JavaCodeProductions whose nodes must be created ("%" syntax) and of BNFProductions whose nodes must not be created ("!" syntax), - a HashMap (
prodHM
) of all JavaCodeProductions and BNFProductions identifiers and their result type, - a list (
retVarInfo
) of return variables declarations (for all non "void" JavaCodeProductions for which the node creation has been asked and BNFProductions for which the node creation has not been forbidden) - a HashMap (
tokenHM
) of tokens which have a constant regular expression, e.g. < PLUS : "+" >, which will be used to generate a default constructor, - a HashMap (
nbSubNodesTbcHM
) of (ExpansionChoices
/Expansion
/ExpansionUnit
) nodes with their number of sub-nodes to be created.
This visitor 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 Modifier and Type Class Description class
GlobalDataBuilder.RetVarInfo
Return variable information.-
Nested classes/interfaces inherited from class EDU.purdue.jtb.parser.visitor.DepthFirstVoidVisitor
DepthFirstVoidVisitor.ShouldNotOccurException
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BNF_IND
The indicator for BNFProduction in thenotTbcNodesHM
andprodHM
tablesstatic java.lang.String
DONT_CREATE
The specific regular expression for a token node not to be createdstatic java.lang.String
JC_IND
The indicator for JavaCodeProduction in thenotTbcNodesHM
andprodHM
tablesJTBOptions
jopt
The global JTB options (not thread safe but used only in read-access)java.lang.String
packageName
The parser's package name (from the grammar or the command line)java.lang.String
parserName
The parser name
-
Constructor Summary
Constructors Constructor Description GlobalDataBuilder(JTBOptions aJopt)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getFixedName(java.lang.String aName)
Builds a (class) name with the default prefix and/or suffix, except for the base (class) names.int
getNbSubNodesTbc(Expansion n)
Returns the count of the nodes to be created below a anExpansion
.int
getNbSubNodesTbc(ExpansionChoices n)
Returns the count of the nodes to be created below a anExpansionChoices
.int
getNbSubNodesTbc(ExpansionUnit n)
Returns the count of the nodes to be created below a anExpansionUnit
.java.util.Map<INode,java.lang.Integer>
getNbSubNodesTbcHM()
java.util.Map<java.lang.String,java.lang.String>
getNotTbcNodesHM()
java.util.Map<java.lang.String,java.lang.String>
getProdHM()
java.util.List<GlobalDataBuilder.RetVarInfo>
getRetVarInfo()
java.util.Map<java.lang.String,java.lang.String>
getTokenHM()
void
visit(BNFProduction n)
Visits aBNFProduction
node, whose children are the following :void
visit(ClassOrInterfaceType n)
Visits aClassOrInterfaceType
node, whose children are the following :void
visit(CompilationUnit n)
Visits aCompilationUnit
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(IdentifierAsString n)
Visits aIdentifierAsString
node, whose child is the following :void
visit(JavaCCInput n)
Visits aJavaCCInput
node, whose children are the following :void
visit(JavaCodeProduction n)
Visits aJavaCodeProduction
node, whose children are the following :void
visit(PrimitiveType n)
Visits aPrimitiveType
node, whose child is the following :void
visit(Production n)
Visits aProduction
node, whose child is the following :void
visit(ReferenceType n)
Visits aReferenceType
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(ResultType n)
Visits aResultType
node, whose child is the following :void
visit(StringLiteral n)
Visits aStringLiteral
node, whose child is the following :void
visit(Type n)
Visits aType
node, whose child is the following :void
visit(TypeArgument n)
Visits aTypeArgument
node, whose child is the following :void
visit(TypeArguments n)
Visits aTypeArguments
node, whose children are the following :void
visit(WildcardBounds n)
Visits aWildcardBounds
node, whose child is the following :-
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, visit, visit, visit, visit
-
-
-
-
Field Detail
-
jopt
public final JTBOptions jopt
The global JTB options (not thread safe but used only in read-access)
-
parserName
public java.lang.String parserName
The parser name
-
packageName
public java.lang.String packageName
The parser's package name (from the grammar or the command line)
-
JC_IND
public static final java.lang.String JC_IND
The indicator for JavaCodeProduction in thenotTbcNodesHM
andprodHM
tables- See Also:
- Constant Field Values
-
BNF_IND
public static final java.lang.String BNF_IND
The indicator for BNFProduction in thenotTbcNodesHM
andprodHM
tables- See Also:
- Constant Field Values
-
DONT_CREATE
public static final java.lang.String DONT_CREATE
The specific regular expression for a token node not to be created- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GlobalDataBuilder
public GlobalDataBuilder(JTBOptions aJopt)
Constructor.- Parameters:
aJopt
- - the JTB options
-
-
Method Detail
-
getFixedName
public java.lang.String getFixedName(java.lang.String aName)
Builds a (class) name with the default prefix and/or suffix, except for the base (class) names.- Parameters:
aName
- - string to prefix or suffix- Returns:
- the prefixed and/or suffixed name
-
visit
public void visit(JavaCCInput n)
Visits aJavaCCInput
node, whose children are the following :f0 -> JavaCCOptions()
f1 -> "PARSER_BEGIN"
f2 -> "("
f3 -> IdentifierAsString()
f4 -> ")"
f5 -> CompilationUnit()
f6 -> "PARSER_END"
f7 -> "("
f8 -> IdentifierAsString()
f9 -> ")"
f10 -> ( Production() )+
f11 -> < EOF >
s: 1465207473- 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(CompilationUnit n)
Visits aCompilationUnit
node, whose children are the following :f0 -> [ PackageDeclaration() ]
f1 -> ( ImportDeclaration() )*
f2 -> ( TypeDeclaration() )*
s: 1761039264- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ResultType n)
Visits aResultType
node, whose child is the following :f0 -> ( %0 "void"
.. .. | %1 Type() )
s: 805291204- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(Type n)
Visits aType
node, whose child is the following :f0 -> . %0 ReferenceType()
.. .. | %1 PrimitiveType()
s: -1143267570- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ReferenceType n)
Visits aReferenceType
node, whose child is the following :f0 -> . %0 #0 PrimitiveType()
.. .. . .. #1 ( $0 "[" $1 "]" )+
.. .. | %1 #0 ClassOrInterfaceType()
.. .. . .. #1 ( $0 "[" $1 "]" )*
s: -275468366- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(PrimitiveType n)
Visits aPrimitiveType
node, whose child is the following :f0 -> . %0 "boolean"
.. .. | %1 "char"
.. .. | %2 "byte"
.. .. | %3 "short"
.. .. | %4 "int"
.. .. | %5 "long"
.. .. | %6 "float"
.. .. | %7 "double"
s: 427914477- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(ClassOrInterfaceType n)
Visits aClassOrInterfaceType
node, whose children are the following :f0 -> < IDENTIFIER >
f1 -> [ TypeArguments() ]
f2 -> ( #0 "." #1 < IDENTIFIER >
.. .. . #2 [ TypeArguments() ] )*
s: -1178309727- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(TypeArguments n)
Visits aTypeArguments
node, whose children are the following :f0 -> "<"
f1 -> TypeArgument()
f2 -> ( #0 "," #1 TypeArgument() )*
f3 -> ">"
s: 131755052- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(TypeArgument n)
Visits aTypeArgument
node, whose child is the following :f0 -> . %0 ReferenceType()
.. .. | %1 #0 "?"
.. .. . .. #1 [ WildcardBounds() ]
s: 36461692- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(WildcardBounds n)
Visits aWildcardBounds
node, whose child is the following :f0 -> . %0 #0 "extends" #1 ReferenceType()
.. .. | %1 #0 "super" #1 ReferenceType()
s: 122808000- 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(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(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(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(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
-
getNotTbcNodesHM
public final java.util.Map<java.lang.String,java.lang.String> getNotTbcNodesHM()
- Returns:
- the table of nodes which must not be created : JavaCodeProductions with no "%" indicator and BNFProductions with "!" indicator
-
getProdHM
public final java.util.Map<java.lang.String,java.lang.String> getProdHM()
- Returns:
- the table of all BNFProductions and JavaCodeProductions
-
getNbSubNodesTbcHM
public final java.util.Map<INode,java.lang.Integer> getNbSubNodesTbcHM()
- Returns:
- the map of nodes with their number of sub-nodes to be created
-
getRetVarInfo
public final java.util.List<GlobalDataBuilder.RetVarInfo> getRetVarInfo()
- Returns:
- the list of all return variables information
-
getTokenHM
public java.util.Map<java.lang.String,java.lang.String> getTokenHM()
- Returns:
- * The map of tokens (key = token name, value = regular expression or
DONT_CREATE
for tokens not to be created as Token nodes)
-
getNbSubNodesTbc
public int getNbSubNodesTbc(ExpansionChoices n)
Returns the count of the nodes to be created below a anExpansionChoices
.- Parameters:
n
- - anExpansionChoices
- Returns:
- the number of nodes to be created
-
getNbSubNodesTbc
public int getNbSubNodesTbc(Expansion n)
Returns the count of the nodes to be created below a anExpansion
.- Parameters:
n
- - anExpansion
- Returns:
- the number of nodes to be created
-
getNbSubNodesTbc
public int getNbSubNodesTbc(ExpansionUnit n)
Returns the count of the nodes to be created below a anExpansionUnit
.- Parameters:
n
- - anExpansionUnit
- Returns:
- the number of nodes to be created
-
-