gecoder 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.
Files changed (75) hide show
  1. data/COPYING +17 -0
  2. data/LGPL-LICENSE +458 -0
  3. data/README +20 -0
  4. data/Rakefile +6 -0
  5. data/ext/extconf.rb +29 -0
  6. data/ext/missing.cpp +295 -0
  7. data/ext/missing.h +116 -0
  8. data/ext/vararray.cpp +312 -0
  9. data/ext/vararray.h +146 -0
  10. data/lib/gecoder.rb +4 -0
  11. data/lib/gecoder/bindings.rb +7 -0
  12. data/lib/gecoder/bindings/bindings.rb +2055 -0
  13. data/lib/gecoder/interface.rb +6 -0
  14. data/lib/gecoder/interface/binding_changes.rb +111 -0
  15. data/lib/gecoder/interface/branch.rb +102 -0
  16. data/lib/gecoder/interface/constraints.rb +10 -0
  17. data/lib/gecoder/interface/constraints/distinct.rb +15 -0
  18. data/lib/gecoder/interface/constraints/linear.rb +158 -0
  19. data/lib/gecoder/interface/constraints/relation.rb +76 -0
  20. data/lib/gecoder/interface/enum_wrapper.rb +64 -0
  21. data/lib/gecoder/interface/model.rb +130 -0
  22. data/lib/gecoder/interface/search.rb +23 -0
  23. data/vendor/rust/README +28 -0
  24. data/vendor/rust/bin/cxxgenerator.rb +93 -0
  25. data/vendor/rust/include/rust_checks.hh +115 -0
  26. data/vendor/rust/include/rust_conversions.hh +103 -0
  27. data/vendor/rust/rust.rb +67 -0
  28. data/vendor/rust/rust/attribute.rb +51 -0
  29. data/vendor/rust/rust/bindings.rb +172 -0
  30. data/vendor/rust/rust/class.rb +334 -0
  31. data/vendor/rust/rust/constants.rb +48 -0
  32. data/vendor/rust/rust/container.rb +110 -0
  33. data/vendor/rust/rust/cppifaceparser.rb +129 -0
  34. data/vendor/rust/rust/cwrapper.rb +72 -0
  35. data/vendor/rust/rust/cxxclass.rb +98 -0
  36. data/vendor/rust/rust/element.rb +81 -0
  37. data/vendor/rust/rust/enum.rb +63 -0
  38. data/vendor/rust/rust/function.rb +407 -0
  39. data/vendor/rust/rust/namespace.rb +61 -0
  40. data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
  41. data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
  42. data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
  43. data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
  44. data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
  45. data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
  46. data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
  47. data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
  48. data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +91 -0
  49. data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
  50. data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +12 -0
  51. data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
  52. data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
  53. data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
  54. data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
  55. data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
  56. data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
  57. data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
  58. data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
  59. data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +5 -0
  60. data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
  61. data/vendor/rust/rust/type.rb +98 -0
  62. data/vendor/rust/test/Makefile +4 -0
  63. data/vendor/rust/test/constants.rb +35 -0
  64. data/vendor/rust/test/cppclass.cc +40 -0
  65. data/vendor/rust/test/cppclass.hh +63 -0
  66. data/vendor/rust/test/cppclass.rb +59 -0
  67. data/vendor/rust/test/cwrapper.c +74 -0
  68. data/vendor/rust/test/cwrapper.h +41 -0
  69. data/vendor/rust/test/cwrapper.rb +56 -0
  70. data/vendor/rust/test/dummyclass.hh +31 -0
  71. data/vendor/rust/test/lib/extension-test.rb +98 -0
  72. data/vendor/rust/test/test-constants.rb +43 -0
  73. data/vendor/rust/test/test-cppclass.rb +82 -0
  74. data/vendor/rust/test/test-cwrapper.rb +77 -0
  75. metadata +144 -0
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2005-2007 Diego Pettenò <flameeyes@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE
19
+ # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20
+ # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'rust/element'
24
+
25
+ module Rust
26
+ # This class represents a C/C++ constants or enumeration, it is
27
+ # simply going to map a Ruby constant with the given name under its
28
+ # parent with the given value
29
+ class Constant < Element
30
+ def initialize(name, value, parent)
31
+ super()
32
+
33
+ @name = name.upcase
34
+ @value = value
35
+ @parent = parent
36
+
37
+ @declaration_template = ""
38
+ @definition_template = ""
39
+ @initialization_template =
40
+ "rb_define_const(r!parent_varname!, \"!name!\", cxx2ruby(!value!));\n"
41
+
42
+ add_expansion 'parent_varname', '@parent.varname'
43
+ add_expansion 'name', '@name'
44
+ add_expansion 'value', '@value'
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,110 @@
1
+ # Copyright (c) 2007 Diego Pettenò <flameeyes@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE
19
+ # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20
+ # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'rust/element'
24
+ require 'rust/enum'
25
+
26
+ module Rust
27
+ # This class defines a 'container', an element that can contain
28
+ # functions, constants and classes. Both modules and classes are
29
+ # modules, as you can have singleton methods and constants in both
30
+ # of them
31
+ class Container < Element
32
+ def initialize
33
+ super
34
+
35
+ @functions = {}
36
+ end
37
+
38
+ def add_cxx_class(name, parent = nil)
39
+ klass = CxxClass.new(name, self, parent)
40
+
41
+ yield klass
42
+
43
+ @children << klass
44
+ return klass
45
+ end
46
+
47
+ def add_class_wrapper(name, type)
48
+ klass = ClassWrapper.new(name, type, self)
49
+
50
+ yield klass
51
+
52
+ @children << klass
53
+ return klass
54
+ end
55
+
56
+ def add_function(name, return_value = "void", bindname = name)
57
+ function = Function.new({ :name => name,
58
+ :bindname => bindname,
59
+ :return => return_value,
60
+ :parent => self
61
+ })
62
+
63
+ begin
64
+ yield function
65
+ rescue LocalJumpError
66
+ # Ignore this, we can easily have methods without parameters
67
+ # or other extra informations.
68
+ end if block_given?
69
+
70
+ register_function(function)
71
+
72
+ return function
73
+ end
74
+
75
+ def add_constant(name, value = name)
76
+ @children << Constant.new(name, value, self)
77
+ end
78
+
79
+ def add_enum(name, ctype = nil)
80
+ enum = Enum.new(name, self, ctype)
81
+
82
+ yield enum
83
+
84
+ @children << enum
85
+
86
+ return enum
87
+ end
88
+
89
+ def add_namespace(name, cname = name)
90
+ ns = Namespace.new(name, cname, self)
91
+
92
+ yield ns
93
+
94
+ @children << ns
95
+ end
96
+
97
+
98
+ protected
99
+ def register_function(func)
100
+ key = func.name
101
+ if not @functions.has_key? key
102
+ @functions[key] = func
103
+ @children << func
104
+ else
105
+ @functions[key].add_overload(func)
106
+ end
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,129 @@
1
+
2
+
3
+ module Rust
4
+
5
+ module Cpp
6
+
7
+ class IfaceParser
8
+ def initialize
9
+ end
10
+
11
+ def parseFile(path)
12
+ lines = ""
13
+ File.open(path) { |f|
14
+ lines = f.readlines.join
15
+ }
16
+
17
+ parse(lines)
18
+ end
19
+
20
+ def parse(cpph)
21
+ classes = []
22
+
23
+ ignore = true
24
+
25
+ # FIXME: remove \n and split by ";" and "*/"
26
+
27
+ cpph.to_s.split(/$/).each { |line|
28
+ line = line.split("//").first
29
+ if line =~ /\/\*/ # open comment
30
+ ignore = true
31
+ end
32
+
33
+ if line =~ /\*\// # close comment
34
+ ignore = false
35
+ end
36
+
37
+ if line =~ /public:/
38
+ ignore = false
39
+ elsif line =~ /private:|protected:/
40
+ ignore = true
41
+ elsif line =~ /class\s+(\w+\s+){0,1}(\w+)/ # function
42
+ if not classes.last.nil?
43
+ if classes.last[:name] == $2
44
+ next
45
+ end
46
+ end
47
+
48
+ classes << {:name => $2, :methods => [], :constructors => [] }
49
+ elsif line =~ /namespace\s+(\w+)\s+\{{0,1}/
50
+ $stderr << "Warning: Namespace will be ignore.\n"
51
+ end
52
+
53
+ if not ignore and classes.last
54
+ parseEntity(line, classes.last)
55
+ end
56
+ }
57
+
58
+ classes.delete_if { |klass|
59
+ klass[:methods].empty?
60
+ }
61
+
62
+ classes
63
+ end
64
+
65
+ private
66
+ def parseEntity(line, klass)
67
+ if line =~ /((\w+::)*\w+)\s+(const\s+){0,1}(\*{0,3}|&){0,1}\s*(\w+)\s*\((.*)\)/
68
+ type = "#{$1}#{$4}"
69
+ fname = $5
70
+ params = []
71
+
72
+ if not $6.nil?
73
+ $6.strip!
74
+ if not $6.empty?
75
+ params = parseParams($6)
76
+ end
77
+ end
78
+
79
+ klass[:methods] << { :name => fname, :type => type, :params => params }
80
+ elsif line =~ /^\s*#{klass[:name]}\s*\((.*)\)/ #constructor
81
+ params = parseParams($1)
82
+ klass[:constructors] << { :params => params }
83
+ end
84
+ end
85
+
86
+ def parseParams(params)
87
+ result = []
88
+ params.split(",").each { |param|
89
+ param = param.split("=").first
90
+ param.strip!
91
+
92
+ if param =~ /((\w+::)*\w+)\s*(const){0,1}(\*{0,3}|&){0,1}(const\s+){0,1}\s*(\w*)\s*$/
93
+ type = "#{$1}#{$2}#{$4}"
94
+
95
+ name = $6
96
+ if name.empty?
97
+ name = "par#{result.size}"
98
+ end
99
+ result << {:type => type, :name => name}
100
+ end
101
+ }
102
+
103
+ result
104
+ end
105
+ end
106
+
107
+ end # Cpp
108
+
109
+ end # Rust
110
+
111
+ if __FILE__ == $0
112
+ parser = Rust::Cpp::IfaceParser.new
113
+
114
+ classes = parser.parseFile(ARGV[0].to_s)
115
+
116
+ classes.each { |klass|
117
+ puts "Class: #{klass[:name]}"
118
+ klass[:methods].each { |method|
119
+ params = "("
120
+
121
+ method[:params].each { |par|
122
+ params += "#{par[:type]} #{par[:name]}, "
123
+ }
124
+ params += ")"
125
+ puts "Method: #{method[:type]} #{method[:name]} #{params};"
126
+ }
127
+ }
128
+ end
129
+
@@ -0,0 +1,72 @@
1
+ # Copyright (c) 2005-2007 Diego Pettenò <flameeyes@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE
19
+ # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20
+ # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ module Rust
24
+
25
+ # C class wrapper class, this is used to provide support for those
26
+ # wrappers around C libraries that are bound by Rust.
27
+ class ClassWrapper < Class
28
+ attr_reader :cleanup_functions
29
+
30
+ def initialize(name, type, namespace) # :notnew:
31
+ super(name, namespace)
32
+
33
+ @cname = type
34
+ @varcname = @cname.sub("*", "Ptr").gsub("::", "_").gsub(' ', '')
35
+ @cleanup_functions = ""
36
+
37
+ @definition_template = Templates["CWrapperClassDefinitions"]
38
+ @declaration_template << Templates["StandaloneClassDeclarations"]
39
+
40
+ add_expansion 'cleanup_functions', '@cleanup_functions'
41
+ end
42
+
43
+ def add_constructor(name)
44
+ constructor = super()
45
+
46
+ constructor.name = name
47
+
48
+ return constructor
49
+ end
50
+
51
+ def add_cleanup_function(call)
52
+ @cleanup_functions << call << "\n"
53
+ end
54
+
55
+ # This class is used to represente the constructor of a C++ class
56
+ # bound in a Ruby extension.
57
+ class Constructor < Class::Constructor
58
+ attr_writer :name
59
+
60
+ def raw_call(nparam = nil)
61
+ "tmp = #{super(nparam)}"
62
+ end
63
+ end
64
+
65
+ class Method < Class::Method
66
+ def add_instance_parameter
67
+ add_static_parameter 'tmp'
68
+ end
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,98 @@
1
+ # Copyright (c) 2005-2007 Diego Pettenò <flameeyes@gmail.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge,
7
+ # publish, distribute, sublicense, and/or sell copies of the Software,
8
+ # and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ # BE LIABLE
19
+ # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20
+ # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'rust/class'
24
+
25
+ module Rust
26
+ class CxxClass < Class
27
+ # This function initializes the CxxClass instance by setting the
28
+ # values to the attributes defining its parent, namespace, name
29
+ # and a few other needed information.
30
+ #
31
+ # When a C++ Class is bound that is a child of another class, it
32
+ # shares its highest anchestor's pointer map (as that is the
33
+ # more general pointer type it can be referred to with), and
34
+ # function to call when free()'ing.
35
+ #
36
+ # Don't call this function directly, use Namespace.add_cxx_class
37
+ #
38
+ # *FIXME*: multiple inheritance can make Rust bail out, badly.
39
+ def initialize(name, namespace, parent = nil) # :notnew:
40
+ super(name, namespace)
41
+ @parent = parent
42
+
43
+ @children_classes = []
44
+
45
+ @definition_template = Templates["CxxClassDefinitions"]
46
+
47
+ @varname = "#{complete_name.gsub("::", "_")}"
48
+
49
+ if @parent
50
+ @ptrmap = @parent.ptrmap
51
+ @function_free = @parent.function_free
52
+ @parent_varname = "r#{@parent.varname}"
53
+ else
54
+ @declaration_template << Templates["StandaloneClassDeclarations"]
55
+ @definition_template << Templates["CxxStandaloneClassDefinitions"]
56
+ end
57
+
58
+ add_expansion 'test_children'
59
+ end
60
+
61
+ def custom_extends(parent)
62
+ @parent_varname = parent
63
+ end
64
+
65
+ # This function is used during ruby to C/C++ conversion of the
66
+ # types, and test for the deepest class the pointer is valid for.
67
+ def test_children
68
+ return unless @children_classes
69
+
70
+ ret = ""
71
+
72
+ @children_classes.each do |klass|
73
+ ret << %@
74
+ if ( dynamic_cast< #{klass.namespace.cname}::#{klass.name}* >(instance) != NULL )
75
+ {
76
+ klass = c#{klass.varname};
77
+ #{klass.test_children}
78
+ }
79
+ @
80
+ end
81
+
82
+ return ret
83
+ end
84
+
85
+ class Method < Class::Method
86
+ def raw_call(nparam = nil)
87
+ "tmp->#{super(nparam)}"
88
+ end
89
+ end
90
+
91
+ class Constructor < Class::Constructor
92
+ def raw_call(nparam = nil)
93
+ "tmp = new #{@parent.namespace.cname}::#{super(nparam)}"
94
+ end
95
+ end
96
+
97
+ end
98
+ end