-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathMakeModelMainPage.rb
More file actions
229 lines (181 loc) · 5.59 KB
/
MakeModelMainPage.rb
File metadata and controls
229 lines (181 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
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
200
201
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
# run from inside /developer/ruby
# add path to ruby bindings to ruby include
# ruby -I ../../build/ruby/Release MakeModelMainPage.rb > out.txt
require 'openstudio'
class ClassInfo
attr_accessor :name, :abstract, :base_class, :idd_object_type, :children_src, :allowable_child_types_src, :parent_src
def to_s
result = ""
if @abstract
result = "abstract class #{@name} < #{@base_class}\n"
else
result = "concrete class #{@name} < #{@base_class} wraps #{@idd_object_type}\n"
end
if @parent_src
result += @parent_src
end
if @children_src
result += @children_src
end
if @allowable_child_types_src
result += @allowable_child_types_src
end
return result
end
end
def parse_impl(obj_name, impl_header)
info = ClassInfo.new
info.name = obj_name
info.abstract = true
File.open(impl_header, 'r') do |file|
while line = file.gets
if m = Regexp.new("#{obj_name}\_Impl\s*:\s*public\s*([^\s]*)\_Impl").match(line)
info.base_class = m[1]
end
if /virtual\s+const\s+IddObjectType\&\s+iddObjectType\(\)\s+const/.match(line)
info.abstract = false
end
end
end
return info
end
def parse_cpp(info, cpp_filename)
File.open(cpp_filename, 'r') do |file|
while line = file.gets
if /_Impl::children\(\s*\)\s+const/.match(line)
first_time = true
curly_count = line.count('{')
children_src = line
while (first_time or curly_count > 0) and line = file.gets
first_time = false
curly_count += line.count('{')
curly_count -= line.count('}')
children_src += line
end
info.children_src = children_src
elsif /_Impl::allowableChildTypes\(\s*\)\s+const/.match(line)
first_time = true
curly_count = line.count('{')
allowable_child_types_src = line
while (first_time or curly_count > 0) and line = file.gets
first_time = false
curly_count += line.count('{')
curly_count -= line.count('}')
allowable_child_types_src += line
end
info.allowable_child_types_src = allowable_child_types_src
elsif /_Impl::parent\(\s*\)\s+const/.match(line)
first_time = true
curly_count = line.count('{')
parent_src = line
while (first_time or curly_count > 0) and line = file.gets
first_time = false
curly_count += line.count('{')
curly_count -= line.count('}')
parent_src += line
end
info.parent_src = parent_src
end
end
end
return info
end
model_dir = "../../src/model/"
puts
puts "***************************************************"
puts "parsing mainpage"
# parse main page
main_page_objects = Hash.new
File.open(model_dir + "mainpage.hpp", 'r') do |file|
while line = file.gets
if /\\subsection modelobject_hierachy Parent-Child Hierarchy/.match(line)
while line = file.gets
if /\<ul\>/.match(line)
break
end
end
ul_count = 1
while ul_count > 0 and line = file.gets
if m = /\<li\>\s+([^\s]+)\s+\(([^,\s\)]+)/.match(line)
info = ClassInfo.new
info.abstract = false
info.name = m[1]
info.base_class = m[2]
end
ul_count += (line.split('<ul>').size - 1)
ul_count -= (line.split('</ul>').size - 1)
main_page_objects[info.name] = info
end
end
end
end
puts
puts "***************************************************"
puts "parsing source files"
# parse files to find model objects
src_objects = Hash.new
Dir.glob(model_dir + "*.cpp").each do |cpp_filename|
obj_name = File.basename(cpp_filename, '.cpp')
next if obj_name == "ModelObject"
impl_header = model_dir + obj_name + "_Impl.hpp"
if not File.exists?(impl_header)
puts "Can't find impl header for #{obj_name}"
next
end
info = parse_impl(obj_name, impl_header)
info = parse_cpp(info, cpp_filename)
if not info.abstract
begin
idd_object_type = nil
cmd = "idd_object_type = OpenStudio::Model::#{obj_name}::iddObjectType"
#puts cmd
eval(cmd, binding)
info.idd_object_type = idd_object_type.valueName
rescue => e
puts "Could not determine iddObjectType for #{obj_name}. #{e}"
info.idd_object_type = "Unknown"
end
end
src_objects[obj_name] = info
end
puts
puts "***************************************************"
puts "comparing mainpage to source files"
# compare mainpage to src objects
main_page_objects.each_pair do |name, main_page_info|
info = src_objects[name]
if not info
puts "#{name} is listed in the mainpage but there is no model object"
else
if main_page_info.base_class != info.base_class
puts "mainpage lists #{name}'s base class as #{main_page_info.base_class} but it really is #{info.base_class}"
end
end
end
src_objects.each_pair do |name, info|
main_page_info = main_page_objects[name]
if not info.abstract and not main_page_info
puts "#{name} is not listed in the mainpage"
end
end
puts
puts "***************************************************"
puts "printing object information from source files"
def recursive_print(info, object_map)
puts info.to_s
if info.base_class != "ModelObject"
base_info = object_map[info.base_class]
if base_info
recursive_print(base_info, object_map)
else
raise "Can't find info for base class #{info.base_class}"
end
end
end
src_objects.each_value do |info|
if not info.abstract
puts
puts "***************************************************"
recursive_print(info, src_objects)
end
end