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 newSourceLocationreferencing a file as a whole.SourceLocation(String filename, int lineIndex) Create a newSourceLocationreferencing a line as a whole.SourceLocation(String filename, int lineIndex, int columnIndex) Create a newSourceLocationreferencing a specific column in a line.SourceLocation(SourceLocation location) Create a clone of an existingSourceLocation. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(SourceLocation that) Compare two locations.booleanintGet 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.intGet the line number referenced by this location, where the first line in the file is line 0.inthashCode()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 newSourceLocationreferencing a file as a whole.- Parameters:
filename- The name of the source file.
-
SourceLocation
Create a newSourceLocationreferencing a line as a whole.- Parameters:
filename- The name of the source file.lineIndex- The zero-based index of the line.
-
SourceLocation
Create a newSourceLocationreferencing 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
nullif 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. Thepathis compared first; if it is the same, thelineIndexis compared; if it is the same, thecolumnIndexis compared.- Specified by:
compareToin interfaceComparable<SourceLocation>- Parameters:
that- The location to compare against.- Returns:
- An integer whose value is positive, negative, or zero to indicate whether
thisis 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 apathofpath/to/file.asm, alineIndexof 10, and acolumnIndexof 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.
nullor negative).
-