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.
Files changed (54) hide show
  1. data/lib/rbind.rb +1 -0
  2. data/lib/rbind/clang/clang.rb +3699 -0
  3. data/lib/rbind/clang/clang_types.rb +327 -0
  4. data/lib/rbind/clang_parser.rb +451 -0
  5. data/lib/rbind/core.rb +7 -4
  6. data/lib/rbind/core/rattribute.rb +17 -21
  7. data/lib/rbind/core/rbase.rb +98 -64
  8. data/lib/rbind/core/rcallback.rb +15 -0
  9. data/lib/rbind/core/rclass.rb +79 -16
  10. data/lib/rbind/core/rdata_type.rb +40 -39
  11. data/lib/rbind/core/renum.rb +18 -0
  12. data/lib/rbind/core/rnamespace.rb +189 -52
  13. data/lib/rbind/core/roperation.rb +52 -20
  14. data/lib/rbind/core/rparameter.rb +43 -8
  15. data/lib/rbind/core/rpointer.rb +70 -0
  16. data/lib/rbind/core/rreference.rb +54 -0
  17. data/lib/rbind/core/rtemplate_class.rb +49 -0
  18. data/lib/rbind/core/rtype_qualifier.rb +60 -0
  19. data/lib/rbind/default_parser.rb +48 -36
  20. data/lib/rbind/generator_c.rb +2 -2
  21. data/lib/rbind/generator_extern.rb +1 -3
  22. data/lib/rbind/generator_ruby.rb +201 -47
  23. data/lib/rbind/logger.rb +3 -0
  24. data/lib/rbind/rbind.rb +25 -9
  25. data/lib/rbind/templates/c/CMakeLists.txt +6 -6
  26. data/lib/rbind/templates/ruby/rbind.rb +1 -1
  27. data/lib/rbind/templates/ruby/rmethod.rb +4 -1
  28. data/lib/rbind/templates/ruby/rnamespace.rb +2 -1
  29. data/lib/rbind/templates/ruby/roverloaded_method.rb +3 -1
  30. data/lib/rbind/templates/ruby/roverloaded_method_call.rb +1 -0
  31. data/lib/rbind/templates/ruby/roverloaded_static_method.rb +3 -2
  32. data/lib/rbind/templates/ruby/rstatic_method.rb +4 -1
  33. data/lib/rbind/templates/ruby/rtype.rb +19 -16
  34. data/lib/rbind/templates/ruby/rtype_template.rb +7 -0
  35. data/lib/rbind/{core/rstring.rb → types/std_string.rb} +8 -8
  36. data/lib/rbind/types/std_vector.rb +100 -0
  37. data/rbind.gemspec +2 -2
  38. data/test/headers/cfunctions.h +7 -0
  39. data/test/headers/classes.hpp +29 -0
  40. data/test/headers/constants.hpp +14 -0
  41. data/test/headers/enums.hpp +22 -0
  42. data/test/headers/std_string.hpp +26 -0
  43. data/test/headers/std_vector.hpp +31 -0
  44. data/test/headers/structs.hpp +34 -0
  45. data/test/headers/templates.hpp +20 -0
  46. data/test/test_clang_parser.rb +146 -0
  47. data/test/test_generator_ruby.rb +0 -5
  48. data/test/test_roperation.rb +144 -0
  49. data/test/test_rparameter.rb +88 -0
  50. metadata +24 -7
  51. data/lib/rbind/core/.roperation.rb.swp +0 -0
  52. data/lib/rbind/core/rconst.rb +0 -35
  53. data/lib/rbind/core/rstruct.rb +0 -87
  54. data/lib/rbind/core/rvector.rb +0 -27
@@ -0,0 +1,7 @@
1
+ #ifndef RBIND_CFUNCTIONS_H
2
+ #define RBIND_CFUNCTIONS_H
3
+
4
+ void test1(int i){};
5
+ int test2(int i){};
6
+
7
+ #endif
@@ -0,0 +1,29 @@
1
+ #ifndef RBIND_CLASSES_HPP
2
+ #define RBIND_CLASSES_HPP
3
+
4
+
5
+ struct TestClass
6
+ {
7
+ TestClass(int i1,char c){};
8
+ void setB(bool val){};
9
+ void setF(float &val){};
10
+ void setF2(const float &val){};
11
+ void setD(double &val)const{};
12
+
13
+ void setS(TestClass other)const{};
14
+ void setS2(TestClass *other)const{};
15
+ void setS3(TestClass **other)const{};
16
+ void setS4(TestClass &other)const{};
17
+ void setS5(const TestClass &other)const{};
18
+ void setS6(const TestClass *other)const{};
19
+
20
+ TestClass getS(){};
21
+ TestClass* getS2(){};
22
+ TestClass& getS3(){};
23
+ const TestClass& getS4(){};
24
+
25
+ bool bfield;
26
+ int ifield;
27
+ };
28
+
29
+ #endif
@@ -0,0 +1,14 @@
1
+
2
+ #ifndef RBIND_CONSTANTS_HPP
3
+ #define RBIND_CONSTANTS_HPP
4
+
5
+ const int INT_CONST = 11;
6
+ const unsigned int UINT_CONST = 12;
7
+
8
+ namespace ns_const
9
+ {
10
+ const int INT_CONST2 = 11;
11
+ const unsigned int UINT_CONST2 = 12;
12
+ }
13
+
14
+ #endif
@@ -0,0 +1,22 @@
1
+
2
+ #ifndef RBIND_ENUMS_HPP
3
+ #define RBIND_ENUMS_HPP
4
+
5
+ enum Test1
6
+ {
7
+ VAL1 = 1,
8
+ VAL2,
9
+ VAL3
10
+ };
11
+
12
+ namespace ns_enum
13
+ {
14
+ enum Test2
15
+ {
16
+ VAL1 = 1,
17
+ VAL2 = VAL1+3,
18
+ VAL3
19
+ };
20
+ }
21
+
22
+ #endif
@@ -0,0 +1,26 @@
1
+
2
+ #ifndef RBIND_STD_STRING_HPP
3
+ #define RBIND_STD_STRING_HPP
4
+
5
+ #include <string>
6
+ #include <stdlib.h>
7
+
8
+ class TestClass
9
+ {
10
+ private:
11
+ std::string private_var;
12
+
13
+ public:
14
+ std::string public_var;
15
+
16
+ // basic types
17
+ void setValues(std::string str){};
18
+ void setValues1(std::string &str){};
19
+ void setValues2(std::string *str){};
20
+
21
+ std::string getString(){ return private_var;};
22
+ std::string &getString2(){ return private_var;};
23
+ std::string *getString3(){ return &private_var;};
24
+ };
25
+
26
+ #endif
@@ -0,0 +1,31 @@
1
+
2
+ #ifndef RBIND_STD_VECTOR_HPP
3
+ #define RBIND_STD_VECTOR_HPP
4
+
5
+ #include <vector>
6
+ #include <stdlib.h>
7
+
8
+ class TestClass
9
+ {
10
+ private:
11
+ std::vector<float> private_var;
12
+
13
+ public:
14
+ class MStruct{};
15
+ std::vector<int> public_var;
16
+
17
+ // basic types
18
+ void setValues(std::vector<int> ints){};
19
+ void setValues1(std::vector<int> &ints){};
20
+
21
+ void setValues2(const std::vector<unsigned int> uints){};
22
+ void setValues3(const std::vector<unsigned int*> &uints){};
23
+
24
+ void setValues4(std::vector<MStruct> objs){};
25
+ void setValues5(std::vector<MStruct*> objs){};
26
+ void setValues6(std::vector<MStruct**> objs){};
27
+
28
+ std::vector<float> &getFloats(){ return private_var;};
29
+ };
30
+
31
+ #endif
@@ -0,0 +1,34 @@
1
+ #ifndef RBIND_STRUCTS_HPP
2
+ #define RBIND_STRUCTS_HPP
3
+
4
+
5
+ struct TestStruct
6
+ {
7
+ TestStruct(int i1,char c){};
8
+ void setB(bool val){};
9
+ void setF(float &val){};
10
+ void setF2(const float &val){};
11
+ void setD(double &val)const{};
12
+
13
+ void setS(TestStruct other)const{};
14
+ void setS2(TestStruct *other)const{};
15
+ void setS3(TestStruct **other)const{};
16
+ void setS4(TestStruct &other)const{};
17
+ void setS5(const TestStruct &other)const{};
18
+
19
+ TestStruct getS(){};
20
+ TestStruct* getS2(){};
21
+ TestStruct& getS3(){};
22
+ const TestStruct& getS4(){};
23
+
24
+ bool bfield;
25
+ int ifield;
26
+ };
27
+
28
+ typedef struct
29
+ {
30
+ int i;
31
+ }TestStruct2;
32
+
33
+
34
+ #endif
@@ -0,0 +1,20 @@
1
+
2
+ #ifndef RBIND_TEMPLATES_HPP
3
+ #define RBIND_TEMPLATES_HPP
4
+
5
+ template<typename T> class TemplateType
6
+ {
7
+ public:
8
+ T field;
9
+
10
+ void setInt(int i){};
11
+ void setT(T val){};
12
+ };
13
+
14
+ class Test
15
+ {
16
+ public:
17
+ void setType(TemplateType<int> type){};
18
+ };
19
+
20
+ #endif
@@ -0,0 +1,146 @@
1
+ require 'minitest/spec'
2
+ require 'rbind'
3
+
4
+ MiniTest::Unit.autorun
5
+ describe Rbind::ClangParser do
6
+ before do
7
+ end
8
+
9
+ after do
10
+ end
11
+
12
+ describe "parse" do
13
+
14
+ it "must parse enums" do
15
+ next
16
+ file = File.join(File.dirname(__FILE__),'headers','enums.hpp')
17
+ parser = Rbind::ClangParser.new
18
+ parser.parse file
19
+ assert parser.Test1
20
+ assert_equal({"VAL1" => "1", "VAL2" => nil ,"VAL3" => nil},parser.Test1.values)
21
+
22
+ assert parser.ns_enum.Test2
23
+ assert_equal({"VAL1" => "1", "VAL2" => "VAL1+3" ,"VAL3" => nil},parser.ns_enum.Test2.values)
24
+ end
25
+
26
+ it "must parse constants" do
27
+ next
28
+ file = File.join(File.dirname(__FILE__),'headers','constants.hpp')
29
+ parser = Rbind::ClangParser.new
30
+ parser.parse file
31
+ assert parser.INT_CONST
32
+ assert_equal "11", parser.INT_CONST.default_value
33
+ assert_equal "int", parser.INT_CONST.type.full_name
34
+ assert_equal "12", parser.UINT_CONST.default_value
35
+ assert_equal "uint", parser.UINT_CONST.type.full_name
36
+
37
+ assert_equal "11", parser.ns_const.INT_CONST.default_value
38
+ assert_equal "int", parser.ns_const.INT_CONST.type.full_name
39
+ assert_equal "12", parser.ns_const.UINT_CONST.default_value
40
+ assert_equal "uint", parser.ns_const.UINT_CONST.type.full_name
41
+ end
42
+
43
+ it "must parse c functions" do
44
+ next
45
+ file = File.join(File.dirname(__FILE__),'headers','cfunctions.h')
46
+ parser = Rbind::ClangParser.new
47
+ parser.parse file
48
+
49
+ assert parser.test1
50
+ assert_equal "int",parser.test1.parameters[0].type.full_name
51
+ assert_equal "void",parser.test1.return_type.full_name
52
+
53
+ assert parser.test2
54
+ assert_equal "int",parser.test2.parameters[0].type.full_name
55
+ assert_equal "int",parser.test2.return_type.full_name
56
+ end
57
+
58
+ it "must parse structs" do
59
+ file = File.join(File.dirname(__FILE__),'headers','structs.hpp')
60
+ parser = Rbind::ClangParser.new
61
+ parser.parse file
62
+
63
+ assert_equal "TestStruct::TestStruct(int i1, char c)", parser.TestStruct.TestStruct.signature
64
+ assert_equal "void TestStruct::setB(bool val)", parser.TestStruct.setB.signature
65
+ assert_equal "void TestStruct::setF(float& val)", parser.TestStruct.setF.signature
66
+ assert_equal "void TestStruct::setF2(const float& val)", parser.TestStruct.setF2.signature
67
+ assert_equal "void TestStruct::setD(double& val)", parser.TestStruct.setD.signature
68
+ assert_equal "void TestStruct::setS(TestStruct other)", parser.TestStruct.setS.signature
69
+ assert_equal "void TestStruct::setS2(TestStruct* other)", parser.TestStruct.setS2.signature
70
+ assert_equal "void TestStruct::setS3(TestStruct** other)", parser.TestStruct.setS3.signature
71
+ assert_equal "void TestStruct::setS4(TestStruct& other)", parser.TestStruct.setS4.signature
72
+ assert_equal "void TestStruct::setS5(const TestStruct& other)", parser.TestStruct.setS5.signature
73
+ assert_equal "TestStruct TestStruct::getS()", parser.TestStruct.getS.signature
74
+ assert_equal "TestStruct* TestStruct::getS2()", parser.TestStruct.getS2.signature
75
+ assert_equal "TestStruct& TestStruct::getS3()", parser.TestStruct.getS3.signature
76
+ assert_equal "const TestStruct& TestStruct::getS4()", parser.TestStruct.getS4.signature
77
+ assert parser.TestStruct.attribute("bfield")
78
+ assert parser.TestStruct.attribute("ifield")
79
+ #TODO test csignature
80
+ end
81
+
82
+ it "must parse classes" do
83
+ next
84
+ file = File.join(File.dirname(__FILE__),'headers','classes.hpp')
85
+ parser = Rbind::ClangParser.new
86
+ parser.parse file
87
+
88
+ assert_equal "void TestClass::TestClass(int i1, char c)", parser.TestClass.TestClass.signature
89
+ assert_equal "void TestClass::setB(bool val)", parser.TestClass.setB.signature
90
+ assert_equal "void TestClass::setF(float& val)", parser.TestClass.setF.signature
91
+ assert_equal "void TestClass::setF2(const float& val)", parser.TestClass.setF2.signature
92
+ assert_equal "void TestClass::setD(double& val)", parser.TestClass.setD.signature
93
+ assert_equal "TestClass TestClass::setS(TestClass other)", parser.TestClass.setS.signature
94
+ assert_equal "TestClass TestClass::setS2(TestClass* other)", parser.TestClass.setS2.signature
95
+ assert_equal "TestClass TestClass::setS3(TestClass** other)", parser.TestClass.setS3.signature
96
+ assert_equal "TestClass TestClass::setS4(TestClass& other)", parser.TestClass.setS4.signature
97
+ assert_equal "TestClass TestClass::setS5(const TestClass& other)", parser.TestClass.setS5.signature
98
+ assert_equal "TestClass TestClass::setS6(const TestClass* other)", parser.TestClass.setS6.signature
99
+ assert_equal "TestClass TestClass::getS()", parser.TestClass.getS.signature
100
+ assert_equal "TestClass* TestClass::getS2()", parser.TestClass.getS2.signature
101
+ assert_equal "TestClass& TestClass::getS3()", parser.TestClass.getS3.signature
102
+ assert_equal "const TestClass& TestClass::getS4()", parser.TestClass.getS4.signature
103
+ assert parser.TestClass.attribute("bfield")
104
+ assert parser.TestClass.attribute("ifield")
105
+ end
106
+
107
+ it "must parse std vector types" do
108
+ next
109
+ file = File.join(File.dirname(__FILE__),'headers','std_vector.hpp')
110
+ parser = Rbind::ClangParser.new
111
+ parser.parse file
112
+
113
+ assert_equal "void TestClass::setValues(std::vector<int> ints)", parser.TestClass.setValues.signature
114
+ assert_equal "void TestClass::setValues1(std::vector<int>& ints)", parser.TestClass.setValues1.signature
115
+ assert_equal "void TestClass::setValues2(const std::vector<uint> uints)", parser.TestClass.setValues2.signature
116
+ assert_equal "void TestClass::setValues3(const std::vector<uint*>& uints)", parser.TestClass.setValues3.signature
117
+ assert_equal "void TestClass::setValues4(std::vector<TestClass::MStruct> objs)", parser.TestClass.setValues4.signature
118
+ assert_equal "void TestClass::setValues5(std::vector<TestClass::MStruct*> objs)", parser.TestClass.setValues5.signature
119
+ assert_equal "void TestClass::setValues6(std::vector<TestClass::MStruct**> objs)", parser.TestClass.setValues6.signature
120
+ assert_equal "std::vector<float>& TestClass::getFloats()", parser.TestClass.getFloats.signature
121
+ end
122
+
123
+ it "must parse std string types" do
124
+ file = File.join(File.dirname(__FILE__),'headers','std_string.hpp')
125
+ parser = Rbind::ClangParser.new
126
+ parser.add_type(Rbind::StdString.new("std::string",parser))
127
+ parser.type_alias["basic_string"] = parser.std.string
128
+ parser.parse file
129
+
130
+ assert_equal "void TestClass::setValues(std::string str)", parser.TestClass.setValues.signature
131
+ assert_equal "void TestClass::setValues1(std::string& str)", parser.TestClass.setValues1.signature
132
+ assert_equal "void TestClass::setValues2(std::string* str)", parser.TestClass.setValues2.signature
133
+ assert_equal "std::string TestClass::getString()", parser.TestClass.getString.signature
134
+ assert_equal "std::string& TestClass::getString2()", parser.TestClass.getString2.signature
135
+ assert_equal "std::string* TestClass::getString3()", parser.TestClass.getString3.signature
136
+ end
137
+
138
+ # this is not fully supported yet
139
+ #it "must parse templates" do
140
+ # file = File.join(File.dirname(__FILE__),'headers','templates.hpp')
141
+ # parser = Rbind::ClangParser.new
142
+ # parser.parse file
143
+ # #assert_equal("_test123",result)
144
+ #end
145
+ end
146
+ end
@@ -72,8 +72,3 @@ describe Rbind::GeneratorRuby do
72
72
  end
73
73
  end
74
74
  end
75
- #assert(@service.names.include?("Local/dummy"))
76
- #assert_equal(@task,@service.get("dummy"))
77
- #assert_raises(Orocos::NotFound) do
78
- # @service.get("foo")
79
- #end
@@ -0,0 +1,144 @@
1
+ require 'minitest/spec'
2
+ require 'rbind'
3
+
4
+ MiniTest::Unit.autorun
5
+ describe Rbind::ROperation do
6
+ before do
7
+ @root = Rbind::RNamespace.new
8
+ @root.add_default_types
9
+ end
10
+
11
+ after do
12
+ end
13
+
14
+ describe "signature" do
15
+ it "must generate a correct signature for simple methods" do
16
+ op = @root.add_operation("testOperation")
17
+ assert_equal "void testOperation()", op.to_s
18
+
19
+ op = @root.add_operation("testOperation2") do |op|
20
+ op.return_type = int
21
+ end
22
+ assert_equal "int testOperation2()", op.to_s
23
+
24
+ op = @root.add_operation("testOperation3") do |op|
25
+ op.add_parameter("para") do |p|
26
+ p.type = int
27
+ end
28
+ end
29
+ assert_equal "void testOperation3(int para)", op.to_s
30
+
31
+ op = @root.add_operation("testOperation4") do |op|
32
+ op.add_parameter("para") do |p|
33
+ p.type = int.to_ptr
34
+ end
35
+ op.return_type = char.to_ref
36
+ end
37
+ assert_equal "char& testOperation4(int* para)", op.to_s
38
+ end
39
+
40
+ it "must generate a correct signature for complex methods" do
41
+ @root.add_type Rbind::RClass.new("MStruct")
42
+ @root.add_type Rbind::StdVector.new("std::vector")
43
+
44
+ op = @root.add_operation("testOperation") do |op|
45
+ op.add_parameter("para") do |p|
46
+ p.type = type("MStruct").to_ptr
47
+ end
48
+ op.add_parameter("para2") do |p|
49
+ p.type = type("MStruct")
50
+ end
51
+ op.return_type = int
52
+ end
53
+ assert_equal "int testOperation(MStruct* para, MStruct para2)", op.to_s
54
+
55
+ op = @root.add_operation("testOperation2") do |op|
56
+ op.add_parameter("para") do |p|
57
+ p.type = type("std::vector<MStruct*>").to_ptr.to_const
58
+ p.default_value = "0"
59
+ end
60
+ end
61
+ assert_equal "void testOperation2(const std::vector<MStruct*>* para = 0)", op.to_s
62
+ end
63
+ end
64
+
65
+ describe "csignature" do
66
+ it "must generate a correct csignature for simple methods" do
67
+ op = @root.add_operation("testOperation")
68
+ assert_equal "void rbind_testOperation()", op.csignature
69
+
70
+ op = @root.add_operation("testOperation2") do |op|
71
+ op.return_type = int
72
+ end
73
+ assert_equal "int rbind_testOperation2()", op.csignature
74
+
75
+ op = @root.add_operation("testOperation3") do |op|
76
+ op.add_parameter("para") do |p|
77
+ p.type = int
78
+ end
79
+ end
80
+ assert_equal "void rbind_testOperation3(int para)", op.csignature
81
+
82
+ op = @root.add_operation("testOperation4") do |op|
83
+ op.add_parameter("para") do |p|
84
+ p.type = int.to_ptr
85
+ end
86
+ op.return_type = char.to_ref
87
+ end
88
+ assert_equal "char& rbind_testOperation4(int* para)", op.csignature
89
+ end
90
+
91
+ it "must generate a correct csignature for complex methods" do
92
+ @root.add_type Rbind::RClass.new("MStruct")
93
+ @root.add_type Rbind::StdVector.new("std::vector")
94
+
95
+ op = @root.add_operation("testOperation") do |op|
96
+ op.add_parameter("para") do |p|
97
+ p.type = type("MStruct").to_ptr
98
+ end
99
+ op.add_parameter("para2") do |p|
100
+ p.type = type("MStruct")
101
+ end
102
+ op.return_type = int
103
+ end
104
+ assert_equal "int rbind_testOperation(rbind_MStruct* para, rbind_MStruct* para2)", op.csignature
105
+
106
+ op = @root.add_operation("testOperation2") do |op|
107
+ op.add_parameter("para") do |p|
108
+ p.type = type("std::vector<MStruct*>").to_ptr.to_const
109
+ p.default_value = "0"
110
+ end
111
+ end
112
+ assert_equal "void rbind_testOperation2(const rbind_std_vector_MStruct_ptr* para)", op.csignature
113
+
114
+ op = @root.add_operation("testOperation3") do |op|
115
+ op.add_parameter("para") do |p|
116
+ p.type = type("std::vector<MStruct*>").to_ref.to_const
117
+ p.default_value = "0"
118
+ end
119
+ end
120
+ assert_equal "void rbind_testOperation3(const rbind_std_vector_MStruct_ptr* para)", op.csignature
121
+
122
+ op = @root.add_operation("testOperation4") do |op|
123
+ op.return_type = type("std::vector<MStruct*>").to_ref
124
+ end
125
+ assert_equal "rbind_std_vector_MStruct_ptr* rbind_testOperation4()", op.csignature
126
+ end
127
+
128
+ it "must enumerate overloaded methods" do
129
+ # rbind does not care if two methods have the exact same signature
130
+ op = @root.add_operation("testOperation")
131
+ assert_equal "void rbind_testOperation()", op.csignature
132
+
133
+ op = @root.add_operation("testOperation")
134
+ assert_equal "void rbind_testOperation2()", op.csignature
135
+
136
+ op = @root.add_operation("testOperation")
137
+ assert_equal "void rbind_testOperation3()", op.csignature
138
+
139
+ op = @root.add_operation("testOperation3")
140
+ assert_equal "void rbind_testOperation31()", op.csignature
141
+ end
142
+ end
143
+ end
144
+