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.



19
20
21
22
23
24
25
# File 'lib/ffi/clang/source_range.rb', line 19

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.



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

def range
  @range
end

Class Method Details

.null_rangeObject



15
16
17
# File 'lib/ffi/clang/source_range.rb', line 15

def self.null_range
	SourceRange.new Lib.get_null_range
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
# File 'lib/ffi/clang/source_range.rb', line 54

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

#bytesizeObject

The size, in bytes, of the source range.



36
37
38
# File 'lib/ffi/clang/source_range.rb', line 36

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

#endObject



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

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

#null?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/ffi/clang/source_range.rb', line 48

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

#startObject



27
28
29
# File 'lib/ffi/clang/source_range.rb', line 27

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.



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

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