Class: FFI::Clang::FileLocation

Inherits:
SourceLocation show all
Defined in:
lib/ffi/clang/source_location.rb

Overview

Represents a file location in source code. This provides the physical location in the file system where code appears.

Instance Attribute Summary collapse

Attributes inherited from SourceLocation

#location

Instance Method Summary collapse

Methods inherited from SourceLocation

#<=>, #==, #from_main_file?, #in_system_header?, #null?, null_location

Constructor Details

#initialize(location) ⇒ FileLocation

Create a new file location and extract its components.



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/ffi/clang/source_location.rb', line 222

def initialize(location)
	super(location)
	
	cxfile = MemoryPointer.new :pointer
	line   = MemoryPointer.new :uint
	column = MemoryPointer.new :uint
	offset = MemoryPointer.new :uint
	
	Lib::get_file_location(@location, cxfile, line, column, offset)
	
	@file = Lib.extract_string Lib.get_file_name(cxfile.read_pointer)
	@line = line.get_uint(0)
	@column = column.get_uint(0)
	@offset = offset.get_uint(0)
end

Instance Attribute Details

#columnObject (readonly)



218
# File 'lib/ffi/clang/source_location.rb', line 218

attr_reader :file, :line, :column, :offset

#fileObject (readonly)



218
219
220
# File 'lib/ffi/clang/source_location.rb', line 218

def file
  @file
end

#lineObject (readonly)



218
# File 'lib/ffi/clang/source_location.rb', line 218

attr_reader :file, :line, :column, :offset

#offsetObject (readonly)

Returns the value of attribute offset.



218
# File 'lib/ffi/clang/source_location.rb', line 218

attr_reader :file, :line, :column, :offset

Instance Method Details

#as_stringObject

Get a string representation of this location.



240
241
242
# File 'lib/ffi/clang/source_location.rb', line 240

def as_string
	"#{@file}:#{@line}:#{@column}:#{@offset}"
end

#to_sObject

Get a detailed string representation.



246
247
248
# File 'lib/ffi/clang/source_location.rb', line 246

def to_s
	"FileLocation <#{self.as_string}>"
end