forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdcparse.cxx
More file actions
228 lines (192 loc) · 5.53 KB
/
dcparse.cxx
File metadata and controls
228 lines (192 loc) · 5.53 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
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file dcparse.cxx
* @author drose
* @date 2000-10-05
*/
#include "dcbase.h"
#include "dcFile.h"
#include "dcClass.h"
#include "dcTypedef.h"
#include "memoryUsage.h"
#include "indent.h"
#include "panda_getopt.h"
using std::cerr;
using std::cout;
void
usage() {
cerr <<
"\n"
"Usage:\n\n"
"dcparse [options] [file1 file2 ...]\n"
"dcparse -h\n\n";
}
void
help() {
usage();
cerr <<
"This program reads one or more DC files, which are used to describe the\n"
"communication channels in the distributed class system. By default,\n"
"the file(s) are read and concatenated, and a single hash code is printed\n"
"corresponding to the file's contents.\n\n"
"Options:\n\n"
" -v Writes a complete parseable version of the file to standard\n"
" output instead of printing a hash code.\n\n"
" -b Writes a brief parseable version of the file instead of a full\n"
" version. This is semantically the same as the output produced\n"
" the above -v option--reading it would produce exactly the same\n"
" results--but it is designed to be slightly obfuscated. The\n"
" comments and parameter names are not included.\n\n"
" -c Write a list of class names, showing the inheritance hierarchy.\n"
" Some class names will be listed twice in the presence of multiple\n"
" inheritance.\n\n"
" -f Write a complete list of field names available for each class,\n"
" including all inherited fields.\n\n";
}
void
write_class_hierarchy(int indent_level, const DCFile &file,
const DCClass *this_dclass) {
indent(cout, indent_level)
<< this_dclass->get_name() << "\n";
int num_classes = file.get_num_classes();
for (int i = 0; i < num_classes; ++i) {
const DCClass *dclass = file.get_class(i);
bool is_my_child = false;
int num_parents = dclass->get_num_parents();
for (int j = 0; j < num_parents && !is_my_child; ++j) {
is_my_child = (dclass->get_parent(j) == this_dclass);
}
if (is_my_child) {
write_class_hierarchy(indent_level + 2, file, dclass);
}
}
}
void
write_class_hierarchy(const DCFile &file) {
int num_classes = file.get_num_classes();
for (int i = 0; i < num_classes; ++i) {
const DCClass *dclass = file.get_class(i);
if (dclass->get_num_parents() == 0) {
write_class_hierarchy(0, file, dclass);
cout << "\n";
}
}
}
void
write_complete_field_list(const DCFile &file) {
int num_classes = file.get_num_classes();
for (int i = 0; i < num_classes; ++i) {
const DCClass *dclass = file.get_class(i);
cout << "\n" << dclass->get_name() << "\n";
int num_inherited_fields = dclass->get_num_inherited_fields();
for (int j = 0; j < num_inherited_fields; ++j) {
const DCField *field = dclass->get_inherited_field(j);
cout << " ";
if (field->get_class() != dclass) {
cout << field->get_class()->get_name() << "::";
}
cout << field->get_name();
if (field->as_atomic_field() != nullptr ||
field->as_molecular_field() != nullptr) {
// It's a "method".
cout << "()";
}
field->output_keywords(cout);
cout << "\n";
}
}
}
int
main(int argc, char *argv[]) {
// extern char *optarg;
extern int optind;
const char *optstr = "bvcfh";
bool dump_verbose = false;
bool dump_brief = false;
bool dump_classes = false;
bool dump_fields = false;
int flag = getopt(argc, argv, optstr);
while (flag != EOF) {
switch (flag) {
case 'b':
dump_brief = true;
break;
case 'v':
dump_verbose = true;
break;
case 'c':
dump_classes = true;
break;
case 'f':
dump_fields = true;
break;
case 'h':
help();
exit(1);
default:
exit(1);
}
flag = getopt(argc, argv, optstr);
}
argc -= (optind-1);
argv += (optind-1);
if (argc < 2) {
usage();
exit(1);
}
DCFile file;
for (int i = 1; i < argc; i++) {
if (!file.read(argv[i])) {
return (1);
}
}
if (!file.all_objects_valid() && !dump_brief) {
cerr << "File is incomplete. The following objects are undefined:\n";
int num_typedefs = file.get_num_typedefs();
int i;
for (i = 0; i < num_typedefs; i++) {
DCTypedef *dtypedef = file.get_typedef(i);
if (dtypedef->is_bogus_typedef()) {
cerr << " " << dtypedef->get_name() << "\n";
}
}
int num_classes = file.get_num_classes();
for (i = 0; i < num_classes; i++) {
DCClass *dclass = file.get_class(i);
if (dclass->is_bogus_class()) {
cerr << " " << dclass->get_name() << "\n";
}
}
return 1;
}
if (dump_verbose || dump_brief) {
if (!file.write(cout, dump_brief)) {
return 1;
}
} else if (dump_classes) {
write_class_hierarchy(file);
} else if (dump_fields) {
write_complete_field_list(file);
} else {
unsigned long hash = file.get_hash();
cerr << "File hash is " << hash << " (signed " << (long)hash << ")\n";
}
#ifdef DO_MEMORY_USAGE
if (MemoryUsage::is_tracking()) {
file.clear();
MemoryUsage::show_current_types();
for (int i = 1; i < argc; i++) {
file.read(argv[i]);
}
file.clear();
MemoryUsage::show_current_types();
}
#endif
return 0;
}