cauterize 0.0.1.pre13 → 0.0.1.pre14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -33
- data/.rspec +1 -1
- data/.travisci.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +177 -177
- data/Rakefile +54 -54
- data/bin/cauterize +61 -61
- data/cauterize.gemspec +27 -27
- data/example/Cauterize +68 -68
- data/example/build.sh +25 -25
- data/example/c_example_support/empty_main.c +1 -1
- data/example/c_example_support/example_project_config.c +11 -11
- data/example/c_example_support/example_project_config.h +15 -15
- data/example/ruby_ex.rb +14 -14
- data/lib/cauterize.rb +117 -117
- data/lib/cauterize/base_type.rb +78 -78
- data/lib/cauterize/builders.rb +41 -41
- data/lib/cauterize/builders/c/buildable.rb +91 -91
- data/lib/cauterize/builders/c/builtin.rb +43 -43
- data/lib/cauterize/builders/c/composite.rb +57 -57
- data/lib/cauterize/builders/c/enumeration.rb +60 -60
- data/lib/cauterize/builders/c/fixed_array.rb +74 -74
- data/lib/cauterize/builders/c/group.rb +143 -143
- data/lib/cauterize/builders/c/scalar.rb +34 -34
- data/lib/cauterize/builders/c/variable_array.rb +98 -98
- data/lib/cauterize/builders/cs/buildable.rb +59 -59
- data/lib/cauterize/builders/cs/builtin.rb +22 -22
- data/lib/cauterize/builders/cs/composite.rb +21 -21
- data/lib/cauterize/builders/cs/csarray.rb +32 -32
- data/lib/cauterize/builders/cs/enumeration.rb +21 -21
- data/lib/cauterize/builders/cs/fixed_array.rb +27 -27
- data/lib/cauterize/builders/cs/group.rb +32 -32
- data/lib/cauterize/builders/cs/scalar.rb +10 -10
- data/lib/cauterize/builders/cs/variable_array.rb +40 -34
- data/lib/cauterize/builders/doc/buildable.rb +30 -30
- data/lib/cauterize/builders/doc/builtin.rb +21 -21
- data/lib/cauterize/builders/doc/composite.rb +23 -23
- data/lib/cauterize/builders/doc/enumeration.rb +24 -24
- data/lib/cauterize/builders/doc/fixed_array.rb +26 -26
- data/lib/cauterize/builders/doc/group.rb +29 -29
- data/lib/cauterize/builders/doc/scalar.rb +21 -21
- data/lib/cauterize/builders/doc/variable_array.rb +26 -26
- data/lib/cauterize/builders/ruby/buildable.rb +11 -11
- data/lib/cauterize/builders/ruby/builtin.rb +25 -25
- data/lib/cauterize/builders/ruby/composite.rb +26 -26
- data/lib/cauterize/builders/ruby/enumeration.rb +27 -27
- data/lib/cauterize/builders/ruby/fixed_array.rb +20 -20
- data/lib/cauterize/builders/ruby/group.rb +35 -35
- data/lib/cauterize/builders/ruby/scalar.rb +19 -19
- data/lib/cauterize/builders/ruby/variable_array.rb +22 -22
- data/lib/cauterize/builtin.rb +62 -62
- data/lib/cauterize/c_builder.rb +103 -103
- data/lib/cauterize/cauterize.rb +76 -76
- data/lib/cauterize/composite.rb +64 -64
- data/lib/cauterize/cs_builder.rb +58 -58
- data/lib/cauterize/doc_builder.rb +34 -34
- data/lib/cauterize/enumeration.rb +98 -98
- data/lib/cauterize/fixed_array.rb +50 -50
- data/lib/cauterize/formatter.rb +67 -67
- data/lib/cauterize/group.rb +81 -81
- data/lib/cauterize/representation.rb +32 -32
- data/lib/cauterize/ruby_builder.rb +44 -44
- data/lib/cauterize/scalar.rb +53 -53
- data/lib/cauterize/snake_case.rb +21 -21
- data/lib/cauterize/variable_array.rb +55 -55
- data/lib/cauterize/version.rb +3 -3
- data/spec/base_type_spec.rb +251 -251
- data/spec/builders/c/buildable_spec.rb +25 -25
- data/spec/builders/c/builtin_spec.rb +22 -22
- data/spec/builders/c/composite_spec.rb +50 -50
- data/spec/builders/c/enumeration_spec.rb +95 -95
- data/spec/builders/c/fixed_array_spec.rb +36 -36
- data/spec/builders/c/group_spec.rb +140 -140
- data/spec/builders/c/scalar_spec.rb +26 -26
- data/spec/builders/c/variable_array_spec.rb +48 -48
- data/spec/builders/cs/buildable_spec.rb +8 -8
- data/spec/builders/cs/composite_spec.rb +32 -32
- data/spec/builders/cs/enumeration_spec.rb +33 -33
- data/spec/builders/cs/fixed_array_spec.rb +41 -41
- data/spec/builders/cs/group_spec.rb +56 -56
- data/spec/builders/cs/scalar_spec.rb +7 -7
- data/spec/builders/cs/variable_array_spec.rb +49 -45
- data/spec/builders/doc/buildable_spec.rb +25 -25
- data/spec/builders_spec.rb +57 -57
- data/spec/builtin_spec.rb +43 -43
- data/spec/c_builder_spec.rb +176 -176
- data/spec/cauterize_spec.rb +15 -15
- data/spec/composite_spec.rb +77 -77
- data/spec/cs_builder_spec.rb +115 -115
- data/spec/doc_builder_spec.rb +260 -260
- data/spec/enumeration_spec.rb +145 -145
- data/spec/fixed_array_spec.rb +61 -61
- data/spec/group_spec.rb +111 -111
- data/spec/ruby_builder_spec.rb +83 -83
- data/spec/ruby_generated_spec.rb +735 -735
- data/spec/scalar_spec.rb +44 -44
- data/spec/spec_helper.rb +122 -122
- data/spec/support/shared_examples_for_array_buildables.rb +22 -22
- data/spec/support/shared_examples_for_c_buildables.rb +103 -103
- data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -22
- data/spec/support/shared_examples_for_stubbed_functions.rb +18 -18
- data/spec/support/spec_sample_model.rb +74 -74
- data/spec/test_main.c +13 -13
- data/spec/variable_array_spec.rb +73 -73
- data/support/c/src/cauterize.c +75 -75
- data/support/c/src/cauterize.h +60 -60
- data/support/c/src/cauterize_debug.h +29 -29
- data/support/c/src/cauterize_util.h +8 -8
- data/support/c/test/greatest.h +536 -536
- data/support/c/test/test.c +166 -166
- data/support/cs/src/CauterizeCompositeFormatter.cs +0 -0
- data/support/cs/src/CauterizeContainerFormatter.cs +0 -0
- data/support/cs/src/CauterizeEnumFormatter.cs +0 -0
- data/support/cs/src/CauterizeException.cs +15 -15
- data/support/cs/src/CauterizeFixedArrayFormatter.cs +2 -2
- data/support/cs/src/CauterizeFormatter.cs +0 -0
- data/support/cs/src/CauterizeGroupFormatter.cs +0 -0
- data/support/cs/src/CauterizeTypeFormatterFactory.cs +0 -0
- data/support/cs/src/CauterizeTypes.cs +46 -12
- data/support/cs/src/CauterizeVariableArrayFormatter.cs +1 -1
- data/support/cs/src/ICauterizeTypeFormatter.cs +0 -0
- data/support/cs/src/OrderAttribute.cs +0 -0
- data/support/cs/src/PrimitiveSupport.cs +12 -0
- data/support/cs/test/CauterizeCompositeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeEnumFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeGroupFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeIntegrationTest.cs +0 -0
- data/support/cs/test/CauterizePrimitiveFormatterTest.cs +0 -0
- data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +0 -0
- data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +0 -0
- data/support/cs/test/OrderAttributeTest.cs +0 -0
- data/support/ruby/src/cauterize_ruby_baseclasses.rb +367 -367
- data/support/ruby/src/cauterize_ruby_builtins.rb +148 -148
- metadata +20 -20
@@ -1,34 +1,34 @@
|
|
1
|
-
module Cauterize
|
2
|
-
module Builders
|
3
|
-
module C
|
4
|
-
class Scalar < Buildable
|
5
|
-
def render
|
6
|
-
@blueprint.name.to_s
|
7
|
-
end
|
8
|
-
|
9
|
-
def typedef_decl(formatter)
|
10
|
-
tn_bldr = Builders.get(:c, @blueprint.type_name)
|
11
|
-
formatter << "typedef #{tn_bldr.render} #{render};"
|
12
|
-
end
|
13
|
-
|
14
|
-
def declare(formatter, sym)
|
15
|
-
formatter << "#{render} #{sym};"
|
16
|
-
end
|
17
|
-
|
18
|
-
def preprocessor_defines(formatter)
|
19
|
-
formatter << "#define #{max_enc_len_cpp_sym} sizeof(#{render})"
|
20
|
-
end
|
21
|
-
|
22
|
-
def packer_defn(formatter)
|
23
|
-
formatter << "return CauterizeAppend(dst, (uint8_t*)src, sizeof(*src));"
|
24
|
-
end
|
25
|
-
|
26
|
-
def unpacker_defn(formatter)
|
27
|
-
formatter << "return CauterizeRead(src, (uint8_t*)dst, sizeof(*dst));"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Cauterize::Builders.register(:c, Cauterize::Scalar, Cauterize::Builders::C::Scalar)
|
1
|
+
module Cauterize
|
2
|
+
module Builders
|
3
|
+
module C
|
4
|
+
class Scalar < Buildable
|
5
|
+
def render
|
6
|
+
@blueprint.name.to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def typedef_decl(formatter)
|
10
|
+
tn_bldr = Builders.get(:c, @blueprint.type_name)
|
11
|
+
formatter << "typedef #{tn_bldr.render} #{render};"
|
12
|
+
end
|
13
|
+
|
14
|
+
def declare(formatter, sym)
|
15
|
+
formatter << "#{render} #{sym};"
|
16
|
+
end
|
17
|
+
|
18
|
+
def preprocessor_defines(formatter)
|
19
|
+
formatter << "#define #{max_enc_len_cpp_sym} sizeof(#{render})"
|
20
|
+
end
|
21
|
+
|
22
|
+
def packer_defn(formatter)
|
23
|
+
formatter << "return CauterizeAppend(dst, (uint8_t*)src, sizeof(*src));"
|
24
|
+
end
|
25
|
+
|
26
|
+
def unpacker_defn(formatter)
|
27
|
+
formatter << "return CauterizeRead(src, (uint8_t*)dst, sizeof(*dst));"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Cauterize::Builders.register(:c, Cauterize::Scalar, Cauterize::Builders::C::Scalar)
|
@@ -1,98 +1,98 @@
|
|
1
|
-
module Cauterize
|
2
|
-
module Builders
|
3
|
-
module C
|
4
|
-
class VariableArray < Buildable
|
5
|
-
def render
|
6
|
-
"struct #{@blueprint.name}"
|
7
|
-
end
|
8
|
-
|
9
|
-
def declare(formatter, sym)
|
10
|
-
formatter << "#{render} #{sym};"
|
11
|
-
end
|
12
|
-
|
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
|
20
|
-
|
21
|
-
def packer_defn(formatter)
|
22
|
-
formatter << "CAUTERIZE_STATUS_T err;"
|
23
|
-
formatter << "size_t i;"
|
24
|
-
formatter.blank_line
|
25
|
-
# check the length
|
26
|
-
formatter << "if (src->length > ARRAY_SIZE(src->data)) { return CA_ERR_INVALID_LENGTH; }"
|
27
|
-
|
28
|
-
# store the length
|
29
|
-
formatter << "if (CA_OK != (err = #{size_type_builder.packer_sym}(dst, &src->length))) { return err; }"
|
30
|
-
formatter.blank_line
|
31
|
-
|
32
|
-
# store each used item in the array
|
33
|
-
formatter << "for (i = 0; i < src->length; i++)"
|
34
|
-
formatter.braces do
|
35
|
-
formatter << "if (CA_OK != (err = #{array_type_builder.packer_sym}(dst, &src->data[i]))) { return err; }"
|
36
|
-
end
|
37
|
-
formatter.blank_line
|
38
|
-
|
39
|
-
formatter << "return CA_OK;"
|
40
|
-
end
|
41
|
-
|
42
|
-
def unpacker_defn(formatter)
|
43
|
-
size_type_builder = Builders.get(:c, @blueprint.size_type)
|
44
|
-
array_type_builder = Builders.get(:c, @blueprint.array_type)
|
45
|
-
|
46
|
-
formatter << "CAUTERIZE_STATUS_T err;"
|
47
|
-
formatter << "size_t i;"
|
48
|
-
formatter.blank_line
|
49
|
-
|
50
|
-
# read the length
|
51
|
-
formatter << "if (CA_OK != (err = #{size_type_builder.unpacker_sym}(src, &dst->length))) { return err; }"
|
52
|
-
formatter.blank_line
|
53
|
-
|
54
|
-
# check the length
|
55
|
-
formatter << "if (dst->length > ARRAY_SIZE(dst->data)) { return CA_ERR_INVALID_LENGTH; }"
|
56
|
-
formatter.blank_line
|
57
|
-
|
58
|
-
|
59
|
-
# store each used item in the array
|
60
|
-
formatter << "for (i = 0; i < dst->length; i++)"
|
61
|
-
formatter.braces do
|
62
|
-
formatter << "if (CA_OK != (err = #{array_type_builder.unpacker_sym}(src, &dst->data[i]))) { return err; }"
|
63
|
-
end
|
64
|
-
formatter.blank_line
|
65
|
-
|
66
|
-
formatter << "return CA_OK;"
|
67
|
-
end
|
68
|
-
|
69
|
-
def struct_proto(formatter)
|
70
|
-
formatter << (render + ";")
|
71
|
-
end
|
72
|
-
|
73
|
-
def struct_defn(formatter)
|
74
|
-
formatter << render
|
75
|
-
formatter.braces do
|
76
|
-
at_builder = Builders.get(:c, @blueprint.array_type)
|
77
|
-
st_builder = Builders.get(:c, @blueprint.size_type)
|
78
|
-
|
79
|
-
st_builder.declare(formatter, "length")
|
80
|
-
formatter << "#{at_builder.render} data[#{@blueprint.array_size}];"
|
81
|
-
end
|
82
|
-
formatter.append(";")
|
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
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
Cauterize::Builders.register(:c, Cauterize::VariableArray, Cauterize::Builders::C::VariableArray)
|
1
|
+
module Cauterize
|
2
|
+
module Builders
|
3
|
+
module C
|
4
|
+
class VariableArray < Buildable
|
5
|
+
def render
|
6
|
+
"struct #{@blueprint.name}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def declare(formatter, sym)
|
10
|
+
formatter << "#{render} #{sym};"
|
11
|
+
end
|
12
|
+
|
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
|
20
|
+
|
21
|
+
def packer_defn(formatter)
|
22
|
+
formatter << "CAUTERIZE_STATUS_T err;"
|
23
|
+
formatter << "size_t i;"
|
24
|
+
formatter.blank_line
|
25
|
+
# check the length
|
26
|
+
formatter << "if (src->length > ARRAY_SIZE(src->data)) { return CA_ERR_INVALID_LENGTH; }"
|
27
|
+
|
28
|
+
# store the length
|
29
|
+
formatter << "if (CA_OK != (err = #{size_type_builder.packer_sym}(dst, &src->length))) { return err; }"
|
30
|
+
formatter.blank_line
|
31
|
+
|
32
|
+
# store each used item in the array
|
33
|
+
formatter << "for (i = 0; i < src->length; i++)"
|
34
|
+
formatter.braces do
|
35
|
+
formatter << "if (CA_OK != (err = #{array_type_builder.packer_sym}(dst, &src->data[i]))) { return err; }"
|
36
|
+
end
|
37
|
+
formatter.blank_line
|
38
|
+
|
39
|
+
formatter << "return CA_OK;"
|
40
|
+
end
|
41
|
+
|
42
|
+
def unpacker_defn(formatter)
|
43
|
+
size_type_builder = Builders.get(:c, @blueprint.size_type)
|
44
|
+
array_type_builder = Builders.get(:c, @blueprint.array_type)
|
45
|
+
|
46
|
+
formatter << "CAUTERIZE_STATUS_T err;"
|
47
|
+
formatter << "size_t i;"
|
48
|
+
formatter.blank_line
|
49
|
+
|
50
|
+
# read the length
|
51
|
+
formatter << "if (CA_OK != (err = #{size_type_builder.unpacker_sym}(src, &dst->length))) { return err; }"
|
52
|
+
formatter.blank_line
|
53
|
+
|
54
|
+
# check the length
|
55
|
+
formatter << "if (dst->length > ARRAY_SIZE(dst->data)) { return CA_ERR_INVALID_LENGTH; }"
|
56
|
+
formatter.blank_line
|
57
|
+
|
58
|
+
|
59
|
+
# store each used item in the array
|
60
|
+
formatter << "for (i = 0; i < dst->length; i++)"
|
61
|
+
formatter.braces do
|
62
|
+
formatter << "if (CA_OK != (err = #{array_type_builder.unpacker_sym}(src, &dst->data[i]))) { return err; }"
|
63
|
+
end
|
64
|
+
formatter.blank_line
|
65
|
+
|
66
|
+
formatter << "return CA_OK;"
|
67
|
+
end
|
68
|
+
|
69
|
+
def struct_proto(formatter)
|
70
|
+
formatter << (render + ";")
|
71
|
+
end
|
72
|
+
|
73
|
+
def struct_defn(formatter)
|
74
|
+
formatter << render
|
75
|
+
formatter.braces do
|
76
|
+
at_builder = Builders.get(:c, @blueprint.array_type)
|
77
|
+
st_builder = Builders.get(:c, @blueprint.size_type)
|
78
|
+
|
79
|
+
st_builder.declare(formatter, "length")
|
80
|
+
formatter << "#{at_builder.render} data[#{@blueprint.array_size}];"
|
81
|
+
end
|
82
|
+
formatter.append(";")
|
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
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
Cauterize::Builders.register(:c, Cauterize::VariableArray, Cauterize::Builders::C::VariableArray)
|
@@ -1,59 +1,59 @@
|
|
1
|
-
module Cauterize
|
2
|
-
module Builders
|
3
|
-
module CS
|
4
|
-
# sym - symbol - the lexical symbol associated with the generated entity
|
5
|
-
# sig - signature - the C signature associated with the entity
|
6
|
-
# proto - prototype - the C prototype associated with the entity
|
7
|
-
# defn - definition - the C definition associated with the entity
|
8
|
-
REQUIRED_METHODS = [
|
9
|
-
]
|
10
|
-
|
11
|
-
class BuildableException < Exception; end
|
12
|
-
|
13
|
-
class Buildable
|
14
|
-
def initialize(blueprint)
|
15
|
-
@blueprint = blueprint
|
16
|
-
end
|
17
|
-
|
18
|
-
alias_method :orig_method_missing, :method_missing
|
19
|
-
|
20
|
-
def method_missing(sym, *args)
|
21
|
-
sym_required = REQUIRED_METHODS.include?(sym)
|
22
|
-
|
23
|
-
if sym_required
|
24
|
-
raise BuildableException.new("Classes deriving Buildable must implement the method #{sym}.")
|
25
|
-
else
|
26
|
-
orig_method_missing(sym, *args)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Things below here are tested in shared_examples_for_c_buildables #
|
31
|
-
####################################################################
|
32
|
-
|
33
|
-
# Methods that are pretty much the same for everyone.
|
34
|
-
# WFIXME what do I do with these???
|
35
|
-
# def packer_sym; "Pack_#{@blueprint.name}" end
|
36
|
-
# def packer_sig; "CAUTERIZE_STATUS_T #{packer_sym}(struct Cauterize * dst, #{render} * src)" end
|
37
|
-
# def packer_proto(formatter)
|
38
|
-
# formatter << packer_sig + ";"
|
39
|
-
# end
|
40
|
-
|
41
|
-
# def unpacker_sym; "Unpack_#{@blueprint.name}" end
|
42
|
-
# def unpacker_sig; "CAUTERIZE_STATUS_T #{unpacker_sym}(struct Cauterize * src, #{render} * dst)" end
|
43
|
-
# def unpacker_proto(formatter)
|
44
|
-
# formatter << unpacker_sig + ";"
|
45
|
-
# end
|
46
|
-
|
47
|
-
# These are only different in a few type varieties.
|
48
|
-
def render
|
49
|
-
@blueprint.name.to_s.camel
|
50
|
-
end
|
51
|
-
def declare(formatter, sym)
|
52
|
-
formatter << "public #{render} #{sym.to_s.camel} { get; set; }"
|
53
|
-
end
|
54
|
-
def class_defn(formatter); nil end
|
55
|
-
def enum_defn(formatter); nil end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
1
|
+
module Cauterize
|
2
|
+
module Builders
|
3
|
+
module CS
|
4
|
+
# sym - symbol - the lexical symbol associated with the generated entity
|
5
|
+
# sig - signature - the C signature associated with the entity
|
6
|
+
# proto - prototype - the C prototype associated with the entity
|
7
|
+
# defn - definition - the C definition associated with the entity
|
8
|
+
REQUIRED_METHODS = [
|
9
|
+
]
|
10
|
+
|
11
|
+
class BuildableException < Exception; end
|
12
|
+
|
13
|
+
class Buildable
|
14
|
+
def initialize(blueprint)
|
15
|
+
@blueprint = blueprint
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :orig_method_missing, :method_missing
|
19
|
+
|
20
|
+
def method_missing(sym, *args)
|
21
|
+
sym_required = REQUIRED_METHODS.include?(sym)
|
22
|
+
|
23
|
+
if sym_required
|
24
|
+
raise BuildableException.new("Classes deriving Buildable must implement the method #{sym}.")
|
25
|
+
else
|
26
|
+
orig_method_missing(sym, *args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Things below here are tested in shared_examples_for_c_buildables #
|
31
|
+
####################################################################
|
32
|
+
|
33
|
+
# Methods that are pretty much the same for everyone.
|
34
|
+
# WFIXME what do I do with these???
|
35
|
+
# def packer_sym; "Pack_#{@blueprint.name}" end
|
36
|
+
# def packer_sig; "CAUTERIZE_STATUS_T #{packer_sym}(struct Cauterize * dst, #{render} * src)" end
|
37
|
+
# def packer_proto(formatter)
|
38
|
+
# formatter << packer_sig + ";"
|
39
|
+
# end
|
40
|
+
|
41
|
+
# def unpacker_sym; "Unpack_#{@blueprint.name}" end
|
42
|
+
# def unpacker_sig; "CAUTERIZE_STATUS_T #{unpacker_sym}(struct Cauterize * src, #{render} * dst)" end
|
43
|
+
# def unpacker_proto(formatter)
|
44
|
+
# formatter << unpacker_sig + ";"
|
45
|
+
# end
|
46
|
+
|
47
|
+
# These are only different in a few type varieties.
|
48
|
+
def render
|
49
|
+
@blueprint.name.to_s.camel
|
50
|
+
end
|
51
|
+
def declare(formatter, sym)
|
52
|
+
formatter << "public #{render} #{sym.to_s.camel} { get; set; }"
|
53
|
+
end
|
54
|
+
def class_defn(formatter); nil end
|
55
|
+
def enum_defn(formatter); nil end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
module Cauterize::Builders::CS
|
2
|
-
class BuiltIn < Buildable
|
3
|
-
@@CS_TYPE_MAPPING = {
|
4
|
-
1 => {signed: "SByte", unsigned: "Byte", :float => nil, :bool => "bool"},
|
5
|
-
2 => {signed: "Int16", unsigned: "UInt16", :float => nil, :bool => nil},
|
6
|
-
4 => {signed: "Int32", unsigned: "UInt32", :float => "Single", :bool => nil},
|
7
|
-
8 => {signed: "Int64", unsigned: "UInt64", :float => "Double", :bool => nil},
|
8
|
-
}
|
9
|
-
|
10
|
-
def render
|
11
|
-
render_cstype
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def render_cstype
|
17
|
-
@@CS_TYPE_MAPPING[@blueprint.byte_length][@blueprint.flavor]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
Cauterize::Builders.register(:cs, Cauterize::BuiltIn, Cauterize::Builders::CS::BuiltIn)
|
1
|
+
module Cauterize::Builders::CS
|
2
|
+
class BuiltIn < Buildable
|
3
|
+
@@CS_TYPE_MAPPING = {
|
4
|
+
1 => {signed: "SByte", unsigned: "Byte", :float => nil, :bool => "bool"},
|
5
|
+
2 => {signed: "Int16", unsigned: "UInt16", :float => nil, :bool => nil},
|
6
|
+
4 => {signed: "Int32", unsigned: "UInt32", :float => "Single", :bool => nil},
|
7
|
+
8 => {signed: "Int64", unsigned: "UInt64", :float => "Double", :bool => nil},
|
8
|
+
}
|
9
|
+
|
10
|
+
def render
|
11
|
+
render_cstype
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def render_cstype
|
17
|
+
@@CS_TYPE_MAPPING[@blueprint.byte_length][@blueprint.flavor]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Cauterize::Builders.register(:cs, Cauterize::BuiltIn, Cauterize::Builders::CS::BuiltIn)
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module Cauterize::Builders::CS
|
2
|
-
class Composite < Buildable
|
3
|
-
|
4
|
-
def render_parent
|
5
|
-
"CauterizeComposite"
|
6
|
-
end
|
7
|
-
|
8
|
-
def class_defn(formatter)
|
9
|
-
formatter << "public class #{render} : #{render_parent}"
|
10
|
-
formatter.braces do
|
11
|
-
@blueprint.fields.values.each_with_index do |field, i|
|
12
|
-
formatter << "[Order(#{i})]"
|
13
|
-
Cauterize::Builders.get(:cs, field.type).declare(formatter, field.name)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
formatter.blank_line
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
Cauterize::Builders.register(:cs, Cauterize::Composite, Cauterize::Builders::CS::Composite)
|
1
|
+
module Cauterize::Builders::CS
|
2
|
+
class Composite < Buildable
|
3
|
+
|
4
|
+
def render_parent
|
5
|
+
"CauterizeComposite"
|
6
|
+
end
|
7
|
+
|
8
|
+
def class_defn(formatter)
|
9
|
+
formatter << "public class #{render} : #{render_parent}"
|
10
|
+
formatter.braces do
|
11
|
+
@blueprint.fields.values.each_with_index do |field, i|
|
12
|
+
formatter << "[Order(#{i})]"
|
13
|
+
Cauterize::Builders.get(:cs, field.type).declare(formatter, field.name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
formatter.blank_line
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Cauterize::Builders.register(:cs, Cauterize::Composite, Cauterize::Builders::CS::Composite)
|