From 566735df35488b332bedb2e384221c08c3ec686c Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 2 Aug 2016 15:07:32 -0700 Subject: [PATCH] versioner: purge iostreams. Change-Id: I1b16a4b5c4a8a1333f05636c8c67890d8ce1a090 --- tools/versioner/src/DeclarationDatabase.h | 49 +++++++++-------------- tools/versioner/src/versioner.cpp | 4 +- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/tools/versioner/src/DeclarationDatabase.h b/tools/versioner/src/DeclarationDatabase.h index bba826d00..8fe12eab4 100644 --- a/tools/versioner/src/DeclarationDatabase.h +++ b/tools/versioner/src/DeclarationDatabase.h @@ -16,11 +16,11 @@ #pragma once -#include +#include + #include #include #include -#include #include #include @@ -154,34 +154,23 @@ struct Declaration { return location < rhs.location; } - void dump(const std::string& base_path = "", std::ostream& out = std::cout, - unsigned indent = 0) const { + void dump(const std::string& base_path = "", FILE* out = stdout, unsigned indent = 0) const { std::string indent_str(indent, ' '); - out << indent_str; + fprintf(out, "%s", indent_str.c_str()); - if (is_extern) { - out << "extern"; - } else { - out << "static"; - } - - if (is_definition) { - out << " definition"; - } else { - out << " declaration"; - } - - out << " @ " << StripPrefix(location.filename, base_path).str() << ":" << location.start.line - << ":" << location.start.column; + fprintf(out, "%s ", is_extern ? "extern" : "static"); + fprintf(out, "%s ", is_definition ? "definition" : "declaration"); + fprintf(out, "@ %s:%u:%u", StripPrefix(location.filename, base_path).str().c_str(), + location.start.line, location.start.column); if (!availability.empty()) { DeclarationAvailability avail; - out << "\n" << indent_str << " "; + fprintf(out, "\n%s ", indent_str.c_str()); if (!calculateAvailability(&avail)) { - out << "invalid availability"; + fprintf(out, "invalid availability"); } else { - out << to_string(avail); + fprintf(out, "%s", to_string(avail).c_str()); } } } @@ -202,22 +191,20 @@ struct Symbol { return name == rhs.name; } - void dump(const std::string& base_path = "", std::ostream& out = std::cout) const { + void dump(const std::string& base_path = "", FILE* out = stdout) const { DeclarationAvailability availability; bool valid_availability = calculateAvailability(&availability); - out << " " << name << ": "; + fprintf(out, " %s: ", name.c_str()); if (valid_availability) { - out << to_string(availability); + fprintf(out, "%s\n", to_string(availability).c_str()); } else { - out << "invalid"; + fprintf(out, "invalid\n"); } - out << "\n"; - for (auto& it : declarations) { it.second.dump(base_path, out, 4); - out << "\n"; + fprintf(out, "\n"); } } }; @@ -230,8 +217,8 @@ class HeaderDatabase { void parseAST(CompilationType type, clang::ASTUnit* ast); - void dump(const std::string& base_path = "", std::ostream& out = std::cout) const { - out << "HeaderDatabase contains " << symbols.size() << " symbols:\n"; + void dump(const std::string& base_path = "", FILE* out = stdout) const { + fprintf(out, "HeaderDatabase contains %zu symbols:\n", symbols.size()); for (const auto& pair : symbols) { pair.second.dump(base_path, out); } diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp index 3ae0a7bfc..1b1710911 100644 --- a/tools/versioner/src/versioner.cpp +++ b/tools/versioner/src/versioner.cpp @@ -289,13 +289,13 @@ static bool checkSymbol(const Symbol& symbol) { DeclarationAvailability availability; if (!decl->calculateAvailability(&availability)) { fprintf(stderr, "versioner: failed to calculate availability for declaration:\n"); - decl->dump(cwd, std::cout, 2); + decl->dump(cwd, stderr, 2); return false; } if (decl->is_definition && !availability.empty()) { fprintf(stderr, "versioner: inline definition has non-empty versioning information:\n"); - decl->dump(cwd, std::cout, 2); + decl->dump(cwd, stderr, 2); return false; } }