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.
@@ -7,4 +7,8 @@ describe Index do
7
7
  tu = index.parse_translation_unit fixture_path("a.c")
8
8
  tu.should be_kind_of(TranslationUnit)
9
9
  end
10
+
11
+ it "raises error when file is not found" do
12
+ expect { index.parse_translation_unit fixture_path("xxxxxxxxx.c") }.to raise_error
13
+ end
10
14
  end
@@ -23,9 +23,10 @@ require 'spec_helper'
23
23
 
24
24
  describe Type do
25
25
  let(:cursor) { Index.new.parse_translation_unit(fixture_path("a.c")).cursor }
26
+ let(:cursor_cxx) { Index.new.parse_translation_unit(fixture_path("test.cxx")).cursor }
26
27
  let(:type) { find_first(cursor, :cursor_function).type }
27
28
 
28
- it "can tell us about the main function" do
29
+ it "can tell us about the main function", from_3_3: true do
29
30
  type.variadic?.should equal(false)
30
31
 
31
32
  type.num_arg_types.should equal(2)
@@ -33,4 +34,65 @@ describe Type do
33
34
  type.arg_type(1).spelling.should eq("const char *")
34
35
  type.result_type.spelling.should eq("int")
35
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
+ kind_spelling_type.kind_spelling.should 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', upto_3_2: true do
53
+ expect(canonical_type).to be_kind_of(Type)
54
+ expect(canonical_type.kind).to be(:type_pointer)
55
+ end
56
+
57
+ it 'extracts typedef', from_3_3: true do
58
+ expect(canonical_type).to be_kind_of(Type)
59
+ expect(canonical_type.kind).to be(:type_pointer)
60
+ expect(canonical_type.spelling).to eq('const int *')
61
+ end
62
+ end
63
+
64
+ describe '#pointee' do
65
+ let(:pointee_type) { find_matching(cursor_cxx) { |child, parent|
66
+ child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
67
+ }.type.canonical.pointee }
68
+
69
+ it 'gets pointee type of pointer, C++ reference', upto_3_2: true do
70
+ expect(pointee_type).to be_kind_of(Type)
71
+ expect(pointee_type.kind).to be(:type_int)
72
+ end
73
+
74
+ it 'gets pointee type of pointer, C++ reference', from_3_3: true do
75
+ expect(pointee_type).to be_kind_of(Type)
76
+ expect(pointee_type.kind).to be(:type_int)
77
+ expect(pointee_type.spelling).to eq('const int')
78
+ end
79
+ end
80
+
81
+ describe '#const_qualified?' do
82
+ let(:pointer_type) { find_matching(cursor_cxx) { |child, parent|
83
+ child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
84
+ }.type.canonical }
85
+
86
+ let(:pointee_type) { find_matching(cursor_cxx) { |child, parent|
87
+ child.kind == :cursor_typedef_decl and child.spelling == 'const_int_ptr'
88
+ }.type.canonical.pointee }
89
+
90
+ it 'checks type is const qualified' do
91
+ pointee_type.const_qualified?.should equal true
92
+ end
93
+
94
+ it 'cannot check whether pointee type is const qualified' do
95
+ pointer_type.const_qualified?.should equal false
96
+ end
97
+ end
36
98
  end
@@ -0,0 +1,61 @@
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 'spec_helper'
22
+
23
+ describe FFI::Clang::Utils do
24
+ describe '#self.clang_version_string' do
25
+ let (:version) { Utils::clang_version_string }
26
+ it "returns a version string for showing to user" do
27
+ expect(version).to be_kind_of(String)
28
+ expect(version).to match(/clang version \d+\.\d+/)
29
+ end
30
+ end
31
+
32
+ describe '#self.self.clang_version' do
33
+ let (:version) { Utils::clang_version }
34
+ it "returns only a version of clang as string" do
35
+ expect(version).to be_kind_of(String)
36
+ expect(version).to match(/^\d+\.\d+$/)
37
+ end
38
+ end
39
+
40
+ describe '#self.clang_version_symbol' do
41
+ let (:symbol) { Utils::clang_version_symbol }
42
+ it "returns a symbol that represents clang version" do
43
+ expect(symbol).to be_kind_of(Symbol)
44
+ expect(symbol.to_s).to match(/^clang_\d+\_\d+$/)
45
+ end
46
+ end
47
+
48
+ describe '#self.self.clang_major_version' do
49
+ let (:version) { Utils::clang_major_version }
50
+ it "returns major versions as integer" do
51
+ expect(version).to be_kind_of(Integer)
52
+ end
53
+ end
54
+
55
+ describe '#self.self.clang_minor_version' do
56
+ let (:version) { Utils::clang_minor_version }
57
+ it "returns minor versions as integer" do
58
+ expect(version).to be_kind_of(Integer)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ struct X;
2
+ struct X;
3
+ struct X {
4
+ int a;
5
+ };
@@ -0,0 +1,26 @@
1
+ struct A {
2
+ virtual int func_a() = 0;
3
+ };
4
+
5
+ struct B : public virtual A {
6
+ int func_a() { return 0; }
7
+
8
+ static int func_b() { return 11; }
9
+ };
10
+
11
+ struct C : public virtual A {
12
+ int func_a() { return 1; }
13
+
14
+ enum { EnumC = 100 };
15
+ };
16
+
17
+ struct D : public B, public C {
18
+ private:
19
+ void func_d();
20
+ };
21
+
22
+ void D::func_d() {};
23
+
24
+ void f_variadic(int a, ...);
25
+
26
+ typedef int const* const_int_ptr;
@@ -8,22 +8,55 @@ module ClangSpecHelper
8
8
  File.join File.expand_path("../fixtures", __FILE__), path
9
9
  end
10
10
 
11
- def find_first(cursor, kind)
12
- first = nil
11
+ def find_all(cursor, kind)
12
+ ret = []
13
13
 
14
14
  cursor.visit_children do |cursor, parent|
15
15
  if (cursor.kind == kind)
16
- first = cursor
17
- :break
18
- else
19
- :recurse
16
+ ret << cursor
17
+ end
18
+ :recurse
19
+ end
20
+
21
+ ret
22
+ end
23
+
24
+ def find_first(cursor, kind)
25
+ find_all(cursor, kind).first
26
+ end
27
+
28
+ def find_all_matching(cursor, &term)
29
+ ret = []
30
+
31
+ cursor.visit_children do |child, parent|
32
+ if term.call child, parent
33
+ ret << child
20
34
  end
35
+
36
+ :recurse
21
37
  end
22
38
 
23
- first
39
+ ret
40
+ end
41
+
42
+ def find_matching(cursor, &term)
43
+ find_all_matching(cursor, &term).first
24
44
  end
25
45
  end
26
46
 
27
47
  RSpec.configure do |c|
28
48
  c.include ClangSpecHelper
49
+ supported_versions = ['3.2', '3.3', '3.4', '3.5']
50
+ current_version = ENV['LLVM_VERSION'] || supported_versions.last
51
+ supported_versions.reverse_each { |version|
52
+ break if version == current_version
53
+ sym = ('from_' + version.tr('.', '_')).to_sym
54
+ c.filter_run_excluding sym => true
55
+ }
56
+
57
+ supported_versions.each { |version|
58
+ break if version == current_version
59
+ sym = ('upto_' + version.tr('.', '_')).to_sym
60
+ c.filter_run_excluding sym => true
61
+ }
29
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-clang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-08 00:00:00.000000000 Z
12
+ date: 2014-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -81,6 +81,8 @@ files:
81
81
  - Gemfile
82
82
  - README.md
83
83
  - Rakefile
84
+ - ext/rakefile.rb
85
+ - ext/teapot.rb
84
86
  - ffi-clang.gemspec
85
87
  - lib/ffi/clang.rb
86
88
  - lib/ffi/clang/comment.rb
@@ -98,11 +100,13 @@ files:
98
100
  - lib/ffi/clang/lib/string.rb
99
101
  - lib/ffi/clang/lib/translation_unit.rb
100
102
  - lib/ffi/clang/lib/type.rb
103
+ - lib/ffi/clang/lib/utils.rb
101
104
  - lib/ffi/clang/source_location.rb
102
105
  - lib/ffi/clang/source_range.rb
103
106
  - lib/ffi/clang/translation_unit.rb
104
107
  - lib/ffi/clang/type.rb
105
108
  - lib/ffi/clang/unsaved_file.rb
109
+ - lib/ffi/clang/utils.rb
106
110
  - lib/ffi/clang/version.rb
107
111
  - spec/clang/comment_spec.rb
108
112
  - spec/clang/cursor_spec.rb
@@ -111,9 +115,12 @@ files:
111
115
  - spec/clang/source_location_spec.rb
112
116
  - spec/clang/translation_unit_spec.rb
113
117
  - spec/clang/type_spec.rb
118
+ - spec/clang/utils_spec.rb
114
119
  - spec/fixtures/a.c
120
+ - spec/fixtures/canonical.c
115
121
  - spec/fixtures/docs.h
116
122
  - spec/fixtures/list.c
123
+ - spec/fixtures/test.cxx
117
124
  - spec/spec_helper.rb
118
125
  homepage: ''
119
126
  licenses:
@@ -135,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
142
  version: '0'
136
143
  requirements: []
137
144
  rubyforge_project:
138
- rubygems_version: 2.0.6
145
+ rubygems_version: 2.0.3
139
146
  signing_key:
140
147
  specification_version: 4
141
148
  summary: Ruby FFI bindings for libclang C interface.
@@ -147,7 +154,11 @@ test_files:
147
154
  - spec/clang/source_location_spec.rb
148
155
  - spec/clang/translation_unit_spec.rb
149
156
  - spec/clang/type_spec.rb
157
+ - spec/clang/utils_spec.rb
150
158
  - spec/fixtures/a.c
159
+ - spec/fixtures/canonical.c
151
160
  - spec/fixtures/docs.h
152
161
  - spec/fixtures/list.c
162
+ - spec/fixtures/test.cxx
153
163
  - spec/spec_helper.rb
164
+ has_rdoc: