ffi-clang 0.1.2 → 0.1.3
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 +6 -14
- data/.travis.yml +1 -2
- data/lib/ffi/clang/cursor.rb +10 -1
- data/lib/ffi/clang/lib.rb +2 -2
- data/lib/ffi/clang/lib/cursor.rb +7 -1
- data/lib/ffi/clang/lib/type.rb +28 -0
- data/lib/ffi/clang/type.rb +37 -0
- data/lib/ffi/clang/version.rb +1 -1
- data/spec/clang/cursor_spec.rb +3 -3
- data/spec/clang/type_spec.rb +36 -0
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MGVjMjcwMTg2NDU5MGRmYjgxMzNiYzU5MjY5NzY4OTI1ZDBkZTU0ZDBlNmEx
|
10
|
-
N2RjYzg5NjdjM2E1YWRhNTdiMzk1ZTAzNTAzOTU4MTc3YmRhYmM3YzUwMWFm
|
11
|
-
ZTA2OWQ4ODU3Y2JlMzdmNzQ1ZmM4NWRiNmIwNzIwNDE5Y2NkYjU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzlhMDM1OGViZmZmOGRkNTMzODA5ZjM2OTdlZDBlMmMyNjQyOTg2NGE0MWRj
|
14
|
-
MjY1ZDQyMTBjMzM0YjA3OTg3Yjg5OTdmNzdiODg5YmFkMDExOWY0MGU1M2Vh
|
15
|
-
NGRiNGFhY2QwNTE3NDlmZjM1MDQ4MGU3NWM0MWQ4YzliNWIzMDc=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9dcbefd7f0ba372cb4d7b1f7cdc0486840d8dd22
|
4
|
+
data.tar.gz: b00aec280bd1ae965af5dbe99336bc65a94499f6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c668b1273d5650d12de4a757629a2b02cf398288dc148b5e10a8fef34020d1ff354357c60381baa8597538b871e360d0e188cb6ec7a51420f2d202a5c4c726f3
|
7
|
+
data.tar.gz: b2fadb72c282ee775c8aedc146870d95e12872ee14b1ae182731116b05a2353ce9855554f305004ef0cac5310d252085c10e7a7466daa1ef38a8bc407557331a
|
data/.travis.yml
CHANGED
data/lib/ffi/clang/cursor.rb
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
require 'ffi/clang/lib/cursor'
|
23
23
|
require 'ffi/clang/source_location'
|
24
24
|
require 'ffi/clang/comment'
|
25
|
+
require 'ffi/clang/type'
|
25
26
|
|
26
27
|
module FFI
|
27
28
|
module Clang
|
@@ -90,7 +91,7 @@ module FFI
|
|
90
91
|
SourceRange.new(Lib.get_cursor_extent(@cursor))
|
91
92
|
end
|
92
93
|
|
93
|
-
def
|
94
|
+
def display_name
|
94
95
|
Lib.extract_string Lib.get_cursor_display_name(@cursor)
|
95
96
|
end
|
96
97
|
|
@@ -102,6 +103,14 @@ module FFI
|
|
102
103
|
@cursor[:kind]
|
103
104
|
end
|
104
105
|
|
106
|
+
def type
|
107
|
+
Type.new Lib.get_cursor_type(@cursor)
|
108
|
+
end
|
109
|
+
|
110
|
+
def result_type
|
111
|
+
Type.new Lib.get_cursor_result_type(@cursor)
|
112
|
+
end
|
113
|
+
|
105
114
|
def visit_children(&block)
|
106
115
|
adapter = Proc.new do | cxcursor, parent_cursor, unused |
|
107
116
|
block.call Cursor.new(cxcursor), Cursor.new(parent_cursor)
|
data/lib/ffi/clang/lib.rb
CHANGED
data/lib/ffi/clang/lib/cursor.rb
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
require 'ffi/clang/lib/translation_unit'
|
24
24
|
require 'ffi/clang/lib/diagnostic'
|
25
25
|
require 'ffi/clang/lib/comment'
|
26
|
+
require 'ffi/clang/lib/type'
|
26
27
|
|
27
28
|
module FFI
|
28
29
|
module Clang
|
@@ -34,7 +35,8 @@ module FFI
|
|
34
35
|
:cursor_parm_decl, 10,
|
35
36
|
:cursor_typedef_decl, 20,
|
36
37
|
:cursor_invalid_file, 70,
|
37
|
-
:cursor_translation_unit, 300
|
38
|
+
:cursor_translation_unit, 300
|
39
|
+
]
|
38
40
|
|
39
41
|
class CXCursor < FFI::Struct
|
40
42
|
layout(
|
@@ -74,6 +76,10 @@ module FFI
|
|
74
76
|
|
75
77
|
callback :visit_children_function, [CXCursor.by_value, CXCursor.by_value, :pointer], :child_visit_result
|
76
78
|
attach_function :visit_children, :clang_visitChildren, [CXCursor.by_value, :visit_children_function, :pointer], :uint
|
79
|
+
|
80
|
+
attach_function :get_cursor_type, :clang_getCursorType, [CXCursor.by_value], CXType.by_value
|
81
|
+
attach_function :get_cursor_result_type, :clang_getCursorResultType, [CXCursor.by_value], CXType.by_value
|
82
|
+
|
77
83
|
end
|
78
84
|
end
|
79
85
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FFI
|
2
|
+
module Clang
|
3
|
+
module Lib
|
4
|
+
enum :kind, [
|
5
|
+
:type_invalid, 0,
|
6
|
+
:type_unexposed, 1,
|
7
|
+
:type_void, 2,
|
8
|
+
:type_pointer, 101,
|
9
|
+
:type_function_proto, 111
|
10
|
+
]
|
11
|
+
|
12
|
+
class CXType < FFI::Struct
|
13
|
+
layout(
|
14
|
+
:kind, :kind,
|
15
|
+
:data, [:pointer, 2]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
attach_function :get_type_spelling, :clang_getTypeSpelling, [CXType.by_value], CXString.by_value
|
20
|
+
attach_function :is_function_type_variadic, :clang_isFunctionTypeVariadic, [CXType.by_value], :uint
|
21
|
+
attach_function :is_pod_type, :clang_isPODType, [CXType.by_value], :uint
|
22
|
+
attach_function :get_num_arg_types, :clang_getNumArgTypes, [CXType.by_value], :int
|
23
|
+
attach_function :get_arg_type, :clang_getArgType, [CXType.by_value, :uint], CXType.by_value
|
24
|
+
attach_function :get_result_type, :clang_getResultType, [CXType.by_value], CXType.by_value
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module FFI
|
2
|
+
module Clang
|
3
|
+
class Type
|
4
|
+
def initialize(type)
|
5
|
+
@type = type
|
6
|
+
end
|
7
|
+
|
8
|
+
def kind
|
9
|
+
@type[:kind]
|
10
|
+
end
|
11
|
+
|
12
|
+
def spelling
|
13
|
+
Lib.extract_string Lib.get_type_spelling(@type)
|
14
|
+
end
|
15
|
+
|
16
|
+
def variadic?
|
17
|
+
Lib.is_function_type_variadic(@type) != 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def pod?
|
21
|
+
Lib.is_pod_type(@type) != 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def num_arg_types
|
25
|
+
Lib.get_num_arg_types(@type)
|
26
|
+
end
|
27
|
+
|
28
|
+
def arg_type(i)
|
29
|
+
Type.new Lib.get_arg_type(@type, i)
|
30
|
+
end
|
31
|
+
|
32
|
+
def result_type
|
33
|
+
Type.new Lib.get_result_type(@type)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/ffi/clang/version.rb
CHANGED
data/spec/clang/cursor_spec.rb
CHANGED
@@ -49,7 +49,7 @@ describe Cursor do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "returns the path of the translation unit for the translation unit cursor" do
|
52
|
-
cursor.
|
52
|
+
cursor.display_name.should eq(fixture_path("list.c"))
|
53
53
|
cursor.spelling.should eq(fixture_path("list.c"))
|
54
54
|
end
|
55
55
|
|
@@ -105,7 +105,7 @@ describe Cursor do
|
|
105
105
|
|
106
106
|
it "returns the name of the function" do
|
107
107
|
func.spelling.should eq("sum")
|
108
|
-
func.
|
108
|
+
func.display_name.should eq("sum(union List *)")
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
@@ -124,7 +124,7 @@ describe Cursor do
|
|
124
124
|
|
125
125
|
it "returns the name of the struct" do
|
126
126
|
struct.spelling.should eq("List")
|
127
|
-
struct.
|
127
|
+
struct.display_name.should eq("List")
|
128
128
|
end
|
129
129
|
|
130
130
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright, 2013, by Carlos Martín Nieto <cmn@dwim.me>
|
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
|
+
require 'spec_helper'
|
23
|
+
|
24
|
+
describe Type do
|
25
|
+
let(:cursor) { Index.new.parse_translation_unit(fixture_path("a.c")).cursor }
|
26
|
+
let(:type) { find_first(cursor, :cursor_function).type }
|
27
|
+
|
28
|
+
it "can tell us about the main function" do
|
29
|
+
type.variadic?.should equal(false)
|
30
|
+
|
31
|
+
type.num_arg_types.should equal(2)
|
32
|
+
type.arg_type(0).spelling.should eq("int")
|
33
|
+
type.arg_type(1).spelling.should eq("const char *")
|
34
|
+
type.result_type.spelling.should eq("int")
|
35
|
+
end
|
36
|
+
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.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jari Bakken
|
@@ -9,20 +9,20 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
@@ -43,28 +43,28 @@ dependencies:
|
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
description: Ruby FFI bindings for libclang C interface.
|
@@ -97,9 +97,11 @@ files:
|
|
97
97
|
- lib/ffi/clang/lib/source_range.rb
|
98
98
|
- lib/ffi/clang/lib/string.rb
|
99
99
|
- lib/ffi/clang/lib/translation_unit.rb
|
100
|
+
- lib/ffi/clang/lib/type.rb
|
100
101
|
- lib/ffi/clang/source_location.rb
|
101
102
|
- lib/ffi/clang/source_range.rb
|
102
103
|
- lib/ffi/clang/translation_unit.rb
|
104
|
+
- lib/ffi/clang/type.rb
|
103
105
|
- lib/ffi/clang/unsaved_file.rb
|
104
106
|
- lib/ffi/clang/version.rb
|
105
107
|
- spec/clang/comment_spec.rb
|
@@ -108,6 +110,7 @@ files:
|
|
108
110
|
- spec/clang/index_spec.rb
|
109
111
|
- spec/clang/source_location_spec.rb
|
110
112
|
- spec/clang/translation_unit_spec.rb
|
113
|
+
- spec/clang/type_spec.rb
|
111
114
|
- spec/fixtures/a.c
|
112
115
|
- spec/fixtures/docs.h
|
113
116
|
- spec/fixtures/list.c
|
@@ -122,17 +125,17 @@ require_paths:
|
|
122
125
|
- lib
|
123
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
127
|
requirements:
|
125
|
-
- -
|
128
|
+
- - '>='
|
126
129
|
- !ruby/object:Gem::Version
|
127
130
|
version: '0'
|
128
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
132
|
requirements:
|
130
|
-
- -
|
133
|
+
- - '>='
|
131
134
|
- !ruby/object:Gem::Version
|
132
135
|
version: '0'
|
133
136
|
requirements: []
|
134
137
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.0.
|
138
|
+
rubygems_version: 2.0.6
|
136
139
|
signing_key:
|
137
140
|
specification_version: 4
|
138
141
|
summary: Ruby FFI bindings for libclang C interface.
|
@@ -143,6 +146,7 @@ test_files:
|
|
143
146
|
- spec/clang/index_spec.rb
|
144
147
|
- spec/clang/source_location_spec.rb
|
145
148
|
- spec/clang/translation_unit_spec.rb
|
149
|
+
- spec/clang/type_spec.rb
|
146
150
|
- spec/fixtures/a.c
|
147
151
|
- spec/fixtures/docs.h
|
148
152
|
- spec/fixtures/list.c
|