autoc 0.8 → 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README +15 -4
- data/doc/AutoC.html +245 -0
- data/doc/AutoC/Code.html +520 -0
- data/doc/AutoC/Collection.html +923 -0
- data/doc/AutoC/HashMap.html +1161 -0
- data/doc/AutoC/HashSet.html +1122 -0
- data/doc/AutoC/List.html +1002 -0
- data/doc/AutoC/Module.html +951 -0
- data/doc/AutoC/Module/File.html +412 -0
- data/doc/AutoC/Module/Header.html +432 -0
- data/doc/AutoC/Module/Source.html +704 -0
- data/doc/AutoC/Priority.html +138 -0
- data/doc/AutoC/Queue.html +1167 -0
- data/doc/AutoC/Type.html +1152 -0
- data/doc/AutoC/UserDefinedType.html +655 -0
- data/doc/AutoC/Vector.html +856 -0
- data/doc/_index.html +299 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +112 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +112 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +605 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/autoc.rb +35 -12
- data/lib/autoc/{code_builder.rb → code.rb} +230 -247
- data/lib/autoc/collection.rb +137 -0
- data/lib/autoc/collection/hash_map.rb +388 -0
- data/lib/autoc/collection/hash_set.rb +433 -0
- data/lib/autoc/collection/list.rb +410 -0
- data/lib/autoc/collection/queue.rb +514 -0
- data/lib/autoc/collection/vector.rb +295 -0
- data/lib/autoc/type.rb +198 -0
- data/test/test.c +921 -396
- data/test/test.h +41 -0
- data/test/test.rb +21 -26
- data/test/test_auto.c +2630 -3961
- data/test/test_auto.h +449 -560
- metadata +50 -17
- data/lib/autoc/data_struct_builder.rb +0 -1794
- data/lib/autoc/type_builder.rb +0 -24
- 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
|
+
— 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> »
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
@
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
@
|
102
|
-
|
103
|
-
@
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
def
|
200
|
-
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|