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,76 +1,76 @@
1
- require "require_all"
2
-
3
- lib_path = File.dirname(__FILE__) + "/.."
4
- require_all Dir[lib_path + "/**/*.rb"]
5
-
6
- module Cauterize
7
-
8
- module_function
9
- def generate(language, target_dir, desc_file)
10
- parse_dsl(desc_file)
11
- FileUtils.mkdir_p(target_dir)
12
- output_prefix = get_name || "generated_interface"
13
- builder = send "make_builder_#{language}".to_sym, target_dir, output_prefix
14
- builder.build
15
- end
16
-
17
- # Generate the C code corresponding to the generated configuration
18
- def make_builder_c(target_dir, output_prefix)
19
- h_file = File.join(target_dir, "#{output_prefix}.h")
20
- c_file = File.join(target_dir, "#{output_prefix}.c")
21
-
22
- Cauterize::CBuilder.new(h_file, c_file, output_prefix)
23
- end
24
-
25
- # Generate the CS code corresponding to the generated configuration
26
- def make_builder_cs(target_dir, output_prefix)
27
- cs_file = File.join(target_dir, "#{output_prefix}.cs")
28
-
29
- Cauterize::CSBuilder.new(cs_file, output_prefix)
30
- end
31
-
32
- # Generate the Ruby code corresponding to the generated configuration
33
- def make_builder_ruby(target_dir, output_prefix)
34
- rb_file = File.join(target_dir, "#{output_prefix}.rb")
35
-
36
- Cauterize::RubyBuilder.new(rb_file, output_prefix)
37
- end
38
-
39
- def make_builder_doc(target_dir, output_prefix)
40
- doc_file = File.join(target_dir, "#{output_prefix}.txt")
41
-
42
- Cauterize::DocBuilder.new(doc_file, output_prefix)
43
- end
44
-
45
- def get_name
46
- @@description_name
47
- end
48
-
49
- def get_version
50
- if defined? @@version
51
- @@version
52
- else
53
- "UNDEFINED"
54
- end
55
- end
56
-
57
- def set_name(desc_name)
58
- @@description_name = desc_name
59
- end
60
-
61
- def set_version(version)
62
- @@version = version
63
- end
64
-
65
- def parse_dsl(desc_file)
66
- Object.new.extend(Cauterize).instance_exec do
67
- # this magic allows us to emit useful exception messages when evaling the
68
- # file. if your description file has errors, you'll be able to find them
69
- # because of this magic.
70
- p = Proc.new {}
71
- eval(File.read(desc_file), p.binding, desc_file)
72
- end
73
-
74
- end
75
-
76
- end
1
+ require "require_all"
2
+
3
+ lib_path = File.dirname(__FILE__) + "/.."
4
+ require_all Dir[lib_path + "/**/*.rb"]
5
+
6
+ module Cauterize
7
+
8
+ module_function
9
+ def generate(language, target_dir, desc_file)
10
+ parse_dsl(desc_file)
11
+ FileUtils.mkdir_p(target_dir)
12
+ output_prefix = get_name || "generated_interface"
13
+ builder = send "make_builder_#{language}".to_sym, target_dir, output_prefix
14
+ builder.build
15
+ end
16
+
17
+ # Generate the C code corresponding to the generated configuration
18
+ def make_builder_c(target_dir, output_prefix)
19
+ h_file = File.join(target_dir, "#{output_prefix}.h")
20
+ c_file = File.join(target_dir, "#{output_prefix}.c")
21
+
22
+ Cauterize::CBuilder.new(h_file, c_file, output_prefix)
23
+ end
24
+
25
+ # Generate the CS code corresponding to the generated configuration
26
+ def make_builder_cs(target_dir, output_prefix)
27
+ cs_file = File.join(target_dir, "#{output_prefix}.cs")
28
+
29
+ Cauterize::CSBuilder.new(cs_file, output_prefix)
30
+ end
31
+
32
+ # Generate the Ruby code corresponding to the generated configuration
33
+ def make_builder_ruby(target_dir, output_prefix)
34
+ rb_file = File.join(target_dir, "#{output_prefix}.rb")
35
+
36
+ Cauterize::RubyBuilder.new(rb_file, output_prefix)
37
+ end
38
+
39
+ def make_builder_doc(target_dir, output_prefix)
40
+ doc_file = File.join(target_dir, "#{output_prefix}.txt")
41
+
42
+ Cauterize::DocBuilder.new(doc_file, output_prefix)
43
+ end
44
+
45
+ def get_name
46
+ @@description_name
47
+ end
48
+
49
+ def get_version
50
+ if defined? @@version
51
+ @@version
52
+ else
53
+ "UNDEFINED"
54
+ end
55
+ end
56
+
57
+ def set_name(desc_name)
58
+ @@description_name = desc_name
59
+ end
60
+
61
+ def set_version(version)
62
+ @@version = version
63
+ end
64
+
65
+ def parse_dsl(desc_file)
66
+ Object.new.extend(Cauterize).instance_exec do
67
+ # this magic allows us to emit useful exception messages when evaling the
68
+ # file. if your description file has errors, you'll be able to find them
69
+ # because of this magic.
70
+ p = Proc.new {}
71
+ eval(File.read(desc_file), p.binding, desc_file)
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -1,64 +1,64 @@
1
- # composite.rb
2
- #
3
- # Composites correspond to C structs.
4
-
5
- module Cauterize
6
- module_function
7
-
8
- def composite(name, desc=nil)
9
- c = Cauterize.composites[name] || Cauterize.composites[name] = Composite.new(name, desc)
10
- yield c if block_given?
11
- return c
12
- end
13
-
14
- def composite!(name, &blk)
15
- if Cauterize.composites[name]
16
- raise Exception.new("Composite with name #{name} already exists.")
17
- else
18
- Cauterize.composite(name, &blk)
19
- end
20
- end
21
-
22
- def composites
23
- @composites ||= {}
24
- end
25
-
26
- class CompositeField
27
- attr_reader :name, :type, :description
28
- def initialize(field_name, type_name, desc=nil)
29
- @name = field_name
30
- @type = BaseType.find_type!(type_name)
31
- @description = desc
32
- end
33
-
34
- def field_hash(digest)
35
- digest.update(@name.to_s)
36
- @type.type_hash(digest)
37
- end
38
- end
39
-
40
- class Composite < BaseType
41
- attr_reader :fields
42
-
43
- def initialize(name, desc=nil)
44
- super
45
- @fields = {}
46
- end
47
-
48
- def field(name, type, desc=nil)
49
- if @fields[name]
50
- raise Exception.new("Field name #{name} already used.")
51
- else
52
- @fields[name] = CompositeField.new(name, type, desc)
53
- end
54
- end
55
-
56
- protected
57
-
58
- def local_hash(digest)
59
- @fields.keys.inject(digest) {|d, k|
60
- @fields[k].field_hash(digest)
61
- }
62
- end
63
- end
64
- end
1
+ # composite.rb
2
+ #
3
+ # Composites correspond to C structs.
4
+
5
+ module Cauterize
6
+ module_function
7
+
8
+ def composite(name, desc=nil)
9
+ c = Cauterize.composites[name] || Cauterize.composites[name] = Composite.new(name, desc)
10
+ yield c if block_given?
11
+ return c
12
+ end
13
+
14
+ def composite!(name, &blk)
15
+ if Cauterize.composites[name]
16
+ raise Exception.new("Composite with name #{name} already exists.")
17
+ else
18
+ Cauterize.composite(name, &blk)
19
+ end
20
+ end
21
+
22
+ def composites
23
+ @composites ||= {}
24
+ end
25
+
26
+ class CompositeField
27
+ attr_reader :name, :type, :description
28
+ def initialize(field_name, type_name, desc=nil)
29
+ @name = field_name
30
+ @type = BaseType.find_type!(type_name)
31
+ @description = desc
32
+ end
33
+
34
+ def field_hash(digest)
35
+ digest.update(@name.to_s)
36
+ @type.type_hash(digest)
37
+ end
38
+ end
39
+
40
+ class Composite < BaseType
41
+ attr_reader :fields
42
+
43
+ def initialize(name, desc=nil)
44
+ super
45
+ @fields = {}
46
+ end
47
+
48
+ def field(name, type, desc=nil)
49
+ if @fields[name]
50
+ raise Exception.new("Field name #{name} already used.")
51
+ else
52
+ @fields[name] = CompositeField.new(name, type, desc)
53
+ end
54
+ end
55
+
56
+ protected
57
+
58
+ def local_hash(digest)
59
+ @fields.keys.inject(digest) {|d, k|
60
+ @fields[k].field_hash(digest)
61
+ }
62
+ end
63
+ end
64
+ end
@@ -1,58 +1,58 @@
1
- require 'time'
2
-
3
- module Cauterize
4
- class CSBuilder
5
- attr_reader :cs
6
-
7
- def initialize(cs_file, name="cauterize")
8
- @cs = cs_file
9
- @name = name.camel
10
- end
11
-
12
- def build
13
- build_cs
14
- end
15
-
16
- private
17
-
18
- def build_cs
19
- f = four_space_formatter
20
-
21
- f << "/* WARNING: This is generated code. Do not edit this file directly. */"
22
- f << ""
23
- f << "using System;"
24
- f << "using Cauterize;"
25
- f.blank_line
26
- f << "namespace #{@name}"
27
- f.braces do
28
- f << "public static class #{@name}Cauterize"
29
- f.braces do
30
- f << "public static CauterizeInfo Info = new CauterizeInfo"
31
- f.braces do
32
- f << "Name = \"#{@name}\","
33
- f << "GeneratedVersion = \"#{Cauterize.get_version}\","
34
- f << "GeneratedDate = \"#{DateTime.now.to_s}\","
35
- f << "ModelHashLength = #{BaseType.digest_class.new.length},"
36
- f << "ModelHash = new byte[] {#{BaseType.model_hash.bytes.to_a.join(", ")}}"
37
- end
38
- f << ";"
39
- end
40
- f.blank_line
41
-
42
- instances = BaseType.all_instances
43
- builders = instances.map {|i| Builders.get(:cs, i)}
44
-
45
- builders.each { |b| b.enum_defn(f) }
46
- builders.each { |b| b.class_defn(f) }
47
- # # should we really do these, or is it annotations and a custom
48
- # # formatter in support???
49
- # builders.each { |b| b.packer_defn(f) }
50
- # builders.each { |b| b.unpacker_defn(f) }
51
- end
52
-
53
- File.open(@cs, "wb") do |fh|
54
- fh.write(f.to_s)
55
- end
56
- end
57
- end
58
- end
1
+ require 'time'
2
+
3
+ module Cauterize
4
+ class CSBuilder
5
+ attr_reader :cs
6
+
7
+ def initialize(cs_file, name="cauterize")
8
+ @cs = cs_file
9
+ @name = name.camel
10
+ end
11
+
12
+ def build
13
+ build_cs
14
+ end
15
+
16
+ private
17
+
18
+ def build_cs
19
+ f = four_space_formatter
20
+
21
+ f << "/* WARNING: This is generated code. Do not edit this file directly. */"
22
+ f << ""
23
+ f << "using System;"
24
+ f << "using Cauterize;"
25
+ f.blank_line
26
+ f << "namespace #{@name}"
27
+ f.braces do
28
+ f << "public static class #{@name}Cauterize"
29
+ f.braces do
30
+ f << "public static CauterizeInfo Info = new CauterizeInfo"
31
+ f.braces do
32
+ f << "Name = \"#{@name}\","
33
+ f << "GeneratedVersion = \"#{Cauterize.get_version}\","
34
+ f << "GeneratedDate = \"#{DateTime.now.to_s}\","
35
+ f << "ModelHashLength = #{BaseType.digest_class.new.length},"
36
+ f << "ModelHash = new byte[] {#{BaseType.model_hash.bytes.to_a.join(", ")}}"
37
+ end
38
+ f << ";"
39
+ end
40
+ f.blank_line
41
+
42
+ instances = BaseType.all_instances
43
+ builders = instances.map {|i| Builders.get(:cs, i)}
44
+
45
+ builders.each { |b| b.enum_defn(f) }
46
+ builders.each { |b| b.class_defn(f) }
47
+ # # should we really do these, or is it annotations and a custom
48
+ # # formatter in support???
49
+ # builders.each { |b| b.packer_defn(f) }
50
+ # builders.each { |b| b.unpacker_defn(f) }
51
+ end
52
+
53
+ File.open(@cs, "wb") do |fh|
54
+ fh.write(f.to_s)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,34 +1,34 @@
1
- module Cauterize
2
- class DocBuilder
3
- attr_reader :doc_path, :name
4
- def initialize(doc_path, name="cauterize")
5
- @doc_path = doc_path
6
- @name = name
7
- end
8
-
9
- def build
10
- build_doc
11
- end
12
-
13
- private
14
-
15
- def build_doc
16
- File.open(@doc_path, "wb") do |fh|
17
- doc_sections = []
18
-
19
- instances = BaseType.all_instances
20
- builders = instances.map {|i| Builders.get(:doc, i)}
21
-
22
- builders.each do |b|
23
- body_lines = (b.body || []).map {|l| " " + l}
24
- lines = ([b.heading] + body_lines)
25
-
26
- doc_sections << lines.join("\n") + "\n"
27
- end
28
-
29
- fh.write(doc_sections.join("\n"))
30
- end
31
- end
32
- end
33
- end
34
-
1
+ module Cauterize
2
+ class DocBuilder
3
+ attr_reader :doc_path, :name
4
+ def initialize(doc_path, name="cauterize")
5
+ @doc_path = doc_path
6
+ @name = name
7
+ end
8
+
9
+ def build
10
+ build_doc
11
+ end
12
+
13
+ private
14
+
15
+ def build_doc
16
+ File.open(@doc_path, "wb") do |fh|
17
+ doc_sections = []
18
+
19
+ instances = BaseType.all_instances
20
+ builders = instances.map {|i| Builders.get(:doc, i)}
21
+
22
+ builders.each do |b|
23
+ body_lines = (b.body || []).map {|l| " " + l}
24
+ lines = ([b.heading] + body_lines)
25
+
26
+ doc_sections << lines.join("\n") + "\n"
27
+ end
28
+
29
+ fh.write(doc_sections.join("\n"))
30
+ end
31
+ end
32
+ end
33
+ end
34
+