Class SemanticChecker
- All Implemented Interfaces:
IVoidVisitor
SemanticChecker visitor checks and report informations, warnings or errors for the following
conditions:- when a JavaCodeProduction is to be generated (warning if return type is non "void", information otherwise) (JTB will alter the code),
- when a BNFProduction is not to be generated (information),
- when a to be generated BNFProduction has a return value other than "void" (warning) (JTB will alter the code),
- when a JavaCodeProduction or a BNFProduction is not to be generated locally but is also not to be generated globally (warning) (as unnecessary),
- when a JavaCodeProduction or a BNFProduction has a name reserved for an automatically generated JTB class (e.g. INode, INodeList, ...) or (error) (the project will not compile),
- when a "void" JavaCodeProduction or BNFProduction is used in an assignment (error) (the project will not compile),
- when a "void" JavaCodeProduction or BNFProduction is used in a return statement with expression (error) (the project will not compile),
- when a user declared variable is not initialized (warning) (javac may complain while compiling the generated parser),
- when there are extraneous parentheses in a production (warning) (should be better to remove them),
- when a no node creation indicator appears in an ExpansionChoices in a syntactic lookahead
- when a return statement is transformed (information).
Note: the warning:
"No blocks of Java code must exist within ExpansionUnit" (since the JTB first authors believed they are
generally unnecessary in JTB grammars)
has been replaced by the following new information:
"Return statement in a Java block in production '...' . It will be transformed in an assign statement to
the corresponding new parser class variable."
These blocks are now allowed - as for example JavaCC 4.2 grammar has a lot of Java code blocks -
but as JTB generates return statements to create and return the nodes corresponding to the productions and
changes the production return types, JTB now creates an additional parser class variable to store the user
return information and changes the corresponding return statements.
Note: the warning:
"JavaCodeProduction blocks must be specially handled."
has been replaced by the following new information:
"Non "void" JavaCodeProduction. Result type '...' will be changed into '...', and a parser class variable
'jtbrt_...' of type '...'will be added to hold the return value."
JTB now creates an additional parser class variable to store the user return information and changes the
corresponding return statements.
Note: the warning:
"Non initialized user variable '...'. May lead to compiler error(s). Check in generated parser."
has been added (it may lead to unnecessary warnings).
Note : could be done: check that the JTB generated return variables do not collide with user variables.
This visitor is supposed to be run once and not supposed to be run in parallel threads (on the same grammar).
TODO check coverage-
Nested Class Summary
Nested classes/interfaces inherited from class DepthFirstVoidVisitor
DepthFirstVoidVisitor.ShouldNotOccurException -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVisits aBlocknode, whose children are the following :voidVisits aBlockStatementnode, whose child is the following :voidVisits aBNFProductionnode, whose children are the following :voidVisits aExpansionnode, whose children are the following :voidVisits aExpansionChoicesnode, whose children are the following :voidVisits aExpansionUnitnode, whose child is the following :voidVisits aExpansionUnitTCFnode, whose children are the following :voidvisit(JavaCCInput n) Visits aJavaCCInputnode, whose children are the following :voidVisits aJavaCodeProductionnode, whose children are the following :voidVisits aLocalLookaheadnode, whose children are the following :voidVisits aLocalVariableDeclarationnode, whose children are the following :voidVisits aOptionBindingnode, whose children are the following :voidvisit(Production n) Visits aProductionnode, whose child is the following :voidvisit(RegExprSpec n) Visits aRegExprSpecnode, whose children are the following :voidVisits aRegularExprProductionnode, whose children are the following :voidVisits aStatementnode, whose child is the following :voidVisits aTokenManagerDeclsnode, whose children are the following :voidVisits aVariableDeclaratornode, whose children are the following :Methods inherited from class 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, visit, visit, visit
-
Constructor Details
-
SemanticChecker
Constructor.- Parameters:
aGdbv- - the GlobalDataBuilder visitor
-
-
Method Details
-
visit
Visits aJavaCCInputnode, 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 -> invalid input: '<' EOF >
s: 1465207473- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aOptionBindingnode, whose children are the following :f0 -> ( %0 invalid input: '<' IDENTIFIER >
.. .. | %1 "LOOKAHEAD"
.. .. | %2 "IGNORE_CASE"
.. .. | %3 "static" )
f1 -> "="
f2 -> ( %0 IntegerLiteral()
.. .. | %1 BooleanLiteral()
.. .. | %2 StringLiteral() )
f3 -> ";"- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aProductionnode, whose child is the following :f0 -> . %0 JavaCodeProduction()
.. .. | %1 RegularExprProduction()
.. .. | %2 TokenManagerDecls()
.. .. | %3 BNFProduction()
s: -120615333- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aJavaCodeProductionnode, 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:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aBNFProductionnode, 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:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aExpansionChoicesnode, whose children are the following :f0 -> Expansion()
f1 -> ( #0 "|" #1 Expansion() )*
s: -1726831935- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aExpansionnode, whose children are the following :f0 -> ( #0 "LOOKAHEAD" #1 "(" #2 LocalLookahead() #3 ")" )?
f1 -> ( ExpansionUnit() )+
s: -2134365682- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aLocalLookaheadnode, whose children are the following :f0 -> [ IntegerLiteral() ]
f1 -> [ "," ]
f2 -> [ ExpansionChoices() ]
f3 -> [ "," ]
f4 -> [ #0 "{"
.. .. . #1 [ Expression() ]
.. .. . #2 "}" ]
s: -1879920786- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aExpansionUnitnode, 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 ( invalid input: '&'0 $0 IdentifierAsString() $1 Arguments()
.. .. . .. .. . .. $2 [ "!" ]
.. .. . .. .. | invalid input: '&'1 $0 RegularExpression()
.. .. . .. .. . .. $1 [ ?0 "." ?1 invalid input: '<' IDENTIFIER > ]
.. .. . .. .. . .. $2 [ "!" ] )
.. .. | %5 #0 "(" #1 ExpansionChoices() #2 ")"
.. .. . .. #3 ( invalid input: '&'0 "+"
.. .. . .. .. | invalid input: '&'1 "*"
.. .. . .. .. | invalid input: '&'2 "?" )?
s: 1116287061- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aExpansionUnitTCFnode, whose children are the following :f0 -> "try"
f1 -> "{"
f2 -> ExpansionChoices()
f3 -> "}"
f4 -> ( #0 "catch" #1 "("
.. .. . #2 ( Annotation() )*
.. .. . #3 [ "final" ]
.. .. . #4 Name() #5 invalid input: '<' IDENTIFIER > #6 ")" #7 Block() )*
f5 -> [ #0 "finally" #1 Block() ]
s: 1601707097- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aRegularExprProductionnode, whose children are the following :f0 -> [ %0 #0 "invalid input: '<'" #1 "*" #2 ">"
.. .. | %1 #0 "invalid input: '<'" #1 invalid input: '<' IDENTIFIER >
.. .. . .. #2 ( $0 "," $1 invalid input: '<' IDENTIFIER > )*
.. .. . .. #3 ">" ]
f1 -> RegExprKind()
f2 -> [ #0 "[" #1 "IGNORE_CASE" #2 "]" ]
f3 -> ":"
f4 -> "{"
f5 -> RegExprSpec()
f6 -> ( #0 "|" #1 RegExprSpec() )*
f7 -> "}"
s: 484788342- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aTokenManagerDeclsnode, whose children are the following :f0 -> "TOKEN_MGR_DECLS"
f1 -> ":"
f2 -> ClassOrInterfaceBody()
s: -1566997219- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aRegExprSpecnode, whose children are the following :f0 -> RegularExpression()
f1 -> [ "!" ]
f2 -> [ Block() ]
f3 -> [ #0 ":" #1 invalid input: '<' IDENTIFIER > ]
s: -1949948808- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aVariableDeclaratornode, whose children are the following :f0 -> VariableDeclaratorId()
f1 -> [ #0 "=" #1 VariableInitializer() ]
s: -484955779- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aStatementnode, whose child is the following :f0 -> . %00 LabeledStatement()
.. .. | %01 AssertStatement()
.. .. | %02 Block()
.. .. | %03 EmptyStatement()
.. .. | %04 #0 StatementExpression() #1 ";"
.. .. | %05 SwitchStatement()
.. .. | %06 IfStatement()
.. .. | %07 WhileStatement()
.. .. | %08 DoStatement()
.. .. | %09 ForStatement()
.. .. | %10 BreakStatement()
.. .. | %11 ContinueStatement()
.. .. | %12 ReturnStatement()
.. .. | %13 ThrowStatement()
.. .. | %14 SynchronizedStatement()
.. .. | %15 TryStatement()
s: 1394695492- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aBlocknode, whose children are the following :f0 -> "{"
f1 -> ( BlockStatement() )*
f2 -> "}"
s: -47169424- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aBlockStatementnode, whose child is the following :f0 -> . %0 #0 LocalVariableDeclaration() #1 ";"
.. .. | %1 Statement()
.. .. | %2 ClassOrInterfaceDeclaration()
s: -1009630136- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-
visit
Visits aLocalVariableDeclarationnode, whose children are the following :f0 -> VariableModifiers()
f1 -> Type()
f2 -> VariableDeclarator()
f3 -> ( #0 "," #1 VariableDeclarator() )*
s: 225808290- Specified by:
visitin interfaceIVoidVisitor- Overrides:
visitin classDepthFirstVoidVisitor- Parameters:
n- - the node to visit
-