Package mars.assembler.log
Class SourceLocation
java.lang.Object
mars.assembler.log.SourceLocation
- All Implemented Interfaces:
Comparable<SourceLocation>
Class representing some location in a source file given to the assembler. The location can reference either
a line as a whole or a specific column within the line.
- Author:
- Sean Clarke, October 2024
-
Constructor Summary
ConstructorsConstructorDescriptionSourceLocation
(String filename) Create a newSourceLocation
referencing a file as a whole.SourceLocation
(String filename, int lineIndex) Create a newSourceLocation
referencing a line as a whole.SourceLocation
(String filename, int lineIndex, int columnIndex) Create a newSourceLocation
referencing a specific column in a line.SourceLocation
(SourceLocation location) Create a clone of an existingSourceLocation
. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(SourceLocation that) Compare two locations.boolean
int
Get the column number referenced by this location, where the beginning of the line is column 0.Get the name of the source file referenced by this location.int
Get the line number referenced by this location, where the first line in the file is line 0.int
hashCode()
toColumnLocation
(int columnIndex) Generates a new location referencing a column in the line referenced by this location.Generates a new location referencing the line as a whole rather than a particular column in the line.toString()
Get the string representation of this location.
-
Constructor Details
-
SourceLocation
Create a newSourceLocation
referencing a file as a whole.- Parameters:
filename
- The name of the source file.
-
SourceLocation
Create a newSourceLocation
referencing a line as a whole.- Parameters:
filename
- The name of the source file.lineIndex
- The zero-based index of the line.
-
SourceLocation
Create a newSourceLocation
referencing a specific column in a line.- Parameters:
filename
- The name of the source file.lineIndex
- The zero-based index of the line.columnIndex
- The zero-based index of the column.
-
SourceLocation
Create a clone of an existingSourceLocation
.- Parameters:
location
- The object to clone.
-
-
Method Details
-
getFilename
Get the name of the source file referenced by this location.- Returns:
- The source filename, or
null
if not applicable.
-
getLineIndex
public int getLineIndex()Get the line number referenced by this location, where the first line in the file is line 0.- Returns:
- The zero-based line index.
-
getColumnIndex
public int getColumnIndex()Get the column number referenced by this location, where the beginning of the line is column 0. If this location represents the entire line, the column number will be negative.- Returns:
- The zero-based column index, or -1 if not applicable.
-
toLineLocation
Generates a new location referencing the line as a whole rather than a particular column in the line.- Returns:
- The line location.
-
toColumnLocation
Generates a new location referencing a column in the line referenced by this location.- Parameters:
columnIndex
- The zero-based index of the column.- Returns:
- The column location.
-
compareTo
Compare two locations. Thepath
is compared first; if it is the same, thelineIndex
is compared; if it is the same, thecolumnIndex
is compared.- Specified by:
compareTo
in interfaceComparable<SourceLocation>
- Parameters:
that
- The location to compare against.- Returns:
- An integer whose value is positive, negative, or zero to indicate whether
this
is greater than, less than, or equal tothat
, respectively.
-
equals
-
hashCode
public int hashCode() -
toString
Get the string representation of this location. For example, a location with apath
ofpath/to/file.asm
, alineIndex
of 10, and acolumnIndex
of 20 produces the following string:(path/to/file.asm, line 11, column 21)
Fields are omitted from the output if they are not applicable (i.e.
null
or negative).
-