cauterize 0.0.1.pre1

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 (61) hide show
  1. data/.gitignore +24 -0
  2. data/.rspec +1 -0
  3. data/.travisci.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +152 -0
  7. data/Rakefile +38 -0
  8. data/bin/cauterize +53 -0
  9. data/c/src/cauterize.c +74 -0
  10. data/c/src/cauterize.h +46 -0
  11. data/c/src/cauterize_debug.h +29 -0
  12. data/c/src/cauterize_util.h +7 -0
  13. data/c/test/greatest.h +536 -0
  14. data/c/test/test.c +166 -0
  15. data/cauterize.gemspec +26 -0
  16. data/example/Cauterize +44 -0
  17. data/example/build.sh +4 -0
  18. data/lib/cauterize/base_type.rb +96 -0
  19. data/lib/cauterize/builders.rb +27 -0
  20. data/lib/cauterize/builders/c/buildable.rb +59 -0
  21. data/lib/cauterize/builders/c/composite.rb +55 -0
  22. data/lib/cauterize/builders/c/enumeration.rb +41 -0
  23. data/lib/cauterize/builders/c/fixed_array.rb +62 -0
  24. data/lib/cauterize/builders/c/group.rb +95 -0
  25. data/lib/cauterize/builders/c/scalar.rb +31 -0
  26. data/lib/cauterize/builders/c/variable_array.rb +90 -0
  27. data/lib/cauterize/c_builder.rb +63 -0
  28. data/lib/cauterize/cauterize.rb +33 -0
  29. data/lib/cauterize/composite.rb +50 -0
  30. data/lib/cauterize/enumeration.rb +77 -0
  31. data/lib/cauterize/fixed_array.rb +43 -0
  32. data/lib/cauterize/formatter.rb +59 -0
  33. data/lib/cauterize/group.rb +56 -0
  34. data/lib/cauterize/scalar.rb +38 -0
  35. data/lib/cauterize/snake_case.rb +21 -0
  36. data/lib/cauterize/variable_array.rb +56 -0
  37. data/lib/cauterize/version.rb +3 -0
  38. data/spec/base_type_spec.rb +167 -0
  39. data/spec/builders/c/buildable_spec.rb +25 -0
  40. data/spec/builders/c/composite_spec.rb +46 -0
  41. data/spec/builders/c/enumeration_spec.rb +32 -0
  42. data/spec/builders/c/fixed_array_spec.rb +36 -0
  43. data/spec/builders/c/group_spec.rb +112 -0
  44. data/spec/builders/c/scalar_spec.rb +8 -0
  45. data/spec/builders/c/variable_array_spec.rb +50 -0
  46. data/spec/builders_spec.rb +51 -0
  47. data/spec/c_builder_spec.rb +133 -0
  48. data/spec/cauterize_spec.rb +8 -0
  49. data/spec/composite_spec.rb +62 -0
  50. data/spec/enumeration_spec.rb +104 -0
  51. data/spec/fixed_array_spec.rb +62 -0
  52. data/spec/group_spec.rb +104 -0
  53. data/spec/scalar_spec.rb +36 -0
  54. data/spec/spec_helper.rb +115 -0
  55. data/spec/support/shared_examples_for_array_buildables.rb +22 -0
  56. data/spec/support/shared_examples_for_c_buildables.rb +91 -0
  57. data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -0
  58. data/spec/support/shared_examples_for_stubbed_functions.rb +18 -0
  59. data/spec/test_main.c +13 -0
  60. data/spec/variable_array_spec.rb +92 -0
  61. metadata +212 -0
@@ -0,0 +1,22 @@
1
+ include Cauterize::Builders::C
2
+
3
+ shared_examples "an array buildable" do
4
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
5
+ let(:formatter) { default_formatter }
6
+ subject { described_class.new(desc_instance) }
7
+
8
+ describe :render do
9
+ it "contains the name" do
10
+ t_name = subject.instance_variable_get(:@blueprint).array_type.name
11
+ subject.render.should match /#{t_name}/
12
+ end
13
+ end
14
+
15
+ describe :declare do
16
+ before { subject.declare(formatter, :some_sym) }
17
+
18
+ it "contains the name and a ;" do
19
+ formatter.to_s.should match /uint32_t some_sym\[16\]; \/\* some_type_name \*\//
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,91 @@
1
+ # shared examples for c buildables
2
+
3
+ include Cauterize::Builders::C
4
+
5
+ shared_examples "a buildable" do
6
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
7
+ let(:formatter) { default_formatter }
8
+ let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
9
+ subject { described_class.new(desc_instance) }
10
+
11
+ it "should be registered" do
12
+ builder.class.should be described_class
13
+ end
14
+
15
+ it "errors on duplicate type names" do
16
+ BaseType.class_variable_set(:@@used_names, Set.new([:a_common_name]))
17
+ lambda {
18
+ type_constructor.call(:a_common_name)
19
+ }.should raise_error /already exists/
20
+ end
21
+
22
+ describe :packer_sym do
23
+ it "contains the word Pack" do
24
+ subject.packer_sym.should match /Pack_/
25
+ end
26
+ end
27
+
28
+ describe :packer_sig do
29
+ it "looks like this" do
30
+ r = /CAUTERIZE_STATUS_T (?<sym>[^\(]+)\(struct Cauterize \* dst, (?<rend>(?:(?:struct|enum) )?[^ ]+) \* src\)/
31
+ subject.packer_sig.should match r
32
+ m = subject.packer_sig.match(r)
33
+ m[:sym].should == subject.packer_sym
34
+ m[:rend].should == subject.render
35
+ end
36
+ end
37
+
38
+ describe :packer_proto do
39
+ it "should format the sig + ;" do
40
+ subject.packer_proto(formatter)
41
+ formatter.to_s.should == subject.packer_sig + ";"
42
+ end
43
+ end
44
+
45
+ describe :packer_defn do
46
+ before { subject.packer_defn(formatter) }
47
+
48
+ it "contains the signature" do
49
+ formatter.to_s.should match Regexp.escape(subject.packer_sig)
50
+ end
51
+
52
+ it "contains a return statement" do
53
+ formatter.to_s.should match /return.*;/
54
+ end
55
+ end
56
+
57
+ describe :unpacker_sym do
58
+ it "contains the word Unpack" do
59
+ subject.unpacker_sym.should match /Unpack_/
60
+ end
61
+ end
62
+
63
+ describe :unpacker_sig do
64
+ it "looks like this" do
65
+ r = /CAUTERIZE_STATUS_T (?<sym>[^\(]+)\(struct Cauterize \* src, (?<rend>(?:(?:struct|enum) )?[^ ]+) \* dst\)/
66
+ subject.unpacker_sig.should match r
67
+ m = subject.unpacker_sig.match(r)
68
+ m[:sym].should == subject.unpacker_sym
69
+ m[:rend].should == subject.render
70
+ end
71
+ end
72
+
73
+ describe :unpacker_proto do
74
+ it "should format the sig + ;" do
75
+ subject.unpacker_proto(formatter)
76
+ formatter.to_s.should == subject.unpacker_sig + ";"
77
+ end
78
+ end
79
+
80
+ describe :unpacker_defn do
81
+ before { subject.unpacker_defn(formatter) }
82
+
83
+ it "contains the signature" do
84
+ formatter.to_s.should match Regexp.escape(subject.unpacker_sig)
85
+ end
86
+
87
+ it "contains a return statement" do
88
+ formatter.to_s.should match /return.*;/
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,22 @@
1
+ include Cauterize::Builders::C
2
+
3
+ shared_examples "a sane buildable" do
4
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
5
+ let(:formatter) { default_formatter }
6
+ subject { described_class.new(desc_instance) }
7
+
8
+ describe :render do
9
+ it "contains the name" do
10
+ subject.render.should match /some_type_name/
11
+ end
12
+ end
13
+
14
+ describe :declare do
15
+ before { subject.declare(formatter, :some_sym) }
16
+
17
+ it "contains the name and a ;" do
18
+ formatter.to_s.should match /some_type_name/
19
+ formatter.to_s.should match /;/
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # shared examples for stubbed functions
2
+
3
+ include Cauterize::Builders::C
4
+
5
+ shared_examples "no struct" do
6
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
7
+ let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
8
+
9
+ it { builder.struct_proto(:f).should be_nil }
10
+ it { builder.struct_defn(:f).should be_nil }
11
+ end
12
+
13
+ shared_examples "no enum" do
14
+ let(:desc_instance) { type_constructor.call(:some_type_name) }
15
+ let(:builder) { Cauterize::Builders.get(:c, desc_instance) }
16
+
17
+ it { builder.enum_defn(:f).should be_nil }
18
+ end
data/spec/test_main.c ADDED
@@ -0,0 +1,13 @@
1
+ #include "testing.h"
2
+
3
+ int main(int argc, char * argv[])
4
+ {
5
+ (void)argc;
6
+ (void)argv;
7
+
8
+ void * ptr;
9
+
10
+ ptr = (void *)Pack_enum_group_animal_type;
11
+
12
+ return 0;
13
+ }
@@ -0,0 +1,92 @@
1
+ describe Cauterize do
2
+ before { reset_for_test }
3
+
4
+ describe :variable_array do
5
+ it { creates_a_named_object(:variable_array, VariableArray) }
6
+ it { retrieves_obj_with_identical_name(:variable_array) }
7
+ it { yields_the_object(:variable_array) }
8
+ it { adds_object_to_hash(:variable_array, :variable_arrays) }
9
+ end
10
+
11
+ describe :variable_array! do
12
+ it { creates_a_named_object(:variable_array!, VariableArray) }
13
+ it { raises_exception_with_identical_name(:variable_array!) }
14
+ it { yields_the_object(:variable_array!) }
15
+ it { adds_object_to_hash(:variable_array!, :variable_arrays) }
16
+ end
17
+
18
+ describe :variable_arrays do
19
+ it "is all the variable arrays" do
20
+ variable_array(:a)
21
+ variable_array(:b)
22
+ variable_arrays.values.map(&:name).should == [:a, :b]
23
+ end
24
+ end
25
+
26
+ describe VariableArray do
27
+ before { @a = VariableArray.new(:foo) }
28
+
29
+ describe :initialize do
30
+ it "creates a VariableArray" do
31
+ @a.name.should == :foo
32
+ end
33
+ end
34
+
35
+ describe :array_type do
36
+ it "defines the type of the VariableArray" do
37
+ scalar(:uint32_t)
38
+ @a.array_type :uint32_t
39
+ @a.instance_variable_get(:@array_type).name.should == :uint32_t
40
+ end
41
+
42
+ it "raises an error if type doesn't exist" do
43
+ lambda {
44
+ fixed_array(:fa) do |f|
45
+ f.array_type :lol
46
+ end
47
+ }.should raise_error /lol does not correspond/
48
+ end
49
+
50
+ it "is the defined type if no argument is passed" do
51
+ s = scalar(:uint32_t)
52
+ @a.array_type :uint32_t
53
+ @a.array_type.should be s
54
+ end
55
+ end
56
+
57
+ describe :array_size do
58
+ it "Defines the size of the FixedArray." do
59
+ @a.array_size 46
60
+ @a.instance_variable_get(:@array_size).should == 46
61
+ end
62
+
63
+ it "is the defined size if no argument is passed" do
64
+ @a.array_size 46
65
+ @a.array_size.should == 46
66
+ end
67
+ end
68
+
69
+ describe :size_type do
70
+ it "defines the type to use to encode the array size" do
71
+ scalar(:uint16_t)
72
+ @a.size_type :uint16_t
73
+ @a.instance_variable_get(:@size_type).name.should == :uint16_t
74
+ end
75
+
76
+ it "raises an error if the type doesn't eixst" do
77
+ lambda { @a.size_type :uintLOL_t }.should raise_error /does not correspond to a type/
78
+ end
79
+
80
+ it "raises an error if the type isn't an scalar" do
81
+ enumeration(:lol)
82
+ lambda { @a.size_type :lol }.should raise_error /is not an scalar/
83
+ end
84
+
85
+ it "is the defined type if no argument is passed" do
86
+ s = scalar(:uint32_t)
87
+ @a.size_type :uint32_t
88
+ @a.size_type.should be s
89
+ end
90
+ end
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cauterize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - John Van Enk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: thor
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.16.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.16.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: require_all
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.13.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.13.0
94
+ description: Tools to generate C structures and marshalers with a Ruby DSL.
95
+ email:
96
+ - vanenkj@gmail.com
97
+ executables:
98
+ - cauterize
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .rspec
104
+ - .travisci.yml
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - bin/cauterize
110
+ - c/src/cauterize.c
111
+ - c/src/cauterize.h
112
+ - c/src/cauterize_debug.h
113
+ - c/src/cauterize_util.h
114
+ - c/test/greatest.h
115
+ - c/test/test.c
116
+ - cauterize.gemspec
117
+ - example/Cauterize
118
+ - example/build.sh
119
+ - lib/cauterize/base_type.rb
120
+ - lib/cauterize/builders.rb
121
+ - lib/cauterize/builders/c/buildable.rb
122
+ - lib/cauterize/builders/c/composite.rb
123
+ - lib/cauterize/builders/c/enumeration.rb
124
+ - lib/cauterize/builders/c/fixed_array.rb
125
+ - lib/cauterize/builders/c/group.rb
126
+ - lib/cauterize/builders/c/scalar.rb
127
+ - lib/cauterize/builders/c/variable_array.rb
128
+ - lib/cauterize/c_builder.rb
129
+ - lib/cauterize/cauterize.rb
130
+ - lib/cauterize/composite.rb
131
+ - lib/cauterize/enumeration.rb
132
+ - lib/cauterize/fixed_array.rb
133
+ - lib/cauterize/formatter.rb
134
+ - lib/cauterize/group.rb
135
+ - lib/cauterize/scalar.rb
136
+ - lib/cauterize/snake_case.rb
137
+ - lib/cauterize/variable_array.rb
138
+ - lib/cauterize/version.rb
139
+ - spec/base_type_spec.rb
140
+ - spec/builders/c/buildable_spec.rb
141
+ - spec/builders/c/composite_spec.rb
142
+ - spec/builders/c/enumeration_spec.rb
143
+ - spec/builders/c/fixed_array_spec.rb
144
+ - spec/builders/c/group_spec.rb
145
+ - spec/builders/c/scalar_spec.rb
146
+ - spec/builders/c/variable_array_spec.rb
147
+ - spec/builders_spec.rb
148
+ - spec/c_builder_spec.rb
149
+ - spec/cauterize_spec.rb
150
+ - spec/composite_spec.rb
151
+ - spec/enumeration_spec.rb
152
+ - spec/fixed_array_spec.rb
153
+ - spec/group_spec.rb
154
+ - spec/scalar_spec.rb
155
+ - spec/spec_helper.rb
156
+ - spec/support/shared_examples_for_array_buildables.rb
157
+ - spec/support/shared_examples_for_c_buildables.rb
158
+ - spec/support/shared_examples_for_sane_c_buildables.rb
159
+ - spec/support/shared_examples_for_stubbed_functions.rb
160
+ - spec/test_main.c
161
+ - spec/variable_array_spec.rb
162
+ homepage: https://github.com/sw17ch/cauterize
163
+ licenses: []
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ segments:
175
+ - 0
176
+ hash: -3059868182157898473
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>'
181
+ - !ruby/object:Gem::Version
182
+ version: 1.3.1
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 1.8.24
186
+ signing_key:
187
+ specification_version: 3
188
+ summary: Tools to generate structures and mashalers suitable for static-memory environments.
189
+ test_files:
190
+ - spec/base_type_spec.rb
191
+ - spec/builders/c/buildable_spec.rb
192
+ - spec/builders/c/composite_spec.rb
193
+ - spec/builders/c/enumeration_spec.rb
194
+ - spec/builders/c/fixed_array_spec.rb
195
+ - spec/builders/c/group_spec.rb
196
+ - spec/builders/c/scalar_spec.rb
197
+ - spec/builders/c/variable_array_spec.rb
198
+ - spec/builders_spec.rb
199
+ - spec/c_builder_spec.rb
200
+ - spec/cauterize_spec.rb
201
+ - spec/composite_spec.rb
202
+ - spec/enumeration_spec.rb
203
+ - spec/fixed_array_spec.rb
204
+ - spec/group_spec.rb
205
+ - spec/scalar_spec.rb
206
+ - spec/spec_helper.rb
207
+ - spec/support/shared_examples_for_array_buildables.rb
208
+ - spec/support/shared_examples_for_c_buildables.rb
209
+ - spec/support/shared_examples_for_sane_c_buildables.rb
210
+ - spec/support/shared_examples_for_stubbed_functions.rb
211
+ - spec/test_main.c
212
+ - spec/variable_array_spec.rb