ffi-clang 0.1.3 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +12 -2
- data/README.md +24 -10
- data/ext/rakefile.rb +12 -0
- data/ext/teapot.rb +16 -0
- data/lib/ffi/clang.rb +2 -1
- data/lib/ffi/clang/cursor.rb +126 -7
- data/lib/ffi/clang/index.rb +4 -4
- data/lib/ffi/clang/lib.rb +4 -5
- data/lib/ffi/clang/lib/cursor.rb +207 -4
- data/lib/ffi/clang/lib/type.rb +71 -3
- data/lib/ffi/clang/lib/utils.rb +29 -0
- data/lib/ffi/clang/source_location.rb +2 -2
- data/lib/ffi/clang/translation_unit.rb +3 -2
- data/lib/ffi/clang/type.rb +40 -3
- data/lib/ffi/clang/utils.rb +58 -0
- data/lib/ffi/clang/version.rb +1 -1
- data/spec/clang/comment_spec.rb +28 -15
- data/spec/clang/cursor_spec.rb +263 -9
- data/spec/clang/index_spec.rb +4 -0
- data/spec/clang/type_spec.rb +63 -1
- data/spec/clang/utils_spec.rb +61 -0
- data/spec/fixtures/canonical.c +5 -0
- data/spec/fixtures/test.cxx +26 -0
- data/spec/spec_helper.rb +40 -7
- metadata +14 -3
data/lib/ffi/clang/lib/type.rb
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
+
|
1
21
|
module FFI
|
2
22
|
module Clang
|
3
23
|
module Lib
|
@@ -5,8 +25,51 @@ module FFI
|
|
5
25
|
:type_invalid, 0,
|
6
26
|
:type_unexposed, 1,
|
7
27
|
:type_void, 2,
|
28
|
+
:type_bool, 3,
|
29
|
+
:type_char_u, 4,
|
30
|
+
:type_uchar, 5,
|
31
|
+
:type_char16, 6,
|
32
|
+
:type_char32, 7,
|
33
|
+
:type_ushort, 8,
|
34
|
+
:type_uint, 9,
|
35
|
+
:type_ulong, 10,
|
36
|
+
:type_ulonglong, 11,
|
37
|
+
:type_uint128, 12,
|
38
|
+
:type_char_s, 13,
|
39
|
+
:type_schar, 14,
|
40
|
+
:type_wchar, 15,
|
41
|
+
:type_short, 16,
|
42
|
+
:type_int, 17,
|
43
|
+
:type_long, 18,
|
44
|
+
:type_longlong, 19,
|
45
|
+
:type_int128, 20,
|
46
|
+
:type_float, 21,
|
47
|
+
:type_double, 22,
|
48
|
+
:type_longdouble, 23,
|
49
|
+
:type_nullptr, 24,
|
50
|
+
:type_overload, 25,
|
51
|
+
:type_dependent, 26,
|
52
|
+
:type_obj_c_id, 27,
|
53
|
+
:type_obj_c_class, 28,
|
54
|
+
:type_obj_c_sel, 29,
|
55
|
+
:type_complex, 100,
|
8
56
|
:type_pointer, 101,
|
9
|
-
:
|
57
|
+
:type_block_pointer, 102,
|
58
|
+
:type_lvalue_ref, 103,
|
59
|
+
:type_rvalue_ref, 104,
|
60
|
+
:type_record, 105,
|
61
|
+
:type_enum, 106,
|
62
|
+
:type_typedef, 107,
|
63
|
+
:type_obj_c_interface, 108,
|
64
|
+
:type_obj_c_object_pointer, 109,
|
65
|
+
:type_function_no_proto, 110,
|
66
|
+
:type_function_proto, 111,
|
67
|
+
:type_constant_array, 112,
|
68
|
+
:type_vector, 113,
|
69
|
+
:type_incomplete_array, 114,
|
70
|
+
:type_variable_array, 115,
|
71
|
+
:type_dependent_sized_array, 116,
|
72
|
+
:type_member_pointer, 117,
|
10
73
|
]
|
11
74
|
|
12
75
|
class CXType < FFI::Struct
|
@@ -16,13 +79,18 @@ module FFI
|
|
16
79
|
)
|
17
80
|
end
|
18
81
|
|
19
|
-
attach_function :
|
82
|
+
attach_function :get_pointee_type, :clang_getPointeeType, [CXType.by_value], CXType.by_value
|
83
|
+
attach_function :get_type_kind_spelling, :clang_getTypeKindSpelling, [:kind], CXString.by_value
|
84
|
+
if FFI::Clang::Utils.satisfy_version?('3.3')
|
85
|
+
attach_function :get_type_spelling, :clang_getTypeSpelling, [CXType.by_value], CXString.by_value
|
86
|
+
end
|
20
87
|
attach_function :is_function_type_variadic, :clang_isFunctionTypeVariadic, [CXType.by_value], :uint
|
21
88
|
attach_function :is_pod_type, :clang_isPODType, [CXType.by_value], :uint
|
22
89
|
attach_function :get_num_arg_types, :clang_getNumArgTypes, [CXType.by_value], :int
|
23
90
|
attach_function :get_arg_type, :clang_getArgType, [CXType.by_value, :uint], CXType.by_value
|
24
91
|
attach_function :get_result_type, :clang_getResultType, [CXType.by_value], CXType.by_value
|
25
|
-
|
92
|
+
attach_function :get_canonical_type, :clang_getCanonicalType, [CXType.by_value], CXType.by_value
|
93
|
+
attach_function :is_const_qualified_type, :clang_isConstQualifiedType, [CXType.by_value], :uint
|
26
94
|
end
|
27
95
|
end
|
28
96
|
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
|
@@ -35,8 +35,8 @@ module FFI
|
|
35
35
|
|
36
36
|
Lib::get_expansion_location(@location, cxfile, line, column, offset)
|
37
37
|
|
38
|
-
@file
|
39
|
-
@line
|
38
|
+
@file = Lib.extract_string Lib.get_file_name(cxfile.read_pointer)
|
39
|
+
@line = line.get_uint(0)
|
40
40
|
@column = column.get_uint(0)
|
41
41
|
@offset = offset.get_uint(0)
|
42
42
|
end
|
@@ -25,8 +25,9 @@ require 'ffi/clang/cursor'
|
|
25
25
|
module FFI
|
26
26
|
module Clang
|
27
27
|
class TranslationUnit < AutoPointer
|
28
|
-
def initialize(pointer)
|
28
|
+
def initialize(pointer, index)
|
29
29
|
super pointer
|
30
|
+
@index = index
|
30
31
|
end
|
31
32
|
|
32
33
|
def self.release(pointer)
|
@@ -42,7 +43,7 @@ module FFI
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def cursor
|
45
|
-
Cursor.new(Lib.get_translation_unit_cursor(self))
|
46
|
+
Cursor.new(Lib.get_translation_unit_cursor(self), self)
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
data/lib/ffi/clang/type.rb
CHANGED
@@ -1,14 +1,39 @@
|
|
1
|
+
# Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
+
|
1
21
|
module FFI
|
2
22
|
module Clang
|
3
23
|
class Type
|
4
|
-
def initialize(type)
|
24
|
+
def initialize(type, translation_unit)
|
5
25
|
@type = type
|
26
|
+
@translation_unit = translation_unit
|
6
27
|
end
|
7
28
|
|
8
29
|
def kind
|
9
30
|
@type[:kind]
|
10
31
|
end
|
11
32
|
|
33
|
+
def kind_spelling
|
34
|
+
Lib.extract_string Lib.get_type_kind_spelling @type[:kind]
|
35
|
+
end
|
36
|
+
|
12
37
|
def spelling
|
13
38
|
Lib.extract_string Lib.get_type_spelling(@type)
|
14
39
|
end
|
@@ -25,12 +50,24 @@ module FFI
|
|
25
50
|
Lib.get_num_arg_types(@type)
|
26
51
|
end
|
27
52
|
|
53
|
+
def pointee
|
54
|
+
Type.new Lib.get_pointee_type(@type), @translation_unit
|
55
|
+
end
|
56
|
+
|
57
|
+
def canonical
|
58
|
+
Type.new Lib.get_canonical_type(@type), @translation_unit
|
59
|
+
end
|
60
|
+
|
61
|
+
def const_qualified?
|
62
|
+
Lib.is_const_qualified_type(@type) != 0
|
63
|
+
end
|
64
|
+
|
28
65
|
def arg_type(i)
|
29
|
-
Type.new Lib.get_arg_type(@type, i)
|
66
|
+
Type.new Lib.get_arg_type(@type, i), @translation_unit
|
30
67
|
end
|
31
68
|
|
32
69
|
def result_type
|
33
|
-
Type.new Lib.get_result_type(@type)
|
70
|
+
Type.new Lib.get_result_type(@type), @translation_unit
|
34
71
|
end
|
35
72
|
end
|
36
73
|
end
|
@@ -0,0 +1,58 @@
|
|
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/utils'
|
22
|
+
require 'ffi/clang/lib/string'
|
23
|
+
|
24
|
+
module FFI
|
25
|
+
module Clang
|
26
|
+
class Utils
|
27
|
+
def self.clang_version_string
|
28
|
+
Lib.extract_string Lib.get_clang_version
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.clang_version
|
32
|
+
version = clang_version_string
|
33
|
+
version.match(/clang version (\d+\.\d+)/).values_at(1).first
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.clang_version_symbol
|
37
|
+
version = "clang_" + clang_version.tr('.', '_')
|
38
|
+
version.intern
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.clang_major_version
|
42
|
+
version = clang_version_string
|
43
|
+
version.match(/clang version (\d+)\./).values_at(1).first.to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.clang_minor_version
|
47
|
+
version = clang_version_string
|
48
|
+
version.match(/clang version \d+\.(\d+)/).values_at(1).first.to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.satisfy_version?(min_version, max_version = nil)
|
52
|
+
Gem::Version.create(self.clang_version) >= Gem::Version.create(min_version) and
|
53
|
+
(max_version.nil? or
|
54
|
+
Gem::Version.create(self.clang_version) <= Gem::Version.create(max_version))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/ffi/clang/version.rb
CHANGED
data/spec/clang/comment_spec.rb
CHANGED
@@ -63,22 +63,35 @@ describe Comment do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "understands params" do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
param.valid_index?.should == true
|
70
|
-
param.index.should equal(0)
|
71
|
-
param.name.should eq("input")
|
72
|
-
arg = " some input\n "
|
73
|
-
param.child.text.should eq(arg)
|
74
|
-
param.comment.should eq(arg)
|
75
|
-
end
|
66
|
+
[['input', " some input\n "], ['flags', " some flags\n "]].each_with_index do |v, child_idx|
|
67
|
+
param = comment.child(3 + child_idx)
|
68
|
+
param.should be_kind_of(ParamCommandComment)
|
76
69
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
param.valid_index?.should == true
|
71
|
+
param.index.should equal(child_idx)
|
72
|
+
param.name.should eq(v[0])
|
73
|
+
param.child.text.should eq v[1]
|
74
|
+
param.comment.should eq v[1]
|
75
|
+
end
|
82
76
|
end
|
83
77
|
|
78
|
+
describe "understands blocks" do
|
79
|
+
let (:block) { comment.child(5) }
|
80
|
+
|
81
|
+
it 'is BlockCommandComment' do
|
82
|
+
expect(block).to be_kind_of(BlockCommandComment)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'has name' do
|
86
|
+
expect(block.name).to eq("return")
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'has comment', from_3_4: true do
|
90
|
+
expect(block.comment).to eq(" a random value")
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'has comment', upto_3_3: true do
|
94
|
+
expect(block.comment).to eq(" a random value\n ")
|
95
|
+
end
|
96
|
+
end
|
84
97
|
end
|
data/spec/clang/cursor_spec.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# The above copyright notice and this permission notice shall be included in
|
13
13
|
# all copies or substantial portions of the Software.
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -24,6 +24,8 @@ require 'spec_helper'
|
|
24
24
|
|
25
25
|
describe Cursor do
|
26
26
|
let(:cursor) { Index.new.parse_translation_unit(fixture_path("list.c")).cursor }
|
27
|
+
let(:cursor_cxx) { Index.new.parse_translation_unit(fixture_path("test.cxx")).cursor }
|
28
|
+
let(:cursor_canon) { Index.new.parse_translation_unit(fixture_path("canonical.c")).cursor }
|
27
29
|
|
28
30
|
it "can be obtained from a translation unit" do
|
29
31
|
cursor.should be_kind_of(Cursor)
|
@@ -37,15 +39,26 @@ describe Cursor do
|
|
37
39
|
location.should be_kind_of(SourceLocation)
|
38
40
|
end
|
39
41
|
|
40
|
-
|
41
|
-
extent
|
42
|
-
extent
|
42
|
+
describe '#extent' do
|
43
|
+
let(:extent) { cursor.extent }
|
44
|
+
it "has an extent which is a SourceRange" do
|
45
|
+
expect(extent).to be_kind_of(SourceRange)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'has filename and posion at start point' do
|
49
|
+
expect(extent.start.file).to eq(fixture_path("list.c"))
|
50
|
+
expect(extent.start.line).to equal(1)
|
51
|
+
end
|
43
52
|
|
44
|
-
|
45
|
-
|
53
|
+
it 'has filename and posion at end point', from_3_4: true do
|
54
|
+
expect(extent.end.file).to eq(fixture_path("list.c"))
|
55
|
+
expect(extent.end.line).to equal(11)
|
56
|
+
end
|
46
57
|
|
47
|
-
|
48
|
-
|
58
|
+
it 'has filename and posion at end point', upto_3_3: true do
|
59
|
+
expect(extent.end.file).to eq(fixture_path("list.c"))
|
60
|
+
expect(extent.end.line).to equal(10)
|
61
|
+
end
|
49
62
|
end
|
50
63
|
|
51
64
|
it "returns the path of the translation unit for the translation unit cursor" do
|
@@ -128,5 +141,246 @@ describe Cursor do
|
|
128
141
|
end
|
129
142
|
|
130
143
|
end
|
131
|
-
|
144
|
+
|
145
|
+
describe '#virtual_base?' do
|
146
|
+
let(:virtual_base_cursor) { find_matching(cursor_cxx) { |child, parent|
|
147
|
+
child.kind == :cursor_cxx_base_specifier and parent.spelling == 'B' } }
|
148
|
+
|
149
|
+
it 'checks cursor is virtual base' do
|
150
|
+
virtual_base_cursor.virtual_base?.should equal true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#virtual?' do
|
155
|
+
let(:virtual_cursor) { find_matching(cursor_cxx) { |child, parent|
|
156
|
+
child.kind == :cursor_cxx_method and child.spelling == 'func_a' } }
|
157
|
+
|
158
|
+
it 'checks member function is virtual' do
|
159
|
+
virtual_cursor.virtual?.should equal true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#pure_virtual?', from_3_4: true do
|
164
|
+
let(:pure_virtual_cursor) { find_matching(cursor_cxx) { |child, parent|
|
165
|
+
child.kind == :cursor_cxx_method and
|
166
|
+
child.spelling == 'func_a' and parent.spelling == 'A' } }
|
167
|
+
|
168
|
+
it 'checks member function is purely virtual' do
|
169
|
+
pure_virtual_cursor.pure_virtual?.should equal true
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#static?' do
|
174
|
+
let(:static_method_cursor) { find_matching(cursor_cxx) { |child, parent|
|
175
|
+
child.kind == :cursor_cxx_method and child.spelling == 'func_b' } }
|
176
|
+
|
177
|
+
it 'checks cursor is static member function' do
|
178
|
+
static_method_cursor.static?.should equal true
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe '#enum_value' do
|
183
|
+
let(:enum_value_cursor) { find_matching(cursor_cxx) { |child, parent|
|
184
|
+
child.kind == :cursor_enum_constant_decl and child.spelling == 'EnumC' } }
|
185
|
+
|
186
|
+
it 'returns enum value' do
|
187
|
+
enum_value_cursor.enum_value.should equal 100
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe '#dynamic_call?' do
|
192
|
+
# TODO
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '#specialized_template' do
|
196
|
+
# TODO
|
197
|
+
end
|
198
|
+
|
199
|
+
describe '#canonical' do
|
200
|
+
let (:structs) { find_all(cursor_canon, :cursor_struct) }
|
201
|
+
|
202
|
+
it "mathes 3 cursors" do
|
203
|
+
structs.size.should eq(3)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "refers the first cursor as canonical one" do
|
207
|
+
structs[0].canonical.should eq(structs[0])
|
208
|
+
structs[1].canonical.should eq(structs[0])
|
209
|
+
structs[2].canonical.should eq(structs[0])
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#definition' do
|
214
|
+
let (:structs) { find_all(cursor_canon, :cursor_struct) }
|
215
|
+
|
216
|
+
it "mathes 3 cursors" do
|
217
|
+
structs.size.should eq(3)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "refers the third cursor as definition one" do
|
221
|
+
structs[0].definition.should eq(structs[2])
|
222
|
+
structs[1].definition.should eq(structs[2])
|
223
|
+
structs[2].definition.should eq(structs[2])
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '#template_kind' do
|
228
|
+
# TODO
|
229
|
+
end
|
230
|
+
|
231
|
+
describe '#access_specifier' do
|
232
|
+
let(:access_specifier_cursor) { find_matching(cursor_cxx) { |child, parent|
|
233
|
+
child.kind == :cursor_cxx_method and child.spelling == 'func_d' } }
|
234
|
+
|
235
|
+
it 'returns access specifier symbol', from_3_3: true do
|
236
|
+
access_specifier_cursor.access_specifier.should equal :private
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'returns access specifier symbol(invalid, why?)', upto_3_2: true do
|
240
|
+
access_specifier_cursor.access_specifier.should equal :invalid
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe '#language' do
|
245
|
+
let(:c_language_cursor) { find_matching(cursor) { |c, p| c.kind == :cursor_struct } }
|
246
|
+
let(:cxx_language_cursor) { find_matching(cursor_cxx) { |c, p| c.kind == :cursor_struct } }
|
247
|
+
|
248
|
+
it 'returns :c if the cursor language is C' do
|
249
|
+
c_language_cursor.language.should equal :c
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'returns :c_plus_plus if the cursor language is C++' do
|
253
|
+
cxx_language_cursor.language.should equal :c_plus_plus
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '#translation_unit' do
|
258
|
+
let (:struct) { find_first(cursor, :cursor_struct) }
|
259
|
+
|
260
|
+
it "can find the first struct" do
|
261
|
+
struct.should_not equal(nil)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "returns the translation unit that a cursor originated from" do
|
265
|
+
struct.translation_unit.should be_kind_of(TranslationUnit)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe '#linkage' do
|
270
|
+
let (:ref) { find_first(cursor, :cursor_type_ref) }
|
271
|
+
let (:func) { find_first(cursor, :cursor_function) }
|
272
|
+
|
273
|
+
it "returns :external if the cursor is non-static function" do
|
274
|
+
func.linkage.should equal :external
|
275
|
+
end
|
276
|
+
|
277
|
+
it "returns :invalid if the cursor does not have linkage" do
|
278
|
+
ref.linkage.should equal :invalid
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe '#semantic_parent' do
|
283
|
+
let(:parent) { find_matching(cursor_cxx) { |child, parent|
|
284
|
+
child.kind == :cursor_cxx_method and child.spelling == 'func_d' and parent.spelling != 'D' } }
|
285
|
+
|
286
|
+
it 'returns base class as semantic parent' do
|
287
|
+
parent.semantic_parent.spelling.should eq('D')
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe '#lexical_parent' do
|
292
|
+
let(:parent) { find_matching(cursor_cxx) { |child, parent|
|
293
|
+
child.kind == :cursor_cxx_method and child.spelling == 'func_d' and parent.spelling != 'D' } }
|
294
|
+
|
295
|
+
it 'returns translation unit as lexical parent' do
|
296
|
+
parent.lexical_parent.kind.should eq(:cursor_translation_unit)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
describe '#included_file' do
|
301
|
+
#TODO
|
302
|
+
end
|
303
|
+
|
304
|
+
describe '#definition?' do
|
305
|
+
let (:struct) { find_all(cursor_canon, :cursor_struct).at(2) }
|
306
|
+
|
307
|
+
it "checks cursor is a definition" do
|
308
|
+
struct.definition?.should be_true
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
describe '#usr' do
|
313
|
+
let (:func) { find_first(cursor, :cursor_function) }
|
314
|
+
|
315
|
+
it "returns something in string" do
|
316
|
+
func.usr.should be_kind_of(String)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
describe '#variadic?', from_3_3: true do
|
321
|
+
let(:func) { find_matching(cursor_cxx) { |child, parent|
|
322
|
+
child.kind == :cursor_function and child.spelling == 'f_variadic' } }
|
323
|
+
|
324
|
+
it "checks cursor is a variadic function" do
|
325
|
+
func.variadic?.should be_true
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
describe '#referenced' do
|
330
|
+
let(:struct) { find_matching(cursor_cxx) { |child, parent|
|
331
|
+
child.kind == :cursor_struct and child.spelling == 'A' } }
|
332
|
+
let(:ref) { find_matching(cursor_cxx) { |child, parent|
|
333
|
+
child.kind == :cursor_type_ref and child.spelling == 'struct A' } }
|
334
|
+
|
335
|
+
it "returns a cursor that this cursor references" do
|
336
|
+
ref.referenced.should eq(struct)
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
describe '#hash' do
|
342
|
+
let (:func) { find_first(cursor, :cursor_function) }
|
343
|
+
|
344
|
+
it "computes hash for the cursor" do
|
345
|
+
func.hash.should be_kind_of(Fixnum)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
describe '#availability' do
|
350
|
+
let (:func) { find_first(cursor, :cursor_function) }
|
351
|
+
|
352
|
+
it "returns :available for the cursor availability" do
|
353
|
+
func.availability.should equal(:available)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
describe '#type' do
|
358
|
+
let (:field) { find_first(cursor, :cursor_field_decl) }
|
359
|
+
|
360
|
+
it "returns type for the cursor" do
|
361
|
+
field.type.should be_kind_of(Type)
|
362
|
+
field.type.kind.should equal(:type_int)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
describe '#underlying_type' do
|
367
|
+
let (:typedef) { find_first(cursor_cxx, :cursor_typedef_decl) }
|
368
|
+
|
369
|
+
it "returns type that the cursor type is underlying" do
|
370
|
+
typedef.underlying_type.should be_kind_of(Type)
|
371
|
+
typedef.underlying_type.kind.should equal(:type_pointer)
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
describe '#enum_decl_integer_type' do
|
376
|
+
#TODO
|
377
|
+
end
|
378
|
+
|
379
|
+
describe '#platform_availability' do
|
380
|
+
#TODO
|
381
|
+
end
|
382
|
+
|
383
|
+
describe '#get_overridden_cursors' do
|
384
|
+
#TODO
|
385
|
+
end
|
132
386
|
end
|