gecoder 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,61 @@
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/container"
24
+ require "rust/cxxclass"
25
+ require "rust/cwrapper"
26
+ require "rust/constants"
27
+
28
+ module Rust
29
+
30
+ class Namespace < Container
31
+ attr_reader :name, :cname, :varname
32
+
33
+ def initialize(name, cname, parent = nil)
34
+ super()
35
+
36
+ @name = name
37
+
38
+ if parent.kind_of?(Namespace)
39
+ cname = "#{parent.cname}::#{cname}"
40
+ end
41
+
42
+ @parent = parent
43
+ @cname = cname == "" ? nil : cname
44
+ @varname = "#{@name.gsub("::", "_")}"
45
+
46
+ @declaration_template = Templates["ModuleDeclarations"]
47
+ @definition_template = Templates["ModuleDefinitions"]
48
+ unless parent.kind_of?(Namespace)
49
+ @initialization_template = "r!namespace_varname! = rb_define_module(\"!module_name!\");\n"
50
+ else
51
+ # TODO this should use the expansion
52
+ @initialization_template = "r!namespace_varname! = rb_define_module_under(r#{parent.varname}, \"#{@name}\");\n"
53
+ end
54
+
55
+ add_expansion 'module_name', 'name'
56
+ add_expansion 'namespace_varname', 'varname'
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,17 @@
1
+ //-*-c++-*-
2
+ // Template of a generic C function call
3
+
4
+ VALUE set!parent_varname!!attribute_bindname!(VALUE self, VALUE val) {
5
+ !c_class_name!* tmp = ruby2!class_varcname!Ptr(self);
6
+ if ( ! tmp ) return Qnil;
7
+
8
+ tmp->!attribute_name! = ruby2!attribute_type!(val);
9
+ return Qnil;
10
+ }
11
+
12
+ VALUE get!parent_varname!!attribute_bindname!(VALUE self) {
13
+ !c_class_name!* tmp = ruby2!class_varcname!Ptr(self);
14
+ if ( ! tmp ) return Qnil;
15
+
16
+ return cxx2ruby(static_cast<!attribute_type!>(tmp->!attribute_name!));
17
+ }
@@ -0,0 +1,9 @@
1
+ //-*-c++-*-
2
+ // Template for the init function snippet registering a method.
3
+ // Note that in the case of a method, !parent_varname! would be a
4
+ // synonim for !class_varname!.
5
+
6
+ // Set
7
+ rb_define_method(r!parent_varname!, "!attribute_bindname!=", RUBY_METHOD_FUNC(set!parent_varname!!attribute_bindname!), 1);
8
+ // Get
9
+ rb_define_method(r!parent_varname!, "!attribute_bindname!", RUBY_METHOD_FUNC(get!parent_varname!!attribute_bindname!), 0);
@@ -0,0 +1,24 @@
1
+ //-*-c++-*-
2
+ // General template for the header file (.hh) of the bindings.
3
+ // This is the base that's recursively expanded to create the actual
4
+ // header file.
5
+ //
6
+ // Please note that the ruby header and the C header files coming
7
+ // from the bound library are included with C linkage rules, while
8
+ // the rest of the header follows C++ linkage rules.
9
+
10
+ extern "C" {
11
+ #include <ruby.h>
12
+ !c_includes!
13
+ }
14
+
15
+ !cxx_includes!
16
+
17
+ /* This is for the ptrMap */
18
+ #include <map>
19
+
20
+ namespace Rust_!bindings_name! {
21
+
22
+ !modules_declaration!
23
+
24
+ }
@@ -0,0 +1,46 @@
1
+ //-*-c++-*-
2
+ // General template for the unit file (.cc) of the bindings.
3
+ // This is the base that's recursively expanded to create the actual
4
+ // header file.
5
+ //
6
+ // Please note that the visibility is set to the Init function only
7
+ // if the build processo found it, so that all the other functions
8
+ // and types are actually considered hidden, and thus not exported by
9
+ // the extension. Unfortunately GCC's libstdc++ does not correctly
10
+ // hide all of its symbols yet.
11
+
12
+ // This is needed here because I need to put the rust_conversions.hh
13
+ // include inside these bindings' namespace.
14
+ #include <string>
15
+
16
+ #include "!bindings_name!.hh"
17
+
18
+ #ifdef DEBUG
19
+ #include <stdio.h> /* Used for fprintf */
20
+ #endif
21
+
22
+ namespace Rust_!bindings_name! {
23
+
24
+ #include <rust_conversions.hh>
25
+ #include <rust_checks.hh>
26
+
27
+ !custom_definition!
28
+
29
+ !modules_definition!
30
+
31
+ }
32
+
33
+ using namespace Rust_!bindings_name!;
34
+
35
+ extern "C" {
36
+
37
+ #ifdef HAVE_VISIBILITY
38
+ void Init_!bindings_name!() __attribute__((visibility("default")));
39
+ #endif
40
+
41
+ void Init_!bindings_name!() {
42
+ !modules_initialization!
43
+ !custom_initialization!
44
+ } /* Init_!bindings_name! */
45
+
46
+ }
@@ -0,0 +1,64 @@
1
+ //-*-c++-*-
2
+
3
+ VALUE r!class_varname!;
4
+ T!class_ptrmap! !class_ptrmap!;
5
+
6
+ !c_class_name!* ruby2!class_varcname!Ptr(VALUE rval) {
7
+ !c_class_name!* ptr;
8
+ Data_Get_Struct(rval, !c_class_name!, ptr);
9
+
10
+ if ( ptr ) return reinterpret_cast< !c_class_name!* >(ptr);
11
+
12
+ T!class_ptrmap!::iterator it = !class_ptrmap!.find(rval);
13
+
14
+ if ( it == !class_ptrmap!.end() ) {
15
+ rb_raise(rb_eRuntimeError, "Unable to find !c_class_name! instance for value %x (type %d)\\n", rval, TYPE(rval));
16
+ return NULL;
17
+ }
18
+
19
+ return reinterpret_cast< !c_class_name!* >((*it).second);
20
+ }
21
+
22
+
23
+ !c_class_name!& ruby2!class_varcname!Ptr(VALUE rval) {
24
+ return *ruby2!class_varcname!Ptr(rval);
25
+ }
26
+
27
+
28
+ VALUE cxx2ruby(!c_class_name!* instance) {
29
+ if ( instance == NULL ) return Qnil;
30
+
31
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
32
+
33
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
34
+ if ( (*it).second == (!c_class_name!*)instance ) break;
35
+
36
+ if ( it != !class_ptrmap!.end() )
37
+ return (*it).first;
38
+ else {
39
+ VALUE klass = r!class_varname!;
40
+
41
+ VALUE rval = Data_Wrap_Struct(klass, 0, 0, (void*)instance);
42
+ !class_ptrmap![rval] = instance;
43
+
44
+ #ifdef DEBUG
45
+ fprintf(stderr, "rust: wrapping instance %p in value %x (type %d)\\n", instance, rval, TYPE(rval));
46
+ #endif
47
+
48
+ return rval;
49
+ }
50
+ }
51
+
52
+ static VALUE !class_varname!_alloc(VALUE self) {
53
+ return Data_Wrap_Struct(self, 0, !class_free_function!, 0);
54
+ }
55
+
56
+ static void !class_varname!_free(void *p) {
57
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
58
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
59
+ if ( (*it).second == (!c_class_name!*)p ) {
60
+ !class_ptrmap!.erase(it); break;
61
+ }
62
+
63
+ !cleanup_functions!;
64
+ }
@@ -0,0 +1,7 @@
1
+ //-*-c++-*-
2
+
3
+ extern VALUE r!class_varname!;
4
+ VALUE cxx2ruby(!c_class_name!* instance, bool free = false);
5
+ bool is_!class_varname!(VALUE val);
6
+ !c_class_name!* ruby2!class_varcname!Ptr(VALUE rval, int argn = -1);
7
+ !c_class_name!& ruby2!class_varcname!(VALUE rval, int argn = -1);
@@ -0,0 +1,6 @@
1
+ //-*-c++-*-
2
+ // Template for the initialization calls for a C/C++ class
3
+
4
+ r!class_varname! = rb_define_class_under(r!namespace_varname!,
5
+ "!bind_name!", !parent_varname!);
6
+ rb_define_alloc_func(r!class_varname!, !class_varname!_alloc);
@@ -0,0 +1,21 @@
1
+ //-*-c++-*-
2
+ // Template of a C++ Constructor stub, the function used to convert the
3
+ // parameters from Ruby objects to C++, and then call the real C++ constructor.
4
+
5
+ !function_prototype! {
6
+ !c_class_name!* tmp;
7
+ Data_Get_Struct(self, !c_class_name!, tmp);
8
+
9
+ /* The exception is thrown already by ruby2* if not found */
10
+
11
+ !function_call!;
12
+
13
+ DATA_PTR(self) = tmp;
14
+ !class_ptrmap![self] = tmp;
15
+
16
+ #ifdef DEBUG
17
+ fprintf(stderr, "rust: creating new instance of !c_class_name! (%p) with value %x\n", tmp, self);
18
+ #endif
19
+
20
+ return self;
21
+ }
@@ -0,0 +1,91 @@
1
+ //-*-c++-*-
2
+
3
+ VALUE r!class_varname!;
4
+
5
+ bool is_!class_varname!(VALUE val)
6
+ {
7
+ if ( isType(val, T_DATA) )
8
+ {
9
+ !c_class_name! *obj = 0;
10
+
11
+ Data_Get_Struct(val, !c_class_name!, obj);
12
+
13
+ if( obj == 0 ) return false;
14
+
15
+ return rb_obj_is_kind_of(val, r!class_varname!) == Qtrue;
16
+ }
17
+
18
+ return false;
19
+ }
20
+
21
+ !c_class_name!* ruby2!class_varcname!Ptr(VALUE rval, int argn) {
22
+ if(rval == Qnil || rval == 0) return 0;
23
+
24
+ if( ! is_!class_varname!(rval) )
25
+ {
26
+ VALUE klass = rb_funcall(rval, rb_intern("class"), 0);
27
+
28
+ if( argn > 0)
29
+ rb_raise(rb_eArgError, "Expecting !c_class_name! given %s for argument %d", RSTRING(rb_funcall(klass, rb_intern("to_s"), 0))->ptr, argn);
30
+ else
31
+ rb_raise(rb_eArgError, "Expecting !c_class_name! given %s", RSTRING(rb_funcall(klass, rb_intern("to_s"), 0))->ptr, argn);
32
+ return 0;
33
+ }
34
+
35
+ !c_class_name!* ptr;
36
+ Data_Get_Struct(rval, !c_class_name!, ptr);
37
+
38
+ if ( ptr ) return dynamic_cast< !c_class_name!* >(ptr);
39
+
40
+ T!class_ptrmap!::iterator it = !class_ptrmap!.find(rval);
41
+
42
+ if ( it == !class_ptrmap!.end() ) {
43
+ rb_raise(rb_eRuntimeError, "Unable to find !c_class_name! instance for value %x (type %d)\\n", rval, TYPE(rval));
44
+ return NULL;
45
+ }
46
+
47
+ return dynamic_cast< !c_class_name!* >((*it).second);
48
+ }
49
+
50
+ !c_class_name!& ruby2!class_varcname!(VALUE rval, int argn) {
51
+ return *ruby2!class_varcname!Ptr(rval, argn);
52
+ }
53
+
54
+ VALUE cxx2ruby(!c_class_name!* instance, bool free) {
55
+ if ( instance == NULL ) return Qnil;
56
+
57
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
58
+
59
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
60
+ if ( (*it).second == (!c_class_name!*)instance ) break;
61
+
62
+ if ( it != !class_ptrmap!.end() )
63
+ return (*it).first;
64
+ else {
65
+ VALUE klass = r!class_varname!;
66
+
67
+ !test_children!
68
+
69
+ VALUE rval;
70
+ if( !free )
71
+ {
72
+ rval = Data_Wrap_Struct(klass, 0, 0, (void*)instance);
73
+ }
74
+ else
75
+ {
76
+ rval = Data_Wrap_Struct(klass, 0, !class_free_function!, (void*)instance);
77
+ }
78
+
79
+ !class_ptrmap![rval] = instance;
80
+
81
+ #ifdef DEBUG
82
+ fprintf(stderr, "rust: wrapping instance %p in value %x (type %d)\\n", instance, rval, TYPE(rval));
83
+ #endif
84
+
85
+ return rval;
86
+ }
87
+ }
88
+
89
+ static VALUE !class_varname!_alloc(VALUE self) {
90
+ return Data_Wrap_Struct(self, 0, !class_free_function!, 0);
91
+ }
@@ -0,0 +1,12 @@
1
+ //-*-c++-*-
2
+ // Template of a C++ Method stub, the function used to convert the
3
+ // parameters from Ruby objects to C++, and then call the real C++ function.
4
+
5
+ !function_prototype! {
6
+ !c_class_name!* tmp = ruby2!class_varcname!Ptr(self);
7
+ if ( ! tmp ) return Qnil;
8
+
9
+ // The exception is thrown already by ruby2*
10
+
11
+ !function_call!
12
+ }
@@ -0,0 +1,12 @@
1
+ //-*-c++-*-
2
+
3
+ T!class_ptrmap! !class_ptrmap!;
4
+
5
+ static void !class_varname!_free(void *p) {
6
+ T!class_ptrmap!::iterator it, eend = !class_ptrmap!.end();
7
+ for(it = !class_ptrmap!.begin(); it != eend; it++)
8
+ if ( (*it).second == (!c_class_name!*)p ) {
9
+ !class_ptrmap!.erase(it); break;
10
+ }
11
+ delete (!c_class_name!*)p;
12
+ }
@@ -0,0 +1,3 @@
1
+ //-*-c++-*-
2
+
3
+ !enum_cname! ruby2!enum_varname!(VALUE rval, int argn = -1);
@@ -0,0 +1,29 @@
1
+ //-*-c++-*-
2
+
3
+ !enum_cname! ruby2!enum_varname!(VALUE rval, int argn) {
4
+ int cval = ruby2int(rval, argn);
5
+
6
+ switch(cval) {
7
+ !enum_cases!
8
+ return static_cast<!enum_cname!>(cval);
9
+ default:
10
+ if( argn > 0)
11
+ rb_raise(rb_eArgError, "value %d for enum !enum_name! is out of bound for argument %d", cval, argn);
12
+ else
13
+ rb_raise(rb_eArgError, "value %d for enum !enum_name! is out of bound", cval);
14
+ return static_cast<!enum_cname!>(-1);
15
+ }
16
+ }
17
+
18
+ bool is_!enum_varname!(VALUE rval) {
19
+ if( is_int(rval) )
20
+ {
21
+ switch(ruby2int(rval))
22
+ {
23
+ !enum_cases!
24
+ return true;
25
+ }
26
+ }
27
+
28
+ return false;
29
+ }
@@ -0,0 +1,9 @@
1
+ //-*-c++-*-
2
+ // Template of a generic C function call
3
+
4
+ !function_prototype! {
5
+ !function_call!
6
+
7
+ rb_raise(rb_eArgError, "Mantatory parameters missing"); // FIXME
8
+ return Qnil;
9
+ }
@@ -0,0 +1,5 @@
1
+ //-*-c++-*-
2
+ // Template for the init function snipped registering an alias for a
3
+ // function or a method.
4
+
5
+ rb_define_alias(r!parent_varname!, "!function_alias!", "!function_bindname!");