Skip to content

Commit e672c49

Browse files
committed
interrogatedb: Add new textual output for regression testing
Internal and unstable for now
1 parent 223fd8a commit e672c49

22 files changed

+1307
-177
lines changed

src/interrogate/interrogate.cxx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ CPPParser parser;
3232
Filename output_code_filename;
3333
Filename output_include_filename;
3434
Filename output_data_filename;
35+
Filename output_text_filename;
3536
Filename source_file_directory;
3637
string output_data_basename;
3738
bool output_module_specific = false;
@@ -62,6 +63,7 @@ static const char *short_options = "I:S:D:F:vh";
6263
enum CommandOptions {
6364
CO_oc = 256,
6465
CO_od,
66+
CO_oh,
6567
CO_srcdir,
6668
CO_module,
6769
CO_library,
@@ -90,6 +92,7 @@ enum CommandOptions {
9092
static struct option long_options[] = {
9193
{ "oc", required_argument, nullptr, CO_oc },
9294
{ "od", required_argument, nullptr, CO_od },
95+
{ "oh", required_argument, nullptr, CO_oh },
9396
{ "srcdir", required_argument, nullptr, CO_srcdir },
9497
{ "module", required_argument, nullptr, CO_module },
9598
{ "library", required_argument, nullptr, CO_library },
@@ -366,6 +369,11 @@ main(int argc, char **argv) {
366369
output_data_filename.make_absolute();
367370
break;
368371

372+
case CO_oh:
373+
output_text_filename = Filename::from_os_specific(optarg);
374+
output_text_filename.make_absolute();
375+
break;
376+
369377
case CO_srcdir:
370378
source_file_directory = Filename::from_os_specific(optarg);
371379
source_file_directory.make_absolute();
@@ -489,6 +497,7 @@ main(int argc, char **argv) {
489497

490498
output_code_filename.set_text();
491499
output_data_filename.set_text();
500+
output_text_filename.set_text();
492501
// output_include_filename.set_text();
493502
output_data_basename = output_data_filename.get_basename();
494503

@@ -655,5 +664,17 @@ main(int argc, char **argv) {
655664
}
656665
}
657666

667+
if (!output_text_filename.empty()) {
668+
std::ofstream output_text;
669+
output_text_filename.open_write(output_text);
670+
671+
if (output_text.fail()) {
672+
nout << "Unable to write to " << output_text_filename << "\n";
673+
status = -1;
674+
} else {
675+
InterrogateDatabase::get_ptr()->write_text(output_text);
676+
}
677+
}
678+
658679
return status;
659680
}

src/interrogatedb/interrogateComponent.cxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
// functions that must return a const string reference.
1919
std::string InterrogateComponent::_empty_string;
2020

21+
void InterrogateComponent::
22+
write_names(std::ostream &out) const {
23+
out << "\"" << _name << "\"";
24+
25+
if (!_alt_names.empty()) {
26+
out << " /";
27+
28+
for (const std::string &alt_name : _alt_names) {
29+
out << " \"" << alt_name << "\"";
30+
}
31+
}
32+
}
33+
2134
/**
2235
* Formats the component for output to a data file.
2336
*/

src/interrogatedb/interrogateComponent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class EXPCL_INTERROGATEDB InterrogateComponent {
4545
INLINE int get_num_alt_names() const;
4646
INLINE const std::string &get_alt_name(int n) const;
4747

48+
void write_names(std::ostream &out) const;
4849
void output(std::ostream &out) const;
4950
void input(std::istream &in);
5051

src/interrogatedb/interrogateDatabase.cxx

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,151 @@ remap_indices(int first_index, IndexRemapper &remap) {
733733
return _next_index;
734734
}
735735

736+
/**
737+
* Writes the database in a human readable text format.
738+
*/
739+
void InterrogateDatabase::
740+
write_text(std::ostream &out) const {
741+
// Write out the file header.
742+
out << "version: " << _current_major_version << "." << _current_minor_version << "\n\n";
743+
744+
// Write out the index. Simultaneously, make a big vector of everything to
745+
// be sorted by scoped name.
746+
std::vector<std::pair<std::string, int> > things;
747+
out << "index:\n";
748+
for (int index = 1; index < _next_index; ++index) {
749+
out << " -";
750+
751+
FunctionMap::const_iterator fi;
752+
fi = _function_map.find(index);
753+
if (fi != _function_map.end() && (*fi).second != nullptr) {
754+
out << " function " << (*fi).second->get_scoped_name();
755+
things.push_back(std::make_pair((*fi).second->get_scoped_name(), index));
756+
}
757+
758+
FunctionWrapperMap::const_iterator wi;
759+
wi = _wrapper_map.find(index);
760+
if (wi != _wrapper_map.end()) {
761+
out << " wrapper";
762+
if ((*wi).second.has_name()) {
763+
out << " \"" << (*wi).second.get_name() << "\"";
764+
}
765+
766+
// Wrappers often have no name, show associated function
767+
fi = _function_map.find((*wi).second.get_function());
768+
if (fi != _function_map.end() && (*fi).second != nullptr) {
769+
out << " for " << (*fi).second->get_scoped_name();
770+
}
771+
}
772+
773+
TypeMap::const_iterator ti;
774+
ti = _type_map.find(index);
775+
if (ti != _type_map.end()) {
776+
out << " type " << (*ti).second.get_scoped_name();
777+
things.push_back(std::make_pair((*ti).second.get_scoped_name(), index));
778+
}
779+
780+
ManifestMap::const_iterator mi;
781+
mi = _manifest_map.find(index);
782+
if (mi != _manifest_map.end()) {
783+
out << " manifest " << (*mi).second.get_name();
784+
things.push_back(std::make_pair((*mi).second.get_name(), index));
785+
}
786+
787+
ElementMap::const_iterator ei;
788+
ei = _element_map.find(index);
789+
if (ei != _element_map.end()) {
790+
out << " element " << (*ei).second.get_scoped_name();
791+
things.push_back(std::make_pair((*ei).second.get_scoped_name(), index));
792+
}
793+
794+
MakeSeqMap::const_iterator msi;
795+
msi = _make_seq_map.find(index);
796+
if (msi != _make_seq_map.end()) {
797+
out << " make_seq " << (*msi).second.get_scoped_name();
798+
things.push_back(std::make_pair((*msi).second.get_scoped_name(), index));
799+
}
800+
801+
out << "\n";
802+
}
803+
804+
// Sort everything by scoped name and write it out.
805+
std::sort(things.begin(), things.end());
806+
807+
for (const auto &pair : things) {
808+
out << "\n";
809+
810+
int index = pair.second;
811+
812+
FunctionMap::const_iterator fi;
813+
fi = _function_map.find(index);
814+
if (fi != _function_map.end() && (*fi).second != nullptr) {
815+
(*fi).second->write(out);
816+
}
817+
818+
TypeMap::const_iterator ti;
819+
ti = _type_map.find(index);
820+
if (ti != _type_map.end()) {
821+
(*ti).second.write(out);
822+
}
823+
824+
ManifestMap::const_iterator mi;
825+
mi = _manifest_map.find(index);
826+
if (mi != _manifest_map.end()) {
827+
(*mi).second.write(out);
828+
}
829+
830+
ElementMap::const_iterator ei;
831+
ei = _element_map.find(index);
832+
if (ei != _element_map.end()) {
833+
(*ei).second.write(out);
834+
}
835+
836+
MakeSeqMap::const_iterator msi;
837+
msi = _make_seq_map.find(index);
838+
if (msi != _make_seq_map.end()) {
839+
(*msi).second.write(out);
840+
}
841+
}
842+
843+
// Write out the type hierarchy, global functions, etc.
844+
/*for (TypeIndex type : _global_types) {
845+
TypeMap::const_iterator ti;
846+
ti = _type_map.find(type);
847+
if (ti != _type_map.end()) {
848+
(*ti).second.write(out);
849+
}
850+
out << "\n";
851+
}
852+
853+
for (FunctionIndex function : _global_functions) {
854+
FunctionMap::const_iterator fi;
855+
fi = _function_map.find(function);
856+
if (fi != _function_map.end() && (*fi).second != nullptr) {
857+
(*fi).second->write(out);
858+
}
859+
out << "\n";
860+
}
861+
862+
for (ManifestIndex manifest : _global_manifests) {
863+
ManifestMap::const_iterator mi;
864+
mi = _manifest_map.find(manifest);
865+
if (mi != _manifest_map.end()) {
866+
(*mi).second.write(out);
867+
}
868+
out << "\n";
869+
}
870+
871+
for (ElementIndex element : _global_elements) {
872+
ElementMap::const_iterator ei;
873+
ei = _element_map.find(element);
874+
if (ei != _element_map.end()) {
875+
(*ei).second.write(out);
876+
}
877+
out << "\n";
878+
}*/
879+
}
880+
736881
/**
737882
* Writes the database to the indicated stream for later reading.
738883
*/

src/interrogatedb/interrogateDatabase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class EXPCL_INTERROGATEDB InterrogateDatabase {
106106
int remap_indices(int first_index);
107107
int remap_indices(int first_index, IndexRemapper &remap);
108108

109+
void write_text(std::ostream &out) const;
110+
109111
void write(std::ostream &out, InterrogateModuleDef *def) const;
110112
bool read(std::istream &in, InterrogateModuleDef *def);
111113

src/interrogatedb/interrogateElement.cxx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,127 @@
1515
#include "interrogateDatabase.h"
1616
#include "indexRemapper.h"
1717
#include "interrogate_datafile.h"
18+
#include "indent.h"
19+
20+
/**
21+
* Formats the element in a human-readable manner.
22+
*/
23+
void InterrogateElement::
24+
write(std::ostream &out, int indent_level) const {
25+
indent(out, indent_level) << "element \"" << get_scoped_name() << "\"";
26+
//write_names(out);
27+
out << " {\n";
28+
29+
InterrogateDatabase *idb = InterrogateDatabase::get_ptr();
30+
if (_type != 0) {
31+
indent(out, indent_level) << " type: " << idb->get_type(_type).get_scoped_name() << "\n";
32+
}
33+
34+
if (_flags != 0) {
35+
indent(out, indent_level) << " flags:";
36+
if (_flags & F_global) {
37+
out << " global";
38+
}
39+
if (_flags & F_has_getter) {
40+
out << " has_getter";
41+
}
42+
if (_flags & F_has_setter) {
43+
out << " has_setter";
44+
}
45+
if (_flags & F_has_has_function) {
46+
out << " has_has_function";
47+
}
48+
if (_flags & F_has_clear_function) {
49+
out << " has_clear_function";
50+
}
51+
if (_flags & F_has_del_function) {
52+
out << " has_del_function";
53+
}
54+
if (_flags & F_sequence) {
55+
out << " sequence";
56+
}
57+
if (_flags & F_mapping) {
58+
out << " mapping";
59+
}
60+
if (_flags & F_has_insert_function) {
61+
out << " has_insert_function";
62+
}
63+
if (_flags & F_has_getkey_function) {
64+
out << " has_getkey_function";
65+
}
66+
out << "\n";
67+
}
68+
69+
if (!_comment.empty()) {
70+
indent(out, indent_level) << " comment:";
71+
bool next_indent = true;
72+
for (char c : _comment) {
73+
if (c == '\n') {
74+
next_indent = true;
75+
} else {
76+
if (next_indent) {
77+
out << "\n";
78+
indent(out, indent_level + 4);
79+
next_indent = false;
80+
}
81+
out << c;
82+
}
83+
}
84+
out << "\n";
85+
}
86+
87+
//out << "\n";
88+
89+
if (_length_function != 0) {
90+
//idb->get_function(_length_function).write(out, indent_level + 2, "length function");
91+
indent(out, indent_level + 2) << "length_function: "
92+
<< idb->get_function(_length_function).get_scoped_name() << "\n";
93+
}
94+
95+
if (_getter != 0) {
96+
//idb->get_function(_getter).write(out, indent_level + 2, "getter");
97+
indent(out, indent_level + 2) << "getter: "
98+
<< idb->get_function(_getter).get_scoped_name() << "\n";
99+
}
100+
101+
if (_setter != 0) {
102+
//idb->get_function(_setter).write(out, indent_level + 2, "setter");
103+
indent(out, indent_level + 2) << "setter: "
104+
<< idb->get_function(_setter).get_scoped_name() << "\n";
105+
}
106+
107+
if (_has_function != 0) {
108+
//idb->get_function(_has_function).write(out, indent_level + 2, "has function");
109+
indent(out, indent_level + 2) << "has_function: "
110+
<< idb->get_function(_has_function).get_scoped_name() << "\n";
111+
}
112+
113+
if (_clear_function != 0) {
114+
//idb->get_function(_clear_function).write(out, indent_level + 2, "clear function");
115+
indent(out, indent_level + 2) << "clear_function: "
116+
<< idb->get_function(_clear_function).get_scoped_name() << "\n";
117+
}
118+
119+
if (_del_function != 0) {
120+
//idb->get_function(_del_function).write(out, indent_level + 2, "del function");
121+
indent(out, indent_level + 2) << "del_function: "
122+
<< idb->get_function(_del_function).get_scoped_name() << "\n";
123+
}
124+
125+
if (_insert_function != 0) {
126+
//idb->get_function(_insert_function).write(out, indent_level + 2, "insert function");
127+
indent(out, indent_level + 2) << "insert_function: "
128+
<< idb->get_function(_insert_function).get_scoped_name() << "\n";
129+
}
130+
131+
if (_getkey_function != 0) {
132+
//idb->get_function(_getkey_function).write(out, indent_level + 2, "getkey function");
133+
indent(out, indent_level + 2) << "getkey_function: "
134+
<< idb->get_function(_getkey_function).get_scoped_name() << "\n";
135+
}
136+
137+
indent(out, indent_level) << "}\n";
138+
}
18139

19140
/**
20141
* Formats the InterrogateElement data for output to a data file.

src/interrogatedb/interrogateElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class EXPCL_INTERROGATEDB InterrogateElement : public InterrogateComponent {
5858
INLINE FunctionIndex get_length_function() const;
5959
INLINE bool is_mapping() const;
6060

61+
void write(std::ostream &out, int indent_level = 0) const;
6162
void output(std::ostream &out) const;
6263
void input(std::istream &in);
6364

0 commit comments

Comments
 (0)