cauterize 0.0.1.pre12 → 0.0.1.pre13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/example/Cauterize +0 -2
- data/lib/cauterize/builders/c/buildable.rb +7 -0
- data/lib/cauterize/builders/c/builtin.rb +4 -0
- data/lib/cauterize/builders/c/composite.rb +8 -0
- data/lib/cauterize/builders/c/enumeration.rb +8 -4
- data/lib/cauterize/builders/c/fixed_array.rb +11 -2
- data/lib/cauterize/builders/c/group.rb +26 -1
- data/lib/cauterize/builders/c/scalar.rb +4 -0
- data/lib/cauterize/builders/c/variable_array.rb +17 -3
- data/lib/cauterize/builders/cs/builtin.rb +1 -1
- data/lib/cauterize/builders/cs/fixed_array.rb +3 -1
- data/lib/cauterize/builders/ruby/builtin.rb +1 -1
- data/lib/cauterize/builders/ruby/composite.rb +10 -7
- data/lib/cauterize/builders/ruby/enumeration.rb +9 -9
- data/lib/cauterize/builders/ruby/fixed_array.rb +4 -4
- data/lib/cauterize/builders/ruby/group.rb +9 -9
- data/lib/cauterize/builders/ruby/scalar.rb +3 -3
- data/lib/cauterize/builders/ruby/variable_array.rb +5 -5
- data/lib/cauterize/c_builder.rb +6 -0
- data/lib/cauterize/enumeration.rb +4 -14
- data/lib/cauterize/representation.rb +32 -0
- data/lib/cauterize/ruby_builder.rb +7 -5
- data/lib/cauterize/variable_array.rb +3 -12
- data/lib/cauterize/version.rb +1 -1
- data/spec/base_type_spec.rb +2 -2
- data/spec/builders/c/group_spec.rb +21 -0
- data/spec/builders/c/variable_array_spec.rb +2 -4
- data/spec/builders/cs/fixed_array_spec.rb +2 -1
- data/spec/builders/cs/variable_array_spec.rb +0 -1
- data/spec/c_builder_spec.rb +22 -2
- data/spec/cs_builder_spec.rb +0 -2
- data/spec/doc_builder_spec.rb +0 -2
- data/spec/ruby_builder_spec.rb +5 -2
- data/spec/ruby_generated_spec.rb +735 -0
- data/spec/support/spec_sample_model.rb +1 -3
- data/spec/variable_array_spec.rb +5 -19
- data/support/cs/src/CauterizeFixedArrayFormatter.cs +27 -9
- data/support/cs/src/CauterizeVariableArrayFormatter.cs +28 -11
- data/support/ruby/src/cauterize_ruby_baseclasses.rb +297 -176
- data/support/ruby/src/cauterize_ruby_builtins.rb +121 -95
- metadata +25 -39
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8dc3160a85139642df941d4afd5e3e7bbac2b32b
|
4
|
+
data.tar.gz: 827cf33e36a85a7acf94e0c92418e4a5ece5b419
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f4311c1ca2b228a9cad06b595756f57e40327fdba18664b8419770c91e7f2b1fd95aa1cb0a7b94e66b7f8007d1cbd2aeea19a41209197ece8bf7da8c082b9dd
|
7
|
+
data.tar.gz: c32033d4dfd4575cc11ff4dda714211df2cbf46b552903a69659278b90f8ee049bf3f2ef4191da363f4664f2e115a8aa4dd143a401c2017b34233c19cd8edfd7
|
data/.gitignore
CHANGED
data/example/Cauterize
CHANGED
@@ -5,7 +5,6 @@ scalar(:bigint) { |t| t.type_name(:int32) }
|
|
5
5
|
scalar(:usmallint) { |t| t.type_name(:uint8) }
|
6
6
|
|
7
7
|
variable_array(:uint8_buffer) do |a|
|
8
|
-
a.size_type :uint8
|
9
8
|
a.array_type :uint8
|
10
9
|
a.array_size 128
|
11
10
|
end
|
@@ -37,7 +36,6 @@ fixed_array(:color_list_list) do |a|
|
|
37
36
|
end
|
38
37
|
|
39
38
|
variable_array(:numbers) do |a|
|
40
|
-
a.size_type :usmallint
|
41
39
|
a.array_type :bigint
|
42
40
|
a.array_size 128
|
43
41
|
end
|
@@ -57,6 +57,12 @@ module Cauterize
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
# This is the symbol used to define the maximum encoded length of any type
|
61
|
+
##########################################################################
|
62
|
+
def max_enc_len_cpp_sym
|
63
|
+
"MAX_ENCODED_LENGTH_#{@blueprint.name}"
|
64
|
+
end
|
65
|
+
|
60
66
|
# Things below here are tested in shared_examples_for_c_buildables #
|
61
67
|
####################################################################
|
62
68
|
|
@@ -74,6 +80,7 @@ module Cauterize
|
|
74
80
|
end
|
75
81
|
|
76
82
|
# These are only different in a few type varieties.
|
83
|
+
def preprocessor_defines(formatter); nil end
|
77
84
|
def typedef_decl(formatter); nil end
|
78
85
|
def struct_proto(formatter); nil end
|
79
86
|
def struct_defn(formatter); nil end
|
@@ -17,6 +17,10 @@ module Cauterize
|
|
17
17
|
formatter << "#{render} #{sym};"
|
18
18
|
end
|
19
19
|
|
20
|
+
def preprocessor_defines(formatter)
|
21
|
+
formatter << "#define #{max_enc_len_cpp_sym} sizeof(#{render_ctype})"
|
22
|
+
end
|
23
|
+
|
20
24
|
# These are identical to the Scalar definitions. For now.
|
21
25
|
def packer_defn(formatter)
|
22
26
|
formatter << "return CauterizeAppend(dst, (uint8_t*)src, sizeof(*src));"
|
@@ -10,6 +10,14 @@ module Cauterize
|
|
10
10
|
formatter << "#{render} #{sym};"
|
11
11
|
end
|
12
12
|
|
13
|
+
def preprocessor_defines(formatter)
|
14
|
+
field_lens = @blueprint.fields.values.map do |field|
|
15
|
+
Builders.get(:c, field.type).max_enc_len_cpp_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
formatter << "#define #{max_enc_len_cpp_sym} (#{field_lens.join(" + ")})"
|
19
|
+
end
|
20
|
+
|
13
21
|
def packer_defn(formatter)
|
14
22
|
formatter << "CAUTERIZE_STATUS_T err;"
|
15
23
|
@blueprint.fields.values.each do |field|
|
@@ -10,9 +10,11 @@ module Cauterize
|
|
10
10
|
formatter << "#{render} #{sym};"
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def preprocessor_defines(formatter)
|
14
|
+
formatter << "#define #{max_enc_len_cpp_sym} (#{rep_builder.max_enc_len_cpp_sym})"
|
15
|
+
end
|
15
16
|
|
17
|
+
def packer_defn(formatter)
|
16
18
|
rep = "enum_representation"
|
17
19
|
rep_builder.declare(formatter, rep)
|
18
20
|
|
@@ -21,8 +23,6 @@ module Cauterize
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def unpacker_defn(formatter)
|
24
|
-
rep_builder = Builders.get(:c, @blueprint.representation)
|
25
|
-
|
26
26
|
rep = "enum_representation"
|
27
27
|
rep_builder.declare(formatter, rep)
|
28
28
|
|
@@ -48,6 +48,10 @@ module Cauterize
|
|
48
48
|
end
|
49
49
|
formatter.append(";")
|
50
50
|
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def rep_builder; Builders.get(:c, @blueprint.representation) end
|
51
55
|
end
|
52
56
|
end
|
53
57
|
end
|
@@ -10,13 +10,18 @@ module Cauterize
|
|
10
10
|
formatter << "#{render} #{sym};"
|
11
11
|
end
|
12
12
|
|
13
|
+
def preprocessor_defines(formatter)
|
14
|
+
formatter << "#define #{length_sym} (#{@blueprint.array_size})"
|
15
|
+
formatter << "#define #{max_enc_len_cpp_sym} (#{length_sym} * #{ty_bldr.max_enc_len_cpp_sym})"
|
16
|
+
end
|
17
|
+
|
13
18
|
def packer_defn(formatter)
|
14
19
|
formatter << "CAUTERIZE_STATUS_T err;"
|
15
20
|
formatter << "size_t i;"
|
16
21
|
formatter.blank_line
|
17
22
|
|
18
23
|
# store each used item in the array
|
19
|
-
formatter << "for (i = 0; i < #{
|
24
|
+
formatter << "for (i = 0; i < #{length_sym}; i++)"
|
20
25
|
formatter.braces do
|
21
26
|
formatter << "if (CA_OK != (err = #{ty_bldr.packer_sym}(dst, &src->data[i]))) { return err; }"
|
22
27
|
end
|
@@ -31,7 +36,7 @@ module Cauterize
|
|
31
36
|
formatter.blank_line
|
32
37
|
|
33
38
|
# store each used item in the array
|
34
|
-
formatter << "for (i = 0; i < #{
|
39
|
+
formatter << "for (i = 0; i < #{length_sym}; i++)"
|
35
40
|
formatter.braces do
|
36
41
|
formatter << "if (CA_OK != (err = #{ty_bldr.unpacker_sym}(src, &dst->data[i]))) { return err; }"
|
37
42
|
end
|
@@ -54,6 +59,10 @@ module Cauterize
|
|
54
59
|
|
55
60
|
private
|
56
61
|
|
62
|
+
def length_sym
|
63
|
+
"FIXED_ARRAY_LENGTH_#{@blueprint.name}"
|
64
|
+
end
|
65
|
+
|
57
66
|
def ty_bldr
|
58
67
|
@ty_bldr ||= Builders.get(:c, @blueprint.array_type)
|
59
68
|
end
|
@@ -1,6 +1,16 @@
|
|
1
1
|
module Cauterize
|
2
2
|
module Builders
|
3
3
|
module C
|
4
|
+
class Maxer
|
5
|
+
# Produce a preprocessor string that results in the maximum size of the passed
|
6
|
+
# in symbols. Uses the CA_MAX macro from the Cauterize support C files.
|
7
|
+
def self.max_str(*syms)
|
8
|
+
a = syms.to_a
|
9
|
+
pre = syms.to_a.inject("") {|s, v| s + "CA_MAX(" + v.to_s + ", "}
|
10
|
+
return pre + "0" + (")" * a.length)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
class Group < Buildable
|
5
15
|
def initialize(blueprint)
|
6
16
|
super(blueprint)
|
@@ -15,8 +25,21 @@ module Cauterize
|
|
15
25
|
formatter << "#{render} #{sym};"
|
16
26
|
end
|
17
27
|
|
28
|
+
def preprocessor_defines(formatter)
|
29
|
+
field_lens = @blueprint.fields.values.map do |field|
|
30
|
+
if field.type.nil?
|
31
|
+
nil
|
32
|
+
else
|
33
|
+
Builders.get(:c, field.type).max_enc_len_cpp_sym
|
34
|
+
end
|
35
|
+
end.compact
|
36
|
+
|
37
|
+
formatter << ["#define #{max_enc_len_cpp_sym}",
|
38
|
+
"(#{enum_builder.max_enc_len_cpp_sym} +",
|
39
|
+
Maxer.max_str(*field_lens)].join(" ") + ")"
|
40
|
+
end
|
41
|
+
|
18
42
|
def packer_defn(formatter)
|
19
|
-
enum_builder = Builders.get(:c, @tag_enum)
|
20
43
|
formatter << "CAUTERIZE_STATUS_T err;"
|
21
44
|
|
22
45
|
# pack the tag
|
@@ -110,6 +133,8 @@ module Cauterize
|
|
110
133
|
formatter << "break;"
|
111
134
|
end
|
112
135
|
end
|
136
|
+
|
137
|
+
def enum_builder; Builders.get(:c, @tag_enum) end
|
113
138
|
end
|
114
139
|
end
|
115
140
|
end
|
@@ -15,6 +15,10 @@ module Cauterize
|
|
15
15
|
formatter << "#{render} #{sym};"
|
16
16
|
end
|
17
17
|
|
18
|
+
def preprocessor_defines(formatter)
|
19
|
+
formatter << "#define #{max_enc_len_cpp_sym} sizeof(#{render})"
|
20
|
+
end
|
21
|
+
|
18
22
|
def packer_defn(formatter)
|
19
23
|
formatter << "return CauterizeAppend(dst, (uint8_t*)src, sizeof(*src));"
|
20
24
|
end
|
@@ -10,10 +10,15 @@ module Cauterize
|
|
10
10
|
formatter << "#{render} #{sym};"
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
13
|
+
def preprocessor_defines(formatter)
|
14
|
+
formatter << "#define #{length_sym} (#{@blueprint.array_size})"
|
15
|
+
formatter << [
|
16
|
+
"#define #{max_enc_len_cpp_sym} (",
|
17
|
+
"#{size_type_builder.max_enc_len_cpp_sym} + ",
|
18
|
+
"(#{length_sym} * #{array_type_builder.max_enc_len_cpp_sym}))"].join
|
19
|
+
end
|
16
20
|
|
21
|
+
def packer_defn(formatter)
|
17
22
|
formatter << "CAUTERIZE_STATUS_T err;"
|
18
23
|
formatter << "size_t i;"
|
19
24
|
formatter.blank_line
|
@@ -76,6 +81,15 @@ module Cauterize
|
|
76
81
|
end
|
77
82
|
formatter.append(";")
|
78
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def length_sym
|
88
|
+
"VARIABLE_ARRAY_MAX_LENGTH_#{@blueprint.name}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def size_type_builder; Builders.get(:c, @blueprint.size_type) end
|
92
|
+
def array_type_builder; Builders.get(:c, @blueprint.array_type) end
|
79
93
|
end
|
80
94
|
end
|
81
95
|
end
|
@@ -3,7 +3,7 @@ module Cauterize::Builders::CS
|
|
3
3
|
@@CS_TYPE_MAPPING = {
|
4
4
|
1 => {signed: "SByte", unsigned: "Byte", :float => nil, :bool => "bool"},
|
5
5
|
2 => {signed: "Int16", unsigned: "UInt16", :float => nil, :bool => nil},
|
6
|
-
4 => {signed: "Int32", unsigned: "UInt32", :float => "
|
6
|
+
4 => {signed: "Int32", unsigned: "UInt32", :float => "Single", :bool => nil},
|
7
7
|
8 => {signed: "Int64", unsigned: "UInt64", :float => "Double", :bool => nil},
|
8
8
|
}
|
9
9
|
|
@@ -10,9 +10,11 @@ module Cauterize::Builders::CS
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def size_defn(formatter)
|
13
|
+
formatter << "public static int MySize = #{size};"
|
14
|
+
formatter.blank_line
|
13
15
|
formatter << "protected override int Size"
|
14
16
|
formatter.braces do
|
15
|
-
formatter << "get { return
|
17
|
+
formatter << "get { return MySize; }"
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -5,16 +5,19 @@ module Cauterize::Builders::Ruby
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def class_defn(f)
|
8
|
-
f << "class #{render} <
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
f << " class #{render} < CauterizeRuby::Composite"
|
9
|
+
@blueprint.fields.values.each do |field|
|
10
|
+
f << " def #{field.name}() fields[:#{field.name}] end"
|
11
|
+
end
|
12
|
+
f << " def self.fields"
|
13
|
+
f << " {"
|
14
|
+
@blueprint.fields.values.each do |field|
|
12
15
|
t = Cauterize::Builders.get(:ruby, field.type).render
|
13
|
-
f << "
|
16
|
+
f << " #{field.name}: #{t},"
|
14
17
|
end
|
15
|
-
f << "
|
18
|
+
f << " }"
|
19
|
+
f << " end"
|
16
20
|
f << " end"
|
17
|
-
f << "end"
|
18
21
|
f << ""
|
19
22
|
end
|
20
23
|
end
|
@@ -6,19 +6,19 @@ module Cauterize::Builders::Ruby
|
|
6
6
|
|
7
7
|
def class_defn(f)
|
8
8
|
rep_builder = Cauterize::Builders.get(:ruby, @blueprint.representation)
|
9
|
-
f << "class #{render} <
|
10
|
-
f << "
|
11
|
-
f << "
|
12
|
-
f << "
|
9
|
+
f << " class #{render} < CauterizeRuby::Enumeration"
|
10
|
+
f << " def self.repr_type() #{rep_builder.render} end"
|
11
|
+
f << " def self.fields"
|
12
|
+
f << " {"
|
13
13
|
@blueprint.values.values.each do |v|
|
14
|
-
f << "
|
14
|
+
f << " #{v.name.to_s.upcase}: #{v.value},"
|
15
15
|
end
|
16
|
-
f << "
|
17
|
-
f << "
|
16
|
+
f << " }"
|
17
|
+
f << " end"
|
18
18
|
@blueprint.values.values.each do |v|
|
19
|
-
f << "
|
19
|
+
f << " #{v.name.to_s.upcase} = #{render}.new(:#{v.name.to_s.upcase})"
|
20
20
|
end
|
21
|
-
f << "end"
|
21
|
+
f << " end"
|
22
22
|
f << ""
|
23
23
|
end
|
24
24
|
end
|
@@ -7,10 +7,10 @@ module Cauterize::Builders::Ruby
|
|
7
7
|
def class_defn(f)
|
8
8
|
array_type_bldr = Cauterize::Builders.get(:ruby, @blueprint.array_type)
|
9
9
|
x = <<EOF
|
10
|
-
class #{render} <
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
class #{render} < CauterizeRuby::FixedArray
|
11
|
+
def self.length () #{@blueprint.array_size} end
|
12
|
+
def self.elem_type() #{array_type_bldr.render} end
|
13
|
+
end
|
14
14
|
EOF
|
15
15
|
f << x
|
16
16
|
end
|
@@ -11,22 +11,22 @@ module Cauterize::Builders::Ruby
|
|
11
11
|
def class_defn(f)
|
12
12
|
tag = Cauterize::Builders.get(:ruby, @tag_enum).render
|
13
13
|
|
14
|
-
f << "class #{render} <
|
15
|
-
f << "
|
16
|
-
f << "
|
17
|
-
f << "
|
18
|
-
f << "
|
14
|
+
f << " class #{render} < CauterizeRuby::Group"
|
15
|
+
f << " def self.tag_type() #{tag} end"
|
16
|
+
f << " def self.tag_prefix() '#{@blueprint.tag_enum.name.upcase}_' end"
|
17
|
+
f << " def self.fields"
|
18
|
+
f << " {"
|
19
19
|
@blueprint.fields.values.each_with_index do |field, i|
|
20
20
|
if field.type
|
21
21
|
t = Cauterize::Builders.get(:ruby, field.type).render
|
22
|
-
f << "
|
22
|
+
f << " #{field.name.to_s.upcase}: #{t},"
|
23
23
|
else
|
24
|
-
f << "
|
24
|
+
f << " #{field.name.to_s.upcase}: nil,"
|
25
25
|
end
|
26
26
|
end
|
27
|
-
f << "
|
27
|
+
f << " }"
|
28
|
+
f << " end"
|
28
29
|
f << " end"
|
29
|
-
f << "end"
|
30
30
|
f << ""
|
31
31
|
end
|
32
32
|
end
|
@@ -7,9 +7,9 @@ module Cauterize::Builders::Ruby
|
|
7
7
|
def class_defn(f)
|
8
8
|
tn_bldr = Cauterize::Builders.get(:ruby, @blueprint.type_name)
|
9
9
|
x = <<EOF
|
10
|
-
class #{render} <
|
11
|
-
|
12
|
-
end
|
10
|
+
class #{render} < CauterizeRuby::Scalar
|
11
|
+
def self.builtin() #{tn_bldr.render} end
|
12
|
+
end
|
13
13
|
EOF
|
14
14
|
f << x
|
15
15
|
end
|
@@ -8,11 +8,11 @@ module Cauterize::Builders::Ruby
|
|
8
8
|
array_type_bldr = Cauterize::Builders.get(:ruby, @blueprint.array_type)
|
9
9
|
size_type_bldr = Cauterize::Builders.get(:ruby, @blueprint.size_type)
|
10
10
|
x = <<EOF
|
11
|
-
class #{render} <
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
11
|
+
class #{render} < CauterizeRuby::VariableArray
|
12
|
+
def self.size_type () #{size_type_bldr.render} end
|
13
|
+
def self.max_length () #{@blueprint.array_size} end
|
14
|
+
def self.elem_type() #{array_type_bldr.render} end
|
15
|
+
end
|
16
16
|
EOF
|
17
17
|
f << x
|
18
18
|
end
|
data/lib/cauterize/c_builder.rb
CHANGED
@@ -40,10 +40,16 @@ module Cauterize
|
|
40
40
|
instances = BaseType.all_instances
|
41
41
|
builders = instances.map {|i| Builders.get(:c, i)}
|
42
42
|
|
43
|
+
builders.each { |b| b.preprocessor_defines(f) }
|
44
|
+
f.blank_line
|
43
45
|
builders.each { |b| b.typedef_decl(f) }
|
46
|
+
f.blank_line
|
44
47
|
builders.each { |b| b.enum_defn(f) }
|
48
|
+
f.blank_line
|
45
49
|
builders.each { |b| b.struct_proto(f) }
|
50
|
+
f.blank_line
|
46
51
|
builders.each { |b| b.struct_defn(f) }
|
52
|
+
f.blank_line
|
47
53
|
|
48
54
|
f << "#ifdef __cplusplus"
|
49
55
|
f << "extern \"C\" {"
|