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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +33 -33
  3. data/.rspec +1 -1
  4. data/.travisci.yml +4 -4
  5. data/Gemfile +4 -4
  6. data/LICENSE.txt +21 -21
  7. data/README.md +177 -177
  8. data/Rakefile +54 -54
  9. data/bin/cauterize +61 -61
  10. data/cauterize.gemspec +27 -27
  11. data/example/Cauterize +68 -68
  12. data/example/build.sh +25 -25
  13. data/example/c_example_support/empty_main.c +1 -1
  14. data/example/c_example_support/example_project_config.c +11 -11
  15. data/example/c_example_support/example_project_config.h +15 -15
  16. data/example/ruby_ex.rb +14 -14
  17. data/lib/cauterize.rb +117 -117
  18. data/lib/cauterize/base_type.rb +78 -78
  19. data/lib/cauterize/builders.rb +41 -41
  20. data/lib/cauterize/builders/c/buildable.rb +91 -91
  21. data/lib/cauterize/builders/c/builtin.rb +43 -43
  22. data/lib/cauterize/builders/c/composite.rb +57 -57
  23. data/lib/cauterize/builders/c/enumeration.rb +60 -60
  24. data/lib/cauterize/builders/c/fixed_array.rb +74 -74
  25. data/lib/cauterize/builders/c/group.rb +143 -143
  26. data/lib/cauterize/builders/c/scalar.rb +34 -34
  27. data/lib/cauterize/builders/c/variable_array.rb +98 -98
  28. data/lib/cauterize/builders/cs/buildable.rb +59 -59
  29. data/lib/cauterize/builders/cs/builtin.rb +22 -22
  30. data/lib/cauterize/builders/cs/composite.rb +21 -21
  31. data/lib/cauterize/builders/cs/csarray.rb +32 -32
  32. data/lib/cauterize/builders/cs/enumeration.rb +21 -21
  33. data/lib/cauterize/builders/cs/fixed_array.rb +27 -27
  34. data/lib/cauterize/builders/cs/group.rb +32 -32
  35. data/lib/cauterize/builders/cs/scalar.rb +10 -10
  36. data/lib/cauterize/builders/cs/variable_array.rb +40 -34
  37. data/lib/cauterize/builders/doc/buildable.rb +30 -30
  38. data/lib/cauterize/builders/doc/builtin.rb +21 -21
  39. data/lib/cauterize/builders/doc/composite.rb +23 -23
  40. data/lib/cauterize/builders/doc/enumeration.rb +24 -24
  41. data/lib/cauterize/builders/doc/fixed_array.rb +26 -26
  42. data/lib/cauterize/builders/doc/group.rb +29 -29
  43. data/lib/cauterize/builders/doc/scalar.rb +21 -21
  44. data/lib/cauterize/builders/doc/variable_array.rb +26 -26
  45. data/lib/cauterize/builders/ruby/buildable.rb +11 -11
  46. data/lib/cauterize/builders/ruby/builtin.rb +25 -25
  47. data/lib/cauterize/builders/ruby/composite.rb +26 -26
  48. data/lib/cauterize/builders/ruby/enumeration.rb +27 -27
  49. data/lib/cauterize/builders/ruby/fixed_array.rb +20 -20
  50. data/lib/cauterize/builders/ruby/group.rb +35 -35
  51. data/lib/cauterize/builders/ruby/scalar.rb +19 -19
  52. data/lib/cauterize/builders/ruby/variable_array.rb +22 -22
  53. data/lib/cauterize/builtin.rb +62 -62
  54. data/lib/cauterize/c_builder.rb +103 -103
  55. data/lib/cauterize/cauterize.rb +76 -76
  56. data/lib/cauterize/composite.rb +64 -64
  57. data/lib/cauterize/cs_builder.rb +58 -58
  58. data/lib/cauterize/doc_builder.rb +34 -34
  59. data/lib/cauterize/enumeration.rb +98 -98
  60. data/lib/cauterize/fixed_array.rb +50 -50
  61. data/lib/cauterize/formatter.rb +67 -67
  62. data/lib/cauterize/group.rb +81 -81
  63. data/lib/cauterize/representation.rb +32 -32
  64. data/lib/cauterize/ruby_builder.rb +44 -44
  65. data/lib/cauterize/scalar.rb +53 -53
  66. data/lib/cauterize/snake_case.rb +21 -21
  67. data/lib/cauterize/variable_array.rb +55 -55
  68. data/lib/cauterize/version.rb +3 -3
  69. data/spec/base_type_spec.rb +251 -251
  70. data/spec/builders/c/buildable_spec.rb +25 -25
  71. data/spec/builders/c/builtin_spec.rb +22 -22
  72. data/spec/builders/c/composite_spec.rb +50 -50
  73. data/spec/builders/c/enumeration_spec.rb +95 -95
  74. data/spec/builders/c/fixed_array_spec.rb +36 -36
  75. data/spec/builders/c/group_spec.rb +140 -140
  76. data/spec/builders/c/scalar_spec.rb +26 -26
  77. data/spec/builders/c/variable_array_spec.rb +48 -48
  78. data/spec/builders/cs/buildable_spec.rb +8 -8
  79. data/spec/builders/cs/composite_spec.rb +32 -32
  80. data/spec/builders/cs/enumeration_spec.rb +33 -33
  81. data/spec/builders/cs/fixed_array_spec.rb +41 -41
  82. data/spec/builders/cs/group_spec.rb +56 -56
  83. data/spec/builders/cs/scalar_spec.rb +7 -7
  84. data/spec/builders/cs/variable_array_spec.rb +49 -45
  85. data/spec/builders/doc/buildable_spec.rb +25 -25
  86. data/spec/builders_spec.rb +57 -57
  87. data/spec/builtin_spec.rb +43 -43
  88. data/spec/c_builder_spec.rb +176 -176
  89. data/spec/cauterize_spec.rb +15 -15
  90. data/spec/composite_spec.rb +77 -77
  91. data/spec/cs_builder_spec.rb +115 -115
  92. data/spec/doc_builder_spec.rb +260 -260
  93. data/spec/enumeration_spec.rb +145 -145
  94. data/spec/fixed_array_spec.rb +61 -61
  95. data/spec/group_spec.rb +111 -111
  96. data/spec/ruby_builder_spec.rb +83 -83
  97. data/spec/ruby_generated_spec.rb +735 -735
  98. data/spec/scalar_spec.rb +44 -44
  99. data/spec/spec_helper.rb +122 -122
  100. data/spec/support/shared_examples_for_array_buildables.rb +22 -22
  101. data/spec/support/shared_examples_for_c_buildables.rb +103 -103
  102. data/spec/support/shared_examples_for_sane_c_buildables.rb +22 -22
  103. data/spec/support/shared_examples_for_stubbed_functions.rb +18 -18
  104. data/spec/support/spec_sample_model.rb +74 -74
  105. data/spec/test_main.c +13 -13
  106. data/spec/variable_array_spec.rb +73 -73
  107. data/support/c/src/cauterize.c +75 -75
  108. data/support/c/src/cauterize.h +60 -60
  109. data/support/c/src/cauterize_debug.h +29 -29
  110. data/support/c/src/cauterize_util.h +8 -8
  111. data/support/c/test/greatest.h +536 -536
  112. data/support/c/test/test.c +166 -166
  113. data/support/cs/src/CauterizeCompositeFormatter.cs +0 -0
  114. data/support/cs/src/CauterizeContainerFormatter.cs +0 -0
  115. data/support/cs/src/CauterizeEnumFormatter.cs +0 -0
  116. data/support/cs/src/CauterizeException.cs +15 -15
  117. data/support/cs/src/CauterizeFixedArrayFormatter.cs +2 -2
  118. data/support/cs/src/CauterizeFormatter.cs +0 -0
  119. data/support/cs/src/CauterizeGroupFormatter.cs +0 -0
  120. data/support/cs/src/CauterizeTypeFormatterFactory.cs +0 -0
  121. data/support/cs/src/CauterizeTypes.cs +46 -12
  122. data/support/cs/src/CauterizeVariableArrayFormatter.cs +1 -1
  123. data/support/cs/src/ICauterizeTypeFormatter.cs +0 -0
  124. data/support/cs/src/OrderAttribute.cs +0 -0
  125. data/support/cs/src/PrimitiveSupport.cs +12 -0
  126. data/support/cs/test/CauterizeCompositeFormatterTest.cs +0 -0
  127. data/support/cs/test/CauterizeEnumFormatterTest.cs +0 -0
  128. data/support/cs/test/CauterizeFixedArrayFormatterTest.cs +0 -0
  129. data/support/cs/test/CauterizeFormatterTest.cs +0 -0
  130. data/support/cs/test/CauterizeGroupFormatterTest.cs +0 -0
  131. data/support/cs/test/CauterizeIntegrationTest.cs +0 -0
  132. data/support/cs/test/CauterizePrimitiveFormatterTest.cs +0 -0
  133. data/support/cs/test/CauterizeTypeFormatterFactoryTest.cs +0 -0
  134. data/support/cs/test/CauterizeVariableArrayFormatterTest.cs +0 -0
  135. data/support/cs/test/OrderAttributeTest.cs +0 -0
  136. data/support/ruby/src/cauterize_ruby_baseclasses.rb +367 -367
  137. data/support/ruby/src/cauterize_ruby_builtins.rb +148 -148
  138. metadata +20 -20
@@ -1,35 +1,35 @@
1
- module Cauterize::Builders::Ruby
2
- class Group < Buildable
3
- def render
4
- @blueprint.name.to_s.camel
5
- end
6
- def initialize(blueprint)
7
- super(blueprint)
8
- @tag_enum = blueprint.tag_enum
9
- end
10
-
11
- def class_defn(f)
12
- tag = Cauterize::Builders.get(:ruby, @tag_enum).render
13
-
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
- @blueprint.fields.values.each_with_index do |field, i|
20
- if field.type
21
- t = Cauterize::Builders.get(:ruby, field.type).render
22
- f << " #{field.name.to_s.upcase}: #{t},"
23
- else
24
- f << " #{field.name.to_s.upcase}: nil,"
25
- end
26
- end
27
- f << " }"
28
- f << " end"
29
- f << " end"
30
- f << ""
31
- end
32
- end
33
- end
34
-
35
- Cauterize::Builders.register(:ruby, Cauterize::Group, Cauterize::Builders::Ruby::Group)
1
+ module Cauterize::Builders::Ruby
2
+ class Group < Buildable
3
+ def render
4
+ @blueprint.name.to_s.camel
5
+ end
6
+ def initialize(blueprint)
7
+ super(blueprint)
8
+ @tag_enum = blueprint.tag_enum
9
+ end
10
+
11
+ def class_defn(f)
12
+ tag = Cauterize::Builders.get(:ruby, @tag_enum).render
13
+
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
+ @blueprint.fields.values.each_with_index do |field, i|
20
+ if field.type
21
+ t = Cauterize::Builders.get(:ruby, field.type).render
22
+ f << " #{field.name.to_s.upcase}: #{t},"
23
+ else
24
+ f << " #{field.name.to_s.upcase}: nil,"
25
+ end
26
+ end
27
+ f << " }"
28
+ f << " end"
29
+ f << " end"
30
+ f << ""
31
+ end
32
+ end
33
+ end
34
+
35
+ Cauterize::Builders.register(:ruby, Cauterize::Group, Cauterize::Builders::Ruby::Group)
@@ -1,19 +1,19 @@
1
- module Cauterize::Builders::Ruby
2
- class Scalar < Buildable
3
- def render
4
- @blueprint.name.to_s.camel
5
- end
6
-
7
- def class_defn(f)
8
- tn_bldr = Cauterize::Builders.get(:ruby, @blueprint.type_name)
9
- x = <<EOF
10
- class #{render} < CauterizeRuby::Scalar
11
- def self.builtin() #{tn_bldr.render} end
12
- end
13
- EOF
14
- f << x
15
- end
16
- end
17
- end
18
-
19
- Cauterize::Builders.register(:ruby, Cauterize::Scalar, Cauterize::Builders::Ruby::Scalar)
1
+ module Cauterize::Builders::Ruby
2
+ class Scalar < Buildable
3
+ def render
4
+ @blueprint.name.to_s.camel
5
+ end
6
+
7
+ def class_defn(f)
8
+ tn_bldr = Cauterize::Builders.get(:ruby, @blueprint.type_name)
9
+ x = <<EOF
10
+ class #{render} < CauterizeRuby::Scalar
11
+ def self.builtin() #{tn_bldr.render} end
12
+ end
13
+ EOF
14
+ f << x
15
+ end
16
+ end
17
+ end
18
+
19
+ Cauterize::Builders.register(:ruby, Cauterize::Scalar, Cauterize::Builders::Ruby::Scalar)
@@ -1,22 +1,22 @@
1
- module Cauterize::Builders::Ruby
2
- class VariableArray < Buildable
3
- def render
4
- @blueprint.name.to_s.camel
5
- end
6
-
7
- def class_defn(f)
8
- array_type_bldr = Cauterize::Builders.get(:ruby, @blueprint.array_type)
9
- size_type_bldr = Cauterize::Builders.get(:ruby, @blueprint.size_type)
10
- x = <<EOF
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
- EOF
17
- f << x
18
- end
19
- end
20
- end
21
-
22
- Cauterize::Builders.register(:ruby, Cauterize::VariableArray, Cauterize::Builders::Ruby::VariableArray)
1
+ module Cauterize::Builders::Ruby
2
+ class VariableArray < Buildable
3
+ def render
4
+ @blueprint.name.to_s.camel
5
+ end
6
+
7
+ def class_defn(f)
8
+ array_type_bldr = Cauterize::Builders.get(:ruby, @blueprint.array_type)
9
+ size_type_bldr = Cauterize::Builders.get(:ruby, @blueprint.size_type)
10
+ x = <<EOF
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
+ EOF
17
+ f << x
18
+ end
19
+ end
20
+ end
21
+
22
+ Cauterize::Builders.register(:ruby, Cauterize::VariableArray, Cauterize::Builders::Ruby::VariableArray)
@@ -1,62 +1,62 @@
1
- module Cauterize
2
- module_function
3
-
4
- BUILT_IN_TYPES = [
5
- { :name => :int8, :size => 1, :flavor => :signed },
6
- { :name => :int16, :size => 2, :flavor => :signed },
7
- { :name => :int32, :size => 4, :flavor => :signed },
8
- { :name => :int64, :size => 8, :flavor => :signed },
9
- { :name => :uint8, :size => 1, :flavor => :unsigned },
10
- { :name => :uint16, :size => 2, :flavor => :unsigned },
11
- { :name => :uint32, :size => 4, :flavor => :unsigned },
12
- { :name => :uint64, :size => 8, :flavor => :unsigned },
13
- { :name => :float32, :size => 4, :flavor => :float },
14
- { :name => :float64, :size => 8, :flavor => :float },
15
- { :name => :bool, :size => 1, :flavor => :bool },
16
- ]
17
-
18
- def builtins
19
- @builtins ||= {}
20
- end
21
-
22
- def create_builtins
23
- BUILT_IN_TYPES.each do |b|
24
- _b = BuiltIn.new(b[:name], nil)
25
- _b.byte_length(b[:size])
26
- _b.flavor(b[:flavor])
27
- builtins[b[:name]] = _b
28
- end
29
- end
30
-
31
- class BuiltIn < BaseType
32
- def initialize(name, desc=nil)
33
- super
34
- end
35
-
36
- def flavor(f = nil)
37
- unless f.nil?
38
- @flavor = f
39
- else
40
- @flavor
41
- end
42
- end
43
-
44
- def byte_length(len = nil)
45
- unless len.nil?
46
- @byte_length = len
47
- else
48
- @byte_length
49
- end
50
- end
51
-
52
- protected
53
-
54
- def local_hash(digest)
55
- digest.update(@flavor.to_s)
56
- digest.update(@byte_length.to_s)
57
- end
58
- end
59
-
60
- # Create all the builtin types.
61
- create_builtins
62
- end
1
+ module Cauterize
2
+ module_function
3
+
4
+ BUILT_IN_TYPES = [
5
+ { :name => :int8, :size => 1, :flavor => :signed },
6
+ { :name => :int16, :size => 2, :flavor => :signed },
7
+ { :name => :int32, :size => 4, :flavor => :signed },
8
+ { :name => :int64, :size => 8, :flavor => :signed },
9
+ { :name => :uint8, :size => 1, :flavor => :unsigned },
10
+ { :name => :uint16, :size => 2, :flavor => :unsigned },
11
+ { :name => :uint32, :size => 4, :flavor => :unsigned },
12
+ { :name => :uint64, :size => 8, :flavor => :unsigned },
13
+ { :name => :float32, :size => 4, :flavor => :float },
14
+ { :name => :float64, :size => 8, :flavor => :float },
15
+ { :name => :bool, :size => 1, :flavor => :bool },
16
+ ]
17
+
18
+ def builtins
19
+ @builtins ||= {}
20
+ end
21
+
22
+ def create_builtins
23
+ BUILT_IN_TYPES.each do |b|
24
+ _b = BuiltIn.new(b[:name], nil)
25
+ _b.byte_length(b[:size])
26
+ _b.flavor(b[:flavor])
27
+ builtins[b[:name]] = _b
28
+ end
29
+ end
30
+
31
+ class BuiltIn < BaseType
32
+ def initialize(name, desc=nil)
33
+ super
34
+ end
35
+
36
+ def flavor(f = nil)
37
+ unless f.nil?
38
+ @flavor = f
39
+ else
40
+ @flavor
41
+ end
42
+ end
43
+
44
+ def byte_length(len = nil)
45
+ unless len.nil?
46
+ @byte_length = len
47
+ else
48
+ @byte_length
49
+ end
50
+ end
51
+
52
+ protected
53
+
54
+ def local_hash(digest)
55
+ digest.update(@flavor.to_s)
56
+ digest.update(@byte_length.to_s)
57
+ end
58
+ end
59
+
60
+ # Create all the builtin types.
61
+ create_builtins
62
+ end
@@ -1,103 +1,103 @@
1
- require 'time'
2
- require 'digest'
3
-
4
- module Cauterize
5
- class CBuilder
6
- attr_reader :h, :c
7
-
8
- def initialize(h_file, c_file, name="cauterize")
9
- @h = h_file
10
- @c = c_file
11
- @name = name
12
- end
13
-
14
- def build
15
- build_h
16
- build_c
17
- end
18
-
19
- private
20
-
21
- def build_h
22
- f = default_formatter
23
-
24
- excluder = @name.up_snake + "_H_#{Time.now.to_i}"
25
- f << "/* WARNING: This is generated code. Do not edit this file directly. */"
26
- f << ""
27
- f << "#ifndef #{excluder}"
28
- f << "#define #{excluder}"
29
- f.blank_line
30
- f << %Q{#include <cauterize.h>}
31
- f.blank_line
32
- f << "#define GEN_VERSION (\"#{Cauterize.get_version}\")"
33
- f << "#define GEN_DATE (\"#{DateTime.now.to_s}\")"
34
- f.blank_line
35
-
36
- f << "#define MODEL_HASH_LEN (#{BaseType.digest_class.new.length})"
37
- f << "#define MODEL_HASH {#{BaseType.model_hash.bytes.to_a.join(", ")}}"
38
- f.blank_line
39
-
40
- instances = BaseType.all_instances
41
- builders = instances.map {|i| Builders.get(:c, i)}
42
-
43
- builders.each { |b| b.preprocessor_defines(f) }
44
- f.blank_line
45
- builders.each { |b| b.typedef_decl(f) }
46
- f.blank_line
47
- builders.each { |b| b.enum_defn(f) }
48
- f.blank_line
49
- builders.each { |b| b.struct_proto(f) }
50
- f.blank_line
51
- builders.each { |b| b.struct_defn(f) }
52
- f.blank_line
53
-
54
- f << "#ifdef __cplusplus"
55
- f << "extern \"C\" {"
56
- f << "#endif"
57
-
58
- builders.each { |b| b.packer_proto(f) }
59
- builders.each { |b| b.unpacker_proto(f) }
60
-
61
- f << "#ifdef __cplusplus"
62
- f << "}"
63
- f << "#endif"
64
-
65
- f.blank_line
66
- f << "#endif /* #{excluder} */"
67
- f << "\n"
68
-
69
- File.open(@h, "wb") do |fh|
70
- fh.write(f.to_s)
71
- end
72
- end
73
-
74
- def build_c
75
- f = default_formatter
76
-
77
- f << "/* WARNING: This is generated code. Do not edit this file directly. */"
78
- f << ""
79
- f << %Q{#include <cauterize_util.h>}
80
- f << %Q{#include "#{@name}.h"}
81
- f.blank_line
82
-
83
- f << %Q{/* Some extra configuration information may be provided. This is}
84
- f << %Q{ * a good place for the user to put prototypes or defines used}
85
- f << %Q{ * elsewhere. This is a user defined file and should be in the}
86
- f << %Q{ * include search path. */}
87
- f << %Q{#ifdef USE_CAUTERIZE_CONFIG_HEADER}
88
- f << %Q{#include "#{@name}_config.h"}
89
- f << %Q{#endif}
90
- f.blank_line
91
-
92
- instances = BaseType.all_instances
93
- builders = instances.map {|i| Builders.get(:c, i)}
94
-
95
- builders.each { |b| b.wrapped_packer_defn(f); f.blank_line }
96
- builders.each { |b| b.wrapped_unpacker_defn(f); f.blank_line }
97
-
98
- File.open(@c, "wb") do |fh|
99
- fh.write(f.to_s)
100
- end
101
- end
102
- end
103
- end
1
+ require 'time'
2
+ require 'digest'
3
+
4
+ module Cauterize
5
+ class CBuilder
6
+ attr_reader :h, :c
7
+
8
+ def initialize(h_file, c_file, name="cauterize")
9
+ @h = h_file
10
+ @c = c_file
11
+ @name = name
12
+ end
13
+
14
+ def build
15
+ build_h
16
+ build_c
17
+ end
18
+
19
+ private
20
+
21
+ def build_h
22
+ f = default_formatter
23
+
24
+ excluder = @name.up_snake + "_H_#{Time.now.to_i}"
25
+ f << "/* WARNING: This is generated code. Do not edit this file directly. */"
26
+ f << ""
27
+ f << "#ifndef #{excluder}"
28
+ f << "#define #{excluder}"
29
+ f.blank_line
30
+ f << %Q{#include <cauterize.h>}
31
+ f.blank_line
32
+ f << "#define GEN_VERSION (\"#{Cauterize.get_version}\")"
33
+ f << "#define GEN_DATE (\"#{DateTime.now.to_s}\")"
34
+ f.blank_line
35
+
36
+ f << "#define MODEL_HASH_LEN (#{BaseType.digest_class.new.length})"
37
+ f << "#define MODEL_HASH {#{BaseType.model_hash.bytes.to_a.join(", ")}}"
38
+ f.blank_line
39
+
40
+ instances = BaseType.all_instances
41
+ builders = instances.map {|i| Builders.get(:c, i)}
42
+
43
+ builders.each { |b| b.preprocessor_defines(f) }
44
+ f.blank_line
45
+ builders.each { |b| b.typedef_decl(f) }
46
+ f.blank_line
47
+ builders.each { |b| b.enum_defn(f) }
48
+ f.blank_line
49
+ builders.each { |b| b.struct_proto(f) }
50
+ f.blank_line
51
+ builders.each { |b| b.struct_defn(f) }
52
+ f.blank_line
53
+
54
+ f << "#ifdef __cplusplus"
55
+ f << "extern \"C\" {"
56
+ f << "#endif"
57
+
58
+ builders.each { |b| b.packer_proto(f) }
59
+ builders.each { |b| b.unpacker_proto(f) }
60
+
61
+ f << "#ifdef __cplusplus"
62
+ f << "}"
63
+ f << "#endif"
64
+
65
+ f.blank_line
66
+ f << "#endif /* #{excluder} */"
67
+ f << "\n"
68
+
69
+ File.open(@h, "wb") do |fh|
70
+ fh.write(f.to_s)
71
+ end
72
+ end
73
+
74
+ def build_c
75
+ f = default_formatter
76
+
77
+ f << "/* WARNING: This is generated code. Do not edit this file directly. */"
78
+ f << ""
79
+ f << %Q{#include <cauterize_util.h>}
80
+ f << %Q{#include "#{@name}.h"}
81
+ f.blank_line
82
+
83
+ f << %Q{/* Some extra configuration information may be provided. This is}
84
+ f << %Q{ * a good place for the user to put prototypes or defines used}
85
+ f << %Q{ * elsewhere. This is a user defined file and should be in the}
86
+ f << %Q{ * include search path. */}
87
+ f << %Q{#ifdef USE_CAUTERIZE_CONFIG_HEADER}
88
+ f << %Q{#include "#{@name}_config.h"}
89
+ f << %Q{#endif}
90
+ f.blank_line
91
+
92
+ instances = BaseType.all_instances
93
+ builders = instances.map {|i| Builders.get(:c, i)}
94
+
95
+ builders.each { |b| b.wrapped_packer_defn(f); f.blank_line }
96
+ builders.each { |b| b.wrapped_unpacker_defn(f); f.blank_line }
97
+
98
+ File.open(@c, "wb") do |fh|
99
+ fh.write(f.to_s)
100
+ end
101
+ end
102
+ end
103
+ end