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 class
The main compile error for the parser(package private) static interface
(package private) static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ParserAnnotation
other parser components(package private) ClassData
private ArrayList<AnnotationData>
private final ParserCP
(package private) CodeAttr
(package private) CFVersion
private boolean
private final ParserInstr
private ArrayList<AnnotationData>
private ModuleAttr
private String
private ArrayList<AnnotationData>
private String
protected ConstantPool
Fields inherited from class org.openjdk.asmtools.jasm.ParseBase
debugFlag, environment, parser, scanner
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Parser
(JasmEnvironment environment, CFVersion cfVersion) Create a parser -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkReferenceIndex
(int position, ClassFileConst.ConstType defaultTag, ClassFileConst.ConstType defaultTag2) 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 int
countParams
(ConstCell sigCell) Scan method's signature to determine size of parameters.(package private) String
encodeClassString
(String classname) private void
endClass()
End classprivate void
End moduleprivate void
End package-info(package private) final ClassData[]
int
private void
private void
match
(JasmTokens.Token open, JasmTokens.Token close) The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counterpart.private void
parseClass
(int mod) Parse a class or interface declaration.private void
parseClasses
(Consumer<ArrayList<ConstCell>> classesConsumer) Parse a list of classes belonging to the [NestMembers | PermittedSubclasses | Preload] entryprivate void
private void
parseClassRef
(Consumer<ConstCell<?>> consumer) Parse class reference used by statements: this_class[:] (CPINDEX | STRING); super_class[:] (CPINDEX | STRING);private void
Parse the class Signature entry.(package private) ConstCell
parseConstantClassInfo
(boolean uncond) (package private) ConstCell
(package private) ConstCell
private void
Parse constant declarationprivate void
Parse a (CPX based) BootstrapMethod entry.private void
parseField
(int mod) Parse a field.(package private) void
Parse an Jasm file.(package private) String
private void
parseInnerClass
(int mod) Parse an inner class.private void
parseInnerClass_s1
(int mod, ConstCell nameCell, ConstCell innerClass, ConstCell outerClass) private void
parseInnerClass_s2
(int mod, ConstCell nameCell, ConstCell innerClass, ConstCell outerClass) private void
parseInnerClass_s3
(int mod, ConstCell nameCell, ConstCell innerClass, ConstCell outerClass) (package private) Indexer
Parse a signed integer of size bytes long.private void
Determines whether the JASM file is for a package-info class or for a module-info class.(package private) void
Parse a local variable presented in the form (var) index #name_index:#descriptor_index; [ (var) index name:descriptor; ](package private) void
Parse The index (LOCAL_VARIABLE) into the local variable array of the instructions: endvar LOCAL_VARIABLE;(package private) Indexer
Parse The index (LOCAL_VARIABLE) into the local variable array of the instructions: [wide]aload, astore, fload, fstore, iload, istore, lload, lstore, dload, dstore LOCAL_VARIABLE; [wide]iinc LOCAL_VARIABLE, NUMBER;(package private) void
parseMapItem
(DataVector map) private void
parseMethod
(int mod) Parse a method.(package private) ConstCell
Parses a field or method reference for method handle.private void
parseModule
(int mod) Parse a module declaration.private NameInfo
Parses a module name in a module statement(s)(package private) ConstCell
Parse an external name: CPINDEX, string, or identifier.private void
Parse a NestHost entryprivate void
Parse the Record entryprivate void
Parse a SourceDebugExtension attributeprivate void
(package private) ClassFileConst.SubTag
Parses a sub-tag value in method handle.private NameInfo
Parses a package or type name in a module statement(s)(package private) Indexer
parseUInt
(int size) Parse an unsigned integer of size bytes long.private void
private void
private void
pic_tracecreate
(int mod, ConstCell nameCell, ConstCell innerClass, ConstCell outerClass) private String
prependPackage
(String className, boolean uncond) private void
Recover after a syntax error in a field.private void
Recover 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 the following ModuleStatement: exports PackageName [to ModuleName {, ModuleName}] ;, opens PackageName [to ModuleName {, ModuleName}] ; provides TypeName with TypeName [,typeName] ; uses TypeName;private int
scanModifier
(int mod) Parse the modifiers(package private) int
private void
scanRequires
(Consumer<ModuleContent.Dependence> action) Scans ModuleStatement: requires [transitive|static|mandated|synthetic] ModuleName ; Scans ModuleStatement: requires [transitive|static|mandated|synthetic] #ref ;private <T extends ModuleContent.TargetType>
voidscanStatement
(BiConsumer<T, Set<ModuleContent.TargetType>> action, Parser.NameSupplier source, Parser.NameSupplier target, JasmTokens.Token startList, boolean emptyListAllowed, String err) Scans Module Statement(s): exports [mandated|synthetic] packageName [to ModuleName {, ModuleName}*] ; opens [mandated|synthetic] packageName [to ModuleName {, ModuleName}*] ; provides TypeName with TypeName {,typeName} ;private void
scanStatement
(Consumer<ModuleContent.TargetType> action, String err) Scans ModuleStatement: uses TypeName;(package private) void
setDebugFlags
(boolean debugScanner, boolean debugMembers, boolean debugCP, boolean debugAnnot, boolean debugInstr) private void
throwSyntaxError
(String msgId) Methods inherited from class org.openjdk.asmtools.jasm.ParseBase
init, init, init, setDebugFlag, traceMethodInfoLn, traceMethodInfoLn
-
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
-
getPosition
public int getPosition() -
parseVersion
private void parseVersion() -
parseIdent
- Throws:
SyntaxError
-
parseLocVarDef
Parse a local variable presented in the form (var) index #name_index:#descriptor_index; [ (var) index name:descriptor; ]index - a valid index into the local variable array of the current frame. name - valid unqualified name denoting a local variable descriptor - a field descriptor which encodes the type of a local variable in the source program
- Throws:
SyntaxError
-
parseLocVarRef
Parse The index (LOCAL_VARIABLE) into the local variable array of the instructions: [wide]aload, astore, fload, fstore, iload, istore, lload, lstore, dload, dstore LOCAL_VARIABLE; [wide]iinc LOCAL_VARIABLE, NUMBER;- Throws:
SyntaxError
IOException
-
parseLocVarEnd
Parse The index (LOCAL_VARIABLE) into the local variable array of the instructions: endvar LOCAL_VARIABLE;- Throws:
SyntaxError
IOException
-
parseMapItem
- Throws:
SyntaxError
IOException
-
parseName
Parse an external name: CPINDEX, string, or identifier.- Throws:
SyntaxError
-
parseMethodHandle
Parses a field or method reference for method handle.- Throws:
SyntaxError
-
checkReferenceIndex
private void checkReferenceIndex(int position, ClassFileConst.ConstType defaultTag, ClassFileConst.ConstType defaultTag2) 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)defaultTag2
- 2nd expected reference_index tag (Method or InterfaceMethod)
-
parseSubtag
Parses a sub-tag value in method handle.- Throws:
SyntaxError
-
parseConstantPackageInfo
- Throws:
SyntaxError
-
parseConstantModuleInfo
- Throws:
SyntaxError
-
parseConstantClassInfo
- Throws:
SyntaxError
-
throwSyntaxError
- Throws:
SyntaxError
-
prependPackage
-
parseInt
Parse a signed integer of size bytes long. size = 1 or 2- Throws:
SyntaxError
IOException
-
parseUInt
Parse an unsigned integer of size bytes long. size = 1 or 2- Throws:
SyntaxError
IOException
-
parseConstDef
private void parseConstDef()Parse constant declaration -
scanModifier
Parse the modifiers- Throws:
SyntaxError
-
scanModifiers
- Throws:
SyntaxError
-
parseField
Parse a field.- Throws:
SyntaxError
-
countParams
Scan method's signature to determine size of parameters.- Throws:
SyntaxError
-
parseMethod
Parse a method.- Throws:
SyntaxError
IOException
-
parseCPXBootstrapMethod
Parse a (CPX based) BootstrapMethod entry.- Throws:
SyntaxError
-
parseClassSignature
Parse the class Signature entry.- Throws:
SyntaxError
-
parseClassRef
Parse class reference used by statements: this_class[:] (CPINDEX | STRING); super_class[:] (CPINDEX | STRING); -
parseSourceFile
- Throws:
SyntaxError
-
parseSourceDebugExtension
Parse a SourceDebugExtension attribute- Throws:
SyntaxError
-
parseNestHost
Parse a NestHost entry- Throws:
SyntaxError
-
parseClasses
Parse a list of classes belonging to the [NestMembers | PermittedSubclasses | Preload] entry- Throws:
SyntaxError
-
parseRecord
Parse the Record entry- Throws:
SyntaxError
-
parseInnerClass
Parse an inner class.- Throws:
SyntaxError
IOException
-
parseInnerClass_s1
private void parseInnerClass_s1(int mod, ConstCell nameCell, ConstCell innerClass, ConstCell outerClass) throws IOException - Throws:
IOException
-
parseInnerClass_s2
private void parseInnerClass_s2(int mod, ConstCell nameCell, ConstCell innerClass, ConstCell outerClass) throws IOException - Throws:
IOException
-
parseInnerClass_s3
private void parseInnerClass_s3(int mod, ConstCell nameCell, ConstCell innerClass, ConstCell outerClass) throws IOException - Throws:
IOException
-
pic_tracecreate
-
pic_error
private void pic_error() -
match
The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counterpart. 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:
SyntaxError
IOException
-
parseClass
Parse a class or interface declaration.- Throws:
IOException
-
parseTypeName
Parses a package or type name in a module statement(s)- Returns:
- Pair Either Package/Type name or CP Index for this Package/Type name.
- Throws:
IOException
-
parseModuleName
Parses a module name in a module statement(s)- Returns:
- Pair Either Module name or CP Index for the module name.
- Throws:
IOException
-
parseModule
Parse a module declaration.- Throws:
IOException
-
scanRequires
Scans ModuleStatement: requires [transitive|static|mandated|synthetic] ModuleName ; Scans ModuleStatement: requires [transitive|static|mandated|synthetic] #ref ;- Throws:
IOException
-
scanStatement
private <T extends ModuleContent.TargetType> void scanStatement(BiConsumer<T, Set<ModuleContent.TargetType>> action, Parser.NameSupplier source, Parser.NameSupplier target, JasmTokens.Token startList, boolean emptyListAllowed, String err) throws IOExceptionScans Module Statement(s): exports [mandated|synthetic] packageName [to ModuleName {, ModuleName}*] ; opens [mandated|synthetic] packageName [to ModuleName {, ModuleName}*] ; provides TypeName with TypeName {,typeName} ;- Throws:
IOException
-
scanStatement
private void scanStatement(Consumer<ModuleContent.TargetType> action, String err) throws IOException Scans ModuleStatement: uses TypeName;- Throws:
IOException
-
scanList
private HashSet<NameInfo> scanList(Parser.Method scanMethod, Parser.NameSupplier target, String err, boolean onlyOneElement) throws IOException Scans the "to" or "with" part of the following 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 -
endPackageInfo
private void endPackageInfo()End package-info -
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
- if any parse exception is met
-
parseFile
void parseFile()Parse an Jasm file. -
initializeClassData
private void initializeClassData()
-