rbind 0.0.1
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 +5 -0
- data/lib/rbind/.default_parser.rb.swp +0 -0
- data/lib/rbind/.generator_c.rb.swp +0 -0
- data/lib/rbind/core.rb +13 -0
- data/lib/rbind/core/.rbase.rb.swp +0 -0
- data/lib/rbind/core/.rclass.rb.swp +0 -0
- data/lib/rbind/core/.rdata_type.rb.swp +0 -0
- data/lib/rbind/core/.roperation.rb.swp +0 -0
- data/lib/rbind/core/rattribute.rb +45 -0
- data/lib/rbind/core/rbase.rb +172 -0
- data/lib/rbind/core/rclass.rb +149 -0
- data/lib/rbind/core/rconst.rb +35 -0
- data/lib/rbind/core/rdata_type.rb +93 -0
- data/lib/rbind/core/renum.rb +5 -0
- data/lib/rbind/core/rgetter.rb +19 -0
- data/lib/rbind/core/rnamespace.rb +305 -0
- data/lib/rbind/core/roperation.rb +128 -0
- data/lib/rbind/core/rparameter.rb +40 -0
- data/lib/rbind/core/rsetter.rb +20 -0
- data/lib/rbind/core/rstruct.rb +87 -0
- data/lib/rbind/default_parser.rb +253 -0
- data/lib/rbind/generator_c.rb +352 -0
- data/lib/rbind/generator_ruby.rb +357 -0
- data/lib/rbind/logger.rb +13 -0
- data/lib/rbind/rbind.rb +68 -0
- data/lib/rbind/templates/c/CMakeLists.txt +11 -0
- data/lib/rbind/templates/c/consts.h +5 -0
- data/lib/rbind/templates/c/conversions.cc +4 -0
- data/lib/rbind/templates/c/conversions.hpp +10 -0
- data/lib/rbind/templates/c/find_package.txt +5 -0
- data/lib/rbind/templates/c/operation_wrapper.cc +15 -0
- data/lib/rbind/templates/c/operations.cc +23 -0
- data/lib/rbind/templates/c/operations.h +20 -0
- data/lib/rbind/templates/c/type_conversion.cc +45 -0
- data/lib/rbind/templates/c/type_conversion.hpp +5 -0
- data/lib/rbind/templates/c/type_delete.h +14 -0
- data/lib/rbind/templates/c/type_typedef.h +2 -0
- data/lib/rbind/templates/c/type_wrapper.h +12 -0
- data/lib/rbind/templates/c/types.cc +6 -0
- data/lib/rbind/templates/c/types.h +17 -0
- data/lib/rbind/templates/ruby/rbind.rb +44 -0
- data/lib/rbind/templates/ruby/rmethod.rb +12 -0
- data/lib/rbind/templates/ruby/rnamespace.rb +7 -0
- data/lib/rbind/templates/ruby/rstatic_method.rb +5 -0
- data/lib/rbind/templates/ruby/rtype.rb +77 -0
- data/lib/rbind/templates/ruby/rtype_constructor.rb +4 -0
- data/rbind.gemspec +17 -0
- metadata +101 -0
data/lib/rbind.rb
ADDED
Binary file
|
Binary file
|
data/lib/rbind/core.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rbind/logger.rb'
|
2
|
+
require 'rbind/core/rbase.rb'
|
3
|
+
require 'rbind/core/rdata_type.rb'
|
4
|
+
require 'rbind/core/rconst.rb'
|
5
|
+
require 'rbind/core/renum.rb'
|
6
|
+
require 'rbind/core/rattribute.rb'
|
7
|
+
require 'rbind/core/rparameter.rb'
|
8
|
+
require 'rbind/core/roperation.rb'
|
9
|
+
require 'rbind/core/rgetter.rb'
|
10
|
+
require 'rbind/core/rsetter.rb'
|
11
|
+
require 'rbind/core/rnamespace.rb'
|
12
|
+
require 'rbind/core/rstruct.rb'
|
13
|
+
require 'rbind/core/rclass.rb'
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Rbind
|
2
|
+
class RAttribute < RBase
|
3
|
+
attr_accessor :type
|
4
|
+
|
5
|
+
def initialize(name,type,*flags)
|
6
|
+
super(name,*flags)
|
7
|
+
raise ArgumentError,"no type" unless type
|
8
|
+
raise "wrong name #{name}" if name =~/.*\*.*/
|
9
|
+
@type = type
|
10
|
+
end
|
11
|
+
|
12
|
+
def ==(other)
|
13
|
+
type == other.type
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_signatures
|
17
|
+
s = "#{type.signature}#{" " if !type.ptr? && !type.ref?}#{name}"
|
18
|
+
cs= "#{type.csignature}#{" " if !type.ptr? && !type.ref?}#{name}"
|
19
|
+
|
20
|
+
if read_only? && !type.basic_type?
|
21
|
+
s = "const #{s}"
|
22
|
+
cs = "const #{cs}"
|
23
|
+
end
|
24
|
+
[s,cs]
|
25
|
+
end
|
26
|
+
|
27
|
+
def valid_flags
|
28
|
+
super << :RW
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_ptr
|
32
|
+
a = self.dup
|
33
|
+
a.type = type.to_ptr
|
34
|
+
a
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_only?
|
38
|
+
!write?
|
39
|
+
end
|
40
|
+
|
41
|
+
def write?
|
42
|
+
flags.include?(:RW) || flags.include?(:IO) || flags.include?(:O)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
module Rbind
|
2
|
+
class RBase
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :cname
|
5
|
+
attr_accessor :alias
|
6
|
+
attr_accessor :namespace
|
7
|
+
attr_accessor :owner
|
8
|
+
attr_accessor :flags
|
9
|
+
attr_accessor :version
|
10
|
+
attr_accessor :signature
|
11
|
+
attr_accessor :csignature
|
12
|
+
|
13
|
+
class << self
|
14
|
+
attr_accessor :cprefix
|
15
|
+
|
16
|
+
def to_cname(name)
|
17
|
+
name = normalize(name)
|
18
|
+
cn = "#{cprefix}#{name.gsub("::","_")}"
|
19
|
+
cn = cn.gsub("()","_fct")
|
20
|
+
cn = cn.gsub("!=","_unequal")
|
21
|
+
cn = cn.gsub("==","_equal")
|
22
|
+
cn = cn.gsub("&=","_and_set")
|
23
|
+
cn = cn.gsub("+=","_add")
|
24
|
+
cn = cn.gsub("-=","_sub")
|
25
|
+
cn = cn.gsub("+","_plus")
|
26
|
+
cn = cn.gsub("-","_minus")
|
27
|
+
cn = cn.gsub("*","_mult")
|
28
|
+
cn = cn.gsub("/","_div")
|
29
|
+
cn = cn.gsub("!","_not")
|
30
|
+
cn = cn.gsub("&","_and")
|
31
|
+
cn.gsub("[]","_array")
|
32
|
+
end
|
33
|
+
|
34
|
+
def normalize(name)
|
35
|
+
name = name.to_s
|
36
|
+
if name.split("/n").size > 1
|
37
|
+
raise "mulitple lines for a name is not supported: #{name}"
|
38
|
+
end
|
39
|
+
name.gsub(".","::").gsub(" ","")
|
40
|
+
end
|
41
|
+
|
42
|
+
def basename(name)
|
43
|
+
name = normalize(name)
|
44
|
+
if !!(name =~/.*::(.*)$/)
|
45
|
+
$1
|
46
|
+
else
|
47
|
+
name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def namespace(name)
|
52
|
+
name = normalize(name)
|
53
|
+
if !!(name =~/(.*)::.*$/)
|
54
|
+
$1
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
self.cprefix = "rbind_"
|
61
|
+
|
62
|
+
def pretty_print(pp)
|
63
|
+
pp.text "#{signature}#{" Flags: #{flags.join(", ")}" unless flags.empty?}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def initialize(name,*flags)
|
67
|
+
name = RBase::normalize(name)
|
68
|
+
raise ArgumentError, "no name" unless name && name.size > 0
|
69
|
+
@name = RBase::basename(name)
|
70
|
+
@namespace = RBase::namespace(name)
|
71
|
+
@version = 1
|
72
|
+
self.flags = flags.flatten
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_signatures
|
76
|
+
["#{full_name}","#{cname}"]
|
77
|
+
end
|
78
|
+
|
79
|
+
def signature(sig=nil)
|
80
|
+
return @signature || generate_signatures[0] unless sig
|
81
|
+
@signature = sig
|
82
|
+
end
|
83
|
+
|
84
|
+
def csignature(sig=nil)
|
85
|
+
return @csignature || generate_signatures[1] unless sig
|
86
|
+
@csignature = sig
|
87
|
+
end
|
88
|
+
|
89
|
+
def alias(val=nil)
|
90
|
+
return @alias if !val || val.empty?
|
91
|
+
@alias = val
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def alias=(val)
|
96
|
+
self.alias(val)
|
97
|
+
val
|
98
|
+
end
|
99
|
+
|
100
|
+
def cname(name=nil)
|
101
|
+
if name
|
102
|
+
@cname = name
|
103
|
+
self
|
104
|
+
else
|
105
|
+
if @cname
|
106
|
+
@cname
|
107
|
+
elsif @alias
|
108
|
+
RBase::to_cname(map_to_namespace(@alias))
|
109
|
+
else
|
110
|
+
RBase::to_cname(full_name)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def flags=(*flags)
|
116
|
+
flags.flatten!
|
117
|
+
validate_flags(flags)
|
118
|
+
@flags = flags
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_flag(*flags)
|
122
|
+
@flags += flags
|
123
|
+
self
|
124
|
+
end
|
125
|
+
|
126
|
+
def valid_flags
|
127
|
+
[]
|
128
|
+
end
|
129
|
+
|
130
|
+
def validate_flags(flags,valid_flags = self.valid_flags)
|
131
|
+
valid_flags.flatten!
|
132
|
+
flags.each do |flag|
|
133
|
+
if !valid_flags.include?(flag)
|
134
|
+
raise "flag #{flag} is not supported for #{self.class.name}. Supported flags are #{valid_flags}"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def owner=(obj)
|
140
|
+
if obj.respond_to?(:root?) && !obj.root?
|
141
|
+
@namespace = obj.full_name
|
142
|
+
else
|
143
|
+
@namespace = nil
|
144
|
+
end
|
145
|
+
@owner = obj
|
146
|
+
end
|
147
|
+
|
148
|
+
def ignore?
|
149
|
+
!!@ignore
|
150
|
+
end
|
151
|
+
|
152
|
+
def namespace?
|
153
|
+
namespace && namespace.size != 0
|
154
|
+
end
|
155
|
+
|
156
|
+
def full_name
|
157
|
+
map_to_namespace(name)
|
158
|
+
end
|
159
|
+
|
160
|
+
def map_to_namespace(name)
|
161
|
+
if namespace
|
162
|
+
"#{namespace}::#{name}"
|
163
|
+
else
|
164
|
+
name
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def binding
|
169
|
+
Kernel.binding
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
|
2
|
+
module Rbind
|
3
|
+
class RClass < RStruct
|
4
|
+
attr_accessor :parent_classes
|
5
|
+
|
6
|
+
def initialize(name,*parent_classes)
|
7
|
+
@parent_classes = Hash.new
|
8
|
+
parent_classes.flatten!
|
9
|
+
parent_classes.each do |p|
|
10
|
+
add_parent(p)
|
11
|
+
end
|
12
|
+
super(name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def attributes
|
16
|
+
attribs = @attributes.values
|
17
|
+
parent_classes.each do |k|
|
18
|
+
others = k.attributes
|
19
|
+
others.delete_if do |other|
|
20
|
+
attribs.inclue? other
|
21
|
+
end
|
22
|
+
others = others.map(&:dup)
|
23
|
+
others.each do |other|
|
24
|
+
other.owner = self
|
25
|
+
end
|
26
|
+
attribs += others
|
27
|
+
end
|
28
|
+
attribs
|
29
|
+
end
|
30
|
+
|
31
|
+
def attribute(name)
|
32
|
+
attrib = @attributes[name]
|
33
|
+
attrib ||= begin
|
34
|
+
p = parent_classes.find do |k|
|
35
|
+
k.attribute(name)
|
36
|
+
end
|
37
|
+
a = p.attribute(name).dup if p
|
38
|
+
a.owner = self if a
|
39
|
+
a
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def operations
|
44
|
+
# temporarily add all base class operations
|
45
|
+
own_ops = @operations.dup
|
46
|
+
parent_classes.each do |k|
|
47
|
+
k.operations.each do |other_ops|
|
48
|
+
next if other_ops.empty?
|
49
|
+
ops = if @operations.has_key?(other_ops.first.name)
|
50
|
+
@operations[other_ops.first.name]
|
51
|
+
else
|
52
|
+
[]
|
53
|
+
end
|
54
|
+
other_ops.delete_if do |other_op|
|
55
|
+
next true if !other_op
|
56
|
+
op = ops.find do |o|
|
57
|
+
o == other_op
|
58
|
+
end
|
59
|
+
next false if !op
|
60
|
+
next true if op.base_class == self
|
61
|
+
next true if op.base_class == other_op.base_class
|
62
|
+
# ambiguous name look up due to multi
|
63
|
+
# inheritance
|
64
|
+
op.ambiguous_name = true
|
65
|
+
other_op.ambiguous_name = true
|
66
|
+
false
|
67
|
+
end
|
68
|
+
other_ops = other_ops.map(&:dup)
|
69
|
+
other_ops.each do |other|
|
70
|
+
old = other.alias
|
71
|
+
add_operation other
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
# copy embedded arrays other wise they might get modified outside
|
76
|
+
result = @operations.values.map(&:dup)
|
77
|
+
@operations = own_ops
|
78
|
+
result
|
79
|
+
end
|
80
|
+
|
81
|
+
def used_namespaces
|
82
|
+
namespaces = super.clone
|
83
|
+
parent_classes.each do |k|
|
84
|
+
namespaces.merge k.used_namespaces
|
85
|
+
end
|
86
|
+
namespaces
|
87
|
+
end
|
88
|
+
|
89
|
+
def operation(name,raise_=true)
|
90
|
+
ops = if @operations.has_key? name
|
91
|
+
@operations[name].dup
|
92
|
+
else
|
93
|
+
[]
|
94
|
+
end
|
95
|
+
parent_classes.each do |k|
|
96
|
+
other_ops = Array(k.operation(name,false))
|
97
|
+
other_ops.delete_if do |other_op|
|
98
|
+
ops.include? other_op
|
99
|
+
end
|
100
|
+
ops += other_ops
|
101
|
+
end
|
102
|
+
if(ops.size == 1)
|
103
|
+
ops.first
|
104
|
+
elsif ops.empty?
|
105
|
+
raise "#{full_name} has no operation called #{name}." if raise_
|
106
|
+
else
|
107
|
+
ops
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def parent_classes
|
112
|
+
@parent_classes.values
|
113
|
+
end
|
114
|
+
|
115
|
+
def parent_class(name)
|
116
|
+
@parent_classes[name]
|
117
|
+
end
|
118
|
+
|
119
|
+
def pretty_print_name
|
120
|
+
str = "class #{full_name}"
|
121
|
+
unless parent_classes.empty?
|
122
|
+
parents = parent_classes.map do |p|
|
123
|
+
p.full_name
|
124
|
+
end
|
125
|
+
str += " : " + parents.join(", ")
|
126
|
+
end
|
127
|
+
str
|
128
|
+
end
|
129
|
+
|
130
|
+
def pretty_print(pp)
|
131
|
+
super
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_parent(klass)
|
135
|
+
if @parent_classes.has_key? klass.name
|
136
|
+
raise ArgumentError,"#A parent class with the name #{klass.name} already exists"
|
137
|
+
end
|
138
|
+
# we have to disable the type check for the parent class
|
139
|
+
# otherwise derived types cannot be parsed
|
140
|
+
klass.check_type = false
|
141
|
+
@parent_classes[klass.name] = klass
|
142
|
+
self
|
143
|
+
end
|
144
|
+
|
145
|
+
def parent_class(name)
|
146
|
+
@parent_class[name]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
module Rbind
|
3
|
+
class RDataType < RBase
|
4
|
+
attr_accessor :ptr,:ref
|
5
|
+
attr_accessor :typedef
|
6
|
+
attr_accessor :invalid_value
|
7
|
+
attr_accessor :cdelete_method;
|
8
|
+
attr_accessor :check_type;
|
9
|
+
|
10
|
+
def initialize(name,*flags)
|
11
|
+
super
|
12
|
+
@invalid_value = 0
|
13
|
+
@type_check = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
other.name == name && other.ptr == ptr
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_signatures
|
21
|
+
if ref?
|
22
|
+
["#{full_name} &","#{cname} &"]
|
23
|
+
elsif ptr?
|
24
|
+
["#{full_name} *","#{cname} *"]
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_type?
|
31
|
+
@check_type
|
32
|
+
end
|
33
|
+
|
34
|
+
def cname(value=nil)
|
35
|
+
if !value
|
36
|
+
if basic_type? && !@cname
|
37
|
+
name
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
else
|
42
|
+
super
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def typedef(value=nil)
|
48
|
+
return @typedef unless value
|
49
|
+
@typedef = value
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def typedef?
|
54
|
+
!!@typedef
|
55
|
+
end
|
56
|
+
|
57
|
+
def basic_type?
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
def container?
|
62
|
+
false
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_value
|
66
|
+
owner.type(name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_ptr
|
70
|
+
return self if ptr? && !ref?
|
71
|
+
t = self.dup
|
72
|
+
t.ref = false
|
73
|
+
t.ptr = true
|
74
|
+
t
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete!
|
78
|
+
if @owner
|
79
|
+
@owner.delete_type self.name
|
80
|
+
else
|
81
|
+
raise "#{self} has no owner."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def ptr?
|
86
|
+
!!ptr
|
87
|
+
end
|
88
|
+
|
89
|
+
def ref?
|
90
|
+
!!ref
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|