Package org.openjdk.asmtools.jcoder
Class Scanner
- java.lang.Object
-
- org.openjdk.asmtools.jcoder.Scanner
-
public class Scanner extends java.lang.ObjectA Scanner for Jcoder tokens. Errors are reported to the environment object.The scanner keeps track of the current token, the value of the current token (if any), and the start position of the current token.
The scan() method advances the scanner to the next token in the input.
The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counter part. This is useful during error recovery.
The compiler treats either "\n", "\r" or "\r\n" as the end of a line.
-
-
Field Summary
Fields Modifier and Type Field Description private char[]bufferprotected intchThe current characterprivate intcountA growable character buffer.private booleandebugCPprotected java.lang.StringdocCommentprotected SourceFileenvWhere errors are reportedstatic intEOFEnd of inputprotected SourceFileinInput streamprotected intindexMacroprotected intintSizeprotected intintValuestatic intLBRACEprotected ByteBufferlongStringValueprotected longlongValueprotected java.lang.Stringmacro(package private) java.util.HashMap<java.lang.String,java.lang.String>macrosprivate intnumCPentrsprotected intposThe position of the current tokenprotected intprevChThe current characterprotected intprevPosThe position of the previous tokenprotected intsignprotected java.lang.StringstringValueprotected JcodTokens.TokentokenCurrent token
-
Constructor Summary
Constructors Modifier Constructor Description protectedScanner(SourceFile sf)for use in jcfront.protectedScanner(SourceFile sf, java.util.HashMap<java.lang.String,java.lang.String> macros)Create a scanner to scan an input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddConstDebug(JcodTokens.ConstType ct)private java.lang.StringbufferString()protected voidmatch(JcodTokens.Token open, JcodTokens.Token close)Scan to a matching '}', ']' or ')'.private voidputc(int ch)(package private) voidreadCh()protected intscan()Scan the next token.private voidscanCharArray()Scan a character array.private voidscanDecNumber()Scan a decimal numberprivate java.lang.StringscanDocComment()Scan a doc comment.private intscanEscapeChar()Scan an escape character.private voidscanHexNumber()Scan a hex number.private voidscanIdentifier()Scan an Identifier.protected intscanMacro()Scan the next token.private voidscanString()Scan a string.(package private) voidsetDebugCP(boolean enable)(package private) voidsetMacro(java.lang.String macro)private voidskipComment()Scan a comment.protected voidskipTill(int sym)protected intxscan()
-
-
-
Field Detail
-
EOF
public static final int EOF
End of input- See Also:
- Constant Field Values
-
LBRACE
public static final int LBRACE
- See Also:
- Constant Field Values
-
debugCP
private boolean debugCP
-
numCPentrs
private int numCPentrs
-
env
protected SourceFile env
Where errors are reported
-
in
protected SourceFile in
Input stream
-
macros
java.util.HashMap<java.lang.String,java.lang.String> macros
-
ch
protected int ch
The current character
-
prevCh
protected int prevCh
The current character
-
macro
protected java.lang.String macro
-
indexMacro
protected int indexMacro
-
token
protected JcodTokens.Token token
Current token
-
pos
protected int pos
The position of the current token
-
prevPos
protected int prevPos
The position of the previous token
-
longValue
protected long longValue
-
intValue
protected int intValue
-
intSize
protected int intSize
-
stringValue
protected java.lang.String stringValue
-
longStringValue
protected ByteBuffer longStringValue
-
sign
protected int sign
-
docComment
protected java.lang.String docComment
-
count
private int count
A growable character buffer.
-
buffer
private char[] buffer
-
-
Constructor Detail
-
Scanner
protected Scanner(SourceFile sf, java.util.HashMap<java.lang.String,java.lang.String> macros) throws java.io.IOException
Create a scanner to scan an input stream.- Throws:
java.io.IOException
-
Scanner
protected Scanner(SourceFile sf) throws java.io.IOException
for use in jcfront.- Throws:
java.io.IOException
-
-
Method Detail
-
setDebugCP
void setDebugCP(boolean enable)
-
addConstDebug
void addConstDebug(JcodTokens.ConstType ct)
-
setMacro
void setMacro(java.lang.String macro)
-
readCh
void readCh() throws java.io.IOException- Throws:
java.io.IOException
-
putc
private void putc(int ch)
-
bufferString
private java.lang.String bufferString()
-
skipComment
private void skipComment() throws java.io.IOExceptionScan a comment. This method should be called once the initial /, * and the next character have been read.- Throws:
java.io.IOException
-
scanDocComment
private java.lang.String scanDocComment() throws java.io.IOExceptionScan a doc comment. This method should be called once the initial /, * and * have been read. It gathers the content of the comment (witout leading spaces and '*'s) in the string buffer.- Throws:
java.io.IOException
-
scanDecNumber
private void scanDecNumber() throws java.io.IOExceptionScan a decimal number- Throws:
java.io.IOException
-
scanHexNumber
private void scanHexNumber() throws java.io.IOExceptionScan a hex number.- Throws:
java.io.IOException
-
scanEscapeChar
private int scanEscapeChar() throws java.io.IOExceptionScan an escape character.- Returns:
- the character or -1 if it escaped an end-of-line.
- Throws:
java.io.IOException
-
scanString
private void scanString() throws java.io.IOExceptionScan a string. The current character should be the opening " of the string.- Throws:
java.io.IOException
-
scanCharArray
private void scanCharArray() throws java.io.IOExceptionScan a character array. The current character should be the opening ' of the array.- Throws:
java.io.IOException
-
scanIdentifier
private void scanIdentifier() throws java.io.IOExceptionScan an Identifier. The current character should be the first character of the identifier.- Throws:
java.io.IOException
-
skipTill
protected void skipTill(int sym) throws java.io.IOException- Throws:
java.io.IOException
-
xscan
protected int xscan() throws java.io.IOException- Throws:
java.io.IOException
-
match
protected void match(JcodTokens.Token open, JcodTokens.Token close) throws java.io.IOException
Scan to a matching '}', ']' or ')'. The current token must be a '{', '[' or '(';- Throws:
java.io.IOException
-
scan
protected int scan() throws java.io.IOExceptionScan the next token.- Returns:
- the position of the previous token.
- Throws:
java.io.IOException
-
scanMacro
protected int scanMacro() throws java.io.IOExceptionScan the next token.- Returns:
- the position of the previous token.
- Throws:
java.io.IOException
-
-