@@ -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 */
0 commit comments