class SourceLocation
Represents a location in source code. This base class provides common functionality for source locations, with specific subclasses for different types of location information.
Definitions
def self.null_location
Get a null source location.
Signature
-
returns
ExpansionLocation A null location that can be used for comparisons.
Implementation
def self.null_location
ExpansionLocation.new Lib.get_null_location
end
attr_reader :location
Signature
-
attribute
r location
-
returns
FFI::Pointer The underlying location pointer.
-
returns
def initialize(location)
Create a new source location.
Signature
-
parameter
locationFFI::Pointer The low-level location handle.
Implementation
def initialize(location)
@location = location
end
def in_system_header?
Check if this location is in a system header.
Signature
-
returns
Boolean True if the location is in a system header file.
Implementation
def in_system_header?
Lib.location_in_system_header(@location) != 0
end
def from_main_file?
Check if this location is from the main file.
Signature
-
returns
Boolean True if the location is from the main translation unit file.
Implementation
def from_main_file?
Lib.location_is_from_main_file(@location) != 0
end
def null?
Check if this location is null.
Signature
-
returns
Boolean True if this is a null location.
Implementation
def null?
Lib.equal_locations(@location, Lib.get_null_location) != 0
end
def ==(other)
Compare this location with another for equality.
Signature
-
parameter
otherSourceLocation The other location to compare.
-
returns
Boolean True if the locations are equal.
Implementation
def ==(other)
Lib.equal_locations(@location, other.location) != 0
end
def <=>(other)
Compare this location with another for ordering. Returns nil for null locations or locations from different translation units, which causes Comparable operators (<, >, etc.) to raise ArgumentError.
Signature
-
parameter
otherSourceLocation The other location to compare.
-
returns
Integer | Nil -1, 0, or 1 for ordering, or nil if not comparable.
Implementation
def <=>(other)
return nil unless other.is_a?(SourceLocation)
return 0 if Lib.equal_locations(@location, other.location) != 0
return nil if null? || other.null?
return -1 if Lib.is_before_in_translation_unit(@location, other.location) != 0
return 1 if Lib.is_before_in_translation_unit(other.location, @location) != 0
nil
end