cauterize 0.0.1.pre1 → 0.0.1.pre5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -1
  3. data/Gemfile +1 -1
  4. data/README.md +0 -2
  5. data/Rakefile +19 -3
  6. data/bin/cauterize +14 -6
  7. data/example/Cauterize +22 -10
  8. data/example/build.sh +15 -2
  9. data/lib/cauterize/base_type.rb +2 -5
  10. data/lib/cauterize/builders.rb +1 -3
  11. data/lib/cauterize/builders/c/buildable.rb +3 -2
  12. data/lib/cauterize/builders/c/builtin.rb +46 -0
  13. data/lib/cauterize/builders/c/enumeration.rb +23 -2
  14. data/lib/cauterize/builders/c/fixed_array.rb +16 -7
  15. data/lib/cauterize/builders/c/group.rb +32 -3
  16. data/lib/cauterize/builders/c/scalar.rb +5 -0
  17. data/lib/cauterize/builders/c/variable_array.rb +1 -1
  18. data/lib/cauterize/builders/cs/buildable.rb +59 -0
  19. data/lib/cauterize/builders/cs/builtin.rb +23 -0
  20. data/lib/cauterize/builders/cs/composite.rb +21 -0
  21. data/lib/cauterize/builders/cs/csarray.rb +32 -0
  22. data/lib/cauterize/builders/cs/enumeration.rb +21 -0
  23. data/lib/cauterize/builders/cs/fixed_array.rb +25 -0
  24. data/lib/cauterize/builders/cs/group.rb +33 -0
  25. data/lib/cauterize/builders/cs/scalar.rb +10 -0
  26. data/lib/cauterize/builders/cs/variable_array.rb +34 -0
  27. data/lib/cauterize/builtin.rb +52 -0
  28. data/lib/cauterize/c_builder.rb +15 -1
  29. data/lib/cauterize/cauterize.rb +44 -13
  30. data/lib/cauterize/composite.rb +3 -3
  31. data/lib/cauterize/cs_builder.rb +53 -0
  32. data/lib/cauterize/enumeration.rb +20 -3
  33. data/lib/cauterize/fixed_array.rb +3 -3
  34. data/lib/cauterize/formatter.rb +7 -3
  35. data/lib/cauterize/group.rb +5 -8
  36. data/lib/cauterize/scalar.rb +16 -7
  37. data/lib/cauterize/variable_array.rb +6 -6
  38. data/lib/cauterize/version.rb +1 -1
  39. data/spec/base_type_spec.rb +133 -125
  40. data/spec/builders/c/buildable_spec.rb +18 -18
  41. data/spec/builders/c/builtin_spec.rb +22 -0
  42. data/spec/builders/c/composite_spec.rb +37 -33
  43. data/spec/builders/c/enumeration_spec.rb +84 -21
  44. data/spec/builders/c/fixed_array_spec.rb +6 -6
  45. data/spec/builders/c/group_spec.rb +97 -90
  46. data/spec/builders/c/scalar_spec.rb +24 -6
  47. data/spec/builders/c/variable_array_spec.rb +37 -37
  48. data/spec/builders/cs/buildable_spec.rb +8 -0
  49. data/spec/builders/cs/composite_spec.rb +32 -0
  50. data/spec/builders/cs/enumeration_spec.rb +33 -0
  51. data/spec/builders/cs/fixed_array_spec.rb +40 -0
  52. data/spec/builders/cs/group_spec.rb +56 -0
  53. data/spec/builders/cs/scalar_spec.rb +7 -0
  54. data/spec/builders/cs/variable_array_spec.rb +46 -0
  55. data/spec/builders_spec.rb +38 -38
  56. data/spec/builtin_spec.rb +46 -0
  57. data/spec/c_builder_spec.rb +116 -102
  58. data/spec/cauterize_spec.rb +8 -1
  59. data/spec/composite_spec.rb +52 -48
  60. data/spec/cs_builder_spec.rb +113 -0
  61. data/spec/enumeration_spec.rb +55 -16
  62. data/spec/fixed_array_spec.rb +7 -9
  63. data/spec/group_spec.rb +81 -76
  64. data/spec/scalar_spec.rb +20 -10
  65. data/spec/spec_helper.rb +103 -94
  66. data/spec/support/shared_examples_for_c_buildables.rb +68 -64
  67. data/spec/variable_array_spec.rb +12 -17
  68. data/{c → support/c}/src/cauterize.c +8 -7
  69. data/support/c/src/cauterize.h +59 -0
  70. data/{c → support/c}/src/cauterize_debug.h +0 -0
  71. data/support/c/src/cauterize_util.h +49 -0
  72. data/{c → support/c}/test/greatest.h +0 -0
  73. data/{c → support/c}/test/test.c +0 -0
  74. data/support/cs/src/CauterizeCompositeFormatter.cs +34 -0
  75. data/support/cs/src/CauterizeContainerFormatter.cs +18 -0
  76. data/support/cs/src/CauterizeEnumFormatter.cs +67 -0
  77. data/support/cs/src/CauterizeException.cs +15 -0
  78. data/support/cs/src/CauterizeFixedArrayFormatter.cs +39 -0
  79. data/support/cs/src/CauterizeFormatter.cs +40 -0
  80. data/support/cs/src/CauterizeGroupFormatter.cs +46 -0
  81. data/support/cs/src/CauterizePrimitiveFormatter.cs +33 -0
  82. data/support/cs/src/CauterizeTypeFormatterFactory.cs +39 -0
  83. data/support/cs/src/CauterizeTypes.cs +107 -0
  84. data/support/cs/src/CauterizeVariableArrayFormatter.cs +49 -0
  85. data/support/cs/src/ICauterizeTypeFormatter.cs +12 -0
  86. data/support/cs/src/OrderAttribute.cs +50 -0
  87. data/support/cs/src/PrimitiveSupport.cs +134 -0
  88. data/support/cs/src/SerializedRepresentationAttribute.cs +24 -0
  89. data/support/cs/test/CauterizeCompositeFormatterTest.cs +59 -0
  90. data/support/cs/test/CauterizeEnumFormatterTest.cs +110 -0
  91. data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +91 -0
  92. data/support/cs/test/CauterizeFormatterTest.cs +40 -0
  93. data/support/cs/test/CauterizeGroupFormatterTest.cs +147 -0
  94. data/support/cs/test/CauterizeIntegrationTest.cs +129 -0
  95. data/support/cs/test/CauterizePrimitiveFormatterTest.cs +98 -0
  96. data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +73 -0
  97. data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +130 -0
  98. data/support/cs/test/OrderAttributeTest.cs +39 -0
  99. data/support/cs/test/SerializedRepresentationAttributeTest.cs +39 -0
  100. metadata +68 -10
  101. data/c/src/cauterize.h +0 -46
  102. data/c/src/cauterize_util.h +0 -7
@@ -1,24 +1,24 @@
1
- include Cauterize::Builders::C
1
+ module Cauterize::Builders::C
2
+ describe Cauterize::Builders::C do
3
+ describe Buildable do
4
+ subject { Buildable.new(:some_blueprint) }
2
5
 
3
- describe Cauterize::Builders::C do
4
- describe Buildable do
5
- subject { Buildable.new(:some_blueprint) }
6
-
7
- describe "required methods" do
8
- it "raises errors on required interfaces" do
9
- lambda {
10
- REQUIRED_METHODS.each do |m|
11
- subject.send(m)
12
- end
13
- }.should raise_error /must implement/
6
+ describe "required methods" do
7
+ it "raises errors on required interfaces" do
8
+ lambda {
9
+ REQUIRED_METHODS.each do |m|
10
+ subject.send(m)
11
+ end
12
+ }.should raise_error /must implement/
13
+ end
14
14
  end
15
- end
16
15
 
17
- describe :method_missing do
18
- it "calls the original if method not required" do
19
- lambda {
20
- subject.is_not_defined
21
- }.should raise_error NoMethodError
16
+ describe :method_missing do
17
+ it "calls the original if method not required" do
18
+ lambda {
19
+ subject.is_not_defined
20
+ }.should raise_error NoMethodError
21
+ end
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,22 @@
1
+ module Cauterize
2
+ describe Builders::C::BuiltIn do
3
+ let(:bi) do
4
+ b = BuiltIn.new(:foo)
5
+ b.is_signed(false)
6
+ b.byte_length(4)
7
+ b
8
+ end
9
+
10
+ let (:bi_bldr) do
11
+ Builders.get(:c, bi)
12
+ end
13
+
14
+ describe ".declare" do
15
+ it "declares a variable with the BuiltIn's type" do
16
+ f = default_formatter
17
+ bi_bldr.declare(f, :meep)
18
+ f.to_s.should == "uint32_t meep;"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,45 +1,49 @@
1
- describe Cauterize::Builders::C::Composite do
2
- let(:type_constructor) do
3
- lambda do |name|
4
- scalar(:int32)
5
- composite(name) do |c|
6
- c.field :an_int, :int32
7
- c.field :another_int, :int32
1
+ module Cauterize
2
+ describe Cauterize::Builders::C::Composite do
3
+ before do
4
+ Cauterize.scalar(:my_int) {|t| t.type_name(:int32)}
5
+ end
6
+
7
+ let(:type_constructor) do
8
+ lambda do |name|
9
+ Cauterize.composite(name) do |c|
10
+ c.field :an_int, :my_int
11
+ c.field :another_int, :my_int
12
+ end
8
13
  end
9
14
  end
10
- end
11
15
 
12
- it_behaves_like "a buildable"
13
- it_behaves_like "a sane buildable"
14
- include_examples "no enum"
16
+ it_behaves_like "a buildable"
17
+ it_behaves_like "a sane buildable"
18
+ include_examples "no enum"
15
19
 
16
- context "structure definition" do
17
- let(:comp) do
18
- scalar(:int32)
19
- _c = composite(:foo) do |c|
20
- c.field(:an_int, :int32)
21
- end
20
+ context "structure definition" do
21
+ let(:comp) do
22
+ _c = Cauterize.composite(:foo) do |c|
23
+ c.field(:an_int, :my_int)
24
+ end
22
25
 
23
- Builders.get(:c, _c)
24
- end
26
+ Builders.get(:c, _c)
27
+ end
25
28
 
26
- describe ".struct_proto" do
27
- it "defines a structure prototype" do
28
- f = default_formatter
29
- comp.struct_proto(f)
30
- f.to_s.should == "struct foo;"
29
+ describe ".struct_proto" do
30
+ it "defines a structure prototype" do
31
+ f = default_formatter
32
+ comp.struct_proto(f)
33
+ f.to_s.should == "struct foo;"
34
+ end
31
35
  end
32
- end
33
36
 
34
- describe ".struct_defn" do
35
- it "defines a structure definition" do
36
- f = default_formatter
37
- comp.struct_defn(f)
38
- fs = f.to_s
37
+ describe ".struct_defn" do
38
+ it "defines a structure definition" do
39
+ f = default_formatter
40
+ comp.struct_defn(f)
41
+ fs = f.to_s
39
42
 
40
- fs.should match /struct foo/
41
- fs.should match /int32 an_int;/
42
- fs.should match /};/
43
+ fs.should match /struct foo/
44
+ fs.should match /my_int an_int;/
45
+ fs.should match /};/
46
+ end
43
47
  end
44
48
  end
45
49
  end
@@ -1,32 +1,95 @@
1
- describe Cauterize::Builders::C::Enumeration do
2
- let(:type_constructor) { lambda {|name| enumeration(name)}}
1
+ module Cauterize
2
+ describe Cauterize::Builders::C::Enumeration do
3
+ let(:type_constructor) { lambda {|name|
4
+ Cauterize.enumeration(name) do |t|
5
+ t.value :a, 100
6
+ end
7
+ }}
8
+
9
+ it_behaves_like "a buildable"
10
+ it_behaves_like "a sane buildable"
11
+ include_examples "no struct"
3
12
 
4
- it_behaves_like "a buildable"
5
- it_behaves_like "a sane buildable"
6
- include_examples "no struct"
13
+ describe ".enum_defn" do
14
+ let(:en) do
15
+ _e = Cauterize.enumeration(:foo) do |e|
16
+ e.value :aaa
17
+ e.value :bbb
18
+ e.value "QuickBrownFox".to_sym
19
+ end
7
20
 
8
- describe ".enum_defn" do
9
- let(:en) do
10
- _e = enumeration(:foo) do |e|
11
- e.value :aaa
12
- e.value :bbb
13
- e.value "QuickBrownFox".to_sym
21
+ f = default_formatter
22
+ Builders.get(:c, _e).enum_defn(f)
23
+ f.to_s
14
24
  end
15
25
 
16
- f = default_formatter
17
- Builders.get(:c, _e).enum_defn(f)
18
- f.to_s
26
+ it "contains the enum name" do
27
+ en.should match /enum foo/
28
+ end
29
+
30
+ it "contains an entry for each value" do
31
+ en.should match /AAA = 0,/
32
+ en.should match /BBB = 1,/
33
+ en.should match /QUICK_BROWN_FOX = 2,/
34
+ en.should match /};/
35
+ end
19
36
  end
20
37
 
21
- it "contains the enum name" do
22
- en.should match /enum foo/
38
+ describe ".packer_defn" do
39
+ let(:en0) do
40
+ _e = Cauterize.enumeration(:foo) do |e|
41
+ e.value :aaa
42
+ e.value :bbb
43
+ e.value "QuickBrownFox".to_sym
44
+ end
45
+
46
+ f = default_formatter
47
+ Builders.get(:c, _e).packer_defn(f)
48
+ f.to_s
49
+ end
50
+
51
+ let(:en1) do
52
+ _e = Cauterize.enumeration(:bar) do |e|
53
+ e.value :aaa, 500
54
+ e.value :bbb, -30
55
+ end
56
+
57
+ f = default_formatter
58
+ Builders.get(:c, _e).packer_defn(f)
59
+ f.to_s
60
+ end
61
+
62
+ it "defines a representation variable" do
63
+ en0.should match /int8_t enum_representation;/
64
+ en1.should match /int16_t enum_representation;/
65
+ end
66
+
67
+ it "references a packer for the representation" do
68
+ en0.should match /Pack_int8/
69
+ en1.should match /Pack_int16/
70
+ end
23
71
  end
24
72
 
25
- it "contains an entry for each value" do
26
- en.should match /AAA = 0,/
27
- en.should match /BBB = 1,/
28
- en.should match /QUICK_BROWN_FOX = 2,/
29
- en.should match /};/
73
+ describe ".unpacker_defn" do
74
+ let(:en) do
75
+ _e = Cauterize.enumeration(:foo) do |e|
76
+ e.value :aaa
77
+ e.value :bbb
78
+ e.value "QuickBrownFox".to_sym
79
+ end
80
+
81
+ f = default_formatter
82
+ Builders.get(:c, _e).unpacker_defn(f)
83
+ f.to_s
84
+ end
85
+
86
+ it "defines a representation variable" do
87
+ en.should match /int8_t enum_representation;/
88
+ end
89
+
90
+ it "references a unpacker for the representation" do
91
+ en.should match /Unpack_int8/
92
+ end
30
93
  end
31
94
  end
32
95
  end
@@ -1,8 +1,8 @@
1
1
  describe Cauterize::Builders::C::FixedArray do
2
2
  let(:type_constructor) do
3
- scalar(:uint32_t)
3
+ Cauterize.scalar(:uint32_t)
4
4
  lambda do |name|
5
- fixed_array(name) do |a|
5
+ Cauterize.fixed_array(name) do |a|
6
6
  a.array_type :uint32_t
7
7
  a.array_size 16
8
8
  end
@@ -10,8 +10,8 @@ describe Cauterize::Builders::C::FixedArray do
10
10
  end
11
11
 
12
12
  it_behaves_like "a buildable"
13
+ it_behaves_like "a sane buildable"
13
14
  include_examples "no enum"
14
- include_examples "no struct"
15
15
 
16
16
  context "an array buildable" do
17
17
  let(:desc_instance) { type_constructor.call(:some_type_name) }
@@ -20,8 +20,8 @@ describe Cauterize::Builders::C::FixedArray do
20
20
 
21
21
  describe :render do
22
22
  it "contains the name" do
23
- t_name = subject.instance_variable_get(:@blueprint).array_type.name
24
- subject.render.should match /#{t_name}/
23
+ name = subject.instance_variable_get(:@blueprint).name
24
+ subject.render.should match /#{name}/
25
25
  end
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ describe Cauterize::Builders::C::FixedArray do
29
29
  before { subject.declare(formatter, :some_sym) }
30
30
 
31
31
  it "contains the name and a ;" do
32
- formatter.to_s.should match /uint32_t some_sym\[16\]; \/\* some_type_name \*\//
32
+ formatter.to_s.should match /struct some_type_name some_sym;/
33
33
  end
34
34
  end
35
35
  end
@@ -1,111 +1,118 @@
1
- describe Cauterize::Builders::C::Group do
2
- let(:type_constructor) { lambda {|name| group(name)}}
3
-
4
- it_behaves_like "a buildable"
5
- it_behaves_like "a sane buildable"
6
- include_examples "no enum"
7
-
8
- context "enumeration for type tag" do
9
- before do
10
- scalar(:uint8_t)
11
- @g = group!(:some_name) do |_g|
12
- _g.field(:a, :uint8_t)
13
- _g.field(:b, :uint8_t)
14
- end
15
- @b = Cauterize::Builders::C::Group.new(@g)
16
- end
17
-
18
- describe ".initialize" do
19
- it "creates the enumeration tag" do
20
- @b.instance_variable_get(:@tag_enum).class.name.should == "Cauterize::Enumeration"
21
- end
22
- end
1
+ module Cauterize
2
+ describe Cauterize::Builders::C::Group do
3
+ let(:type_constructor) { lambda {|name| Cauterize.group(name)}}
23
4
 
24
- describe "@tag_enum" do
25
- it "contains a entry for each field in the group" do
26
- e = @b.instance_variable_get(:@tag_enum)
27
- e.values.keys.should =~ [ :GROUP_SOME_NAME_TYPE_A,
28
- :GROUP_SOME_NAME_TYPE_B ]
29
- end
30
- end
5
+ it_behaves_like "a buildable"
6
+ it_behaves_like "a sane buildable"
7
+ include_examples "no enum"
31
8
 
32
- describe ".packer_defn" do
9
+ context "enumeration for type tag" do
33
10
  before do
34
- f = default_formatter
35
- @b.packer_defn(f)
36
- @fs = f.to_s
37
- end
38
-
39
- it "contains the enum packer" do
40
- @fs.should match /Pack_group_some_name_type/
41
- end
42
-
43
- it "contains each tag" do
44
- @fs.should match /GROUP_SOME_NAME_TYPE_A/
45
- @fs.should match /GROUP_SOME_NAME_TYPE_B/
11
+ Cauterize.scalar(:uint8_t)
12
+ @g = Cauterize.group!(:some_name) do |_g|
13
+ _g.field(:a, :uint8_t)
14
+ _g.field(:b, :uint8_t)
15
+ _g.field(:c)
16
+ end
17
+ @b = Cauterize::Builders::C::Group.new(@g)
46
18
  end
47
19
 
48
- it "contains each field" do
49
- @fs.should match /src->data\.a/
50
- @fs.should match /src->data\.b/
51
- end
52
- end
53
-
54
- describe ".unpacker_defn" do
55
- before do
56
- f = default_formatter
57
- @b.unpacker_defn(f)
58
- @fs = f.to_s
20
+ describe ".initialize" do
21
+ it "creates the enumeration tag" do
22
+ @b.instance_variable_get(:@tag_enum).class.name.should == "Cauterize::Enumeration"
23
+ end
59
24
  end
60
25
 
61
- it "contains the enum unpacker" do
62
- @fs.should match /Unpack_group_some_name_type/
26
+ describe "@tag_enum" do
27
+ it "contains a entry for each field in the group" do
28
+ e = @b.instance_variable_get(:@tag_enum)
29
+ e.values.keys.should =~ [ :GROUP_SOME_NAME_TYPE_A,
30
+ :GROUP_SOME_NAME_TYPE_B,
31
+ :GROUP_SOME_NAME_TYPE_C ]
32
+ end
63
33
  end
64
34
 
65
- it "contains each tag" do
66
- @fs.should match /GROUP_SOME_NAME_TYPE_A/
67
- @fs.should match /GROUP_SOME_NAME_TYPE_B/
35
+ describe ".packer_defn" do
36
+ before do
37
+ f = default_formatter
38
+ @b.packer_defn(f)
39
+ @fs = f.to_s
40
+ end
41
+
42
+ it "contains the enum packer" do
43
+ @fs.should match /Pack_group_some_name_type/
44
+ end
45
+
46
+ it "contains each tag" do
47
+ @fs.should match /GROUP_SOME_NAME_TYPE_A/
48
+ @fs.should match /GROUP_SOME_NAME_TYPE_B/
49
+ @fs.should match /GROUP_SOME_NAME_TYPE_C/
50
+ end
51
+
52
+ it "contains each data field" do
53
+ @fs.should match /src->data\.a/
54
+ @fs.should match /src->data\.b/
55
+ end
68
56
  end
69
57
 
70
- it "contains each field" do
71
- @fs.should match /dst->data\.a/
72
- @fs.should match /dst->data\.b/
58
+ describe ".unpacker_defn" do
59
+ before do
60
+ f = default_formatter
61
+ @b.unpacker_defn(f)
62
+ @fs = f.to_s
63
+ end
64
+
65
+ it "contains the enum unpacker" do
66
+ @fs.should match /Unpack_group_some_name_type/
67
+ end
68
+
69
+ it "contains each tag" do
70
+ @fs.should match /GROUP_SOME_NAME_TYPE_A/
71
+ @fs.should match /GROUP_SOME_NAME_TYPE_B/
72
+ @fs.should match /GROUP_SOME_NAME_TYPE_C/
73
+ end
74
+
75
+ it "contains each data field" do
76
+ @fs.should match /dst->data\.a/
77
+ @fs.should match /dst->data\.b/
78
+ end
73
79
  end
74
80
  end
75
- end
76
81
 
77
- context "structure definition" do
78
- let(:grp) do
79
- scalar(:int32)
80
- _g = group(:oof) do |g|
81
- g.field(:aaa, :int32)
82
- g.field(:bbb, :int32)
83
- end
82
+ context "structure definition" do
83
+ let(:grp) do
84
+ _g = Cauterize.group(:oof) do |g|
85
+ g.field(:aaa, :int32)
86
+ g.field(:bbb, :int32)
87
+ g.field(:empty)
88
+ end
84
89
 
85
- Builders.get(:c, _g)
86
- end
90
+ Builders.get(:c, _g)
91
+ end
87
92
 
88
- describe ".struct_proto" do
89
- it "defines a structure prototype" do
90
- f = default_formatter
91
- grp.struct_proto(f)
92
- f.to_s.should == "struct oof;"
93
+ describe ".struct_proto" do
94
+ it "defines a structure prototype" do
95
+ f = default_formatter
96
+ grp.struct_proto(f)
97
+ f.to_s.should == "struct oof;"
98
+ end
93
99
  end
94
- end
95
100
 
96
- describe ".struct_defn" do
97
- it "defines a structure definition" do
98
- f = default_formatter
99
- grp.struct_defn(f)
100
- fs = f.to_s
101
-
102
- fs.should match /struct oof/
103
- fs.should match /enum group_oof_type tag;/
104
- fs.should match /union/
105
- fs.should match /int32 aaa;/
106
- fs.should match /int32 bbb;/
107
- fs.should match /} data;/
108
- fs.should match /};/
101
+ describe ".struct_defn" do
102
+ it "defines a structure definition" do
103
+ f = default_formatter
104
+ grp.struct_defn(f)
105
+ fs = f.to_s
106
+
107
+ fs.should match /struct oof/
108
+ fs.should match /enum group_oof_type tag;/
109
+ fs.should match /union/
110
+ fs.should match /int32_t aaa;/ # built-in types are represented as their C type
111
+ fs.should match /int32_t bbb;/ # built-in types are represented as their C type
112
+ fs.should match /No data associated with 'empty'./
113
+ fs.should match /} data;/
114
+ fs.should match /};/
115
+ end
109
116
  end
110
117
  end
111
118
  end