Class SemanticChecker
- java.lang.Object
-
- EDU.purdue.jtb.parser.visitor.DepthFirstVoidVisitor
-
- EDU.purdue.jtb.analyse.SemanticChecker
-
- All Implemented Interfaces:
IVoidVisitor
public class SemanticChecker extends DepthFirstVoidVisitor
TheSemanticChecker
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 EDU.purdue.jtb.parser.visitor.DepthFirstVoidVisitor
DepthFirstVoidVisitor.ShouldNotOccurException
-
-
Constructor Summary
Constructors Constructor Description SemanticChecker(GlobalDataBuilder aGdbv)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
visit(Block n)
Visits aBlock
node, whose children are the following :void
visit(BlockStatement n)
Visits aBlockStatement
node, whose child is the following :void
visit(BNFProduction n)
Visits aBNFProduction
node, whose children are 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(JavaCCInput n)
Visits aJavaCCInput
node, whose children are 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(LocalVariableDeclaration n)
Visits aLocalVariableDeclaration
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(RegExprSpec n)
Visits aRegExprSpec
node, whose children are the following :void
visit(RegularExprProduction n)
Visits aRegularExprProduction
node, whose children are the following :void
visit(Statement n)
Visits aStatement
node, whose child is the following :void
visit(TokenManagerDecls n)
Visits aTokenManagerDecls
node, whose children are the following :void
visit(VariableDeclarator n)
Visits aVariableDeclarator
node, whose children are 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, visit, visit, visit
-
-
-
-
Constructor Detail
-
SemanticChecker
public SemanticChecker(GlobalDataBuilder aGdbv)
Constructor.- Parameters:
aGdbv
- - the GlobalDataBuilder visitor
-
-
Method Detail
-
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(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 -> ";"- 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(ExpansionChoices n)
Visits aExpansionChoices
node, whose children are the following :f0 -> Expansion()
f1 -> ( #0 "|" #1 Expansion() )*
s: -1726831935- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- 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
- 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(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
- Overrides:
visit
in classDepthFirstVoidVisitor
- 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
- 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(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(VariableDeclarator n)
Visits aVariableDeclarator
node, whose children are the following :f0 -> VariableDeclaratorId()
f1 -> [ #0 "=" #1 VariableInitializer() ]
s: -484955779- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(Statement n)
Visits aStatement
node, 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:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(Block n)
Visits aBlock
node, whose children are the following :f0 -> "{"
f1 -> ( BlockStatement() )*
f2 -> "}"
s: -47169424- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(BlockStatement n)
Visits aBlockStatement
node, whose child is the following :f0 -> . %0 #0 LocalVariableDeclaration() #1 ";"
.. .. | %1 Statement()
.. .. | %2 ClassOrInterfaceDeclaration()
s: -1009630136- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
visit
public void visit(LocalVariableDeclaration n)
Visits aLocalVariableDeclaration
node, whose children are the following :f0 -> VariableModifiers()
f1 -> Type()
f2 -> VariableDeclarator()
f3 -> ( #0 "," #1 VariableDeclarator() )*
s: 225808290- Specified by:
visit
in interfaceIVoidVisitor
- Overrides:
visit
in classDepthFirstVoidVisitor
- Parameters:
n
- - the node to visit
-
-