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
data/lib/cauterize/builders.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
module Cauterize
|
2
|
-
module Builders
|
3
|
-
class UnregisteredException < Exception; end
|
4
|
-
class DuplicateException < Exception; end
|
5
|
-
|
6
|
-
module_function
|
7
|
-
|
8
|
-
def builders
|
9
|
-
@builders
|
10
|
-
end
|
11
|
-
|
12
|
-
def register(language, description_class, builder_class)
|
13
|
-
@builders ||= {}
|
14
|
-
@builders[language] ||= {}
|
15
|
-
|
16
|
-
if @builders[language][description_class]
|
17
|
-
raise DuplicateException.new("A builder for #{description_class} is already registered for language #{language}.")
|
18
|
-
else
|
19
|
-
@builders[language][description_class] = builder_class
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def get(language, description_instance)
|
24
|
-
unless @builders
|
25
|
-
raise UnregisteredException.new("No builders are registered.")
|
26
|
-
end
|
27
|
-
|
28
|
-
unless @builders[language]
|
29
|
-
s = "Language #{language} not registered."
|
30
|
-
raise UnregisteredException.new(s)
|
31
|
-
end
|
32
|
-
|
33
|
-
unless @builders[language][description_instance.class]
|
34
|
-
s = "Class #{description_instance.class} not registered for #{language}."
|
35
|
-
raise UnregisteredException.new(s)
|
36
|
-
end
|
37
|
-
|
38
|
-
@builders[language][description_instance.class].new(description_instance)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
module Cauterize
|
2
|
+
module Builders
|
3
|
+
class UnregisteredException < Exception; end
|
4
|
+
class DuplicateException < Exception; end
|
5
|
+
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def builders
|
9
|
+
@builders
|
10
|
+
end
|
11
|
+
|
12
|
+
def register(language, description_class, builder_class)
|
13
|
+
@builders ||= {}
|
14
|
+
@builders[language] ||= {}
|
15
|
+
|
16
|
+
if @builders[language][description_class]
|
17
|
+
raise DuplicateException.new("A builder for #{description_class} is already registered for language #{language}.")
|
18
|
+
else
|
19
|
+
@builders[language][description_class] = builder_class
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(language, description_instance)
|
24
|
+
unless @builders
|
25
|
+
raise UnregisteredException.new("No builders are registered.")
|
26
|
+
end
|
27
|
+
|
28
|
+
unless @builders[language]
|
29
|
+
s = "Language #{language} not registered."
|
30
|
+
raise UnregisteredException.new(s)
|
31
|
+
end
|
32
|
+
|
33
|
+
unless @builders[language][description_instance.class]
|
34
|
+
s = "Class #{description_instance.class} not registered for #{language}."
|
35
|
+
raise UnregisteredException.new(s)
|
36
|
+
end
|
37
|
+
|
38
|
+
@builders[language][description_instance.class].new(description_instance)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,91 +1,91 @@
|
|
1
|
-
module Cauterize
|
2
|
-
module Builders
|
3
|
-
module C
|
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
|
-
:render,
|
10
|
-
:declare,
|
11
|
-
:packer_sym, :packer_sig, :packer_proto, :packer_defn,
|
12
|
-
:unpacker_sym, :unpacker_sig, :unpacker_proto, :unpacker_defn,
|
13
|
-
:struct_proto, :struct_defn,
|
14
|
-
:enumeration,
|
15
|
-
]
|
16
|
-
|
17
|
-
class BuildableException < Exception; end
|
18
|
-
|
19
|
-
class Buildable
|
20
|
-
def initialize(blueprint)
|
21
|
-
@blueprint = blueprint
|
22
|
-
end
|
23
|
-
|
24
|
-
alias_method :orig_method_missing, :method_missing
|
25
|
-
|
26
|
-
def method_missing(sym, *args)
|
27
|
-
sym_required = REQUIRED_METHODS.include?(sym)
|
28
|
-
|
29
|
-
if sym_required
|
30
|
-
raise BuildableException.new("Classes deriving Buildable must implement the method #{sym}.")
|
31
|
-
else
|
32
|
-
orig_method_missing(sym, *args)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# wrapped_(un)packer_defn allow us to wrap every definition in some text #
|
37
|
-
##########################################################################
|
38
|
-
def wrapped_packer_defn(formatter)
|
39
|
-
formatter << packer_sig
|
40
|
-
formatter.braces do
|
41
|
-
formatter.backdent("#ifdef SPECIALIZED_#{packer_sym}")
|
42
|
-
formatter << "return SPECIALIZED_#{packer_sym}(dst, src);"
|
43
|
-
formatter.backdent("#else")
|
44
|
-
packer_defn(formatter)
|
45
|
-
formatter.backdent("#endif")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def wrapped_unpacker_defn(formatter)
|
50
|
-
formatter << unpacker_sig
|
51
|
-
formatter.braces do
|
52
|
-
formatter.backdent("#ifdef SPECIALIZED_#{unpacker_sym}")
|
53
|
-
formatter << "return SPECIALIZED_#{unpacker_sym}(src, dst);"
|
54
|
-
formatter.backdent("#else")
|
55
|
-
unpacker_defn(formatter)
|
56
|
-
formatter.backdent("#endif")
|
57
|
-
end
|
58
|
-
end
|
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
|
-
|
66
|
-
# Things below here are tested in shared_examples_for_c_buildables #
|
67
|
-
####################################################################
|
68
|
-
|
69
|
-
# Methods that are pretty much the same for everyone.
|
70
|
-
def packer_sym; "Pack_#{@blueprint.name}" end
|
71
|
-
def packer_sig; "CAUTERIZE_STATUS_T #{packer_sym}(struct Cauterize * dst, #{render} * src)" end
|
72
|
-
def packer_proto(formatter)
|
73
|
-
formatter << packer_sig + ";"
|
74
|
-
end
|
75
|
-
|
76
|
-
def unpacker_sym; "Unpack_#{@blueprint.name}" end
|
77
|
-
def unpacker_sig; "CAUTERIZE_STATUS_T #{unpacker_sym}(struct Cauterize * src, #{render} * dst)" end
|
78
|
-
def unpacker_proto(formatter)
|
79
|
-
formatter << unpacker_sig + ";"
|
80
|
-
end
|
81
|
-
|
82
|
-
# These are only different in a few type varieties.
|
83
|
-
def preprocessor_defines(formatter); nil end
|
84
|
-
def typedef_decl(formatter); nil end
|
85
|
-
def struct_proto(formatter); nil end
|
86
|
-
def struct_defn(formatter); nil end
|
87
|
-
def enum_defn(formatter); nil end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
1
|
+
module Cauterize
|
2
|
+
module Builders
|
3
|
+
module C
|
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
|
+
:render,
|
10
|
+
:declare,
|
11
|
+
:packer_sym, :packer_sig, :packer_proto, :packer_defn,
|
12
|
+
:unpacker_sym, :unpacker_sig, :unpacker_proto, :unpacker_defn,
|
13
|
+
:struct_proto, :struct_defn,
|
14
|
+
:enumeration,
|
15
|
+
]
|
16
|
+
|
17
|
+
class BuildableException < Exception; end
|
18
|
+
|
19
|
+
class Buildable
|
20
|
+
def initialize(blueprint)
|
21
|
+
@blueprint = blueprint
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_method :orig_method_missing, :method_missing
|
25
|
+
|
26
|
+
def method_missing(sym, *args)
|
27
|
+
sym_required = REQUIRED_METHODS.include?(sym)
|
28
|
+
|
29
|
+
if sym_required
|
30
|
+
raise BuildableException.new("Classes deriving Buildable must implement the method #{sym}.")
|
31
|
+
else
|
32
|
+
orig_method_missing(sym, *args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# wrapped_(un)packer_defn allow us to wrap every definition in some text #
|
37
|
+
##########################################################################
|
38
|
+
def wrapped_packer_defn(formatter)
|
39
|
+
formatter << packer_sig
|
40
|
+
formatter.braces do
|
41
|
+
formatter.backdent("#ifdef SPECIALIZED_#{packer_sym}")
|
42
|
+
formatter << "return SPECIALIZED_#{packer_sym}(dst, src);"
|
43
|
+
formatter.backdent("#else")
|
44
|
+
packer_defn(formatter)
|
45
|
+
formatter.backdent("#endif")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def wrapped_unpacker_defn(formatter)
|
50
|
+
formatter << unpacker_sig
|
51
|
+
formatter.braces do
|
52
|
+
formatter.backdent("#ifdef SPECIALIZED_#{unpacker_sym}")
|
53
|
+
formatter << "return SPECIALIZED_#{unpacker_sym}(src, dst);"
|
54
|
+
formatter.backdent("#else")
|
55
|
+
unpacker_defn(formatter)
|
56
|
+
formatter.backdent("#endif")
|
57
|
+
end
|
58
|
+
end
|
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
|
+
|
66
|
+
# Things below here are tested in shared_examples_for_c_buildables #
|
67
|
+
####################################################################
|
68
|
+
|
69
|
+
# Methods that are pretty much the same for everyone.
|
70
|
+
def packer_sym; "Pack_#{@blueprint.name}" end
|
71
|
+
def packer_sig; "CAUTERIZE_STATUS_T #{packer_sym}(struct Cauterize * dst, #{render} * src)" end
|
72
|
+
def packer_proto(formatter)
|
73
|
+
formatter << packer_sig + ";"
|
74
|
+
end
|
75
|
+
|
76
|
+
def unpacker_sym; "Unpack_#{@blueprint.name}" end
|
77
|
+
def unpacker_sig; "CAUTERIZE_STATUS_T #{unpacker_sym}(struct Cauterize * src, #{render} * dst)" end
|
78
|
+
def unpacker_proto(formatter)
|
79
|
+
formatter << unpacker_sig + ";"
|
80
|
+
end
|
81
|
+
|
82
|
+
# These are only different in a few type varieties.
|
83
|
+
def preprocessor_defines(formatter); nil end
|
84
|
+
def typedef_decl(formatter); nil end
|
85
|
+
def struct_proto(formatter); nil end
|
86
|
+
def struct_defn(formatter); nil end
|
87
|
+
def enum_defn(formatter); nil end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
module Cauterize
|
2
|
-
module Builders
|
3
|
-
module C
|
4
|
-
class BuiltIn < Buildable
|
5
|
-
@@C_TYPE_MAPPING = {
|
6
|
-
1 => {signed: :int8_t, unsigned: :uint8_t, :float => nil, :bool => :bool},
|
7
|
-
2 => {signed: :int16_t, unsigned: :uint16_t, :float => nil, :bool => nil},
|
8
|
-
4 => {signed: :int32_t, unsigned: :uint32_t, :float => :float, :bool => nil},
|
9
|
-
8 => {signed: :int64_t, unsigned: :uint64_t, :float => :double, :bool => nil},
|
10
|
-
}
|
11
|
-
|
12
|
-
def render
|
13
|
-
render_ctype
|
14
|
-
end
|
15
|
-
|
16
|
-
def declare(formatter, sym)
|
17
|
-
formatter << "#{render} #{sym};"
|
18
|
-
end
|
19
|
-
|
20
|
-
def preprocessor_defines(formatter)
|
21
|
-
formatter << "#define #{max_enc_len_cpp_sym} sizeof(#{render_ctype})"
|
22
|
-
end
|
23
|
-
|
24
|
-
# These are identical to the Scalar definitions. For now.
|
25
|
-
def packer_defn(formatter)
|
26
|
-
formatter << "return CauterizeAppend(dst, (uint8_t*)src, sizeof(*src));"
|
27
|
-
end
|
28
|
-
|
29
|
-
def unpacker_defn(formatter)
|
30
|
-
formatter << "return CauterizeRead(src, (uint8_t*)dst, sizeof(*dst));"
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def render_ctype
|
36
|
-
@@C_TYPE_MAPPING[@blueprint.byte_length][@blueprint.flavor]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
Cauterize::Builders.register(:c, Cauterize::BuiltIn, Cauterize::Builders::C::BuiltIn)
|
1
|
+
module Cauterize
|
2
|
+
module Builders
|
3
|
+
module C
|
4
|
+
class BuiltIn < Buildable
|
5
|
+
@@C_TYPE_MAPPING = {
|
6
|
+
1 => {signed: :int8_t, unsigned: :uint8_t, :float => nil, :bool => :bool},
|
7
|
+
2 => {signed: :int16_t, unsigned: :uint16_t, :float => nil, :bool => nil},
|
8
|
+
4 => {signed: :int32_t, unsigned: :uint32_t, :float => :float, :bool => nil},
|
9
|
+
8 => {signed: :int64_t, unsigned: :uint64_t, :float => :double, :bool => nil},
|
10
|
+
}
|
11
|
+
|
12
|
+
def render
|
13
|
+
render_ctype
|
14
|
+
end
|
15
|
+
|
16
|
+
def declare(formatter, sym)
|
17
|
+
formatter << "#{render} #{sym};"
|
18
|
+
end
|
19
|
+
|
20
|
+
def preprocessor_defines(formatter)
|
21
|
+
formatter << "#define #{max_enc_len_cpp_sym} sizeof(#{render_ctype})"
|
22
|
+
end
|
23
|
+
|
24
|
+
# These are identical to the Scalar definitions. For now.
|
25
|
+
def packer_defn(formatter)
|
26
|
+
formatter << "return CauterizeAppend(dst, (uint8_t*)src, sizeof(*src));"
|
27
|
+
end
|
28
|
+
|
29
|
+
def unpacker_defn(formatter)
|
30
|
+
formatter << "return CauterizeRead(src, (uint8_t*)dst, sizeof(*dst));"
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def render_ctype
|
36
|
+
@@C_TYPE_MAPPING[@blueprint.byte_length][@blueprint.flavor]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Cauterize::Builders.register(:c, Cauterize::BuiltIn, Cauterize::Builders::C::BuiltIn)
|
@@ -1,57 +1,57 @@
|
|
1
|
-
module Cauterize
|
2
|
-
module Builders
|
3
|
-
module C
|
4
|
-
class Composite < Buildable
|
5
|
-
def render
|
6
|
-
"struct #{@blueprint.name.to_s}"
|
7
|
-
end
|
8
|
-
|
9
|
-
def declare(formatter, sym)
|
10
|
-
formatter << "#{render} #{sym};"
|
11
|
-
end
|
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
|
-
|
21
|
-
def packer_defn(formatter)
|
22
|
-
formatter << "CAUTERIZE_STATUS_T err;"
|
23
|
-
@blueprint.fields.values.each do |field|
|
24
|
-
p_sym = Builders.get(:c, field.type).packer_sym
|
25
|
-
formatter << "if (CA_OK != (err = #{p_sym}(dst, &src->#{field.name}))) { return err; }"
|
26
|
-
end
|
27
|
-
formatter << "return CA_OK;"
|
28
|
-
end
|
29
|
-
|
30
|
-
def unpacker_defn(formatter)
|
31
|
-
formatter << "CAUTERIZE_STATUS_T err;"
|
32
|
-
@blueprint.fields.values.each do |field|
|
33
|
-
u_sym = Builders.get(:c, field.type).unpacker_sym
|
34
|
-
formatter << "if (CA_OK != (err = #{u_sym}(src, &dst->#{field.name}))) { return err; }"
|
35
|
-
end
|
36
|
-
formatter << "return CA_OK;"
|
37
|
-
end
|
38
|
-
|
39
|
-
def struct_proto(formatter)
|
40
|
-
formatter << (render + ";")
|
41
|
-
end
|
42
|
-
|
43
|
-
def struct_defn(formatter)
|
44
|
-
formatter << render
|
45
|
-
formatter.braces do
|
46
|
-
@blueprint.fields.values.each do |field|
|
47
|
-
Builders.get(:c, field.type).declare(formatter, field.name)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
formatter.append(";")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
Cauterize::Builders.register(:c, Cauterize::Composite, Cauterize::Builders::C::Composite)
|
1
|
+
module Cauterize
|
2
|
+
module Builders
|
3
|
+
module C
|
4
|
+
class Composite < Buildable
|
5
|
+
def render
|
6
|
+
"struct #{@blueprint.name.to_s}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def declare(formatter, sym)
|
10
|
+
formatter << "#{render} #{sym};"
|
11
|
+
end
|
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
|
+
|
21
|
+
def packer_defn(formatter)
|
22
|
+
formatter << "CAUTERIZE_STATUS_T err;"
|
23
|
+
@blueprint.fields.values.each do |field|
|
24
|
+
p_sym = Builders.get(:c, field.type).packer_sym
|
25
|
+
formatter << "if (CA_OK != (err = #{p_sym}(dst, &src->#{field.name}))) { return err; }"
|
26
|
+
end
|
27
|
+
formatter << "return CA_OK;"
|
28
|
+
end
|
29
|
+
|
30
|
+
def unpacker_defn(formatter)
|
31
|
+
formatter << "CAUTERIZE_STATUS_T err;"
|
32
|
+
@blueprint.fields.values.each do |field|
|
33
|
+
u_sym = Builders.get(:c, field.type).unpacker_sym
|
34
|
+
formatter << "if (CA_OK != (err = #{u_sym}(src, &dst->#{field.name}))) { return err; }"
|
35
|
+
end
|
36
|
+
formatter << "return CA_OK;"
|
37
|
+
end
|
38
|
+
|
39
|
+
def struct_proto(formatter)
|
40
|
+
formatter << (render + ";")
|
41
|
+
end
|
42
|
+
|
43
|
+
def struct_defn(formatter)
|
44
|
+
formatter << render
|
45
|
+
formatter.braces do
|
46
|
+
@blueprint.fields.values.each do |field|
|
47
|
+
Builders.get(:c, field.type).declare(formatter, field.name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
formatter.append(";")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Cauterize::Builders.register(:c, Cauterize::Composite, Cauterize::Builders::C::Composite)
|