Class IMPFrontend
- java.lang.Object
-
- org.antlr.v4.runtime.tree.AbstractParseTreeVisitor<T>
-
- it.unive.lisa.imp.antlr.IMPParserBaseVisitor<java.lang.Object>
-
- it.unive.lisa.imp.IMPFrontend
-
- All Implemented Interfaces:
IMPParserVisitor<java.lang.Object>
,org.antlr.v4.runtime.tree.ParseTreeVisitor<java.lang.Object>
public class IMPFrontend extends IMPParserBaseVisitor<java.lang.Object>
AnIMPParserBaseVisitor
that will parse the IMP code building a representation that can be analyzed through LiSA. Methods overridden in this class return aPair
ofStatement
s to uniquely mark the entry- and exit-points of the code that has been generated by vising an AST node.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static it.unive.lisa.program.Program
processFile(java.lang.String file)
static it.unive.lisa.program.Program
processFile(java.lang.String file, boolean onlyMain)
static it.unive.lisa.program.Program
processText(java.lang.String text)
static it.unive.lisa.program.Program
processText(java.lang.String text, boolean onlyMain)
it.unive.lisa.program.ClassUnit
visitClassUnit(IMPParser.ClassUnitContext ctx)
Visit a parse tree produced byIMPParser.classUnit()
.it.unive.lisa.program.ConstantGlobal
visitConstantDeclaration(IMPParser.ConstantDeclarationContext ctx)
Visit a parse tree produced byIMPParser.constantDeclaration()
.it.unive.lisa.program.cfg.CFG
visitConstructorDeclaration(IMPParser.ConstructorDeclarationContext ctx)
Visit a parse tree produced byIMPParser.constructorDeclaration()
.it.unive.lisa.program.Global
visitFieldDeclaration(IMPParser.FieldDeclarationContext ctx)
Visit a parse tree produced byIMPParser.fieldDeclaration()
.it.unive.lisa.program.Program
visitFile(IMPParser.FileContext ctx)
Visit a parse tree produced byIMPParser.file()
.it.unive.lisa.program.cfg.Parameter
visitFormal(IMPParser.FormalContext ctx)
Visit a parse tree produced byIMPParser.formal()
.it.unive.lisa.program.cfg.Parameter[]
visitFormals(IMPParser.FormalsContext ctx)
Visit a parse tree produced byIMPParser.formals()
.it.unive.lisa.program.InterfaceUnit
visitInterfaceUnit(IMPParser.InterfaceUnitContext ctx)
Visit a parse tree produced byIMPParser.interfaceUnit()
.it.unive.lisa.symbolic.value.Constant
visitLiteral(IMPParser.LiteralContext ctx)
Visit a parse tree produced byIMPParser.literal()
.it.unive.lisa.program.cfg.CFG
visitMethodDeclaration(IMPParser.MethodDeclarationContext ctx)
Visit a parse tree produced byIMPParser.methodDeclaration()
.it.unive.lisa.program.cfg.AbstractCodeMember
visitSignatureDeclaration(IMPParser.SignatureDeclarationContext ctx)
Visit a parse tree produced byIMPParser.signatureDeclaration()
.it.unive.lisa.program.Unit
visitUnit(IMPParser.UnitContext ctx)
Visit a parse tree produced byIMPParser.unit()
.-
Methods inherited from class it.unive.lisa.imp.antlr.IMPParserBaseVisitor
visitAnnotation, visitAnnotationMember, visitAnnotationMembers, visitAnnotations, visitAnnotationValue, visitArg, visitArguments, visitArrayAccess, visitArrayAnnotationValue, visitArrayCreatorRest, visitArrayExpr, visitArraySqDeclaration, visitAssignment, visitBasicAnnotationValue, visitBasicExpr, visitBinaryStringExpr, visitBlock, visitBlockOrStatement, visitClassMemberDeclarations, visitExpression, visitFieldAccess, visitForDeclaration, visitForLoop, visitIndex, visitInterfaceMemberDeclarations, visitLocalDeclaration, visitLoop, visitMethodCall, visitNewBasicArrayExpr, visitNewReferenceType, visitParExpr, visitPrimitiveType, visitReceiver, visitStatement, visitStringExpr, visitTernaryStringExpr, visitUnaryStringExpr, visitUnitName, visitUnitNames, visitWhileLoop
-
Methods inherited from class org.antlr.v4.runtime.tree.AbstractParseTreeVisitor
aggregateResult, defaultResult, shouldVisitNextChild, visit, visitChildren, visitErrorNode, visitTerminal
-
-
-
-
Method Detail
-
processFile
public static it.unive.lisa.program.Program processFile(java.lang.String file) throws ParsingException
Parses a file using theIMPLexer
and theIMPParser
produced by compiling the ANTLR4 grammar, and yields theProgram
that corresponds to the one parsed from that file. Invoking this method is equivalent to invokingprocessFile(String, boolean)
passingfalse
as second parameter.- Parameters:
file
- the complete path (relative or absolute) of the file to parse- Returns:
- the resulting
Program
- Throws:
ParsingException
- if this frontend is unable to parse the file
-
processFile
public static it.unive.lisa.program.Program processFile(java.lang.String file, boolean onlyMain) throws ParsingException
Parses a file using theIMPLexer
and theIMPParser
produced by compiling the ANTLR4 grammar, and yields theProgram
that corresponds to the one parsed from that file.- Parameters:
file
- the complete path (relative or absolute) of the file to parseonlyMain
- true iff the only entry point is the main method- Returns:
- the resulting
Program
- Throws:
ParsingException
- if this frontend is unable to parse the file
-
processText
public static it.unive.lisa.program.Program processText(java.lang.String text) throws ParsingException
Parses a piece of IMP code using theIMPLexer
and theIMPParser
produced by compiling the ANTLR4 grammar, and yields theProgram
that corresponds to the one parsed from the given text. Invoking this method is equivalent to invokingprocessText(String, boolean)
passingfalse
as second parameter.- Parameters:
text
- the IMP program to parse- Returns:
- the resulting
Program
- Throws:
ParsingException
- if this frontend is unable to parse the text
-
processText
public static it.unive.lisa.program.Program processText(java.lang.String text, boolean onlyMain) throws ParsingException
Parses a piece of IMP code using theIMPLexer
and theIMPParser
produced by compiling the ANTLR4 grammar, and yields theProgram
that corresponds to the one parsed from the given text.- Parameters:
text
- the IMP program to parseonlyMain
- true iff the only entry point is the main method- Returns:
- the resulting
Program
- Throws:
ParsingException
- if this frontend is unable to parse the text
-
visitFile
public it.unive.lisa.program.Program visitFile(IMPParser.FileContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.file()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitFile
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitFile
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitUnit
public it.unive.lisa.program.Unit visitUnit(IMPParser.UnitContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.unit()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitUnit
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitUnit
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitInterfaceUnit
public it.unive.lisa.program.InterfaceUnit visitInterfaceUnit(IMPParser.InterfaceUnitContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.interfaceUnit()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitInterfaceUnit
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitInterfaceUnit
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitClassUnit
public it.unive.lisa.program.ClassUnit visitClassUnit(IMPParser.ClassUnitContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.classUnit()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitClassUnit
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitClassUnit
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitConstantDeclaration
public it.unive.lisa.program.ConstantGlobal visitConstantDeclaration(IMPParser.ConstantDeclarationContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.constantDeclaration()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitConstantDeclaration
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitConstantDeclaration
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitFieldDeclaration
public it.unive.lisa.program.Global visitFieldDeclaration(IMPParser.FieldDeclarationContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.fieldDeclaration()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitFieldDeclaration
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitFieldDeclaration
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitConstructorDeclaration
public it.unive.lisa.program.cfg.CFG visitConstructorDeclaration(IMPParser.ConstructorDeclarationContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.constructorDeclaration()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitConstructorDeclaration
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitConstructorDeclaration
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitMethodDeclaration
public it.unive.lisa.program.cfg.CFG visitMethodDeclaration(IMPParser.MethodDeclarationContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.methodDeclaration()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitMethodDeclaration
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitMethodDeclaration
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitSignatureDeclaration
public it.unive.lisa.program.cfg.AbstractCodeMember visitSignatureDeclaration(IMPParser.SignatureDeclarationContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.signatureDeclaration()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitSignatureDeclaration
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitSignatureDeclaration
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitFormals
public it.unive.lisa.program.cfg.Parameter[] visitFormals(IMPParser.FormalsContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.formals()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitFormals
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitFormals
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitFormal
public it.unive.lisa.program.cfg.Parameter visitFormal(IMPParser.FormalContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.formal()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitFormal
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitFormal
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
visitLiteral
public it.unive.lisa.symbolic.value.Constant visitLiteral(IMPParser.LiteralContext ctx)
Description copied from class:IMPParserBaseVisitor
Visit a parse tree produced byIMPParser.literal()
.The default implementation returns the result of calling
AbstractParseTreeVisitor.visitChildren(org.antlr.v4.runtime.tree.RuleNode)
onctx
.- Specified by:
visitLiteral
in interfaceIMPParserVisitor<java.lang.Object>
- Overrides:
visitLiteral
in classIMPParserBaseVisitor<java.lang.Object>
- Parameters:
ctx
- the parse tree- Returns:
- the visitor result
-
-