ffi-clang 0.7.0 → 0.8.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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -0
  3. data/ext/rakefile.rb +4 -0
  4. data/ext/teapot.rb +4 -3
  5. data/lib/ffi/clang/clang_version.rb +9 -19
  6. data/lib/ffi/clang/code_completion.rb +4 -18
  7. data/lib/ffi/clang/comment.rb +7 -19
  8. data/lib/ffi/clang/compilation_database.rb +4 -18
  9. data/lib/ffi/clang/cursor.rb +70 -25
  10. data/lib/ffi/clang/diagnostic.rb +8 -21
  11. data/lib/ffi/clang/file.rb +4 -18
  12. data/lib/ffi/clang/index.rb +9 -20
  13. data/lib/ffi/clang/lib/clang_version.rb +5 -19
  14. data/lib/ffi/clang/lib/code_completion.rb +4 -18
  15. data/lib/ffi/clang/lib/comment.rb +7 -20
  16. data/lib/ffi/clang/lib/compilation_database.rb +4 -18
  17. data/lib/ffi/clang/lib/cursor.rb +34 -23
  18. data/lib/ffi/clang/lib/diagnostic.rb +7 -20
  19. data/lib/ffi/clang/lib/file.rb +5 -20
  20. data/lib/ffi/clang/lib/inclusions.rb +5 -19
  21. data/lib/ffi/clang/lib/index.rb +6 -20
  22. data/lib/ffi/clang/lib/source_location.rb +5 -20
  23. data/lib/ffi/clang/lib/source_range.rb +5 -22
  24. data/lib/ffi/clang/lib/string.rb +6 -20
  25. data/lib/ffi/clang/lib/token.rb +4 -18
  26. data/lib/ffi/clang/lib/translation_unit.rb +6 -20
  27. data/lib/ffi/clang/lib/type.rb +8 -20
  28. data/lib/ffi/clang/lib.rb +15 -20
  29. data/lib/ffi/clang/source_location.rb +7 -20
  30. data/lib/ffi/clang/source_range.rb +7 -22
  31. data/lib/ffi/clang/token.rb +4 -18
  32. data/lib/ffi/clang/translation_unit.rb +10 -20
  33. data/lib/ffi/clang/type.rb +7 -19
  34. data/lib/ffi/clang/unsaved_file.rb +6 -20
  35. data/lib/ffi/clang/version.rb +7 -21
  36. data/lib/ffi/clang.rb +9 -20
  37. data/license.md +38 -0
  38. data/readme.md +46 -0
  39. data.tar.gz.sig +0 -0
  40. metadata +71 -73
  41. metadata.gz.sig +2 -0
  42. data/.editorconfig +0 -23
  43. data/.gitignore +0 -19
  44. data/.rspec +0 -5
  45. data/.travis.yml +0 -30
  46. data/Gemfile +0 -12
  47. data/README.md +0 -74
  48. data/Rakefile +0 -12
  49. data/examples/docs.cpp +0 -25
  50. data/examples/docs.rb +0 -31
  51. data/ffi-clang.gemspec +0 -25
  52. data/spec/ffi/clang/code_completion_spec.rb +0 -181
  53. data/spec/ffi/clang/comment_spec.rb +0 -453
  54. data/spec/ffi/clang/compilation_database_spec.rb +0 -180
  55. data/spec/ffi/clang/cursor_spec.rb +0 -741
  56. data/spec/ffi/clang/diagnostic_spec.rb +0 -89
  57. data/spec/ffi/clang/file_spec.rb +0 -82
  58. data/spec/ffi/clang/fixtures/a.c +0 -7
  59. data/spec/ffi/clang/fixtures/canonical.c +0 -5
  60. data/spec/ffi/clang/fixtures/class.cpp +0 -8
  61. data/spec/ffi/clang/fixtures/compile_commands.json +0 -17
  62. data/spec/ffi/clang/fixtures/completion.cxx +0 -8
  63. data/spec/ffi/clang/fixtures/docs.c +0 -1
  64. data/spec/ffi/clang/fixtures/docs.cc +0 -1
  65. data/spec/ffi/clang/fixtures/docs.h +0 -54
  66. data/spec/ffi/clang/fixtures/list.c +0 -11
  67. data/spec/ffi/clang/fixtures/location1.c +0 -7
  68. data/spec/ffi/clang/fixtures/simple.ast +0 -0
  69. data/spec/ffi/clang/fixtures/simple.c +0 -3
  70. data/spec/ffi/clang/fixtures/test.cxx +0 -62
  71. data/spec/ffi/clang/index_spec.rb +0 -90
  72. data/spec/ffi/clang/source_location_spec.rb +0 -138
  73. data/spec/ffi/clang/source_range_spec.rb +0 -74
  74. data/spec/ffi/clang/token_spec.rb +0 -82
  75. data/spec/ffi/clang/translation_unit_spec.rb +0 -220
  76. data/spec/ffi/clang/type_spec.rb +0 -273
  77. data/spec/ffi/clang/version_spec.rb +0 -28
  78. data/spec/spec_helper.rb +0 -51
@@ -1,82 +0,0 @@
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
- describe Tokens do
22
- let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
23
- let(:cursor) { translation_unit.cursor }
24
- let(:range) { find_first(cursor, :cursor_struct).extent }
25
- let(:tokens) { translation_unit.tokenize(range) }
26
-
27
- it "can be obtained from a translation unit" do
28
- expect(tokens).to be_kind_of(Tokens)
29
- expect(tokens.size).to be >= 12
30
- expect(tokens.tokens).to be_kind_of(Array)
31
- expect(tokens.tokens.first).to be_kind_of(Token)
32
- end
33
-
34
- it "calls dispose_tokens on GC" do
35
- tokens.autorelease = false
36
- expect(Lib).to receive(:dispose_tokens).at_least(:once)
37
- expect{tokens.free}.not_to raise_error
38
- end
39
-
40
- it "#each" do
41
- spy = double(stub: nil)
42
- expect(spy).to receive(:stub).exactly(tokens.size).times
43
- tokens.each { spy.stub }
44
- end
45
-
46
- it "#cursors" do
47
- expect(tokens.cursors).to be_kind_of(Array)
48
- expect(tokens.cursors.size).to eq(tokens.size)
49
- expect(tokens.cursors.first).to be_kind_of(Cursor)
50
- end
51
- end
52
-
53
- describe Token do
54
- let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
55
- let(:cursor) { translation_unit.cursor }
56
- let(:range) { find_first(cursor, :cursor_struct).extent }
57
- let(:token) { translation_unit.tokenize(range).first }
58
-
59
- it "can be obtained from a translation unit" do
60
- expect(token).to be_kind_of(Token)
61
- end
62
-
63
- it "#kind" do
64
- expect(token.kind).to be_kind_of(Symbol)
65
- expect(token.kind).to eq(:keyword)
66
- end
67
-
68
- it "#spelling" do
69
- expect(token.spelling).to be_kind_of(String)
70
- expect(token.spelling).to eq('struct')
71
- end
72
-
73
- it "#location" do
74
- expect(token.location).to be_kind_of(SourceLocation)
75
- expect(token.location.line).to eq(1)
76
- end
77
-
78
- it "#extent" do
79
- expect(token.extent).to be_kind_of(SourceRange)
80
- expect(token.extent.start.line).to eq(1)
81
- end
82
- end
@@ -1,220 +0,0 @@
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
- describe TranslationUnit do
22
- before :all do
23
- FileUtils.mkdir_p TMP_DIR
24
- end
25
-
26
- after :all do
27
- FileUtils.rm_rf TMP_DIR
28
- end
29
-
30
- let(:translation_unit) { Index.new.parse_translation_unit fixture_path("a.c") }
31
-
32
- it "returns a list of diagnostics" do
33
- diags = translation_unit.diagnostics
34
- expect(diags).to be_kind_of(Array)
35
- expect(diags).to_not be_empty
36
- end
37
-
38
- it "returns a list of diagnostics from an unsaved file" do
39
- file = UnsavedFile.new("a.c", File.read(fixture_path("a.c")))
40
- translation_unit = Index.new.parse_translation_unit("a.c", nil,[file])
41
- diags = translation_unit.diagnostics
42
- expect(diags).to be_kind_of(Array)
43
- expect(diags).to_not be_empty
44
- end
45
-
46
- it "calls dispose_translation_unit on GC" do
47
- translation_unit.autorelease = false
48
- # expect(Lib).to receive(:dispose_translation_unit).with(translation_unit).once
49
- expect{translation_unit.free}.not_to raise_error
50
- end
51
-
52
- describe "#spelling" do
53
- let (:spelling) { translation_unit.spelling }
54
-
55
- it "returns own filename" do
56
- expect(spelling).to be_kind_of(String)
57
- expect(spelling).to eq(fixture_path("a.c"))
58
- end
59
- end
60
-
61
- describe "#file" do
62
- let (:specified_file) { translation_unit.file(fixture_path("a.c")) }
63
- let (:unspecified_file) { translation_unit.file }
64
-
65
- it "returns File instance" do
66
- expect(specified_file).to be_kind_of(FFI::Clang::File)
67
- end
68
-
69
- it "returns main file when file name is not specified" do
70
- expect(unspecified_file).to be_kind_of(FFI::Clang::File)
71
- expect(unspecified_file.name).to include("a.c")
72
- end
73
- end
74
-
75
- describe "#location" do
76
- let(:file) { translation_unit.file(fixture_path("a.c")) }
77
- let(:column) { 12 }
78
- let(:location) { translation_unit.location(file, 1, column) }
79
-
80
- it "returns source location at a specific point" do
81
- expect(location).to be_kind_of(SourceLocation)
82
- expect(location.file).to eq(fixture_path("a.c"))
83
- expect(location.line).to eq(1)
84
- expect(location.column).to eq(column)
85
- end
86
- end
87
-
88
- describe "#location_offset" do
89
- let(:file) { translation_unit.file(fixture_path("a.c")) }
90
- let(:offset) { 10 }
91
- let(:location) { translation_unit.location_offset(file, offset) }
92
-
93
- it "returns source location at a specific offset point" do
94
- expect(location).to be_kind_of(SourceLocation)
95
- expect(location.file).to eq(fixture_path("a.c"))
96
- expect(location.column).to eq(offset+1)
97
- end
98
- end
99
-
100
- describe "#cursor" do
101
- let(:cursor) { translation_unit.cursor }
102
- let(:location) { translation_unit.location(translation_unit.file(fixture_path("a.c")), 1, 10) }
103
- let(:cursor_with_loc) { translation_unit.cursor(location) }
104
-
105
- it "returns translation unit cursor if no arguments are specified" do
106
- expect(cursor).to be_kind_of(Cursor)
107
- expect(cursor.kind).to eq(:cursor_translation_unit)
108
- end
109
-
110
- it "returns a correspond cursor if a source location is passed" do
111
- expect(cursor_with_loc).to be_kind_of(Cursor)
112
- expect(cursor_with_loc.kind).to eq(:cursor_parm_decl)
113
- end
114
- end
115
-
116
- describe "#self.default_editing_translation_unit_options" do
117
- let (:opts) { FFI::Clang::TranslationUnit.default_editing_translation_unit_options }
118
- it "returns hash with symbols of TranslationUnitFlags" do
119
- expect(opts).to be_kind_of(Hash)
120
- opts.keys.each { |key|
121
- expect(FFI::Clang::Lib::TranslationUnitFlags.symbols).to include(key)
122
- }
123
- end
124
- end
125
-
126
- describe "#default_save_options" do
127
- let (:opts) { translation_unit.default_save_options }
128
- it "returns hash with symbols of SaveTranslationUnitFlags" do
129
- expect(opts).to be_kind_of(Hash)
130
- opts.keys.each { |key|
131
- expect(FFI::Clang::Lib::SaveTranslationUnitFlags.symbols).to include(key)
132
- }
133
- end
134
- end
135
-
136
- describe "#save" do
137
- let (:filepath) { "#{TMP_DIR}/save_translation_unit" }
138
- let (:may_not_exist_filepath) { "#{TMP_DIR}/not_writable_directory/save_translation_unit" }
139
- it "saves translation unit as a file" do
140
- expect{translation_unit.save(filepath)}.not_to raise_error
141
- expect(FileTest.exist?(filepath)).to be true
142
- end
143
-
144
- it "raises exception if save path is not writable" do
145
- FileUtils.mkdir_p File.dirname(may_not_exist_filepath)
146
- File.chmod(0444, File.dirname(may_not_exist_filepath))
147
- expect{translation_unit.save(may_not_exist_filepath)}.to raise_error(FFI::Clang::Error)
148
- expect(FileTest.exist?(may_not_exist_filepath)).to be false
149
- end
150
- end
151
-
152
- describe "#default_reparse_options" do
153
- let (:opts) { translation_unit.default_reparse_options }
154
- it "returns hash with symbols of ReparseFlags" do
155
- expect(opts).to be_kind_of(Hash)
156
- opts.keys.each { |key|
157
- expect(FFI::Clang::Lib::ReparseFlags.symbols).to include(key)
158
- }
159
- end
160
- end
161
-
162
- describe "#reparse" do
163
- let (:path) { "#{TMP_DIR}/reparse_tmp.c" }
164
- before :each do
165
- FileUtils.touch path
166
- @reparse_translation_unit = Index.new.parse_translation_unit(path)
167
- end
168
- after :each do
169
- FileUtils.rm path, :force => true
170
- end
171
-
172
- it "recretes translation unit" do
173
- File::open(path, "w+") { |io|
174
- io.write("int a;")
175
- }
176
- expect(find_first(@reparse_translation_unit.cursor, :cursor_variable)).to be nil
177
- expect{@reparse_translation_unit.reparse}.not_to raise_error
178
- expect(find_first(@reparse_translation_unit.cursor, :cursor_variable).spelling).to eq("a")
179
- end
180
-
181
- it "raises exception if the file is not found when reparsing" do
182
- FileUtils.rm path, :force => true
183
- expect{@reparse_translation_unit.reparse}.to raise_error(FFI::Clang::Error)
184
- end
185
- end
186
-
187
- describe "#resource_usage" do
188
- let (:ru) { translation_unit.resource_usage }
189
- it "returns ResourceUsage instance that represents memory usage of TU" do
190
- expect(ru).to be_kind_of(TranslationUnit::ResourceUsage)
191
- end
192
- end
193
-
194
- describe TranslationUnit::ResourceUsage do
195
- let (:ru) { translation_unit.resource_usage }
196
- describe "#entries" do
197
- let (:entries) { translation_unit.resource_usage.entries }
198
- it "returns array of CXTUResourceUsageEntry" do
199
- expect(entries).to be_kind_of(Array)
200
- expect(entries.first).to be_kind_of(Lib::CXTUResourceUsageEntry)
201
- expect(entries.first[:kind]).to be_kind_of(Symbol)
202
- expect(entries.first[:amount]).to be_kind_of(Integer)
203
- end
204
- end
205
-
206
- describe "#self.name" do
207
- let(:name) { FFI::Clang::TranslationUnit::ResourceUsage.name(:ast) }
208
- it "returns the name of the memory category" do
209
- expect(name).to be_kind_of(String)
210
- end
211
- end
212
-
213
- describe "#self.release" do
214
- it "releases data by calling 'clang_disposeCXTUResourceUsage'" do
215
- ru.autorelease = false
216
- expect{ ru.free }.not_to raise_error
217
- end
218
- end
219
- end
220
- end
@@ -1,273 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # Copyright, 2013, by Carlos Martín Nieto <cmn@dwim.me>
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
- describe Type do
24
- let(:cursor) { Index.new.parse_translation_unit(fixture_path("a.c")).cursor }
25
- let(:cursor_cxx) { Index.new.parse_translation_unit(fixture_path("test.cxx")).cursor }
26
- let(:cursor_list) { Index.new.parse_translation_unit(fixture_path("list.c")).cursor }
27
- let(:type) { find_first(cursor, :cursor_function).type }
28
-
29
- it "can tell us about the main function" do
30
- expect(type.variadic?).to equal(false)
31
-
32
- expect(type.num_arg_types).to equal(2)
33
- expect(type.arg_type(0).spelling).to eq("int")
34
- expect(type.arg_type(1).spelling).to eq("const char *")
35
- expect(type.result_type.spelling).to eq("int")
36
- end
37
-
38
- describe '#kind_spelling' do
39
- let(:kind_spelling_type) { find_matching(cursor_cxx) { |child, parent|
40
- child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'}.type }
41
-
42
- it 'returns type kind name with string' do
43
- expect(kind_spelling_type.kind_spelling).to eq 'Typedef'
44
- end
45
- end
46
-
47
- describe '#canonical' do
48
- let(:canonical_type) { find_matching(cursor_cxx) { |child, parent|
49
- child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
50
- }.type.canonical }
51
-
52
- it 'extracts typedef' do
53
- expect(canonical_type).to be_kind_of(Type)
54
- expect(canonical_type.kind).to be(:type_pointer)
55
- expect(canonical_type.spelling).to eq('const int *')
56
- end
57
- end
58
-
59
- describe '#pointee' do
60
- let(:pointee_type) { find_matching(cursor_cxx) { |child, parent|
61
- child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
62
- }.type.canonical.pointee }
63
-
64
- it 'gets pointee type of pointer, C++ reference' do
65
- expect(pointee_type).to be_kind_of(Type)
66
- expect(pointee_type.kind).to be(:type_int)
67
- expect(pointee_type.spelling).to eq('const int')
68
- end
69
- end
70
-
71
- describe '#const_qualified?' do
72
- let(:pointer_type) { find_matching(cursor_cxx) { |child, parent|
73
- child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
74
- }.type.canonical }
75
-
76
- let(:pointee_type) { find_matching(cursor_cxx) { |child, parent|
77
- child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
78
- }.type.canonical.pointee }
79
-
80
- it 'checks type is const qualified' do
81
- expect(pointee_type.const_qualified?).to equal true
82
- end
83
-
84
- it 'cannot check whether pointee type is const qualified' do
85
- expect(pointer_type.const_qualified?).to equal false
86
- end
87
- end
88
-
89
- describe '#volatile_qualified?' do
90
- let(:pointer_type) { find_matching(cursor) { |child, parent|
91
- child.kind == :cursor_variable and child.spelling == 'volatile_int_ptr'
92
- }.type }
93
-
94
- it 'checks type is volatile qualified' do
95
- expect(pointer_type.volatile_qualified?).to be true
96
- end
97
- end
98
-
99
- describe '#restrict_qualified?' do
100
- let(:pointer_type) { find_matching(cursor) { |child, parent|
101
- child.kind == :cursor_variable and child.spelling == 'restrict_int_ptr'
102
- }.type }
103
-
104
- it 'checks type is restrict qualified' do
105
- expect(pointer_type.restrict_qualified?).to be true
106
- end
107
- end
108
-
109
- describe '#element_type' do
110
- let(:array_type) { find_matching(cursor_cxx) { |child, parent|
111
- child.kind == :cursor_variable and child.spelling == 'int_array'
112
- }.type }
113
-
114
- it 'returns the element type of the array type' do
115
- expect(array_type.element_type).to be_kind_of(Type)
116
- expect(array_type.element_type.kind).to eq(:type_int)
117
- end
118
- end
119
-
120
- describe '#num_elements' do
121
- let(:array_type) { find_matching(cursor_cxx) { |child, parent|
122
- child.kind == :cursor_variable and child.spelling == 'int_array'
123
- }.type }
124
-
125
- it 'returns the number of elements of the array' do
126
- expect(array_type.num_elements).to eq(8)
127
- end
128
- end
129
-
130
- describe '#array_element_type' do
131
- let(:array_type) { find_matching(cursor_cxx) { |child, parent|
132
- child.kind == :cursor_variable and child.spelling == 'int_array'
133
- }.type }
134
-
135
- it 'returns the array element type of the array type' do
136
- expect(array_type.array_element_type).to be_kind_of(Type)
137
- expect(array_type.array_element_type.kind).to eq(:type_int)
138
- end
139
- end
140
-
141
- describe '#array_size' do
142
- let(:array_type) { find_matching(cursor_cxx) { |child, parent|
143
- child.kind == :cursor_variable and child.spelling == 'int_array'
144
- }.type }
145
-
146
- it 'returns the number of elements of the array' do
147
- expect(array_type.array_size).to eq(8)
148
- end
149
- end
150
-
151
- describe '#alignof' do
152
- let(:array_type) { find_matching(cursor_cxx) { |child, parent|
153
- child.kind == :cursor_variable and child.spelling == 'int_array'
154
- }.type }
155
-
156
- it 'returns the alignment of the type in bytes' do
157
- expect(array_type.alignof).to be_kind_of(Integer)
158
- expect(array_type.alignof).to be > 0
159
- end
160
- end
161
-
162
- describe '#sizeof' do
163
- let(:array_type) { find_matching(cursor_cxx) { |child, parent|
164
- child.kind == :cursor_variable and child.spelling == 'int_array'
165
- }.type }
166
-
167
- it 'returns the size of the type in bytes' do
168
- expect(array_type.sizeof).to be_kind_of(Integer)
169
- expect(array_type.sizeof).to be(32)
170
- end
171
- end
172
-
173
- describe '#offsetof' do
174
- let(:struct) { find_matching(cursor_list) { |child, parent|
175
- child.kind == :cursor_struct and child.spelling == 'List'
176
- }.type }
177
-
178
- it 'returns the offset of a field in a record of the type in bits' do
179
- expect(struct.offsetof('Next')).to be_kind_of(Integer)
180
- expect(struct.offsetof('Next')).to be(64)
181
- end
182
- end
183
-
184
- describe '#ref_qualifier' do
185
- let(:lvalue) { find_matching(cursor_cxx) { |child, parent|
186
- child.kind == :cursor_cxx_method and child.spelling == 'func_lvalue_ref'
187
- }.type }
188
- let(:rvalue) { find_matching(cursor_cxx) { |child, parent|
189
- child.kind == :cursor_cxx_method and child.spelling == 'func_rvalue_ref'
190
- }.type }
191
- let(:none) { find_matching(cursor_cxx) { |child, parent|
192
- child.kind == :cursor_cxx_method and child.spelling == 'func_none'
193
- }.type }
194
-
195
- it 'returns :ref_qualifier_lvalue the type is ref-qualified with lvalue' do
196
- expect(lvalue.ref_qualifier).to be(:ref_qualifier_lvalue)
197
- end
198
-
199
- it 'returns :ref_qualifier_rvalue the type is ref-qualified with rvalue' do
200
- expect(rvalue.ref_qualifier).to be(:ref_qualifier_rvalue)
201
- end
202
-
203
- it 'returns :ref_qualifier_none the type is not ref-qualified' do
204
- expect(none.ref_qualifier).to be(:ref_qualifier_none)
205
- end
206
- end
207
-
208
- describe '#pod?' do
209
- let(:struct) { find_matching(cursor_list) { |child, parent|
210
- child.kind == :cursor_struct and child.spelling == 'List'
211
- }.type }
212
-
213
- it 'returns true if the type is a POD type' do
214
- expect(struct.pod?).to be true
215
- end
216
- end
217
-
218
- describe '#class_type' do
219
- let(:member_pointer) { find_matching(cursor_cxx) { |child, parent|
220
- child.kind == :cursor_variable and child.spelling == 'member_pointer'
221
- }.type }
222
-
223
- it 'returns the class type of the member pointer type' do
224
- expect(member_pointer.class_type).to be_kind_of(Type)
225
- expect(member_pointer.class_type.kind).to be(:type_record)
226
- expect(member_pointer.class_type.spelling).to eq('A')
227
- end
228
- end
229
-
230
- describe '#declaration' do
231
- let(:struct_ref) { find_matching(cursor_cxx) { |child, parent|
232
- child.kind == :cursor_type_ref and child.spelling == 'struct D'
233
- }.type }
234
- let(:struct_decl) { find_matching(cursor_cxx) { |child, parent|
235
- child.kind == :cursor_struct and child.spelling == 'D'
236
- } }
237
- let(:no_decl) { find_first(cursor_cxx, :cursor_cxx_method).type }
238
-
239
- it 'returns the class type of the member pointer type' do
240
- expect(struct_ref.declaration).to be_kind_of(Cursor)
241
- expect(struct_ref.declaration.kind).to be(:cursor_struct)
242
- expect(struct_ref.declaration).to eq(struct_decl)
243
- end
244
-
245
- it 'returns :cursor_no_decl_found if the type has no declaration' do
246
- expect(no_decl.declaration).to be_kind_of(Cursor)
247
- expect(no_decl.declaration.kind).to be(:cursor_no_decl_found)
248
- end
249
- end
250
-
251
- describe '#calling_conv' do
252
- let(:function) { find_matching(cursor_cxx) { |child, parent|
253
- child.kind == :cursor_function and child.spelling == 'f_variadic'
254
- }.type }
255
-
256
- it 'returns the calling convention associated with the function type' do
257
- expect(function.calling_conv).to be(:calling_conv_c)
258
- end
259
- end
260
-
261
- describe '#==' do
262
- let(:type_decl) { find_matching(cursor_cxx) { |child, parent|
263
- child.kind == :cursor_field_decl and child.spelling == 'int_member_a'
264
- }.type }
265
- let(:type_ref) { find_matching(cursor_cxx) { |child, parent|
266
- child.kind == :cursor_decl_ref_expr and child.spelling == 'int_member_a'
267
- }.type }
268
-
269
- it 'checks if two types represent the same type' do
270
- expect(type_decl == type_ref).to be true
271
- end
272
- end
273
- end
@@ -1,28 +0,0 @@
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/version'
22
-
23
- describe FFI::Clang.clang_version_string do
24
- it "returns a version string for showing to user" do
25
- expect(subject).to be_kind_of(String)
26
- expect(subject).to match(/Apple LLVM version \d+\.\d+\.\d+|clang version \d+\.\d+/)
27
- end
28
- end
data/spec/spec_helper.rb DELETED
@@ -1,51 +0,0 @@
1
-
2
- require_relative '../lib/ffi/clang'
3
-
4
- require 'pry'
5
-
6
- include FFI::Clang
7
-
8
- TMP_DIR = File.expand_path("tmp", __dir__)
9
-
10
- module ClangSpecHelper
11
- def fixture_path(path)
12
- File.join File.expand_path("ffi/clang/fixtures", __dir__), path
13
- end
14
-
15
- def find_all(cursor, kind)
16
- cursor.find_all(kind)
17
- end
18
-
19
- def find_first(cursor, kind)
20
- cursor.find_first(kind)
21
- end
22
-
23
- def find_all_matching(cursor, &term)
24
- cursor.filter(&term)
25
- end
26
-
27
- def find_matching(cursor, &term)
28
- cursor.filter(&term).first
29
- end
30
- end
31
-
32
- RSpec.configure do |config|
33
- # Enable flags like --only-failures and --next-failure
34
- config.example_status_persistence_file_path = ".rspec_status"
35
-
36
- config.include ClangSpecHelper
37
-
38
- supported_versions = ['3.4', '3.5', '3.6', '3.7', '3.8', '3.9', '4.0']
39
- current_version = ENV['LLVM_VERSION'] || supported_versions.last
40
- supported_versions.reverse_each { |version|
41
- break if version == current_version
42
- sym = ('from_' + version.tr('.', '_')).to_sym
43
- config.filter_run_excluding sym => true
44
- }
45
-
46
- supported_versions.each { |version|
47
- break if version == current_version
48
- sym = ('upto_' + version.tr('.', '_')).to_sym
49
- config.filter_run_excluding sym => true
50
- }
51
- end