FFI::ClangSourceFFIClangSourceRange

class SourceRange

Represents a source range in a file.

Definitions

def self.null_range

Get a null source range.

Signature

returns SourceRange

A null source range.

Implementation

def self.null_range
	SourceRange.new Lib.get_null_range
end

def initialize(range_or_begin_location, end_location = nil)

Initialize a source range.

Signature

parameter range_or_begin_location Lib::CXSourceRange | SourceLocation

Either a range structure or the beginning location.

parameter end_location SourceLocation | Nil

The end location, or nil if first parameter is a range.

Implementation

def initialize(range_or_begin_location, end_location = nil)
	if end_location.nil?
		@range = range_or_begin_location
	else
		@range = Lib.get_range(range_or_begin_location.location, end_location.location)
	end
end

def start

Get the start location of this range.

Signature

returns ExpansionLocation

The start location.

Implementation

def start
	@start ||= ExpansionLocation.new(Lib.get_range_start @range)
end

def end

Get the end location of this range.

Signature

returns ExpansionLocation

The end location.

Implementation

def end
	@end ||= ExpansionLocation.new(Lib.get_range_end @range)
end

def bytesize

Get the size in bytes of the source range.

Signature

returns Integer

The byte size.

Implementation

def bytesize
	self.end.offset - self.start.offset
end

def text

Read the text from the source file for this range.

Signature

returns String

The source text.

Implementation

def text
	::File.open(self.start.file, "r") do |file|
		file.seek(self.start.offset)
		return file.read(self.bytesize)
	end
end

def null?

Check if this range is null.

Signature

returns Boolean

True if the range is null.

Implementation

def null?
	Lib.range_is_null(@range) != 0
end

attr_reader :range

Signature

attribute Lib::CXSourceRange

The underlying range structure.

def ==(other)

Check if this range equals another range.

Signature

parameter other SourceRange

The range to compare with.

returns Boolean

True if the ranges are equal.

Implementation

def ==(other)
	Lib.equal_range(@range, other.range) != 0
end