cauterize 0.0.1.pre5 → 0.0.1.pre7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/Rakefile +1 -1
- data/bin/cauterize +1 -1
- data/cauterize.gemspec +1 -0
- data/example/Cauterize +15 -9
- data/example/build.sh +3 -0
- data/example/doc_cauterize_output/example_project.txt +124 -0
- data/example/ruby_ex.rb +14 -0
- data/lib/cauterize.rb +117 -0
- data/lib/cauterize/base_type.rb +3 -2
- data/lib/cauterize/builders.rb +18 -2
- data/lib/cauterize/builders/c/group.rb +2 -3
- data/lib/cauterize/builders/cs/group.rb +2 -3
- data/lib/cauterize/builders/doc/buildable.rb +30 -0
- data/lib/cauterize/builders/doc/builtin.rb +21 -0
- data/lib/cauterize/builders/doc/composite.rb +23 -0
- data/lib/cauterize/builders/doc/enumeration.rb +24 -0
- data/lib/cauterize/builders/doc/fixed_array.rb +26 -0
- data/lib/cauterize/builders/doc/group.rb +29 -0
- data/lib/cauterize/builders/doc/scalar.rb +21 -0
- data/lib/cauterize/builders/doc/variable_array.rb +26 -0
- data/lib/cauterize/builtin.rb +2 -2
- data/lib/cauterize/c_builder.rb +5 -0
- data/lib/cauterize/cauterize.rb +7 -2
- data/lib/cauterize/composite.rb +8 -7
- data/lib/cauterize/cs_builder.rb +8 -5
- data/lib/cauterize/doc_builder.rb +34 -0
- data/lib/cauterize/enumeration.rb +5 -5
- data/lib/cauterize/fixed_array.rb +3 -3
- data/lib/cauterize/group.rb +18 -8
- data/lib/cauterize/scalar.rb +3 -3
- data/lib/cauterize/variable_array.rb +3 -3
- data/lib/cauterize/version.rb +1 -1
- data/spec/base_type_spec.rb +10 -0
- data/spec/builders/c/group_spec.rb +2 -2
- data/spec/builders/cs/group_spec.rb +1 -1
- data/spec/builders/doc/buildable_spec.rb +25 -0
- data/spec/builders_spec.rb +4 -2
- data/spec/builtin_spec.rb +2 -0
- data/spec/c_builder_spec.rb +12 -3
- data/spec/composite_spec.rb +11 -0
- data/spec/cs_builder_spec.rb +6 -2
- data/spec/doc_builder_spec.rb +247 -0
- data/spec/enumeration_spec.rb +2 -0
- data/spec/fixed_array_spec.rb +2 -0
- data/spec/group_spec.rb +4 -2
- data/spec/scalar_spec.rb +2 -0
- data/spec/spec_helper.rb +4 -0
- data/support/c/src/cauterize.h +1 -1
- data/support/cs/src/CauterizeFormatter.cs +7 -5
- data/support/cs/src/CauterizeTypes.cs +45 -5
- metadata +50 -18
data/lib/cauterize/scalar.rb
CHANGED
@@ -8,8 +8,8 @@
|
|
8
8
|
module Cauterize
|
9
9
|
module_function
|
10
10
|
|
11
|
-
def scalar(name)
|
12
|
-
a = Cauterize.scalars[name] || Cauterize.scalars[name] = Scalar.new(name)
|
11
|
+
def scalar(name, desc=nil)
|
12
|
+
a = Cauterize.scalars[name] || Cauterize.scalars[name] = Scalar.new(name, desc)
|
13
13
|
yield a if block_given?
|
14
14
|
return a
|
15
15
|
end
|
@@ -27,7 +27,7 @@ module Cauterize
|
|
27
27
|
end
|
28
28
|
|
29
29
|
class Scalar < BaseType
|
30
|
-
def initialize(name)
|
30
|
+
def initialize(name, desc=nil)
|
31
31
|
super
|
32
32
|
end
|
33
33
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Cauterize
|
2
2
|
module_function
|
3
3
|
|
4
|
-
def variable_array(name)
|
5
|
-
a = Cauterize.variable_arrays[name] || Cauterize.variable_arrays[name] = VariableArray.new(name)
|
4
|
+
def variable_array(name, desc=nil)
|
5
|
+
a = Cauterize.variable_arrays[name] || Cauterize.variable_arrays[name] = VariableArray.new(name, desc)
|
6
6
|
yield a if block_given?
|
7
7
|
return a
|
8
8
|
end
|
@@ -20,7 +20,7 @@ module Cauterize
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class VariableArray < BaseType
|
23
|
-
def intialize(name)
|
23
|
+
def intialize(name, desc=nil)
|
24
24
|
super
|
25
25
|
end
|
26
26
|
|
data/lib/cauterize/version.rb
CHANGED
data/spec/base_type_spec.rb
CHANGED
@@ -6,6 +6,16 @@ module Cauterize
|
|
6
6
|
it { has_a_unique_id_for_each_instance(BaseType) }
|
7
7
|
end
|
8
8
|
|
9
|
+
describe :description do
|
10
|
+
it "handles nil description" do
|
11
|
+
BaseType.new(:foo, nil).description.should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "sets the description" do
|
15
|
+
BaseType.new(:foo, "a desc").description.should == "a desc"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
9
19
|
describe :type_str do
|
10
20
|
it "is the hexadecimal representation of type" do
|
11
21
|
f = Cauterize.enumeration(:foo) do |e|
|
@@ -12,7 +12,7 @@ module Cauterize
|
|
12
12
|
@g = Cauterize.group!(:some_name) do |_g|
|
13
13
|
_g.field(:a, :uint8_t)
|
14
14
|
_g.field(:b, :uint8_t)
|
15
|
-
_g.
|
15
|
+
_g.dataless(:c)
|
16
16
|
end
|
17
17
|
@b = Cauterize::Builders::C::Group.new(@g)
|
18
18
|
end
|
@@ -84,7 +84,7 @@ module Cauterize
|
|
84
84
|
_g = Cauterize.group(:oof) do |g|
|
85
85
|
g.field(:aaa, :int32)
|
86
86
|
g.field(:bbb, :int32)
|
87
|
-
g.
|
87
|
+
g.dataless(:empty)
|
88
88
|
end
|
89
89
|
|
90
90
|
Builders.get(:c, _g)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cauterize::Builders::Doc
|
2
|
+
describe Cauterize::Builders::Doc do
|
3
|
+
describe Buildable do
|
4
|
+
subject { Buildable.new(:some_blueprint) }
|
5
|
+
|
6
|
+
describe "required methods" do
|
7
|
+
it "raises errorson 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
|
+
end
|
15
|
+
|
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
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/builders_spec.rb
CHANGED
@@ -43,8 +43,10 @@ module Cauterize
|
|
43
43
|
}.should raise_error /already registered/
|
44
44
|
end
|
45
45
|
|
46
|
-
it "
|
47
|
-
|
46
|
+
it "raises exception no builder is registered" do
|
47
|
+
lambda {
|
48
|
+
Cauterize::Builders.get(:c, s)
|
49
|
+
}.should raise_error Cauterize::Builders::UnregisteredException
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
data/spec/builtin_spec.rb
CHANGED
data/spec/c_builder_spec.rb
CHANGED
@@ -77,6 +77,10 @@ module Cauterize
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "header generation" do
|
80
|
+
it "informs the user the code is generated" do
|
81
|
+
@h_text.should include("generated code. Do not edit")
|
82
|
+
end
|
83
|
+
|
80
84
|
it "externs 'c'" do
|
81
85
|
@h_lines.should include("extern \"C\" {\n")
|
82
86
|
end
|
@@ -90,9 +94,10 @@ module Cauterize
|
|
90
94
|
end
|
91
95
|
|
92
96
|
it "prevents multiple inclusion in headers" do
|
93
|
-
@h_lines[
|
94
|
-
@h_lines[
|
95
|
-
@h_lines.
|
97
|
+
@h_lines[2].should match /#ifndef TESTING_H_\d+/
|
98
|
+
@h_lines[3].should match /#define TESTING_H_\d+/
|
99
|
+
@h_lines[-2].should match /#endif \/\* TESTING_H_\d+ \*\//
|
100
|
+
@h_lines.last.should == "\n"
|
96
101
|
end
|
97
102
|
|
98
103
|
it "includes prototype information for all defined types" do
|
@@ -109,6 +114,10 @@ module Cauterize
|
|
109
114
|
end
|
110
115
|
|
111
116
|
describe "c body generation" do
|
117
|
+
it "informs the user the code is generated" do
|
118
|
+
@c_text.should include("generated code. Do not edit")
|
119
|
+
end
|
120
|
+
|
112
121
|
it "includes the generated header file" do
|
113
122
|
@c_text.should match /#include "testing.h"/
|
114
123
|
end
|
data/spec/composite_spec.rb
CHANGED
@@ -20,6 +20,8 @@ module Cauterize
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
it { can_be_documented(Composite) }
|
24
|
+
|
23
25
|
describe :fields do
|
24
26
|
it "defines a new field in the composite" do
|
25
27
|
a = Cauterize.scalar(:foo)
|
@@ -32,6 +34,15 @@ module Cauterize
|
|
32
34
|
comp.fields.values[0].type.should be a
|
33
35
|
end
|
34
36
|
|
37
|
+
it "supports a doc string" do
|
38
|
+
a = Cauterize.scalar(:foo)
|
39
|
+
comp = Cauterize.composite(:comp) do |c|
|
40
|
+
c.field :a_foo, :foo, "some foo"
|
41
|
+
end
|
42
|
+
|
43
|
+
comp.fields.values[0].description.should == "some foo"
|
44
|
+
end
|
45
|
+
|
35
46
|
it "errors on duplicate field names" do
|
36
47
|
a = Cauterize.scalar(:foo)
|
37
48
|
lambda {
|
data/spec/cs_builder_spec.rb
CHANGED
@@ -70,6 +70,10 @@ module Cauterize
|
|
70
70
|
@cs_lines = @cs_text.lines.to_a
|
71
71
|
end
|
72
72
|
|
73
|
+
it "informs the user the code is generated" do
|
74
|
+
@cs_text.should match /generated code. Do not edit/
|
75
|
+
end
|
76
|
+
|
73
77
|
it "includes namespaces" do
|
74
78
|
@cs_lines.should include("using System;\n")
|
75
79
|
@cs_lines.should include("using Cauterize;\n")
|
@@ -80,8 +84,8 @@ module Cauterize
|
|
80
84
|
end
|
81
85
|
|
82
86
|
it "creates a cauterize info class with version and date" do
|
83
|
-
@cs_text.should match /Name = \"Testing\"
|
84
|
-
@cs_text.should match /GeneratedVersion = \"1.2.3\"
|
87
|
+
@cs_text.should match /Name = \"Testing\",/
|
88
|
+
@cs_text.should match /GeneratedVersion = \"1.2.3\",/
|
85
89
|
@cs_text.should match /GeneratedDate = /
|
86
90
|
end
|
87
91
|
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Cauterize
|
5
|
+
describe Cauterize::DocBuilder do
|
6
|
+
before do
|
7
|
+
@tempdir = Dir.mktmpdir
|
8
|
+
@doc_path = File.join(@tempdir, "testing.txt")
|
9
|
+
|
10
|
+
@db = DocBuilder.new(@doc_path, "testing")
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
FileUtils.rm_rf @tempdir
|
15
|
+
end
|
16
|
+
|
17
|
+
describe :initialize do
|
18
|
+
it "should save the name" do
|
19
|
+
@db.name.should == "testing"
|
20
|
+
@db.doc_path.should == @doc_path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :build do
|
25
|
+
before do
|
26
|
+
Cauterize.set_version("1.2.3")
|
27
|
+
|
28
|
+
Cauterize.scalar(:an_int, "a useful int") {|t| t.type_name :int32}
|
29
|
+
Cauterize.scalar(:another_int) {|t| t.type_name :int32}
|
30
|
+
|
31
|
+
Cauterize.composite(:a_composite, "some useful fields") do |t|
|
32
|
+
t.field :an_int, :int32, "a pretty integer"
|
33
|
+
t.field :another_int, :int32, "another pretty integer"
|
34
|
+
t.field :undescribed, :int32
|
35
|
+
end
|
36
|
+
|
37
|
+
Cauterize.composite(:mystery) do |t|
|
38
|
+
t.field :undescribed, :int32
|
39
|
+
end
|
40
|
+
|
41
|
+
Cauterize.fixed_array(:a_fixed_array, "a few things") do |t|
|
42
|
+
t.array_type :an_int
|
43
|
+
t.array_size 5
|
44
|
+
end
|
45
|
+
|
46
|
+
Cauterize.fixed_array(:a_mystery_array) do |t|
|
47
|
+
t.array_type :uint8
|
48
|
+
t.array_size 1
|
49
|
+
end
|
50
|
+
|
51
|
+
Cauterize.variable_array(:a_var_array, "maybe some things") do |t|
|
52
|
+
t.array_type :an_int
|
53
|
+
t.array_size 5
|
54
|
+
t.size_type :uint8
|
55
|
+
end
|
56
|
+
|
57
|
+
Cauterize.variable_array(:a_var_mystery) do |t|
|
58
|
+
t.array_type :uint8
|
59
|
+
t.array_size 1
|
60
|
+
t.size_type :uint8
|
61
|
+
end
|
62
|
+
|
63
|
+
Cauterize.enumeration(:some_colors, "several colors to choose from") do |t|
|
64
|
+
t.value :red
|
65
|
+
t.value :blue
|
66
|
+
t.value :green
|
67
|
+
end
|
68
|
+
|
69
|
+
Cauterize.enumeration(:mystery_things) do |t|
|
70
|
+
t.value :thing1
|
71
|
+
t.value :thing2
|
72
|
+
t.value :thing3
|
73
|
+
end
|
74
|
+
|
75
|
+
Cauterize.group(:oddness, "a mix of weird things") do |t|
|
76
|
+
t.field :a_color, :some_colors, "a color"
|
77
|
+
t.field :a_cool_int, :int16, "only cool ints fit here"
|
78
|
+
t.dataless :a_thing, "only a thing"
|
79
|
+
t.dataless :undescribed
|
80
|
+
end
|
81
|
+
|
82
|
+
Cauterize.group(:mystery_oddness) do |t|
|
83
|
+
t.field :a_color, :some_colors
|
84
|
+
t.field :a_cool_int, :int16
|
85
|
+
t.dataless :a_thing, "only a thing"
|
86
|
+
t.dataless :undescribed
|
87
|
+
end
|
88
|
+
|
89
|
+
@db.build
|
90
|
+
@doc_text = File.read(@doc_path)
|
91
|
+
@doc_lines = @doc_text.lines.to_a
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "doc generation" do
|
95
|
+
it "contains type details" do
|
96
|
+
t = <<EOF
|
97
|
+
Type Name: int8
|
98
|
+
Cauterize Class: built-in
|
99
|
+
Description: <none>
|
100
|
+
data - size: 1 bytes
|
101
|
+
|
102
|
+
Type Name: int16
|
103
|
+
Cauterize Class: built-in
|
104
|
+
Description: <none>
|
105
|
+
data - size: 2 bytes
|
106
|
+
|
107
|
+
Type Name: int32
|
108
|
+
Cauterize Class: built-in
|
109
|
+
Description: <none>
|
110
|
+
data - size: 4 bytes
|
111
|
+
|
112
|
+
Type Name: int64
|
113
|
+
Cauterize Class: built-in
|
114
|
+
Description: <none>
|
115
|
+
data - size: 8 bytes
|
116
|
+
|
117
|
+
Type Name: uint8
|
118
|
+
Cauterize Class: built-in
|
119
|
+
Description: <none>
|
120
|
+
data - size: 1 bytes
|
121
|
+
|
122
|
+
Type Name: uint16
|
123
|
+
Cauterize Class: built-in
|
124
|
+
Description: <none>
|
125
|
+
data - size: 2 bytes
|
126
|
+
|
127
|
+
Type Name: uint32
|
128
|
+
Cauterize Class: built-in
|
129
|
+
Description: <none>
|
130
|
+
data - size: 4 bytes
|
131
|
+
|
132
|
+
Type Name: uint64
|
133
|
+
Cauterize Class: built-in
|
134
|
+
Description: <none>
|
135
|
+
data - size: 8 bytes
|
136
|
+
|
137
|
+
Type Name: an_int
|
138
|
+
Cauterize Class: scalar
|
139
|
+
Description: - a useful int
|
140
|
+
data - type: int32
|
141
|
+
|
142
|
+
Type Name: another_int
|
143
|
+
Cauterize Class: scalar
|
144
|
+
Description: <none>
|
145
|
+
data - type: int32
|
146
|
+
|
147
|
+
Type Name: a_composite
|
148
|
+
Cauterize Class: composite
|
149
|
+
Description: some useful fields
|
150
|
+
an_int - type: int32 - description: a pretty integer
|
151
|
+
another_int - type: int32 - description: another pretty integer
|
152
|
+
undescribed - type: int32
|
153
|
+
|
154
|
+
Type Name: mystery
|
155
|
+
Cauterize Class: composite
|
156
|
+
Description: <none>
|
157
|
+
undescribed - type: int32
|
158
|
+
|
159
|
+
Type Name: a_fixed_array
|
160
|
+
Cauterize Class: fixed-array
|
161
|
+
Description: a few things
|
162
|
+
Stored Type: an_int
|
163
|
+
Value Count: 5
|
164
|
+
data - 5 values of type an_int
|
165
|
+
|
166
|
+
Type Name: a_mystery_array
|
167
|
+
Cauterize Class: fixed-array
|
168
|
+
Description: <none>
|
169
|
+
Stored Type: uint8
|
170
|
+
Value Count: 1
|
171
|
+
data - 1 values of type uint8
|
172
|
+
|
173
|
+
Type Name: a_var_array
|
174
|
+
Cauterize Class: variable-array
|
175
|
+
Description: maybe some things
|
176
|
+
Maximum Value Count: 5
|
177
|
+
length - type uint8
|
178
|
+
data - 0 to 5 values of type an_int
|
179
|
+
|
180
|
+
Type Name: a_var_mystery
|
181
|
+
Cauterize Class: variable-array
|
182
|
+
Description: <none>
|
183
|
+
Maximum Value Count: 1
|
184
|
+
length - type uint8
|
185
|
+
data - 0 to 1 values of type uint8
|
186
|
+
|
187
|
+
Type Name: some_colors
|
188
|
+
Cauterize Class: enumeration
|
189
|
+
Description: several colors to choose from
|
190
|
+
Encoding: int8
|
191
|
+
red = 0
|
192
|
+
blue = 1
|
193
|
+
green = 2
|
194
|
+
|
195
|
+
Type Name: mystery_things
|
196
|
+
Cauterize Class: enumeration
|
197
|
+
Description: <none>
|
198
|
+
Encoding: int8
|
199
|
+
thing1 = 0
|
200
|
+
thing2 = 1
|
201
|
+
thing3 = 2
|
202
|
+
|
203
|
+
Type Name: group_oddness_type
|
204
|
+
Cauterize Class: enumeration
|
205
|
+
Description: <none>
|
206
|
+
Encoding: int8
|
207
|
+
GROUP_ODDNESS_TYPE_A_COLOR = 0
|
208
|
+
GROUP_ODDNESS_TYPE_A_COOL_INT = 1
|
209
|
+
GROUP_ODDNESS_TYPE_A_THING = 2
|
210
|
+
GROUP_ODDNESS_TYPE_UNDESCRIBED = 3
|
211
|
+
|
212
|
+
Type Name: oddness
|
213
|
+
Cauterize Class: group
|
214
|
+
Description: a mix of weird things
|
215
|
+
kind tag: group_oddness_type
|
216
|
+
kinds:
|
217
|
+
a_color - payload: some_colors - description: a color
|
218
|
+
a_cool_int - payload: int16 - description: only cool ints fit here
|
219
|
+
a_thing - payload: <no payload> - description: only a thing
|
220
|
+
undescribed - payload: <no payload>
|
221
|
+
|
222
|
+
Type Name: group_mystery_oddness_type
|
223
|
+
Cauterize Class: enumeration
|
224
|
+
Description: <none>
|
225
|
+
Encoding: int8
|
226
|
+
GROUP_MYSTERY_ODDNESS_TYPE_A_COLOR = 0
|
227
|
+
GROUP_MYSTERY_ODDNESS_TYPE_A_COOL_INT = 1
|
228
|
+
GROUP_MYSTERY_ODDNESS_TYPE_A_THING = 2
|
229
|
+
GROUP_MYSTERY_ODDNESS_TYPE_UNDESCRIBED = 3
|
230
|
+
|
231
|
+
Type Name: mystery_oddness
|
232
|
+
Cauterize Class: group
|
233
|
+
Description: <none>
|
234
|
+
kind tag: group_mystery_oddness_type
|
235
|
+
kinds:
|
236
|
+
a_color - payload: some_colors
|
237
|
+
a_cool_int - payload: int16
|
238
|
+
a_thing - payload: <no payload> - description: only a thing
|
239
|
+
undescribed - payload: <no payload>
|
240
|
+
EOF
|
241
|
+
@doc_text.should == t
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|