Class: FFI::Clang::Tokens

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

Overview

Represents a collection of tokens from a source range.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer, token_size, translation_unit) ⇒ Tokens

Initialize a token collection.



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ffi/clang/token.rb', line 28

def initialize(pointer, token_size, translation_unit)
	super(Lib::TokensPointer.new(pointer, token_size, translation_unit))
	
	@translation_unit = translation_unit
	@size = token_size
	
	@tokens = []
	current = pointer
	token_size.times do
		@tokens << Token.new(current, translation_unit)
		current += Lib::CXToken.size
	end
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



19
20
21
# File 'lib/ffi/clang/token.rb', line 19

def size
  @size
end

#The array of tokens.(arrayoftokens.) ⇒ Object (readonly)



22
# File 'lib/ffi/clang/token.rb', line 22

attr_reader :tokens

#The number of tokens.(numberoftokens.) ⇒ Object (readonly)



19
# File 'lib/ffi/clang/token.rb', line 19

attr_reader :size

#tokensObject (readonly)

Returns the value of attribute tokens.



22
23
24
# File 'lib/ffi/clang/token.rb', line 22

def tokens
  @tokens
end

Class Method Details

.release(pointer) ⇒ Object

Release the tokens pointer.



44
45
46
# File 'lib/ffi/clang/token.rb', line 44

def self.release(pointer)
	Lib.dispose_tokens(pointer.translation_unit, pointer, pointer.token_size)
end

Instance Method Details

#cursorsObject

Get cursors corresponding to each token.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ffi/clang/token.rb', line 60

def cursors
	ptr = MemoryPointer.new(Lib::CXCursor, @size)
	Lib.annotate_tokens(@translation_unit, self, @size, ptr)
	
	cur_ptr = ptr
	array = []
	@size.times do
		array << Cursor.new(cur_ptr, @translation_unit)
		cur_ptr += Lib::CXCursor.size
	end
	
	return array
end

#each(&block) ⇒ Object

Iterate over each token.



52
53
54
55
56
# File 'lib/ffi/clang/token.rb', line 52

def each(&block)
	return to_enum(__method__) unless block_given?
	
	@tokens.each(&block)
end