Class: FFI::Clang::SourceRange

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/clang/source_range.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range_or_begin_location, end_location = nil) ⇒ SourceRange

Returns a new instance of SourceRange.



34
35
36
37
38
39
40
# File 'lib/ffi/clang/source_range.rb', line 34

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

Instance Attribute Details

#rangeObject (readonly)

Returns the value of attribute range.



67
68
69
# File 'lib/ffi/clang/source_range.rb', line 67

def range
  @range
end

Class Method Details

.null_rangeObject



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

def self.null_range
	SourceRange.new Lib.get_null_range
end

Instance Method Details

#==(other) ⇒ Object



69
70
71
# File 'lib/ffi/clang/source_range.rb', line 69

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

#bytesizeObject

The size, in bytes, of the source range.



51
52
53
# File 'lib/ffi/clang/source_range.rb', line 51

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

#endObject



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

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

#null?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/ffi/clang/source_range.rb', line 63

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

#startObject



42
43
44
# File 'lib/ffi/clang/source_range.rb', line 42

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

#textObject

Read the part of the source file referred to by this source range.



56
57
58
59
60
61
# File 'lib/ffi/clang/source_range.rb', line 56

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