Class: FFI::Clang::SourceRange

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

Overview

Represents a source range in a file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range_or_begin_location, end_location = nil) ⇒ SourceRange

Initialize a source range.



25
26
27
28
29
30
31
# File 'lib/ffi/clang/source_range.rb', line 25

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

#The underlying range structure.(underlyingrangestructure.) ⇒ Object (readonly)



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

attr_reader :range

Class Method Details

.null_rangeObject

Get a null source range.



18
19
20
# File 'lib/ffi/clang/source_range.rb', line 18

def self.null_range
  SourceRange.new Lib.get_null_range
end

Instance Method Details

#==(other) ⇒ Object

Check if this range equals another range.



72
73
74
# File 'lib/ffi/clang/source_range.rb', line 72

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

#bytesizeObject

Get the size in bytes of the source range.



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

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

#endObject

Get the end location of this range.



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

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

#null?Boolean

Check if this range is null.

Returns:

  • (Boolean)


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

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

#startObject

Get the start location of this range.



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

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

#textObject

Read the text from the source file for this range.



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

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