Class: FFI::Clang::SpellingLocation

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

Overview

Represents the spelling location of a token in source code. This is the actual location where the token was written in the source file.

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) ⇒ SpellingLocation

Create a new spelling location and extract its components.



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/ffi/clang/source_location.rb', line 178

def initialize(location)
	super(location)
	
	cxfile = MemoryPointer.new :pointer
	line   = MemoryPointer.new :uint
	column = MemoryPointer.new :uint
	offset = MemoryPointer.new :uint
	
	Lib::get_spelling_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)



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

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

#fileObject (readonly)



174
175
176
# File 'lib/ffi/clang/source_location.rb', line 174

def file
  @file
end

#lineObject (readonly)



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

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

#offsetObject (readonly)

Returns the value of attribute offset.



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

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

Instance Method Details

#as_stringObject

Get a string representation of this location.



196
197
198
# File 'lib/ffi/clang/source_location.rb', line 196

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

#to_sObject

Get a detailed string representation.



202
203
204
# File 'lib/ffi/clang/source_location.rb', line 202

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