rbind 0.0.16 → 0.0.17
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.
- data/lib/rbind.rb +1 -0
- data/lib/rbind/clang/clang.rb +3699 -0
- data/lib/rbind/clang/clang_types.rb +327 -0
- data/lib/rbind/clang_parser.rb +451 -0
- data/lib/rbind/core.rb +7 -4
- data/lib/rbind/core/rattribute.rb +17 -21
- data/lib/rbind/core/rbase.rb +98 -64
- data/lib/rbind/core/rcallback.rb +15 -0
- data/lib/rbind/core/rclass.rb +79 -16
- data/lib/rbind/core/rdata_type.rb +40 -39
- data/lib/rbind/core/renum.rb +18 -0
- data/lib/rbind/core/rnamespace.rb +189 -52
- data/lib/rbind/core/roperation.rb +52 -20
- data/lib/rbind/core/rparameter.rb +43 -8
- data/lib/rbind/core/rpointer.rb +70 -0
- data/lib/rbind/core/rreference.rb +54 -0
- data/lib/rbind/core/rtemplate_class.rb +49 -0
- data/lib/rbind/core/rtype_qualifier.rb +60 -0
- data/lib/rbind/default_parser.rb +48 -36
- data/lib/rbind/generator_c.rb +2 -2
- data/lib/rbind/generator_extern.rb +1 -3
- data/lib/rbind/generator_ruby.rb +201 -47
- data/lib/rbind/logger.rb +3 -0
- data/lib/rbind/rbind.rb +25 -9
- data/lib/rbind/templates/c/CMakeLists.txt +6 -6
- data/lib/rbind/templates/ruby/rbind.rb +1 -1
- data/lib/rbind/templates/ruby/rmethod.rb +4 -1
- data/lib/rbind/templates/ruby/rnamespace.rb +2 -1
- data/lib/rbind/templates/ruby/roverloaded_method.rb +3 -1
- data/lib/rbind/templates/ruby/roverloaded_method_call.rb +1 -0
- data/lib/rbind/templates/ruby/roverloaded_static_method.rb +3 -2
- data/lib/rbind/templates/ruby/rstatic_method.rb +4 -1
- data/lib/rbind/templates/ruby/rtype.rb +19 -16
- data/lib/rbind/templates/ruby/rtype_template.rb +7 -0
- data/lib/rbind/{core/rstring.rb → types/std_string.rb} +8 -8
- data/lib/rbind/types/std_vector.rb +100 -0
- data/rbind.gemspec +2 -2
- data/test/headers/cfunctions.h +7 -0
- data/test/headers/classes.hpp +29 -0
- data/test/headers/constants.hpp +14 -0
- data/test/headers/enums.hpp +22 -0
- data/test/headers/std_string.hpp +26 -0
- data/test/headers/std_vector.hpp +31 -0
- data/test/headers/structs.hpp +34 -0
- data/test/headers/templates.hpp +20 -0
- data/test/test_clang_parser.rb +146 -0
- data/test/test_generator_ruby.rb +0 -5
- data/test/test_roperation.rb +144 -0
- data/test/test_rparameter.rb +88 -0
- metadata +24 -7
- data/lib/rbind/core/.roperation.rb.swp +0 -0
- data/lib/rbind/core/rconst.rb +0 -35
- data/lib/rbind/core/rstruct.rb +0 -87
- data/lib/rbind/core/rvector.rb +0 -27
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'rbind'
|
3
|
+
|
4
|
+
MiniTest::Unit.autorun
|
5
|
+
describe Rbind::RParameter do
|
6
|
+
before do
|
7
|
+
@root = Rbind::RNamespace.new
|
8
|
+
@root.add_default_types
|
9
|
+
@root.add_type Rbind::StdVector.new("std::vector")
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "signature" do
|
16
|
+
it "must generate a correct signature for simple types" do
|
17
|
+
parameter = Rbind::RParameter.new("para",@root.int)
|
18
|
+
assert_equal "int para", parameter.to_s
|
19
|
+
|
20
|
+
parameter = Rbind::RParameter.new("para",@root.int)
|
21
|
+
parameter.default_value = "123"
|
22
|
+
assert_equal "int para = 123", parameter.to_s
|
23
|
+
|
24
|
+
parameter = Rbind::RParameter.new("para",@root.int.to_ref)
|
25
|
+
assert_equal "int& para", parameter.to_s
|
26
|
+
|
27
|
+
parameter = Rbind::RParameter.new("para",@root.int.to_ref.to_const)
|
28
|
+
assert_equal "const int& para", parameter.to_s
|
29
|
+
|
30
|
+
parameter = Rbind::RParameter.new("para",@root.int.to_ptr)
|
31
|
+
parameter.default_value = "NULL"
|
32
|
+
assert_equal "int* para = NULL", parameter.to_s
|
33
|
+
|
34
|
+
parameter = Rbind::RParameter.new("para",@root.int.to_ptr.to_ptr)
|
35
|
+
parameter.default_value = "NULL"
|
36
|
+
assert_equal "int** para = NULL", parameter.to_s
|
37
|
+
|
38
|
+
parameter = Rbind::RParameter.new("para",@root.int.to_ptr.to_ptr.to_const)
|
39
|
+
parameter.default_value = "NULL"
|
40
|
+
assert_equal "const int** para = NULL", parameter.to_s
|
41
|
+
|
42
|
+
parameter = Rbind::RParameter.new("para",@root.int.to_const.to_ptr.to_ptr)
|
43
|
+
parameter.default_value = "NULL"
|
44
|
+
assert_equal "const int** para = NULL", parameter.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
it "must generate a correct signature for template types" do
|
48
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>"))
|
49
|
+
assert_equal "std::vector<int> para", parameter.to_s
|
50
|
+
|
51
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>").to_ref)
|
52
|
+
assert_equal "std::vector<int>& para", parameter.to_s
|
53
|
+
|
54
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>").to_ref.to_const)
|
55
|
+
assert_equal "const std::vector<int>& para", parameter.to_s
|
56
|
+
|
57
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>").to_ptr)
|
58
|
+
assert_equal "std::vector<int>* para", parameter.to_s
|
59
|
+
|
60
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<const unsigned int*>").to_ptr.to_const)
|
61
|
+
assert_equal "const std::vector<uint*>* para", parameter.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "csignature" do
|
66
|
+
it "must generate a correct signature for simple types" do
|
67
|
+
parameter = Rbind::RParameter.new("para",@root.int)
|
68
|
+
assert_equal "int para", parameter.csignature
|
69
|
+
end
|
70
|
+
|
71
|
+
it "must generate a correct csignature for template types" do
|
72
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>"))
|
73
|
+
assert_equal "rbind_std_vector_int para", parameter.csignature
|
74
|
+
|
75
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>").to_ref)
|
76
|
+
assert_equal "rbind_std_vector_int& para", parameter.csignature
|
77
|
+
|
78
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>").to_ref.to_const)
|
79
|
+
assert_equal "const rbind_std_vector_int& para", parameter.csignature
|
80
|
+
|
81
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<int>").to_ptr)
|
82
|
+
assert_equal "rbind_std_vector_int* para", parameter.csignature
|
83
|
+
|
84
|
+
parameter = Rbind::RParameter.new("para",@root.type("std::vector<const unsigned int*>").to_ptr.to_const)
|
85
|
+
assert_equal "const rbind_std_vector_uint_ptr* para", parameter.csignature
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rbind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.17
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alexander Duda
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
version: 0.3.1
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
|
-
description: Rbind is developed to automatically generate ruby bindings for OpenCV but is not tight to this library. It allows to import already wrapped types from other gems/libraries using rbind to share the same types across multiple gems/libraries. For now rbind uses a copy of the OpenCV python hdr_parser to parse c/c++ header files
|
26
|
+
description: Rbind is developed to automatically generate ruby bindings for OpenCV but is not tight to this library. It allows to import already wrapped types from other gems/libraries using rbind to share the same types across multiple gems/libraries. For now rbind uses a copy of the OpenCV python hdr_parser to parse c/c++ header files.This gem is still under heavy development and the API might change in the future.
|
27
27
|
email:
|
28
28
|
- Alexander.Duda@dfki.de
|
29
29
|
executables: []
|
@@ -35,22 +35,25 @@ extra_rdoc_files: []
|
|
35
35
|
files:
|
36
36
|
- README.md
|
37
37
|
- lib/rbind.rb
|
38
|
+
- lib/rbind/clang/clang.rb
|
39
|
+
- lib/rbind/clang/clang_types.rb
|
40
|
+
- lib/rbind/clang_parser.rb
|
38
41
|
- lib/rbind/core.rb
|
39
|
-
- lib/rbind/core/.roperation.rb.swp
|
40
42
|
- lib/rbind/core/rattribute.rb
|
41
43
|
- lib/rbind/core/rbase.rb
|
44
|
+
- lib/rbind/core/rcallback.rb
|
42
45
|
- lib/rbind/core/rclass.rb
|
43
|
-
- lib/rbind/core/rconst.rb
|
44
46
|
- lib/rbind/core/rdata_type.rb
|
45
47
|
- lib/rbind/core/renum.rb
|
46
48
|
- lib/rbind/core/rgetter.rb
|
47
49
|
- lib/rbind/core/rnamespace.rb
|
48
50
|
- lib/rbind/core/roperation.rb
|
49
51
|
- lib/rbind/core/rparameter.rb
|
52
|
+
- lib/rbind/core/rpointer.rb
|
53
|
+
- lib/rbind/core/rreference.rb
|
50
54
|
- lib/rbind/core/rsetter.rb
|
51
|
-
- lib/rbind/core/
|
52
|
-
- lib/rbind/core/
|
53
|
-
- lib/rbind/core/rvector.rb
|
55
|
+
- lib/rbind/core/rtemplate_class.rb
|
56
|
+
- lib/rbind/core/rtype_qualifier.rb
|
54
57
|
- lib/rbind/default_parser.rb
|
55
58
|
- lib/rbind/generator_c.rb
|
56
59
|
- lib/rbind/generator_extern.rb
|
@@ -85,10 +88,24 @@ files:
|
|
85
88
|
- lib/rbind/templates/ruby/rstatic_method.rb
|
86
89
|
- lib/rbind/templates/ruby/rtype.rb
|
87
90
|
- lib/rbind/templates/ruby/rtype_constructor.rb
|
91
|
+
- lib/rbind/templates/ruby/rtype_template.rb
|
88
92
|
- lib/rbind/tools/hdr_parser.py
|
89
93
|
- lib/rbind/typelib.rb
|
94
|
+
- lib/rbind/types/std_string.rb
|
95
|
+
- lib/rbind/types/std_vector.rb
|
90
96
|
- rbind.gemspec
|
97
|
+
- test/headers/cfunctions.h
|
98
|
+
- test/headers/classes.hpp
|
99
|
+
- test/headers/constants.hpp
|
100
|
+
- test/headers/enums.hpp
|
101
|
+
- test/headers/std_string.hpp
|
102
|
+
- test/headers/std_vector.hpp
|
103
|
+
- test/headers/structs.hpp
|
104
|
+
- test/headers/templates.hpp
|
105
|
+
- test/test_clang_parser.rb
|
91
106
|
- test/test_generator_ruby.rb
|
107
|
+
- test/test_roperation.rb
|
108
|
+
- test/test_rparameter.rb
|
92
109
|
homepage: http://github.com/D-Alex/rbind
|
93
110
|
licenses: []
|
94
111
|
|
Binary file
|
data/lib/rbind/core/rconst.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
|
2
|
-
module Rbind
|
3
|
-
class RConst < RDataType
|
4
|
-
attr_accessor :value
|
5
|
-
|
6
|
-
def initialize(name,value,*flags)
|
7
|
-
super(name,*flags)
|
8
|
-
@value = value
|
9
|
-
end
|
10
|
-
|
11
|
-
def generate_signatures
|
12
|
-
["#{full_name} = #{value}","const int #{cname} = #{map_value_to_namespace(value)}"]
|
13
|
-
end
|
14
|
-
|
15
|
-
def map_value_to_namespace(value)
|
16
|
-
a = value.split(" ")
|
17
|
-
a = a.map do |str|
|
18
|
-
if str =~/^[a-zA-Z]/
|
19
|
-
RBase.to_cname("#{namespace}::#{str}")
|
20
|
-
else
|
21
|
-
str
|
22
|
-
end
|
23
|
-
end
|
24
|
-
a.join(" ")
|
25
|
-
end
|
26
|
-
|
27
|
-
def basic_type?
|
28
|
-
false
|
29
|
-
end
|
30
|
-
|
31
|
-
def pretty_print(pp)
|
32
|
-
pp.text "#{signature}#{" Flags: #{flags.join(", ")}" unless flags.empty?}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/rbind/core/rstruct.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
|
2
|
-
module Rbind
|
3
|
-
class RStruct < RNamespace
|
4
|
-
attr_reader :attributes
|
5
|
-
|
6
|
-
def initialize(name,*flags)
|
7
|
-
@attributes = Hash.new
|
8
|
-
super(name,*flags)
|
9
|
-
end
|
10
|
-
|
11
|
-
def basic_type?
|
12
|
-
false
|
13
|
-
end
|
14
|
-
|
15
|
-
def valid_flags
|
16
|
-
super << :Simple << :Map
|
17
|
-
end
|
18
|
-
|
19
|
-
def constructor?
|
20
|
-
ops = Array(operation(name,false))
|
21
|
-
return false unless ops
|
22
|
-
op = ops.find do |op|
|
23
|
-
op.constructor?
|
24
|
-
end
|
25
|
-
!!op
|
26
|
-
end
|
27
|
-
|
28
|
-
def attributes
|
29
|
-
@attributes.values
|
30
|
-
end
|
31
|
-
|
32
|
-
def attribute(name)
|
33
|
-
@attributes[name]
|
34
|
-
end
|
35
|
-
|
36
|
-
def cdelete_method
|
37
|
-
if @cdelete_method
|
38
|
-
@cdelete_method
|
39
|
-
else
|
40
|
-
if cname =~ /^#{RBase.cprefix}(.*)/
|
41
|
-
"#{RBase.cprefix}delete_#{$1}"
|
42
|
-
else
|
43
|
-
"#{RBase.cprefix}delete_#{name}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def add_attribute(attr)
|
49
|
-
if attr.namespace?
|
50
|
-
type(attr.namespace).add_attribute(attr)
|
51
|
-
else
|
52
|
-
if @attributes.has_key? attr.name
|
53
|
-
raise "#An attribute with the name #{attr.name} already exists"
|
54
|
-
end
|
55
|
-
attr.owner = self
|
56
|
-
@attributes[attr.name] = attr
|
57
|
-
# add getter and setter methods to the object
|
58
|
-
add_operation(RGetter.new(attr))
|
59
|
-
add_operation(RSetter.new(attr)) if attr.write?
|
60
|
-
end
|
61
|
-
self
|
62
|
-
end
|
63
|
-
|
64
|
-
def pretty_print_name
|
65
|
-
"struct #{full_name}#{" Flags: #{flags.join(", ")}" unless flags.empty?}"
|
66
|
-
end
|
67
|
-
|
68
|
-
def pretty_print(pp)
|
69
|
-
super
|
70
|
-
unless attributes.empty?
|
71
|
-
pp.nest(2) do
|
72
|
-
pp.breakable
|
73
|
-
pp.text "Attributes:"
|
74
|
-
pp.nest(2) do
|
75
|
-
attributes.each do |a|
|
76
|
-
pp.breakable
|
77
|
-
pp.pp(a)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
|
data/lib/rbind/core/rvector.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Rbind
|
2
|
-
class RVector < RStruct
|
3
|
-
def initialize(name,root,type)
|
4
|
-
@vector_type = type
|
5
|
-
super(name)
|
6
|
-
add_operation ROperation.new(self.name,nil)
|
7
|
-
add_operation ROperation.new(self.name,nil,RParameter.new("other",self))
|
8
|
-
|
9
|
-
para = Array.new
|
10
|
-
para << RParameter.new("size",root.type("size_t"))
|
11
|
-
para << RParameter.new("val",type).default_value(type.full_name)
|
12
|
-
add_operation ROperation.new("resize",root.type("void"),para)
|
13
|
-
add_operation ROperation.new("size",root.type("size_t"))
|
14
|
-
add_operation ROperation.new("capacity",root.type("size_t"))
|
15
|
-
add_operation ROperation.new("empty",root.type("bool"))
|
16
|
-
add_operation ROperation.new("reserve",root.type("void"),RParameter.new("size",root.type("size_t")))
|
17
|
-
add_operation ROperation.new("operator[]",type,RParameter.new("size",root.type("size_t")))
|
18
|
-
add_operation ROperation.new("at",type,RParameter.new("size",root.type("size_t")))
|
19
|
-
add_operation ROperation.new("front",type)
|
20
|
-
add_operation ROperation.new("back",type)
|
21
|
-
add_operation ROperation.new("data",root.type("void *"))
|
22
|
-
add_operation ROperation.new("push_back",root.type("void"),RParameter.new("other",type))
|
23
|
-
add_operation ROperation.new("pop_back",root.type("void"))
|
24
|
-
add_operation ROperation.new("swap",root.type("void"),RParameter.new("other",self).add_flag(:IO))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|