Class Parser
This class implements an operator precedence parser. Errors are reported to the Environment object, if the error can't be resolved immediately, a SyntaxError exception is thrown.
Error recovery is implemented by catching Scanner.SyntaxError exceptions and discarding input scanner.tokens until an input token is reached that is possibly a legal continuation.
The parse tree that is constructed represents the input exactly (no rewrites to simpler forms). This is important if the resulting tree is to be used for code formatting in a programming environment. Currently only documentation comments are retained.
A parser owns several components (scanner, constant-parser, instruction-parser, annotations-parser) to which it delegates certain parsing responsibilities. This parser contains functions to parse the overall form of a class, and any members (fields, methods, inner-classes).
Syntax errors, should always be caught inside the parser for error recovery.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classThe main compile error for the parser(package private) static interface(package private) static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ParserAnnotationother parser components(package private) ClassDataprivate ArrayList<AnnotationData> private ParserCP(package private) CodeAttrprivate CFVersionprivate booleanprivate ParserInstrprivate ArrayList<AnnotationData> private ModuleAttrprivate Stringprivate ArrayList<AnnotationData> private Stringprotected ConstantPool -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedParser(Environment sf, CFVersion cfVersion) Create a parser -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckReferenceIndex(int position, Tables.ConstType defaultTag, Tables.ConstType default2Tag) Check the pair reference_kind:reference_index where reference_kind is any from: REF_invokeVirtual, REF_newInvokeSpecial, REF_invokeStatic, REF_invokeSpecial, REF_invokeInterface and reference_index is one of [Empty], Method or InterfaceMethod There are possible entries: ldc Dynamic REF_newInvokeSpecial:InterfaceMethod LdcConDyTwice."": ldc Dynamic REF_invokeInterface:LdcConDyTwice." ": ldc Dynamic REF_newInvokeSpecial:Method LdcConDyTwice." ": ldc MethodHandle REF_newInvokeSpecial:InterfaceMethod LdcConDyTwice." ": ldc MethodHandle REF_invokeInterface:LdcConDyTwice." ": ldc MethodHandle REF_newInvokeSpecial:Method LdcConDyTwice." ": invokedynamic MethodHandle REF_invokeStatic:Method java/lang/invoke/StringConcatFactory.makeConcatWithConstants: invokedynamic MethodHandle REF_invokeStatic:java/lang/invoke/StringConcatFactory.makeConcatWithConstants .... private intcountParams(ConstantPool.ConstCell sigCell) Scan method's signature to determine size of parameters.(package private) StringencodeClassString(String classname) private voidendClass()End classprivate voidEnd module(package private) final ClassData[]private voidmatch(JasmTokens.Token open, JasmTokens.Token close) The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counter part.private voidparseClass(int mod) Parse a class or interface declaration.private voidparseClasses(Consumer<ArrayList<ConstantPool.ConstCell>> classesConsumer) Parse a list of classes belonging to the [NestMembers | PermittedSubclasses] entryprivate void(package private) ConstantPool.ConstCellparseClassName(boolean uncond) private voidParse constant declarationprivate voidParse a (CPX based) BootstrapMethod entry.private voidparseField(int mod) Parse a field.(package private) voidParse an Jasm file.(package private) StringParse an internal name: identifier.private voidparseInnerClass(int mod) Parse an inner class.private voidparseInnerClass_s1(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) private voidparseInnerClass_s2(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) private voidparseInnerClass_s3(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) (package private) ArgumentparseInt(int size) Parse a signed integer of size bytes long.private voidDetermines whether the JASM file is for a package-info class or for a module-info class.(package private) voidParse a local variable(package private) void(package private) Argument(package private) voidparseMapItem(DataVector map) private voidparseMethod(int mod) Parse a method.(package private) ConstantPool.ConstCellparseMethodHandle(Tables.SubTag subtag) Parses a field or method reference for method handle.private voidParse a module declaration.private StringParses a module name in a module statement(s)(package private) ConstantPool.ConstCellParse an external name: CPINDEX, string, or identifier.private voidParse a NestHost entryprivate voidParse the Record entry(package private) Tables.SubTagParses a sub-tag value in method handle.private StringParses a package or type name in a module statement(s)(package private) ArgumentparseUInt(int size) Parse an unsigned integer of size bytes long.private voidprivate voidParses version in package statementsprivate voidprivate voidpic_tracecreate(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) private StringprependPackage(String className, boolean uncond) private voidRecover after a syntax error in a field.private voidRecover after a syntax error in the file.scanList(Parser.Method scanMethod, Parser.NameSupplier target, String err, boolean onlyOneElement) Scans the "to" or "with" part of ModuleStatement: exports PackageName [to ModuleName {, ModuleName}] ;, opens packageName [to ModuleName {, ModuleName}] ; provides TypeName with TypeName [,typeName] ; uses TypeName; : [ModuleName {, ModuleName}]; , [TypeName [,typeName]]; or TypeName;private intscanModifier(int mod) Parse the modifiers(package private) intprivate voidscanRequires(BiConsumer<String, Integer> action) Scans ModuleStatement: requires [transitive] [static] ModuleName ;private voidscanStatement(BiConsumer<String, Set<String>> action, Parser.NameSupplier source, Parser.NameSupplier target, JasmTokens.Token startList, boolean emptyListAllowed, String err) Scans Module Statement(s): exports packageName [to ModuleName {, ModuleName}] ; opens packageName [to ModuleName {, ModuleName}] ; provides TypeName with TypeName [,typeName] ;private voidscanStatement(Consumer<Set<String>> action, String err) Scans ModuleStatement: uses TypeName;(package private) voidsetDebugFlags(boolean debugScanner, boolean debugMembers, boolean debugCP, boolean debugAnnot, boolean debugInstr) Methods inherited from class ParseBase
debugScan, debugStr, enableDebug, init
-
Field Details
-
Constructor Details
-
Parser
Create a parser- Throws:
IOException
-
-
Method Details
-
setDebugFlags
void setDebugFlags(boolean debugScanner, boolean debugMembers, boolean debugCP, boolean debugAnnot, boolean debugInstr) -
encodeClassString
-
parseVersionPkg
Parses version in package statements- Throws:
IOException
-
parseVersion
- Throws:
IOException
-
parseIdent
Parse an internal name: identifier.- Throws:
Scanner.SyntaxErrorIOException
-
parseLocVarDef
Parse a local variable- Throws:
Scanner.SyntaxErrorIOException
-
parseLocVarRef
- Throws:
Scanner.SyntaxErrorIOException
-
parseLocVarEnd
- Throws:
Scanner.SyntaxErrorIOException
-
parseMapItem
- Throws:
Scanner.SyntaxErrorIOException
-
parseName
Parse an external name: CPINDEX, string, or identifier.- Throws:
Scanner.SyntaxErrorIOException
-
parseMethodHandle
ConstantPool.ConstCell parseMethodHandle(Tables.SubTag subtag) throws Scanner.SyntaxError, IOException Parses a field or method reference for method handle.- Throws:
Scanner.SyntaxErrorIOException
-
checkReferenceIndex
private void checkReferenceIndex(int position, Tables.ConstType defaultTag, Tables.ConstType default2Tag) Check the pair reference_kind:reference_index where reference_kind is any from: REF_invokeVirtual, REF_newInvokeSpecial, REF_invokeStatic, REF_invokeSpecial, REF_invokeInterface and reference_index is one of [Empty], Method or InterfaceMethod There are possible entries: ldc Dynamic REF_newInvokeSpecial:InterfaceMethod LdcConDyTwice."": ldc Dynamic REF_invokeInterface:LdcConDyTwice." ": ldc Dynamic REF_newInvokeSpecial:Method LdcConDyTwice." ": ldc MethodHandle REF_newInvokeSpecial:InterfaceMethod LdcConDyTwice." ": ldc MethodHandle REF_invokeInterface:LdcConDyTwice." ": ldc MethodHandle REF_newInvokeSpecial:Method LdcConDyTwice." ": invokedynamic MethodHandle REF_invokeStatic:Method java/lang/invoke/StringConcatFactory.makeConcatWithConstants: invokedynamic MethodHandle REF_invokeStatic:java/lang/invoke/StringConcatFactory.makeConcatWithConstants .... - Parameters:
position- the position in a source filedefaultTag- expected reference_index tag (Method or InterfaceMethod)defaultTag- 2nd expected reference_index tag (Method or InterfaceMethod)
-
parseSubtag
Parses a sub-tag value in method handle.- Throws:
Scanner.SyntaxErrorIOException
-
parseClassName
- Throws:
Scanner.SyntaxErrorIOException
-
prependPackage
-
parseInt
Parse a signed integer of size bytes long. size = 1 or 2- Throws:
Scanner.SyntaxErrorIOException
-
parseUInt
Parse an unsigned integer of size bytes long. size = 1 or 2- Throws:
Scanner.SyntaxErrorIOException
-
parseConstDef
-
scanModifier
-
scanModifiers
- Throws:
IOException
-
parseField
Parse a field.- Throws:
Scanner.SyntaxErrorIOException
-
countParams
Scan method's signature to determine size of parameters.- Throws:
Scanner.SyntaxError
-
parseMethod
Parse a method.- Throws:
Scanner.SyntaxErrorIOException
-
parseCPXBootstrapMethod
Parse a (CPX based) BootstrapMethod entry.- Throws:
Scanner.SyntaxErrorIOException
-
parseNestHost
Parse a NestHost entry- Throws:
Scanner.SyntaxErrorIOException
-
parseClasses
private void parseClasses(Consumer<ArrayList<ConstantPool.ConstCell>> classesConsumer) throws Scanner.SyntaxError, IOException Parse a list of classes belonging to the [NestMembers | PermittedSubclasses] entry- Throws:
Scanner.SyntaxErrorIOException
-
parseRecord
Parse the Record entry- Throws:
Scanner.SyntaxErrorIOException
-
parseInnerClass
Parse an inner class.- Throws:
Scanner.SyntaxErrorIOException
-
parseInnerClass_s1
private void parseInnerClass_s1(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) throws IOException - Throws:
IOException
-
parseInnerClass_s2
private void parseInnerClass_s2(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) throws IOException - Throws:
IOException
-
parseInnerClass_s3
private void parseInnerClass_s3(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) throws IOException - Throws:
IOException
-
pic_tracecreate
private void pic_tracecreate(int mod, ConstantPool.ConstCell nameCell, ConstantPool.ConstCell innerClass, ConstantPool.ConstCell outerClass) -
pic_error
private void pic_error() -
match
The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counter part. This is useful during error recovery.Scan to a matching '}', ']' or ')'. The current scanner.token must be a '{', '[' or '(';
- Throws:
IOException
-
recoverField
Recover after a syntax error in a field. This involves discarding scanner.tokens until an EOF or a possible legal continuation is encountered.- Throws:
Scanner.SyntaxErrorIOException
-
parseClass
Parse a class or interface declaration.- Throws:
IOException
-
parseTypeName
Parses a package or type name in a module statement(s)- Throws:
IOException
-
parseModuleName
Parses a module name in a module statement(s)- Throws:
IOException
-
parseModule
-
scanRequires
Scans ModuleStatement: requires [transitive] [static] ModuleName ;- Throws:
IOException
-
scanStatement
Scans ModuleStatement: uses TypeName;- Throws:
IOException
-
scanStatement
private void scanStatement(BiConsumer<String, Set<String>> action, Parser.NameSupplier source, Parser.NameSupplier target, JasmTokens.Token startList, boolean emptyListAllowed, String err) throws IOException Scans Module Statement(s): exports packageName [to ModuleName {, ModuleName}] ; opens packageName [to ModuleName {, ModuleName}] ; provides TypeName with TypeName [,typeName] ;- Throws:
IOException
-
scanList
private HashSet<String> scanList(Parser.Method scanMethod, Parser.NameSupplier target, String err, boolean onlyOneElement) throws IOException Scans the "to" or "with" part of ModuleStatement: exports PackageName [to ModuleName {, ModuleName}] ;, opens packageName [to ModuleName {, ModuleName}] ; provides TypeName with TypeName [,typeName] ; uses TypeName; : [ModuleName {, ModuleName}]; , [TypeName [,typeName]]; or TypeName;- Throws:
IOException
-
parseClassMembers
- Throws:
IOException
-
recoverFile
Recover after a syntax error in the file. This involves discarding scanner.tokens until an EOF or a possible legal continuation is encountered.- Throws:
IOException
-
endClass
private void endClass()End class -
endModule
private void endModule()End module -
getClassesData
-
parseJasmPackages
Determines whether the JASM file is for a package-info class or for a module-info class.creates the correct kind of ClassData accordingly.
- Throws:
IOException
-
parseFile
void parseFile()Parse an Jasm file.
-