ghazel-ffi-clang 0.2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +4 -0
  6. data/README.md +74 -0
  7. data/Rakefile +12 -0
  8. data/ext/rakefile.rb +12 -0
  9. data/ext/teapot.rb +16 -0
  10. data/ffi-clang.gemspec +26 -0
  11. data/lib/ffi/clang.rb +54 -0
  12. data/lib/ffi/clang/comment.rb +278 -0
  13. data/lib/ffi/clang/cursor.rb +378 -0
  14. data/lib/ffi/clang/diagnostic.rb +113 -0
  15. data/lib/ffi/clang/file.rb +69 -0
  16. data/lib/ffi/clang/index.rb +71 -0
  17. data/lib/ffi/clang/lib.rb +73 -0
  18. data/lib/ffi/clang/lib/comment.rb +117 -0
  19. data/lib/ffi/clang/lib/cursor.rb +353 -0
  20. data/lib/ffi/clang/lib/diagnostic.rb +87 -0
  21. data/lib/ffi/clang/lib/file.rb +57 -0
  22. data/lib/ffi/clang/lib/index.rb +34 -0
  23. data/lib/ffi/clang/lib/source_location.rb +53 -0
  24. data/lib/ffi/clang/lib/source_range.rb +46 -0
  25. data/lib/ffi/clang/lib/string.rb +45 -0
  26. data/lib/ffi/clang/lib/token.rb +58 -0
  27. data/lib/ffi/clang/lib/translation_unit.rb +106 -0
  28. data/lib/ffi/clang/lib/type.rb +154 -0
  29. data/lib/ffi/clang/lib/utils.rb +29 -0
  30. data/lib/ffi/clang/source_location.rb +149 -0
  31. data/lib/ffi/clang/source_range.rb +61 -0
  32. data/lib/ffi/clang/token.rb +95 -0
  33. data/lib/ffi/clang/translation_unit.rb +142 -0
  34. data/lib/ffi/clang/type.rb +135 -0
  35. data/lib/ffi/clang/unsaved_file.rb +49 -0
  36. data/lib/ffi/clang/utils.rb +58 -0
  37. data/lib/ffi/clang/version.rb +26 -0
  38. data/spec/clang/comment_spec.rb +470 -0
  39. data/spec/clang/cursor_spec.rb +709 -0
  40. data/spec/clang/diagnostic_spec.rb +89 -0
  41. data/spec/clang/file_spec.rb +84 -0
  42. data/spec/clang/index_spec.rb +70 -0
  43. data/spec/clang/source_location_spec.rb +140 -0
  44. data/spec/clang/source_range_spec.rb +76 -0
  45. data/spec/clang/token_spec.rb +83 -0
  46. data/spec/clang/translation_unit_spec.rb +214 -0
  47. data/spec/clang/type_spec.rb +289 -0
  48. data/spec/clang/utils_spec.rb +61 -0
  49. data/spec/fixtures/a.c +7 -0
  50. data/spec/fixtures/canonical.c +5 -0
  51. data/spec/fixtures/docs.c +1 -0
  52. data/spec/fixtures/docs.cc +1 -0
  53. data/spec/fixtures/docs.h +54 -0
  54. data/spec/fixtures/list.c +11 -0
  55. data/spec/fixtures/location1.c +7 -0
  56. data/spec/fixtures/simple.c +3 -0
  57. data/spec/fixtures/test.cxx +62 -0
  58. data/spec/spec_helper.rb +64 -0
  59. metadata +180 -0
@@ -0,0 +1,154 @@
1
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ # Copyright, 2014, by Masahiro Sano.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+
22
+ module FFI
23
+ module Clang
24
+ module Lib
25
+ enum :kind, [
26
+ :type_invalid, 0,
27
+ :type_unexposed, 1,
28
+ :type_void, 2,
29
+ :type_bool, 3,
30
+ :type_char_u, 4,
31
+ :type_uchar, 5,
32
+ :type_char16, 6,
33
+ :type_char32, 7,
34
+ :type_ushort, 8,
35
+ :type_uint, 9,
36
+ :type_ulong, 10,
37
+ :type_ulonglong, 11,
38
+ :type_uint128, 12,
39
+ :type_char_s, 13,
40
+ :type_schar, 14,
41
+ :type_wchar, 15,
42
+ :type_short, 16,
43
+ :type_int, 17,
44
+ :type_long, 18,
45
+ :type_longlong, 19,
46
+ :type_int128, 20,
47
+ :type_float, 21,
48
+ :type_double, 22,
49
+ :type_longdouble, 23,
50
+ :type_nullptr, 24,
51
+ :type_overload, 25,
52
+ :type_dependent, 26,
53
+ :type_obj_c_id, 27,
54
+ :type_obj_c_class, 28,
55
+ :type_obj_c_sel, 29,
56
+ :type_complex, 100,
57
+ :type_pointer, 101,
58
+ :type_block_pointer, 102,
59
+ :type_lvalue_ref, 103,
60
+ :type_rvalue_ref, 104,
61
+ :type_record, 105,
62
+ :type_enum, 106,
63
+ :type_typedef, 107,
64
+ :type_obj_c_interface, 108,
65
+ :type_obj_c_object_pointer, 109,
66
+ :type_function_no_proto, 110,
67
+ :type_function_proto, 111,
68
+ :type_constant_array, 112,
69
+ :type_vector, 113,
70
+ :type_incomplete_array, 114,
71
+ :type_variable_array, 115,
72
+ :type_dependent_sized_array, 116,
73
+ :type_member_pointer, 117,
74
+ ]
75
+
76
+ enum :calling_conv, [
77
+ :calling_conv_default, 0,
78
+ :calling_conv_c, 1,
79
+ :calling_conv_x86_stdcall, 2,
80
+ :calling_conv_x86_fastcall, 3,
81
+ :calling_conv_x86_thiscall, 4,
82
+ :calling_conv_x86_pascal, 5,
83
+ :calling_conv_aapcs, 6,
84
+ :calling_conv_aapcs_vfp, 7,
85
+ :calling_conv_pnacl_call, 8,
86
+ :calling_conv_intel_ocl_bicc, 9,
87
+ :calling_conv_x86_64_win64, 10,
88
+ :calling_conv_x86_64_sysv, 11,
89
+ :calling_conv_invalid, 100,
90
+ :calling_conv_unexposed, 200
91
+ ]
92
+
93
+ enum :ref_qualifier_kind, [
94
+ :ref_qualifier_none, 0,
95
+ :ref_qualifier_lvalue, 1,
96
+ :ref_qualifier_rvalue, 2,
97
+ ]
98
+
99
+ enum :layout_error, [
100
+ :layout_error_invalid, -1,
101
+ :layout_error_incomplete, -2,
102
+ :layout_error_dependent, -3,
103
+ :layout_error_not_constant_size, -4,
104
+ :layout_error_invalid_field_name, -5,
105
+ ]
106
+
107
+ class CXType < FFI::Struct
108
+ layout(
109
+ :kind, :kind,
110
+ :data, [:pointer, 2]
111
+ )
112
+ end
113
+
114
+ attach_function :get_type_kind_spelling, :clang_getTypeKindSpelling, [:kind], CXString.by_value
115
+ if FFI::Clang::Utils.satisfy_version?('3.3')
116
+ attach_function :get_type_spelling, :clang_getTypeSpelling, [CXType.by_value], CXString.by_value
117
+ end
118
+
119
+ attach_function :is_function_type_variadic, :clang_isFunctionTypeVariadic, [CXType.by_value], :uint
120
+ attach_function :is_pod_type, :clang_isPODType, [CXType.by_value], :uint
121
+
122
+ attach_function :get_pointee_type, :clang_getPointeeType, [CXType.by_value], CXType.by_value
123
+ attach_function :get_result_type, :clang_getResultType, [CXType.by_value], CXType.by_value
124
+ attach_function :get_canonical_type, :clang_getCanonicalType, [CXType.by_value], CXType.by_value
125
+ if FFI::Clang::Utils.satisfy_version?('3.4')
126
+ attach_function :type_get_class_type, :clang_Type_getClassType, [CXType.by_value], CXType.by_value
127
+ end
128
+
129
+ attach_function :is_const_qualified_type, :clang_isConstQualifiedType, [CXType.by_value], :uint
130
+ attach_function :is_volatile_qualified_type, :clang_isVolatileQualifiedType, [CXType.by_value], :uint
131
+ attach_function :is_restrict_qualified_type, :clang_isRestrictQualifiedType, [CXType.by_value], :uint
132
+
133
+ attach_function :get_num_arg_types, :clang_getNumArgTypes, [CXType.by_value], :int
134
+ attach_function :get_arg_type, :clang_getArgType, [CXType.by_value, :uint], CXType.by_value
135
+ attach_function :get_num_elements, :clang_getNumElements, [CXType.by_value], :long_long
136
+ attach_function :get_element_type, :clang_getElementType, [CXType.by_value], CXType.by_value
137
+ attach_function :get_array_size, :clang_getArraySize, [CXType.by_value], :long_long
138
+ attach_function :get_array_element_type ,:clang_getArrayElementType, [CXType.by_value], CXType.by_value
139
+
140
+ if FFI::Clang::Utils.satisfy_version?('3.3')
141
+ attach_function :type_get_align_of, :clang_Type_getAlignOf, [CXType.by_value], :long_long
142
+ attach_function :type_get_size_of, :clang_Type_getSizeOf, [CXType.by_value], :long_long
143
+ attach_function :type_get_offset_of, :clang_Type_getOffsetOf, [CXType.by_value, :string], :long_long
144
+ end
145
+
146
+ if FFI::Clang::Utils.satisfy_version?('3.4')
147
+ attach_function :type_get_cxx_ref_qualifier, :clang_Type_getCXXRefQualifier, [CXType.by_value], :ref_qualifier_kind
148
+ end
149
+ attach_function :get_fuction_type_calling_conv, :clang_getFunctionTypeCallingConv, [CXType.by_value], :calling_conv
150
+
151
+ attach_function :equal_types, :clang_equalTypes, [CXType.by_value, CXType.by_value], :uint
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,29 @@
1
+ # Copyright, 2014 by Masahiro Sano.
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'ffi/clang/lib/string'
22
+
23
+ module FFI
24
+ module Clang
25
+ module Lib
26
+ attach_function :get_clang_version, :clang_getClangVersion, [], CXString.by_value
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,149 @@
1
+ # Copyright, 2010-2012 by Jari Bakken.
2
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
+ # Copyright, 2014, by Masahiro Sano.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'ffi/clang/lib/source_location'
24
+ require 'ffi/clang/lib/file'
25
+
26
+ module FFI
27
+ module Clang
28
+ class SourceLocation
29
+ def self.null_location
30
+ ExpansionLocation.new Lib.get_null_location
31
+ end
32
+
33
+ attr_reader :location
34
+ def initialize(location)
35
+ @location = location
36
+ end
37
+
38
+ def in_system_header?
39
+ Lib.location_in_system_header(@location) != 0
40
+ end
41
+
42
+ def from_main_file?
43
+ Lib.location_is_from_main_file(@location) != 0
44
+ end
45
+
46
+ def expansion_location
47
+ ExpansionLocation.new(@location)
48
+ end
49
+
50
+ def presumed_location
51
+ PresumedLocation.new(@location)
52
+ end
53
+
54
+ def spelling_location
55
+ SpellingLocation.new(@location)
56
+ end
57
+
58
+ def file_location
59
+ FileLocation.new(@location)
60
+ end
61
+
62
+ def null?
63
+ Lib.equal_locations(@location, Lib.get_null_location) != 0
64
+ end
65
+
66
+ def ==(other)
67
+ Lib.equal_locations(@location, other.location) != 0
68
+ end
69
+ end
70
+
71
+ class ExpansionLocation < SourceLocation
72
+ attr_reader :file, :line, :column, :offset
73
+
74
+ def initialize(location)
75
+ super(location)
76
+
77
+ cxfile = MemoryPointer.new :pointer
78
+ line = MemoryPointer.new :uint
79
+ column = MemoryPointer.new :uint
80
+ offset = MemoryPointer.new :uint
81
+
82
+ Lib::get_expansion_location(@location, cxfile, line, column, offset)
83
+
84
+ @file = Lib.extract_string Lib.get_file_name(cxfile.read_pointer)
85
+ @line = line.get_uint(0)
86
+ @column = column.get_uint(0)
87
+ @offset = offset.get_uint(0)
88
+ end
89
+ end
90
+
91
+ class PresumedLocation < SourceLocation
92
+ attr_reader :filename, :line, :column, :offset
93
+
94
+ def initialize(location)
95
+ super(location)
96
+
97
+ cxstring = MemoryPointer.new Lib::CXString
98
+ line = MemoryPointer.new :uint
99
+ column = MemoryPointer.new :uint
100
+
101
+ Lib::get_presumed_location(@location, cxstring, line, column)
102
+
103
+ @filename = Lib.extract_string cxstring
104
+ @line = line.get_uint(0)
105
+ @column = column.get_uint(0)
106
+ end
107
+ end
108
+
109
+ class SpellingLocation < SourceLocation
110
+ attr_reader :file, :line, :column, :offset
111
+
112
+ def initialize(location)
113
+ super(location)
114
+
115
+ cxfile = MemoryPointer.new :pointer
116
+ line = MemoryPointer.new :uint
117
+ column = MemoryPointer.new :uint
118
+ offset = MemoryPointer.new :uint
119
+
120
+ Lib::get_spelling_location(@location, cxfile, line, column, offset)
121
+
122
+ @file = Lib.extract_string Lib.get_file_name(cxfile.read_pointer)
123
+ @line = line.get_uint(0)
124
+ @column = column.get_uint(0)
125
+ @offset = offset.get_uint(0)
126
+ end
127
+ end
128
+
129
+ class FileLocation < SourceLocation
130
+ attr_reader :file, :line, :column, :offset
131
+
132
+ def initialize(location)
133
+ super(location)
134
+
135
+ cxfile = MemoryPointer.new :pointer
136
+ line = MemoryPointer.new :uint
137
+ column = MemoryPointer.new :uint
138
+ offset = MemoryPointer.new :uint
139
+
140
+ Lib::get_file_location(@location, cxfile, line, column, offset)
141
+
142
+ @file = Lib.extract_string Lib.get_file_name(cxfile.read_pointer)
143
+ @line = line.get_uint(0)
144
+ @column = column.get_uint(0)
145
+ @offset = offset.get_uint(0)
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright, 2010-2012 by Jari Bakken.
3
+ # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ # Copyright, 2013, by Garry C. Marshall. <http://www.meaningfulname.net>
5
+ # Copyright, 2014, by Masahiro Sano.
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+
25
+ require 'ffi/clang/lib/source_range'
26
+
27
+ module FFI
28
+ module Clang
29
+ class SourceRange
30
+ def self.null_range
31
+ SourceRange.new Lib.get_null_range
32
+ end
33
+
34
+ def initialize(range_or_begin_location, end_location = nil)
35
+ if end_location.nil?
36
+ @range = range_or_begin_location
37
+ else
38
+ @range = Lib.get_range(range_or_begin_location.location, end_location.location)
39
+ end
40
+ end
41
+
42
+ def start
43
+ ExpansionLocation.new(Lib.get_range_start @range)
44
+ end
45
+
46
+ def end
47
+ ExpansionLocation.new(Lib.get_range_end @range)
48
+ end
49
+
50
+ def null?
51
+ Lib.range_is_null(@range) != 0
52
+ end
53
+
54
+ attr_reader :range
55
+
56
+ def ==(other)
57
+ Lib.equal_range(@range, other.range) != 0
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,95 @@
1
+ # Copyright, 2014, by Masahiro Sano.
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'ffi/clang/lib/token'
22
+ require 'ffi/clang/lib/cursor'
23
+ require 'ffi/clang/source_location'
24
+
25
+ module FFI
26
+ module Clang
27
+ class Tokens < AutoPointer
28
+ include Enumerable
29
+
30
+ attr_reader :size
31
+ attr_reader :tokens
32
+
33
+ def initialize(pointer, token_size, translation_unit)
34
+ ptr = Lib::TokensPointer.new(pointer,token_size, translation_unit)
35
+ super ptr
36
+
37
+ @translation_unit = translation_unit
38
+ @size = token_size
39
+
40
+ @tokens = []
41
+ cur_ptr = pointer
42
+ token_size.times {
43
+ @tokens << Token.new(cur_ptr, translation_unit)
44
+ cur_ptr += Lib::CXToken.size
45
+ }
46
+ end
47
+
48
+ def self.release(pointer)
49
+ Lib.dispose_tokens(pointer, pointer.token_size, pointer.translation_unit)
50
+ end
51
+
52
+ def each(&block)
53
+ @tokens.each do |token|
54
+ block.call(token)
55
+ end
56
+ end
57
+
58
+ def cursors
59
+ ptr = MemoryPointer.new(Lib::CXCursor, @size)
60
+ Lib.annotate_tokens(@translation_unit, self, @size, ptr)
61
+
62
+ cur_ptr = ptr
63
+ arr = []
64
+ @size.times {
65
+ arr << Cursor.new(cur_ptr, @translation_unit)
66
+ cur_ptr += Lib::CXCursor.size
67
+ }
68
+ arr
69
+ end
70
+ end
71
+
72
+ class Token
73
+ def initialize(token, translation_unit)
74
+ @token = token
75
+ @translation_unit = translation_unit
76
+ end
77
+
78
+ def kind
79
+ Lib.get_token_kind(@token)
80
+ end
81
+
82
+ def spelling
83
+ Lib.extract_string Lib.get_token_spelliing(@translation_unit, @token)
84
+ end
85
+
86
+ def location
87
+ ExpansionLocation.new Lib.get_token_location(@translation_unit, @token)
88
+ end
89
+
90
+ def extent
91
+ SourceRange.new Lib.get_token_extent(@translation_unit, @token)
92
+ end
93
+ end
94
+ end
95
+ end