autoc 0.8 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/README +15 -4
  3. data/doc/AutoC.html +245 -0
  4. data/doc/AutoC/Code.html +520 -0
  5. data/doc/AutoC/Collection.html +923 -0
  6. data/doc/AutoC/HashMap.html +1161 -0
  7. data/doc/AutoC/HashSet.html +1122 -0
  8. data/doc/AutoC/List.html +1002 -0
  9. data/doc/AutoC/Module.html +951 -0
  10. data/doc/AutoC/Module/File.html +412 -0
  11. data/doc/AutoC/Module/Header.html +432 -0
  12. data/doc/AutoC/Module/Source.html +704 -0
  13. data/doc/AutoC/Priority.html +138 -0
  14. data/doc/AutoC/Queue.html +1167 -0
  15. data/doc/AutoC/Type.html +1152 -0
  16. data/doc/AutoC/UserDefinedType.html +655 -0
  17. data/doc/AutoC/Vector.html +856 -0
  18. data/doc/_index.html +299 -0
  19. data/doc/class_list.html +54 -0
  20. data/doc/css/common.css +1 -0
  21. data/doc/css/full_list.css +57 -0
  22. data/doc/css/style.css +339 -0
  23. data/doc/file.README.html +112 -0
  24. data/doc/file_list.html +56 -0
  25. data/doc/frames.html +26 -0
  26. data/doc/index.html +112 -0
  27. data/doc/js/app.js +219 -0
  28. data/doc/js/full_list.js +178 -0
  29. data/doc/js/jquery.js +4 -0
  30. data/doc/method_list.html +605 -0
  31. data/doc/top-level-namespace.html +112 -0
  32. data/lib/autoc.rb +35 -12
  33. data/lib/autoc/{code_builder.rb → code.rb} +230 -247
  34. data/lib/autoc/collection.rb +137 -0
  35. data/lib/autoc/collection/hash_map.rb +388 -0
  36. data/lib/autoc/collection/hash_set.rb +433 -0
  37. data/lib/autoc/collection/list.rb +410 -0
  38. data/lib/autoc/collection/queue.rb +514 -0
  39. data/lib/autoc/collection/vector.rb +295 -0
  40. data/lib/autoc/type.rb +198 -0
  41. data/test/test.c +921 -396
  42. data/test/test.h +41 -0
  43. data/test/test.rb +21 -26
  44. data/test/test_auto.c +2630 -3961
  45. data/test/test_auto.h +449 -560
  46. metadata +50 -17
  47. data/lib/autoc/data_struct_builder.rb +0 -1794
  48. data/lib/autoc/type_builder.rb +0 -24
  49. data/manual/manual.pdf +0 -0
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.8.7.4
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!top-level-namespace.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+
36
+
37
+ <span class="title">Top Level Namespace</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Top Level Namespace
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ </dl>
82
+ <div class="clear"></div>
83
+
84
+ <h2>Defined Under Namespace</h2>
85
+ <p class="children">
86
+
87
+
88
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="AutoC.html" title="AutoC (module)">AutoC</a></span>
89
+
90
+
91
+
92
+
93
+ </p>
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ </div>
104
+
105
+ <div id="footer">
106
+ Generated on Fri Jun 6 18:05:34 2014 by
107
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
+ 0.8.7.4 (ruby-2.0.0).
109
+ </div>
110
+
111
+ </body>
112
+ </html>
data/lib/autoc.rb CHANGED
@@ -1,12 +1,35 @@
1
- =begin rdoc
2
- = AutoC documentation home
3
-
4
- *AutoC* is a host of Ruby modules related to automatic C source code generation.
5
-
6
- [CodeBuilder] Generic C multi-source module generator.
7
- [DataStructBuilder] Strongly-typed data structure generators akin the C++ STL container classes.
8
- =end
9
-
10
-
11
- require "autoc/code_builder"
12
- require "autoc/data_struct_builder"
1
+ =begin rdoc
2
+
3
+ *AutoC* is a host of Ruby modules related to automatic C source code generation.
4
+
5
+ . {AutoC::Code} - generic C multi-source module generator.
6
+ . {AutoC::Collection} - strongly-typed data structure generators similar
7
+ to the C++ STL container classes.
8
+
9
+ == Versioning scheme
10
+
11
+ AutoC adheres to simple major.minor versioning scheme.
12
+
13
+ Change in major number states incompatible changes in the code
14
+ while change in minor number states (rather) small incremental changes that
15
+ should not normally break things.
16
+
17
+ That said, release 1.0 is the _first_ release of version 1 which is considered beta, not stable.
18
+ _Note that it is not necessary stable or feature complete._
19
+ Releases 1.1+ will present incremental improvements, bugfixes, documentation updates etc. to version 1.
20
+ Should the major incompatible changes be made, the new release 2.0 will be introduced and so forth.
21
+
22
+ =end
23
+ module AutoC
24
+ VERSION = "1.0"
25
+ end # AutoC
26
+
27
+
28
+ require "autoc/code"
29
+ require "autoc/type"
30
+ require "autoc/collection"
31
+ require "autoc/collection/list"
32
+ require "autoc/collection/queue"
33
+ require "autoc/collection/vector"
34
+ require "autoc/collection/hash_set"
35
+ require "autoc/collection/hash_map"
@@ -1,247 +1,230 @@
1
- require "set"
2
-
3
-
4
- module CodeBuilder
5
-
6
-
7
- # class Entity
8
- # def entities()
9
- # def priority()
10
- # def source_size()
11
- # def attach(source)
12
- # def write_intf(stream)
13
- # def write_defs(stream)
14
- # def write_decls(stream)
15
- # def hash()
16
- # def eql?(other)
17
- # end
18
-
19
-
20
- # TODO min/max Fixnums
21
- module Priority
22
- DEFAULT = 0
23
- MIN = -1000
24
- MAX = +1000
25
- end
26
-
27
-
28
- # A no-op entity implementation with reasonable defaults
29
- class Code
30
- def entities; [] end
31
- def priority
32
- if entities.empty?
33
- Priority::DEFAULT
34
- else
35
- result = Priority::DEFAULT
36
- entities.each do |e|
37
- ep = e.priority
38
- result = ep if result > ep
39
- end
40
- result-1
41
- end
42
- end
43
- def source_size
44
- s = String.new
45
- write_decls(s)
46
- write_defs(s)
47
- s.size
48
- end
49
- def attach(source) source << self if source.smallest? end
50
- def write_intf(stream) end
51
- def write_defs(stream) end
52
- def write_decls(stream) end
53
- end # Code
54
-
55
-
56
- class Module
57
-
58
- attr_reader :header, :smallest_source, :main_source
59
-
60
- def initialize
61
- @entities = Set.new
62
- @source_size_threshold = 0
63
- end
64
-
65
- def <<(obj)
66
- unless @entities.include?(obj)
67
- @entities << obj
68
- obj.entities.each {|e| self << e}
69
- end
70
- self
71
- end
72
-
73
- # def new_header()
74
-
75
- # def new_source(index)
76
-
77
- def source_count=(count)
78
- @source_count = count
79
- end
80
-
81
- def generate!
82
- @header = new_header
83
- @sources = []
84
- (1..source_count).each {|i| @sources << new_source(i)}
85
- @main_source = @sources.first
86
- @smallest_source = @main_source
87
- # It appears that computing the size of a source might be a fairly expensive operation so do it only when neccessary
88
- refresh_smallest_source = source_count > 1
89
- @entities.each do |e|
90
- @header << e
91
- @smallest_source = @sources.sort_by {|s| s.size}.first if refresh_smallest_source
92
- @sources.each {|s| e.attach(s)}
93
- end
94
- @header.generate
95
- @sources.each {|s| s.generate}
96
- end
97
-
98
- def source_count
99
- if @source_count.nil?
100
- total = 0
101
- @entities.each {|e| total += e.source_size}
102
- count = @source_size_threshold > 0 ? (total/@source_size_threshold + 1) : 1
103
- @source_count = count > 0 ? count : 1
104
- else
105
- @source_count
106
- end
107
- end
108
-
109
- end # Module
110
-
111
-
112
- def self.priority_sort(entities, reverse = false)
113
- list = entities.to_a.sort_by!{|e| e.priority}
114
- list.reverse! unless reverse
115
- list
116
- end # priority_sort
117
-
118
-
119
- class File
120
-
121
- attr_reader :entities
122
-
123
- # def new_stream()
124
-
125
- # def write(stream)
126
-
127
- def initialize(m)
128
- @entities = Set.new
129
- @module = m
130
- end
131
-
132
- def generate
133
- stream = new_stream
134
- begin
135
- write(stream)
136
- ensure
137
- stream.close
138
- end
139
- end
140
-
141
- def <<(e)
142
- @entities << e
143
- self
144
- end
145
-
146
- end # File
147
-
148
-
149
- class Header < File
150
- def write(stream)
151
- CodeBuilder.priority_sort(entities).each {|e| e.write_intf(stream)}
152
- end
153
- end # Header
154
-
155
-
156
- class Source < File
157
-
158
- attr_reader :index
159
-
160
- def initialize(m, i)
161
- super(m)
162
- @index = i
163
- end
164
-
165
- def write(stream)
166
- sorted = CodeBuilder.priority_sort(entities)
167
- sorted.each {|e| e.write_decls(stream)}
168
- sorted.each {|e| e.write_defs(stream)}
169
- end
170
-
171
- def main?
172
- equal?(@module.main_source)
173
- end
174
-
175
- def smallest?
176
- equal?(@module.smallest_source)
177
- end
178
-
179
- def size
180
- size = 0
181
- @entities.each {|e| size += e.source_size}
182
- size
183
- end
184
-
185
- end # Source
186
-
187
-
188
- class CModule < CodeBuilder::Module
189
- def self.generate!(name, &block)
190
- m = self.new(name)
191
- block.call(m)
192
- m.generate!
193
- end
194
- attr_reader :name
195
- def initialize(name)
196
- super()
197
- @name = name.to_s # TODO validate
198
- end
199
- def new_header
200
- Header.new(self)
201
- end
202
- def new_source(index)
203
- Source.new(self, index)
204
- end
205
- class Header < CodeBuilder::Header
206
- attr_reader :file_name
207
- def initialize(*args)
208
- super
209
- @file_name = "#{@module.name.downcase}_auto.h"
210
- @guard_macro = "#{@module.name.upcase}_AUTO_H"
211
- end
212
- def new_stream
213
- ::File.new(@file_name, "wt")
214
- end
215
- def write(stream)
216
- stream << %$
217
- /* AUTOMATICALLY GENERATED HEADER FILE. DO NOT MODIFY. */
218
- #ifndef #{@guard_macro}
219
- #define #{@guard_macro}
220
- $
221
- super
222
- stream << %$
223
- #endif
224
- $
225
- end
226
- end # Header
227
- class Source < CodeBuilder::Source
228
- attr_reader :file_name
229
- def initialize(*args)
230
- super
231
- @file_name = @module.source_count > 1 ? "#{@module.name.downcase}_auto#{index}.c" : "#{@module.name.downcase}_auto.c"
232
- end
233
- def new_stream
234
- ::File.new(@file_name, "wt")
235
- end
236
- def write(stream)
237
- stream << %$
238
- /* AUTOMATICALLY GENERATED SOURCE FILE. DO NOT MODIFY. */
239
- #include "#{@module.header.file_name}"
240
- $
241
- super
242
- end
243
- end # Source
244
- end # Module
245
-
246
-
247
- end # CodeBuilder
1
+ require "set"
2
+
3
+
4
+ module AutoC
5
+
6
+
7
+ # class Entity
8
+ # def entities()
9
+ # def priority()
10
+ # def source_size()
11
+ # def attach(source)
12
+ # def write_intf(stream)
13
+ # def write_defs(stream)
14
+ # def write_decls(stream)
15
+ # def hash()
16
+ # def eql?(other)
17
+ # end
18
+
19
+
20
+ # TODO min/max Fixnums
21
+ module Priority
22
+ DEFAULT = 0
23
+ MIN = -1000
24
+ MAX = +1000
25
+ end
26
+
27
+
28
+ # A no-op entity implementation with reasonable defaults
29
+ class Code
30
+ def entities; [] end
31
+ def priority
32
+ if entities.empty?
33
+ Priority::DEFAULT
34
+ else
35
+ result = Priority::DEFAULT
36
+ entities.each do |e|
37
+ ep = e.priority
38
+ result = ep if result > ep
39
+ end
40
+ result-1
41
+ end
42
+ end
43
+ def source_size
44
+ s = String.new
45
+ write_decls(s)
46
+ write_defs(s)
47
+ s.size
48
+ end
49
+ def attach(source) source << self if source.smallest? end
50
+ def write_intf(stream) end
51
+ def write_defs(stream) end
52
+ def write_decls(stream) end
53
+ end # Code
54
+
55
+
56
+ class Module
57
+
58
+ def self.generate!(name, &block)
59
+ m = self.new(name)
60
+ block.call(m)
61
+ m.generate!
62
+ end
63
+
64
+ attr_reader :name, :header, :smallest_source, :main_source
65
+
66
+ def initialize(name)
67
+ @entities = Set.new
68
+ @source_size_threshold = 0
69
+ @name = name.to_s # TODO validate
70
+ end
71
+
72
+ def <<(obj)
73
+ unless @entities.include?(obj)
74
+ @entities << obj
75
+ obj.entities.each {|e| self << e}
76
+ end
77
+ self
78
+ end
79
+
80
+ def new_header
81
+ Header.new(self)
82
+ end
83
+
84
+ def new_source(index)
85
+ Source.new(self, index)
86
+ end
87
+
88
+ def source_count=(count)
89
+ @source_count = count
90
+ end
91
+
92
+ def generate!
93
+ @header = new_header
94
+ @sources = []
95
+ (1..source_count).each {|i| @sources << new_source(i)}
96
+ @main_source = @sources.first
97
+ @smallest_source = @main_source
98
+ # It appears that computing the size of a source might be a fairly expensive operation so do it only when neccessary
99
+ refresh_smallest_source = source_count > 1
100
+ @entities.each do |e|
101
+ @header << e
102
+ @smallest_source = @sources.sort_by {|s| s.size}.first if refresh_smallest_source
103
+ @sources.each {|s| e.attach(s)}
104
+ end
105
+ @header.generate
106
+ @sources.each {|s| s.generate}
107
+ end
108
+
109
+ def source_count
110
+ if @source_count.nil?
111
+ total = 0
112
+ @entities.each {|e| total += e.source_size}
113
+ count = @source_size_threshold > 0 ? (total/@source_size_threshold + 1) : 1
114
+ @source_count = count > 0 ? count : 1
115
+ else
116
+ @source_count
117
+ end
118
+ end
119
+
120
+ end # Module
121
+
122
+
123
+ def self.priority_sort(entities, reverse = false)
124
+ list = entities.to_a.sort! {|a,b| a.priority <=> b.priority}
125
+ list.reverse! unless reverse
126
+ list
127
+ end # priority_sort
128
+
129
+
130
+ class Module::File
131
+
132
+ attr_reader :entities
133
+
134
+ # def new_stream()
135
+
136
+ # def write(stream)
137
+
138
+ def initialize(m)
139
+ @entities = Set.new
140
+ @module = m
141
+ end
142
+
143
+ def generate
144
+ stream = new_stream
145
+ begin
146
+ write(stream)
147
+ ensure
148
+ stream.close
149
+ end
150
+ end
151
+
152
+ def <<(e)
153
+ @entities << e
154
+ self
155
+ end
156
+
157
+ end # File
158
+
159
+
160
+ class Module::Header < Module::File
161
+
162
+ attr_reader :file_name
163
+
164
+ def initialize(*args)
165
+ super
166
+ @file_name = "#{@module.name.downcase}_auto.h"
167
+ @guard_macro = "#{@module.name.upcase}_AUTO_H"
168
+ end
169
+
170
+ def new_stream
171
+ ::File.new(@file_name, "w")
172
+ end
173
+
174
+ def write(stream)
175
+ stream << %$
176
+ /* AUTOMATICALLY GENERATED HEADER FILE. DO NOT MODIFY. */
177
+ #ifndef #{@guard_macro}
178
+ #define #{@guard_macro}
179
+ $
180
+ AutoC.priority_sort(entities).each {|e| e.write_intf(stream)}
181
+ stream << %$
182
+ #endif
183
+ $
184
+ end
185
+
186
+ end # Header
187
+
188
+
189
+ class Module::Source < Module::File
190
+
191
+ attr_reader :index, :file_name
192
+
193
+ def initialize(m, i)
194
+ super(m)
195
+ @index = i
196
+ @file_name = @module.source_count > 1 ? "#{@module.name.downcase}_auto#{index}.c" : "#{@module.name.downcase}_auto.c"
197
+ end
198
+
199
+ def main?
200
+ equal?(@module.main_source)
201
+ end
202
+
203
+ def smallest?
204
+ equal?(@module.smallest_source)
205
+ end
206
+
207
+ def size
208
+ size = 0
209
+ @entities.each {|e| size += e.source_size}
210
+ size
211
+ end
212
+
213
+ def new_stream
214
+ ::File.new(@file_name, "w")
215
+ end
216
+
217
+ def write(stream)
218
+ stream << %$
219
+ /* AUTOMATICALLY GENERATED SOURCE FILE. DO NOT MODIFY. */
220
+ #include "#{@module.header.file_name}"
221
+ $
222
+ sorted = AutoC.priority_sort(entities)
223
+ sorted.each {|e| e.write_decls(stream)}
224
+ sorted.each {|e| e.write_defs(stream)}
225
+ end
226
+
227
+ end # Source
228
+
229
+
230
+ end # AutoC