Class: FFI::Clang::Token

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

Overview

Represents a single token in the source code.

Defined Under Namespace

Classes: Owner

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, translation_unit, owner = nil) ⇒ Token

Initialize a token.



109
110
111
112
113
# File 'lib/ffi/clang/token.rb', line 109

def initialize(token, translation_unit, owner = nil)
	@token = token
	@translation_unit = translation_unit
	@owner = owner
end

Class Method Details

.from_location(translation_unit, location) ⇒ Object

Look up the token that starts at the given source location.



97
98
99
100
101
102
103
# File 'lib/ffi/clang/token.rb', line 97

def self.from_location(translation_unit, location)
	token_pointer = Lib.get_token(translation_unit, location.location)
	return nil if token_pointer.null?
	
	owner = Owner.new(token_pointer, translation_unit)
	Token.new(owner, translation_unit, owner)
end

Instance Method Details

#extentObject

Get the extent (source range) of this token.



135
136
137
# File 'lib/ffi/clang/token.rb', line 135

def extent
	SourceRange.new Lib.get_token_extent(@translation_unit, @token)
end

#kindObject

Get the kind of this token.



117
118
119
# File 'lib/ffi/clang/token.rb', line 117

def kind
	Lib.get_token_kind(@token)
end

#locationObject

Get the location of this token.



129
130
131
# File 'lib/ffi/clang/token.rb', line 129

def location
	ExpansionLocation.new Lib.get_token_location(@translation_unit, @token)
end

#spellingObject

Get the spelling (text) of this token.



123
124
125
# File 'lib/ffi/clang/token.rb', line 123

def spelling
	Lib.extract_string Lib.get_token_spelling(@translation_unit, @token)
end