Class: FFI::Clang::SourceLocation

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ffi/clang/source_location.rb

Overview

Represents a location in source code. This base class provides common functionality for source locations, with specific subclasses for different types of location information.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ SourceLocation

Create a new source location.



34
35
36
# File 'lib/ffi/clang/source_location.rb', line 34

def initialize(location)
	@location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



30
31
32
# File 'lib/ffi/clang/source_location.rb', line 30

def location
  @location
end

Class Method Details

.null_locationObject

Get a null source location.



24
25
26
# File 'lib/ffi/clang/source_location.rb', line 24

def self.null_location
	ExpansionLocation.new Lib.get_null_location
end

Instance Method Details

#<=>(other) ⇒ Object

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.



68
69
70
71
72
73
74
75
76
# File 'lib/ffi/clang/source_location.rb', line 68

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

#==(other) ⇒ Object

Compare this location with another for equality.



59
60
61
# File 'lib/ffi/clang/source_location.rb', line 59

def ==(other)
	Lib.equal_locations(@location, other.location) != 0
end

#from_main_file?Boolean

Check if this location is from the main file.

Returns:

  • (Boolean)


46
47
48
# File 'lib/ffi/clang/source_location.rb', line 46

def from_main_file?
	Lib.location_is_from_main_file(@location) != 0
end

#in_system_header?Boolean

Check if this location is in a system header.

Returns:

  • (Boolean)


40
41
42
# File 'lib/ffi/clang/source_location.rb', line 40

def in_system_header?
	Lib.location_in_system_header(@location) != 0
end

#null?Boolean

Check if this location is null.

Returns:

  • (Boolean)


52
53
54
# File 'lib/ffi/clang/source_location.rb', line 52

def null?
	Lib.equal_locations(@location, Lib.get_null_location) != 0
end