diff --git a/src/browse.cc b/src/browse.cc index c08c9f4..76bee07 100644 --- a/src/browse.cc +++ b/src/browse.cc @@ -22,6 +22,8 @@ #include "build/browse_py.h" +using namespace std; + void RunBrowsePython(State* state, const char* ninja_command, const char* input_file, int argc, char* argv[]) { // Fork off a Python process and have it run our code via its stdin. diff --git a/src/build.cc b/src/build.cc index 8c6ada5..e3131e2 100644 --- a/src/build.cc +++ b/src/build.cc @@ -40,6 +40,8 @@ #include "subprocess.h" #include "util.h" +using namespace std; + namespace { /// A CommandRunner that doesn't actually run the commands. diff --git a/src/build.h b/src/build.h index 97773c4..2798693 100644 --- a/src/build.h +++ b/src/build.h @@ -46,7 +46,7 @@ struct Plan { /// Add a target to our plan (including all its dependencies). /// Returns false if we don't need to build this target; may /// fill in |err| with an error message if there's a problem. - bool AddTarget(const Node* node, string* err); + bool AddTarget(const Node* node, std::string* err); // Pop a ready edge off the queue of edges to build. // Returns NULL if there's no work to do. @@ -67,11 +67,11 @@ struct Plan { /// If any of the edge's outputs are dyndep bindings of their dependents, /// this loads dynamic dependencies from the nodes' paths. /// Returns 'false' if loading dyndep info fails and 'true' otherwise. - bool EdgeFinished(Edge* edge, EdgeResult result, string* err); + bool EdgeFinished(Edge* edge, EdgeResult result, std::string* err); /// Clean the given node during the build. /// Return false on error. - bool CleanNode(DependencyScan* scan, Node* node, string* err); + bool CleanNode(DependencyScan* scan, Node* node, std::string* err); /// Number of edges with commands to run. int command_edge_count() const { return command_edges_; } @@ -82,18 +82,18 @@ struct Plan { /// Update the build plan to account for modifications made to the graph /// by information loaded from a dyndep file. bool DyndepsLoaded(DependencyScan* scan, const Node* node, - const DyndepFile& ddf, string* err); + const DyndepFile& ddf, std::string* err); private: - bool RefreshDyndepDependents(DependencyScan* scan, const Node* node, string* err); - void UnmarkDependents(const Node* node, set* dependents); - bool AddSubTarget(const Node* node, const Node* dependent, string* err, - set* dyndep_walk); + bool RefreshDyndepDependents(DependencyScan* scan, const Node* node, std::string* err); + void UnmarkDependents(const Node* node, std::set* dependents); + bool AddSubTarget(const Node* node, const Node* dependent, std::string* err, + std::set* dyndep_walk); /// Update plan with knowledge that the given node is up to date. /// If the node is a dyndep binding on any of its dependents, this /// loads dynamic dependencies from the node's path. /// Returns 'false' if loading dyndep info fails and 'true' otherwise. - bool NodeFinished(Node* node, string* err); + bool NodeFinished(Node* node, std::string* err); /// Enumerate possible steps we want for an edge. enum Want @@ -109,20 +109,20 @@ private: }; void EdgeWanted(const Edge* edge); - bool EdgeMaybeReady(map::iterator want_e, string* err); + bool EdgeMaybeReady(std::map::iterator want_e, std::string* err); /// Submits a ready edge as a candidate for execution. /// The edge may be delayed from running, for example if it's a member of a /// currently-full pool. - void ScheduleWork(map::iterator want_e); + void ScheduleWork(std::map::iterator want_e); /// Keep track of which edges we want to build in this plan. If this map does /// not contain an entry for an edge, we do not want to build the entry or its /// dependents. If it does contain an entry, the enumeration indicates what /// we want for the edge. - map want_; + std::map want_; - set ready_; + std::set ready_; Builder* builder_; @@ -146,13 +146,13 @@ struct CommandRunner { Result() : edge(NULL) {} Edge* edge; ExitStatus status; - string output; + std::string output; bool success() const { return status == ExitSuccess; } }; /// Wait for a command to complete, or return false if interrupted. virtual bool WaitForCommand(Result* result) = 0; - virtual vector GetActiveEdges() { return vector(); } + virtual std::vector GetActiveEdges() { return std::vector(); } virtual void Abort() {} }; @@ -186,24 +186,24 @@ struct Builder { /// Clean up after interrupted commands by deleting output files. void Cleanup(); - Node* AddTarget(const string& name, string* err); + Node* AddTarget(const std::string& name, std::string* err); /// Add a target to the build, scanning dependencies. /// @return false on error. - bool AddTarget(Node* target, string* err); + bool AddTarget(Node* target, std::string* err); /// Returns true if the build targets are already up to date. bool AlreadyUpToDate() const; /// Run the build. Returns false on error. /// It is an error to call this function when AlreadyUpToDate() is true. - bool Build(string* err); + bool Build(std::string* err); - bool StartEdge(Edge* edge, string* err); + bool StartEdge(Edge* edge, std::string* err); /// Update status ninja logs following a command termination. /// @return false if the build can not proceed further due to a fatal error. - bool FinishCommand(CommandRunner::Result* result, string* err); + bool FinishCommand(CommandRunner::Result* result, std::string* err); /// Used for tests. void SetBuildLog(BuildLog* log) { @@ -211,22 +211,22 @@ struct Builder { } /// Load the dyndep information provided by the given node. - bool LoadDyndeps(Node* node, string* err); + bool LoadDyndeps(Node* node, std::string* err); State* state_; const BuildConfig& config_; Plan plan_; #if __cplusplus < 201703L - auto_ptr command_runner_; + std::auto_ptr command_runner_; #else - unique_ptr command_runner_; // auto_ptr was removed in C++17. + std::unique_ptr command_runner_; // auto_ptr was removed in C++17. #endif BuildStatus* status_; private: - bool ExtractDeps(CommandRunner::Result* result, const string& deps_type, - const string& deps_prefix, vector* deps_nodes, - string* err); + bool ExtractDeps(CommandRunner::Result* result, const std::string& deps_type, + const std::string& deps_prefix, + std::vector* deps_nodes, std::string* err); DiskInterface* disk_interface_; DependencyScan scan_; @@ -241,7 +241,7 @@ struct BuildStatus { explicit BuildStatus(const BuildConfig& config); void PlanHasTotalEdges(int total); void BuildEdgeStarted(const Edge* edge); - void BuildEdgeFinished(Edge* edge, bool success, const string& output, + void BuildEdgeFinished(Edge* edge, bool success, const std::string& output, int* start_time, int* end_time); void BuildLoadDyndeps(); void BuildStarted(); @@ -257,8 +257,8 @@ struct BuildStatus { /// placeholders. /// @param progress_status_format The format of the progress status. /// @param status The status of the edge. - string FormatProgressStatus(const char* progress_status_format, - EdgeStatus status) const; + std::string FormatProgressStatus(const char* progress_status_format, + EdgeStatus status) const; private: void PrintStatus(const Edge* edge, EdgeStatus status); @@ -271,7 +271,7 @@ struct BuildStatus { int started_edges_, finished_edges_, total_edges_; /// Map of running edge to time the edge started running. - typedef map RunningEdgeMap; + typedef std::map RunningEdgeMap; RunningEdgeMap running_edges_; /// Prints progress output. @@ -327,7 +327,7 @@ struct BuildStatus { double rate_; Stopwatch stopwatch_; const size_t N; - queue times_; + std::queue times_; int last_update_; }; diff --git a/src/build_log.cc b/src/build_log.cc index e5f179c..0a2fac6 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -41,6 +41,8 @@ #define strtoll _strtoi64 #endif +using namespace std; + // Implementation details: // Each run's log appends to the log file. // To load, we run through all log entries in series, throwing away diff --git a/src/build_log.h b/src/build_log.h index 6d060d1..88551e3 100644 --- a/src/build_log.h +++ b/src/build_log.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "hash_map.h" #include "load_status.h" @@ -47,17 +46,17 @@ struct BuildLog { /// Prepares writing to the log file without actually opening it - that will /// happen when/if it's needed - bool OpenForWrite(const string& path, const BuildLogUser& user, string* err); - + bool OpenForWrite(const std::string& path, const BuildLogUser& user, + std::string* err); bool RecordCommand(Edge* edge, int start_time, int end_time, TimeStamp mtime = 0); void Close(); /// Load the on-disk log. - LoadStatus Load(const string& path, string* err); + LoadStatus Load(const std::string& path, std::string* err); struct LogEntry { - string output; + std::string output; uint64_t command_hash; int start_time; int end_time; @@ -72,19 +71,20 @@ struct BuildLog { mtime == o.mtime; } - explicit LogEntry(const string& output); - LogEntry(const string& output, uint64_t command_hash, + explicit LogEntry(const std::string& output); + LogEntry(const std::string& output, uint64_t command_hash, int start_time, int end_time, TimeStamp restat_mtime); }; /// Lookup a previously-run command by its output path. - LogEntry* LookupByOutput(const string& path); + LogEntry* LookupByOutput(const std::string& path); /// Serialize an entry into a log file. bool WriteEntry(FILE* f, const LogEntry& entry); /// Rewrite the known log entries, throwing away old data. - bool Recompact(const string& path, const BuildLogUser& user, string* err); + bool Recompact(const std::string& path, const BuildLogUser& user, + std::string* err); /// Restat all outputs in the log bool Restat(StringPiece path, const DiskInterface& disk_interface, diff --git a/src/build_log_perftest.cc b/src/build_log_perftest.cc index e471d13..ced0df9 100644 --- a/src/build_log_perftest.cc +++ b/src/build_log_perftest.cc @@ -26,6 +26,8 @@ #include #endif +using namespace std; + const char kTestFilename[] = "BuildLogPerfTest-tempfile"; struct NoDeadPaths : public BuildLogUser { diff --git a/src/build_log_test.cc b/src/build_log_test.cc index c81f570..3718299 100644 --- a/src/build_log_test.cc +++ b/src/build_log_test.cc @@ -27,6 +27,8 @@ #endif #include +using namespace std; + namespace { const char kTestFilename[] = "BuildLogTest-tempfile"; diff --git a/src/build_test.cc b/src/build_test.cc index 12c3383..078080d 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -21,6 +21,8 @@ #include "graph.h" #include "test.h" +using namespace std; + struct CompareEdgesByOutput { static bool cmp(const Edge* a, const Edge* b) { return a->outputs_[0]->path() < b->outputs_[0]->path(); diff --git a/src/canon_perftest.cc b/src/canon_perftest.cc index 03f4a2f..088bd45 100644 --- a/src/canon_perftest.cc +++ b/src/canon_perftest.cc @@ -18,6 +18,8 @@ #include "util.h" #include "metrics.h" +using namespace std; + const char kPath[] = "../../third_party/WebKit/Source/WebCore/" "platform/leveldb/LevelDBWriteBatch.cpp"; diff --git a/src/clean.cc b/src/clean.cc index 55d7277..3e57437 100644 --- a/src/clean.cc +++ b/src/clean.cc @@ -22,6 +22,8 @@ #include "state.h" #include "util.h" +using namespace std; + Cleaner::Cleaner(State* state, const BuildConfig& config, DiskInterface* disk_interface) diff --git a/src/clean.h b/src/clean.h index 4c02ff6..cf3f1c3 100644 --- a/src/clean.h +++ b/src/clean.h @@ -22,8 +22,6 @@ #include "dyndep.h" #include "build_log.h" -using namespace std; - struct State; struct Node; struct Rule; @@ -78,15 +76,15 @@ struct Cleaner { private: /// Remove the file @a path. /// @return whether the file has been removed. - int RemoveFile(const string& path); + int RemoveFile(const std::string& path); /// @returns whether the file @a path exists. - bool FileExists(const string& path); - void Report(const string& path); + bool FileExists(const std::string& path); + void Report(const std::string& path); /// Remove the given @a path file only if it has not been already removed. - void Remove(const string& path); + void Remove(const std::string& path); /// @return whether the given @a path has already been removed. - bool IsAlreadyRemoved(const string& path); + bool IsAlreadyRemoved(const std::string& path); /// Remove the depfile and rspfile for an Edge. void RemoveEdgeFiles(Edge* edge); @@ -103,8 +101,8 @@ struct Cleaner { State* state_; const BuildConfig& config_; DyndepLoader dyndep_loader_; - set removed_; - set cleaned_; + std::set removed_; + std::set cleaned_; int cleaned_files_count_; DiskInterface* disk_interface_; int status_; diff --git a/src/clean_test.cc b/src/clean_test.cc index d068f3c..1b843a2 100644 --- a/src/clean_test.cc +++ b/src/clean_test.cc @@ -22,6 +22,8 @@ #include #endif +using namespace std; + namespace { const char kTestFilename[] = "CleanTest-tempfile"; diff --git a/src/clparser.cc b/src/clparser.cc index 7994c06..275641e 100644 --- a/src/clparser.cc +++ b/src/clparser.cc @@ -28,6 +28,8 @@ #include "util.h" #endif +using namespace std; + namespace { /// Return true if \a input ends with \a needle. diff --git a/src/clparser.h b/src/clparser.h index e597e7e..2a33628 100644 --- a/src/clparser.h +++ b/src/clparser.h @@ -17,7 +17,6 @@ #include #include -using namespace std; /// Visual Studio's cl.exe requires some massaging to work with Ninja; /// for example, it emits include information on stderr in a funny @@ -27,26 +26,26 @@ struct CLParser { /// Parse a line of cl.exe output and extract /showIncludes info. /// If a dependency is extracted, returns a nonempty string. /// Exposed for testing. - static string FilterShowIncludes(const string& line, - const string& deps_prefix); + static std::string FilterShowIncludes(const std::string& line, + const std::string& deps_prefix); /// Return true if a mentioned include file is a system path. /// Filtering these out reduces dependency information considerably. - static bool IsSystemInclude(string path); + static bool IsSystemInclude(std::string path); /// Parse a line of cl.exe output and return true if it looks like /// it's printing an input filename. This is a heuristic but it appears /// to be the best we can do. /// Exposed for testing. - static bool FilterInputFilename(string line); + static bool FilterInputFilename(std::string line); /// Parse the full output of cl, filling filtered_output with the text that /// should be printed (if any). Returns true on success, or false with err /// filled. output must not be the same object as filtered_object. - bool Parse(const string& output, const string& deps_prefix, - string* filtered_output, string* err); + bool Parse(const std::string& output, const std::string& deps_prefix, + std::string* filtered_output, std::string* err); - set includes_; + std::set includes_; }; #endif // NINJA_CLPARSER_H_ diff --git a/src/clparser_perftest.cc b/src/clparser_perftest.cc index 7ac5230..008ac46 100644 --- a/src/clparser_perftest.cc +++ b/src/clparser_perftest.cc @@ -18,6 +18,8 @@ #include "clparser.h" #include "metrics.h" +using namespace std; + int main(int argc, char* argv[]) { // Output of /showIncludes from #include string perf_testdata = diff --git a/src/clparser_test.cc b/src/clparser_test.cc index 1549ab1..0b829c1 100644 --- a/src/clparser_test.cc +++ b/src/clparser_test.cc @@ -17,6 +17,8 @@ #include "test.h" #include "util.h" +using namespace std; + TEST(CLParserTest, ShowIncludes) { ASSERT_EQ("", CLParser::FilterShowIncludes("", "")); diff --git a/src/depfile_parser.cc b/src/depfile_parser.cc index 0b7dce1..bffeb76 100644 --- a/src/depfile_parser.cc +++ b/src/depfile_parser.cc @@ -18,6 +18,8 @@ #include +using namespace std; + DepfileParser::DepfileParser(DepfileParserOptions options) : options_(options) { diff --git a/src/depfile_parser.h b/src/depfile_parser.h index 11b1228..0e8db81 100644 --- a/src/depfile_parser.h +++ b/src/depfile_parser.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "string_piece.h" @@ -33,10 +32,10 @@ struct DepfileParser { /// Parse an input file. Input must be NUL-terminated. /// Warning: may mutate the content in-place and parsed StringPieces are /// pointers within it. - bool Parse(string* content, string* err); + bool Parse(std::string* content, std::string* err); std::vector outs_; - vector ins_; + std::vector ins_; DepfileParserOptions options_; }; diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc index 95b4346..75ba982 100644 --- a/src/depfile_parser.in.cc +++ b/src/depfile_parser.in.cc @@ -17,6 +17,8 @@ #include +using namespace std; + DepfileParser::DepfileParser(DepfileParserOptions options) : options_(options) { diff --git a/src/depfile_parser_perftest.cc b/src/depfile_parser_perftest.cc index b215221..52555e6 100644 --- a/src/depfile_parser_perftest.cc +++ b/src/depfile_parser_perftest.cc @@ -19,6 +19,8 @@ #include "util.h" #include "metrics.h" +using namespace std; + int main(int argc, char* argv[]) { if (argc < 2) { printf("usage: %s \n", argv[0]); diff --git a/src/depfile_parser_test.cc b/src/depfile_parser_test.cc index 8e2cd25..8886258 100644 --- a/src/depfile_parser_test.cc +++ b/src/depfile_parser_test.cc @@ -16,6 +16,8 @@ #include "test.h" +using namespace std; + struct DepfileParserTest : public testing::Test { bool Parse(const char* input, string* err); diff --git a/src/deps_log.cc b/src/deps_log.cc index 1fb65ae..0567c95 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -30,6 +30,8 @@ typedef unsigned __int32 uint32_t; #include "state.h" #include "util.h" +using namespace std; + // The version is stored as 4 bytes after the signature and also serves as a // byte order mark. Signature and version combined are 16 bytes long. const char kFileSignature[] = "# ninjadeps\n"; diff --git a/src/deps_log.h b/src/deps_log.h index c4ada8b..cc44b41 100644 --- a/src/deps_log.h +++ b/src/deps_log.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include @@ -71,8 +70,8 @@ struct DepsLog { ~DepsLog(); // Writing (build-time) interface. - bool OpenForWrite(const string& path, string* err); - bool RecordDeps(Node* node, TimeStamp mtime, const vector& nodes); + bool OpenForWrite(const std::string& path, std::string* err); + bool RecordDeps(Node* node, TimeStamp mtime, const std::vector& nodes); bool RecordDeps(Node* node, TimeStamp mtime, int node_count, Node** nodes); void Close(); @@ -85,11 +84,11 @@ struct DepsLog { int node_count; Node** nodes; }; - LoadStatus Load(const string& path, State* state, string* err); + LoadStatus Load(const std::string& path, State* state, std::string* err); Deps* GetDeps(Node* node); /// Rewrite the known log entries, throwing away old data. - bool Recompact(const string& path, string* err); + bool Recompact(const std::string& path, std::string* err); /// Returns if the deps entry for a node is still reachable from the manifest. /// @@ -100,8 +99,8 @@ struct DepsLog { bool IsDepsEntryLiveFor(Node* node); /// Used for tests. - const vector& nodes() const { return nodes_; } - const vector& deps() const { return deps_; } + const std::vector& nodes() const { return nodes_; } + const std::vector& deps() const { return deps_; } private: // Updates the in-memory representation. Takes ownership of |deps|. @@ -119,9 +118,9 @@ struct DepsLog { std::string file_path_; /// Maps id -> Node. - vector nodes_; + std::vector nodes_; /// Maps id -> deps of that id. - vector deps_; + std::vector deps_; friend struct DepsLogTest; }; diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc index 0cdeb45..4055941 100644 --- a/src/deps_log_test.cc +++ b/src/deps_log_test.cc @@ -23,6 +23,8 @@ #include "util.h" #include "test.h" +using namespace std; + namespace { const char kTestFilename[] = "DepsLogTest-tempfile"; diff --git a/src/disk_interface.cc b/src/disk_interface.cc index 594bc51..49af001 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -33,6 +33,8 @@ #include "metrics.h" #include "util.h" +using namespace std; + namespace { string DirName(const string& path) { diff --git a/src/disk_interface.h b/src/disk_interface.h index 145e089..bc29ab7 100644 --- a/src/disk_interface.h +++ b/src/disk_interface.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "timestamp.h" @@ -35,8 +34,8 @@ struct FileReader { /// Read and store in given string. On success, return Okay. /// On error, return another Status and fill |err|. - virtual Status ReadFile(const string& path, string* contents, - string* err) = 0; + virtual Status ReadFile(const std::string& path, std::string* contents, + std::string* err) = 0; }; /// Interface for accessing the disk. @@ -46,25 +45,26 @@ struct FileReader { struct DiskInterface: public FileReader { /// stat() a file, returning the mtime, or 0 if missing and -1 on /// other errors. - virtual TimeStamp Stat(const string& path, string* err) const = 0; + virtual TimeStamp Stat(const std::string& path, std::string* err) const = 0; /// Create a directory, returning false on failure. - virtual bool MakeDir(const string& path) = 0; + virtual bool MakeDir(const std::string& path) = 0; /// Create a file, with the specified name and contents /// Returns true on success, false on failure - virtual bool WriteFile(const string& path, const string& contents) = 0; + virtual bool WriteFile(const std::string& path, + const std::string& contents) = 0; /// Remove the file named @a path. It behaves like 'rm -f path' so no errors /// are reported if it does not exists. /// @returns 0 if the file has been removed, /// 1 if the file does not exist, and /// -1 if an error occurs. - virtual int RemoveFile(const string& path) = 0; + virtual int RemoveFile(const std::string& path) = 0; /// Create all the parent directories for path; like mkdir -p /// `basename path`. - bool MakeDirs(const string& path); + bool MakeDirs(const std::string& path); }; /// Implementation of DiskInterface that actually hits the disk. @@ -75,11 +75,12 @@ struct RealDiskInterface : public DiskInterface { #endif {} virtual ~RealDiskInterface() {} - virtual TimeStamp Stat(const string& path, string* err) const; - virtual bool MakeDir(const string& path); - virtual bool WriteFile(const string& path, const string& contents); - virtual Status ReadFile(const string& path, string* contents, string* err); - virtual int RemoveFile(const string& path); + virtual TimeStamp Stat(const std::string& path, std::string* err) const; + virtual bool MakeDir(const std::string& path); + virtual bool WriteFile(const std::string& path, const std::string& contents); + virtual Status ReadFile(const std::string& path, std::string* contents, + std::string* err); + virtual int RemoveFile(const std::string& path); /// Whether stat information can be cached. Only has an effect on Windows. void AllowStatCache(bool allow); @@ -89,10 +90,10 @@ struct RealDiskInterface : public DiskInterface { /// Whether stat information can be cached. bool use_cache_; - typedef map DirCache; + typedef std::map DirCache; // TODO: Neither a map nor a hashmap seems ideal here. If the statcache // works out, come up with a better data structure. - typedef map Cache; + typedef std::map Cache; mutable Cache cache_; #endif }; diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc index 866d1d6..066c770 100644 --- a/src/disk_interface_test.cc +++ b/src/disk_interface_test.cc @@ -23,6 +23,8 @@ #include "graph.h" #include "test.h" +using namespace std; + namespace { struct DiskInterfaceTest : public testing::Test { diff --git a/src/dyndep.cc b/src/dyndep.cc index 2aee601..b388e9b 100644 --- a/src/dyndep.cc +++ b/src/dyndep.cc @@ -24,6 +24,8 @@ #include "state.h" #include "util.h" +using namespace std; + bool DyndepLoader::LoadDyndeps(Node* node, std::string* err) const { DyndepFile ddf; return LoadDyndeps(node, &ddf, err); diff --git a/src/dyndep_parser.cc b/src/dyndep_parser.cc index baebbac..56da16f 100644 --- a/src/dyndep_parser.cc +++ b/src/dyndep_parser.cc @@ -22,6 +22,8 @@ #include "util.h" #include "version.h" +using namespace std; + DyndepParser::DyndepParser(State* state, FileReader* file_reader, DyndepFile* dyndep_file) : Parser(state, file_reader) diff --git a/src/dyndep_parser.h b/src/dyndep_parser.h index 09a3722..8f4c28d 100644 --- a/src/dyndep_parser.h +++ b/src/dyndep_parser.h @@ -27,17 +27,18 @@ struct DyndepParser: public Parser { DyndepFile* dyndep_file); /// Parse a text string of input. Used by tests. - bool ParseTest(const string& input, string* err) { + bool ParseTest(const std::string& input, std::string* err) { return Parse("input", input, err); } private: /// Parse a file, given its contents as a string. - bool Parse(const string& filename, const string& input, string* err); + bool Parse(const std::string& filename, const std::string& input, + std:: string* err); - bool ParseDyndepVersion(string* err); - bool ParseLet(string* key, EvalString* val, string* err); - bool ParseEdge(string* err); + bool ParseDyndepVersion(std::string* err); + bool ParseLet(std::string* key, EvalString* val, std::string* err); + bool ParseEdge(std::string* err); DyndepFile* dyndep_file_; BindingEnv env_; diff --git a/src/dyndep_parser_test.cc b/src/dyndep_parser_test.cc index 39ec657..1bba7ba 100644 --- a/src/dyndep_parser_test.cc +++ b/src/dyndep_parser_test.cc @@ -22,6 +22,8 @@ #include "state.h" #include "test.h" +using namespace std; + struct DyndepParserTest : public testing::Test { void AssertParse(const char* input) { DyndepParser parser(&state_, &fs_, &dyndep_file_); diff --git a/src/edit_distance.cc b/src/edit_distance.cc index 3bb62b8..34bf0e5 100644 --- a/src/edit_distance.cc +++ b/src/edit_distance.cc @@ -17,6 +17,8 @@ #include #include +using namespace std; + int EditDistance(const StringPiece& s1, const StringPiece& s2, bool allow_replacements, diff --git a/src/eval_env.cc b/src/eval_env.cc index e9b6c43..796a326 100644 --- a/src/eval_env.cc +++ b/src/eval_env.cc @@ -16,6 +16,8 @@ #include "eval_env.h" +using namespace std; + string BindingEnv::LookupVariable(const string& var) { map::iterator i = bindings_.find(var); if (i != bindings_.end()) diff --git a/src/eval_env.h b/src/eval_env.h index 8fb9bf4..ca7daa4 100644 --- a/src/eval_env.h +++ b/src/eval_env.h @@ -18,7 +18,6 @@ #include #include #include -using namespace std; #include "string_piece.h" @@ -27,7 +26,7 @@ struct Rule; /// An interface for a scope for variable (e.g. "$foo") lookups. struct Env { virtual ~Env() {} - virtual string LookupVariable(const string& var) = 0; + virtual std::string LookupVariable(const std::string& var) = 0; }; /// A tokenized string that contains variable references. @@ -35,10 +34,10 @@ struct Env { struct EvalString { /// @return The evaluated string with variable expanded using value found in /// environment @a env. - string Evaluate(Env* env) const; + std::string Evaluate(Env* env) const; /// @return The string with variables not expanded. - string Unparse() const; + std::string Unparse() const; void Clear() { parsed_.clear(); } bool empty() const { return parsed_.empty(); } @@ -48,32 +47,32 @@ struct EvalString { /// Construct a human-readable representation of the parsed state, /// for use in tests. - string Serialize() const; + std::string Serialize() const; private: enum TokenType { RAW, SPECIAL }; - typedef vector > TokenList; + typedef std::vector > TokenList; TokenList parsed_; }; /// An invokable build command and associated metadata (description, etc.). struct Rule { - explicit Rule(const string& name) : name_(name) {} + explicit Rule(const std::string& name) : name_(name) {} - const string& name() const { return name_; } + const std::string& name() const { return name_; } - void AddBinding(const string& key, const EvalString& val); + void AddBinding(const std::string& key, const EvalString& val); - static bool IsReservedBinding(const string& var); + static bool IsReservedBinding(const std::string& var); - const EvalString* GetBinding(const string& key) const; + const EvalString* GetBinding(const std::string& key) const; private: // Allow the parsers to reach into this object and fill out its fields. friend struct ManifestParser; - string name_; - typedef map Bindings; + std::string name_; + typedef std::map Bindings; Bindings bindings_; }; @@ -84,26 +83,26 @@ struct BindingEnv : public Env { explicit BindingEnv(BindingEnv* parent) : parent_(parent) {} virtual ~BindingEnv() {} - virtual string LookupVariable(const string& var); + virtual std::string LookupVariable(const std::string& var); void AddRule(const Rule* rule); - const Rule* LookupRule(const string& rule_name); - const Rule* LookupRuleCurrentScope(const string& rule_name); - const map& GetRules() const; + const Rule* LookupRule(const std::string& rule_name); + const Rule* LookupRuleCurrentScope(const std::string& rule_name); + const std::map& GetRules() const; - void AddBinding(const string& key, const string& val); + void AddBinding(const std::string& key, const std::string& val); /// This is tricky. Edges want lookup scope to go in this order: /// 1) value set on edge itself (edge_->env_) /// 2) value set on rule, with expansion in the edge's scope /// 3) value set on enclosing scope of edge (edge_->env_->parent_) /// This function takes as parameters the necessary info to do (2). - string LookupWithFallback(const string& var, const EvalString* eval, - Env* env); + std::string LookupWithFallback(const std::string& var, const EvalString* eval, + Env* env); private: - map bindings_; - map rules_; + std::map bindings_; + std::map rules_; BindingEnv* parent_; }; diff --git a/src/graph.cc b/src/graph.cc index 28a9653..ea11360 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -28,6 +28,8 @@ #include "state.h" #include "util.h" +using namespace std; + bool Node::Stat(DiskInterface* disk_interface, string* err) { return (mtime_ = disk_interface->Stat(path_, err)) != -1; } diff --git a/src/graph.h b/src/graph.h index 2fa54af..4833f49 100644 --- a/src/graph.h +++ b/src/graph.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "dyndep.h" #include "eval_env.h" @@ -36,7 +35,7 @@ struct State; /// Information about a node in the dependency graph: the file, whether /// it's dirty, mtime, etc. struct Node { - Node(const string& path, uint64_t slash_bits) + Node(const std::string& path, uint64_t slash_bits) : path_(path), slash_bits_(slash_bits), mtime_(-1), @@ -46,10 +45,10 @@ struct Node { id_(-1) {} /// Return false on error. - bool Stat(DiskInterface* disk_interface, string* err); + bool Stat(DiskInterface* disk_interface, std::string* err); /// Return false on error. - bool StatIfNecessary(DiskInterface* disk_interface, string* err) { + bool StatIfNecessary(DiskInterface* disk_interface, std::string* err) { if (status_known()) return true; return Stat(disk_interface, err); @@ -74,13 +73,13 @@ struct Node { return mtime_ != -1; } - const string& path() const { return path_; } + const std::string& path() const { return path_; } /// Get |path()| but use slash_bits to convert back to original slash styles. - string PathDecanonicalized() const { + std::string PathDecanonicalized() const { return PathDecanonicalized(path_, slash_bits_); } - static string PathDecanonicalized(const string& path, - uint64_t slash_bits); + static std::string PathDecanonicalized(const std::string& path, + uint64_t slash_bits); uint64_t slash_bits() const { return slash_bits_; } TimeStamp mtime() const { return mtime_; } @@ -98,13 +97,13 @@ struct Node { int id() const { return id_; } void set_id(int id) { id_ = id; } - const vector& out_edges() const { return out_edges_; } + const std::vector& out_edges() const { return out_edges_; } void AddOutEdge(Edge* edge) { out_edges_.push_back(edge); } void Dump(const char* prefix="") const; private: - string path_; + std::string path_; /// Set bits starting from lowest for backslashes that were normalized to /// forward slashes by CanonicalizePath. See |PathDecanonicalized|. @@ -130,7 +129,7 @@ private: Edge* in_edge_; /// All Edges that use this Node as an input. - vector out_edges_; + std::vector out_edges_; /// A dense integer id for the node, assigned and used by DepsLog. int id_; @@ -158,13 +157,13 @@ struct Edge { std::string EvaluateCommand(bool incl_rsp_file = false) const; /// Returns the shell-escaped value of |key|. - std::string GetBinding(const string& key) const; - bool GetBindingBool(const string& key) const; + std::string GetBinding(const std::string& key) const; + bool GetBindingBool(const std::string& key) const; /// Like GetBinding("depfile"), but without shell escaping. - string GetUnescapedDepfile() const; + std::string GetUnescapedDepfile() const; /// Like GetBinding("dyndep"), but without shell escaping. - string GetUnescapedDyndep() const; + std::string GetUnescapedDyndep() const; /// Like GetBinding("rspfile"), but without shell escaping. std::string GetUnescapedRspfile() const; @@ -172,8 +171,8 @@ struct Edge { const Rule* rule_; Pool* pool_; - vector inputs_; - vector outputs_; + std::vector inputs_; + std::vector outputs_; Node* dyndep_; BindingEnv* env_; VisitMark mark_; @@ -232,7 +231,7 @@ struct ImplicitDepLoader { /// Load implicit dependencies for \a edge. /// @return false on error (without filling \a err if info is just missing // or out of date). - bool LoadDeps(Edge* edge, string* err); + bool LoadDeps(Edge* edge, std::string* err); DepsLog* deps_log() const { return deps_log_; @@ -241,15 +240,15 @@ struct ImplicitDepLoader { private: /// Load implicit dependencies for \a edge from a depfile attribute. /// @return false on error (without filling \a err if info is just missing). - bool LoadDepFile(Edge* edge, const string& path, string* err); + bool LoadDepFile(Edge* edge, const std::string& path, std::string* err); /// Load implicit dependencies for \a edge from the DepsLog. /// @return false on error (without filling \a err if info is just missing). - bool LoadDepsFromLog(Edge* edge, string* err); + bool LoadDepsFromLog(Edge* edge, std::string* err); /// Preallocate \a count spaces in the input array on \a edge, returning /// an iterator pointing at the first new space. - vector::iterator PreallocateSpace(Edge* edge, int count); + std::vector::iterator PreallocateSpace(Edge* edge, int count); /// If we don't have a edge that generates this input already, /// create one; this makes us not abort if the input is missing, @@ -279,12 +278,12 @@ struct DependencyScan { /// needs to be re-run, and update outputs_ready_ and each outputs' |dirty_| /// state accordingly. /// Returns false on failure. - bool RecomputeDirty(Node* node, string* err); + bool RecomputeDirty(Node* node, std::string* err); /// Recompute whether any output of the edge is dirty, if so sets |*dirty|. /// Returns false on failure. bool RecomputeOutputsDirty(Edge* edge, Node* most_recent_input, - bool* dirty, string* err); + bool* dirty, std::string* err); BuildLog* build_log() const { return build_log_; @@ -301,17 +300,17 @@ struct DependencyScan { /// build graph with the new information. One overload accepts /// a caller-owned 'DyndepFile' object in which to store the /// information loaded from the dyndep file. - bool LoadDyndeps(Node* node, string* err) const; - bool LoadDyndeps(Node* node, DyndepFile* ddf, string* err) const; + bool LoadDyndeps(Node* node, std::string* err) const; + bool LoadDyndeps(Node* node, DyndepFile* ddf, std::string* err) const; private: - bool RecomputeDirty(Node* node, vector* stack, string* err); - bool VerifyDAG(Node* node, vector* stack, string* err); + bool RecomputeDirty(Node* node, std::vector* stack, std::string* err); + bool VerifyDAG(Node* node, std::vector* stack, std::string* err); /// Recompute whether a given single output should be marked dirty. /// Returns true if so. bool RecomputeOutputDirty(const Edge* edge, const Node* most_recent_input, - const string& command, Node* output); + const std::string& command, Node* output); BuildLog* build_log_; DiskInterface* disk_interface_; diff --git a/src/graph_test.cc b/src/graph_test.cc index 660943f..14f6375 100644 --- a/src/graph_test.cc +++ b/src/graph_test.cc @@ -17,6 +17,8 @@ #include "test.h" +using namespace std; + struct GraphTest : public StateTestWithBuiltinRules { GraphTest() : scan_(&state_, NULL, NULL, &fs_, NULL) {} diff --git a/src/graphviz.cc b/src/graphviz.cc index 0d07251..37b7108 100644 --- a/src/graphviz.cc +++ b/src/graphviz.cc @@ -20,6 +20,8 @@ #include "dyndep.h" #include "graph.h" +using namespace std; + void GraphViz::AddTarget(Node* node) { if (visited_nodes_.find(node) != visited_nodes_.end()) return; diff --git a/src/hash_collision_bench.cc b/src/hash_collision_bench.cc index ff947dc..52ff56d 100644 --- a/src/hash_collision_bench.cc +++ b/src/hash_collision_bench.cc @@ -15,11 +15,12 @@ #include "build_log.h" #include -using namespace std; #include #include +using namespace std; + int random(int low, int high) { return int(low + (rand() / double(RAND_MAX)) * (high - low) + 0.5); } diff --git a/src/includes_normalize-win32.cc b/src/includes_normalize-win32.cc index 79bf5b4..9f8dfc2 100644 --- a/src/includes_normalize-win32.cc +++ b/src/includes_normalize-win32.cc @@ -24,6 +24,8 @@ #include +using namespace std; + namespace { bool InternalGetFullPathName(const StringPiece& file_name, char* buffer, diff --git a/src/includes_normalize.h b/src/includes_normalize.h index 0339581..7d50556 100644 --- a/src/includes_normalize.h +++ b/src/includes_normalize.h @@ -14,7 +14,6 @@ #include #include -using namespace std; struct StringPiece; @@ -22,18 +21,20 @@ struct StringPiece; /// TODO: this likely duplicates functionality of CanonicalizePath; refactor. struct IncludesNormalize { /// Normalize path relative to |relative_to|. - IncludesNormalize(const string& relative_to); + IncludesNormalize(const std::string& relative_to); // Internal utilities made available for testing, maybe useful otherwise. - static string AbsPath(StringPiece s, string* err); - static string Relativize(StringPiece path, - const vector& start_list, string* err); + static std::string AbsPath(StringPiece s, std::string* err); + static std::string Relativize(StringPiece path, + const std::vector& start_list, + std::string* err); /// Normalize by fixing slashes style, fixing redundant .. and . and makes the /// path |input| relative to |this->relative_to_| and store to |result|. - bool Normalize(const string& input, string* result, string* err) const; + bool Normalize(const std::string& input, std::string* result, + std::string* err) const; private: - string relative_to_; - vector split_relative_to_; + std::string relative_to_; + std::vector split_relative_to_; }; diff --git a/src/includes_normalize_test.cc b/src/includes_normalize_test.cc index dbcdbe0..9214f53 100644 --- a/src/includes_normalize_test.cc +++ b/src/includes_normalize_test.cc @@ -22,6 +22,8 @@ #include "test.h" #include "util.h" +using namespace std; + namespace { string GetCurDir() { diff --git a/src/lexer.cc b/src/lexer.cc index 35ae97b..6e4a470 100644 --- a/src/lexer.cc +++ b/src/lexer.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 */ +/* Generated by re2c 1.1.1 */ // Copyright 2011 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,8 @@ #include "eval_env.h" #include "util.h" +using namespace std; + bool Lexer::Error(const string& message, string* err) { // Compute line/column. int line = 1; @@ -233,8 +235,7 @@ yy8: goto yy5; yy9: yyaccept = 0; - q = ++p; - yych = *p; + yych = *(q = ++p); if (yybm[0+yych] & 32) { goto yy9; } @@ -252,8 +253,7 @@ yy12: if (yych <= 0x00) goto yy5; goto yy33; yy13: - ++p; - yych = *p; + yych = *++p; yy14: if (yybm[0+yych] & 64) { goto yy13; @@ -290,8 +290,8 @@ yy25: if (yych == 'u') goto yy41; goto yy14; yy26: - ++p; - if ((yych = *p) == '|') goto yy42; + yych = *++p; + if (yych == '|') goto yy42; { token = PIPE; break; } yy28: ++p; @@ -307,8 +307,7 @@ yy31: goto yy5; } yy32: - ++p; - yych = *p; + yych = *++p; yy33: if (yybm[0+yych] & 128) { goto yy32; @@ -380,14 +379,14 @@ yy52: if (yych == 'u') goto yy61; goto yy14; yy53: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = POOL; break; } yy55: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = RULE; break; } @@ -396,8 +395,8 @@ yy57: if (yych == 'i') goto yy62; goto yy14; yy58: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = BUILD; break; } @@ -426,22 +425,22 @@ yy65: if (yych == 'j') goto yy70; goto yy14; yy66: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = DEFAULT; break; } yy68: - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = INCLUDE; break; } yy70: yych = *++p; if (yych != 'a') goto yy14; - ++p; - if (yybm[0+(yych = *p)] & 64) { + yych = *++p; + if (yybm[0+yych] & 64) { goto yy13; } { token = SUBNINJA; break; } @@ -521,8 +520,7 @@ yy77: yy78: { break; } yy79: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 128) { goto yy79; } @@ -600,8 +598,7 @@ bool Lexer::ReadIdent(string* out) { return false; } yy93: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 128) { goto yy93; } @@ -681,8 +678,7 @@ yy98: return Error("unexpected EOF", err); } yy100: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 16) { goto yy100; } @@ -704,8 +700,8 @@ yy103: } } yy105: - ++p; - if ((yych = *p) == '\n') goto yy108; + yych = *++p; + if (yych == '\n') goto yy108; { last_token_ = start; return Error(DescribeLastError(), err); @@ -750,8 +746,7 @@ yy111: return Error("bad $-escape (literal $ must be written as $$)", err); } yy112: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 32) { goto yy112; } @@ -775,8 +770,7 @@ yy118: continue; } yy120: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 64) { goto yy120; } @@ -797,15 +791,13 @@ yy125: } goto yy111; yy126: - ++p; - yych = *p; + yych = *++p; if (yych == ' ') goto yy126; { continue; } yy129: - ++p; - yych = *p; + yych = *++p; if (yybm[0+yych] & 128) { goto yy129; } diff --git a/src/lexer.h b/src/lexer.h index f366556..788d948 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -55,7 +55,7 @@ struct Lexer { /// If the last token read was an ERROR token, provide more info /// or the empty string. - string DescribeLastError(); + std::string DescribeLastError(); /// Start parsing some input. void Start(StringPiece filename, StringPiece input); @@ -71,30 +71,30 @@ struct Lexer { /// Read a simple identifier (a rule or variable name). /// Returns false if a name can't be read. - bool ReadIdent(string* out); + bool ReadIdent(std::string* out); /// Read a path (complete with $escapes). /// Returns false only on error, returned path may be empty if a delimiter /// (space, newline) is hit. - bool ReadPath(EvalString* path, string* err) { + bool ReadPath(EvalString* path, std::string* err) { return ReadEvalString(path, true, err); } /// Read the value side of a var = value line (complete with $escapes). /// Returns false only on error. - bool ReadVarValue(EvalString* value, string* err) { + bool ReadVarValue(EvalString* value, std::string* err) { return ReadEvalString(value, false, err); } /// Construct an error message with context. - bool Error(const string& message, string* err); + bool Error(const std::string& message, std::string* err); private: /// Skip past whitespace (called after each read token/ident/etc.). void EatWhitespace(); /// Read a $-escaped string. - bool ReadEvalString(EvalString* eval, bool path, string* err); + bool ReadEvalString(EvalString* eval, bool path, std::string* err); StringPiece filename_; StringPiece input_; diff --git a/src/lexer.in.cc b/src/lexer.in.cc index c1fb822..88007e7 100644 --- a/src/lexer.in.cc +++ b/src/lexer.in.cc @@ -19,6 +19,8 @@ #include "eval_env.h" #include "util.h" +using namespace std; + bool Lexer::Error(const string& message, string* err) { // Compute line/column. int line = 1; diff --git a/src/lexer_test.cc b/src/lexer_test.cc index 331d8e1..c5c416d 100644 --- a/src/lexer_test.cc +++ b/src/lexer_test.cc @@ -17,6 +17,8 @@ #include "eval_env.h" #include "test.h" +using namespace std; + TEST(Lexer, ReadVarValue) { Lexer lexer("plain text $var $VaR ${x}\n"); EvalString eval; diff --git a/src/line_printer.cc b/src/line_printer.cc index c93173e..68c58ad 100644 --- a/src/line_printer.cc +++ b/src/line_printer.cc @@ -30,6 +30,8 @@ #include "util.h" +using namespace std; + LinePrinter::LinePrinter() : have_blank_line_(true), console_locked_(false) { const char* term = getenv("TERM"); #ifndef _WIN32 diff --git a/src/line_printer.h b/src/line_printer.h index 92d4dc4..a8ec9ff 100644 --- a/src/line_printer.h +++ b/src/line_printer.h @@ -17,7 +17,6 @@ #include #include -using namespace std; /// Prints lines of text, possibly overprinting previously printed lines /// if the terminal supports it. @@ -35,10 +34,10 @@ struct LinePrinter { }; /// Overprints the current line. If type is ELIDE, elides to_print to fit on /// one line. - void Print(string to_print, LineType type); + void Print(std::string to_print, LineType type); /// Prints a string on a new line, not overprinting previous output. - void PrintOnNewLine(const string& to_print); + void PrintOnNewLine(const std::string& to_print); /// Lock or unlock the console. Any output sent to the LinePrinter while the /// console is locked will not be printed until it is unlocked. @@ -58,13 +57,13 @@ struct LinePrinter { bool console_locked_; /// Buffered current line while console is locked. - string line_buffer_; + std::string line_buffer_; /// Buffered line type while console is locked. LineType line_type_; /// Buffered console output while console is locked. - string output_buffer_; + std::string output_buffer_; #ifdef _WIN32 void* console_; diff --git a/src/manifest_parser.cc b/src/manifest_parser.cc index bb53dc2..860a8fc 100644 --- a/src/manifest_parser.cc +++ b/src/manifest_parser.cc @@ -23,6 +23,8 @@ #include "util.h" #include "version.h" +using namespace std; + ManifestParser::ManifestParser(State* state, FileReader* file_reader, ManifestParserOptions options) : Parser(state, file_reader), diff --git a/src/manifest_parser.h b/src/manifest_parser.h index e14d069..954cf46 100644 --- a/src/manifest_parser.h +++ b/src/manifest_parser.h @@ -44,24 +44,25 @@ struct ManifestParser : public Parser { ManifestParserOptions options = ManifestParserOptions()); /// Parse a text string of input. Used by tests. - bool ParseTest(const string& input, string* err) { + bool ParseTest(const std::string& input, std::string* err) { quiet_ = true; return Parse("input", input, err); } private: /// Parse a file, given its contents as a string. - bool Parse(const string& filename, const string& input, string* err); + bool Parse(const std::string& filename, const std::string& input, + std::string* err); /// Parse various statement types. - bool ParsePool(string* err); - bool ParseRule(string* err); - bool ParseLet(string* key, EvalString* val, string* err); - bool ParseEdge(string* err); - bool ParseDefault(string* err); + bool ParsePool(std::string* err); + bool ParseRule(std::string* err); + bool ParseLet(std::string* key, EvalString* val, std::string* err); + bool ParseEdge(std::string* err); + bool ParseDefault(std::string* err); /// Parse either a 'subninja' or 'include' line. - bool ParseFileInclude(bool new_scope, string* err); + bool ParseFileInclude(bool new_scope, std::string* err); BindingEnv* env_; ManifestParserOptions options_; diff --git a/src/manifest_parser_perftest.cc b/src/manifest_parser_perftest.cc index 67d11f9..92f5e13 100644 --- a/src/manifest_parser_perftest.cc +++ b/src/manifest_parser_perftest.cc @@ -37,6 +37,8 @@ #include "state.h" #include "util.h" +using namespace std; + bool WriteFakeManifests(const string& dir, string* err) { RealDiskInterface disk_interface; TimeStamp mtime = disk_interface.Stat(dir + "/build.ninja", err); diff --git a/src/manifest_parser_test.cc b/src/manifest_parser_test.cc index f4aee2d..ec2eeed 100644 --- a/src/manifest_parser_test.cc +++ b/src/manifest_parser_test.cc @@ -21,6 +21,8 @@ #include "state.h" #include "test.h" +using namespace std; + struct ParserTest : public testing::Test { void AssertParse(const char* input) { ManifestParser parser(&state, &fs_); diff --git a/src/metrics.cc b/src/metrics.cc index a7d3c7a..dbaf221 100644 --- a/src/metrics.cc +++ b/src/metrics.cc @@ -28,6 +28,8 @@ #include "util.h" +using namespace std; + Metrics* g_metrics = NULL; namespace { diff --git a/src/metrics.h b/src/metrics.h index b6da859..11239b5 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -17,7 +17,6 @@ #include #include -using namespace std; #include "util.h" // For int64_t. @@ -26,7 +25,7 @@ using namespace std; /// A single metrics we're tracking, like "depfile load time". struct Metric { - string name; + std::string name; /// Number of times we've hit the code path. int count; /// Total time (in micros) we've spent on the code path. @@ -49,13 +48,13 @@ private: /// The singleton that stores metrics and prints the report. struct Metrics { - Metric* NewMetric(const string& name); + Metric* NewMetric(const std::string& name); /// Print a summary report to stdout. void Report(); private: - vector metrics_; + std::vector metrics_; }; /// Get the current time as relative to some epoch. diff --git a/src/minidump-win32.cc b/src/minidump-win32.cc index ca93638..9aea767 100644 --- a/src/minidump-win32.cc +++ b/src/minidump-win32.cc @@ -19,6 +19,8 @@ #include "util.h" +using namespace std; + typedef BOOL (WINAPI *MiniDumpWriteDumpFunc) ( IN HANDLE, IN DWORD, diff --git a/src/msvc_helper-win32.cc b/src/msvc_helper-win32.cc index de6147a..1148ae5 100644 --- a/src/msvc_helper-win32.cc +++ b/src/msvc_helper-win32.cc @@ -18,6 +18,8 @@ #include "util.h" +using namespace std; + namespace { string Replace(const string& input, const string& find, const string& replace) { diff --git a/src/msvc_helper.h b/src/msvc_helper.h index 70d1fff..568b9f9 100644 --- a/src/msvc_helper.h +++ b/src/msvc_helper.h @@ -13,9 +13,8 @@ // limitations under the License. #include -using namespace std; -string EscapeForDepfile(const string& path); +std::string EscapeForDepfile(const std::string& path); /// Wraps a synchronous execution of a CL subprocess. struct CLWrapper { @@ -27,7 +26,7 @@ struct CLWrapper { /// Start a process and gather its raw output. Returns its exit code. /// Crashes (calls Fatal()) on error. - int Run(const string& command, string* output); + int Run(const std::string& command, std::string* output); void* env_block_; }; diff --git a/src/msvc_helper_main-win32.cc b/src/msvc_helper_main-win32.cc index 644b2a2..7d59307 100644 --- a/src/msvc_helper_main-win32.cc +++ b/src/msvc_helper_main-win32.cc @@ -24,6 +24,8 @@ #include "getopt.h" +using namespace std; + namespace { void Usage() { diff --git a/src/msvc_helper_test.cc b/src/msvc_helper_test.cc index eaae51f..d9e2ee6 100644 --- a/src/msvc_helper_test.cc +++ b/src/msvc_helper_test.cc @@ -17,6 +17,8 @@ #include "test.h" #include "util.h" +using namespace std; + TEST(EscapeForDepfileTest, SpacesInFilename) { ASSERT_EQ("sub\\some\\ sdk\\foo.h", EscapeForDepfile("sub\\some sdk\\foo.h")); diff --git a/src/ninja.cc b/src/ninja.cc index 00e3a5c..471a023 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -46,6 +46,8 @@ #include "util.h" #include "version.h" +using namespace std; + #ifdef _MSC_VER // Defined in msvc_helper_main-win32.cc. int MSVCHelperMain(int argc, char** argv); diff --git a/src/ninja_test.cc b/src/ninja_test.cc index d642c5c..b40e176 100644 --- a/src/ninja_test.cc +++ b/src/ninja_test.cc @@ -28,6 +28,8 @@ #include "test.h" #include "line_printer.h" +using namespace std; + struct RegisteredTest { testing::Test* (*factory)(); const char *name; diff --git a/src/parser.cc b/src/parser.cc index 745c532..756922d 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -17,6 +17,8 @@ #include "disk_interface.h" #include "metrics.h" +using namespace std; + bool Parser::Load(const string& filename, string* err, Lexer* parent) { METRIC_RECORD(".ninja parse"); string contents; diff --git a/src/parser.h b/src/parser.h index e2d2b97..011fad8 100644 --- a/src/parser.h +++ b/src/parser.h @@ -17,8 +17,6 @@ #include -using namespace std; - #include "lexer.h" struct FileReader; @@ -30,12 +28,12 @@ struct Parser { : state_(state), file_reader_(file_reader) {} /// Load and parse a file. - bool Load(const string& filename, string* err, Lexer* parent = NULL); + bool Load(const std::string& filename, std::string* err, Lexer* parent = NULL); protected: /// If the next token is not \a expected, produce an error string /// saying "expected foo, got bar". - bool ExpectToken(Lexer::Token expected, string* err); + bool ExpectToken(Lexer::Token expected, std::string* err); State* state_; FileReader* file_reader_; @@ -43,8 +41,8 @@ protected: private: /// Parse a file, given its contents as a string. - virtual bool Parse(const string& filename, const string& input, - string* err) = 0; + virtual bool Parse(const std::string& filename, const std::string& input, + std::string* err) = 0; }; #endif // NINJA_PARSER_H_ diff --git a/src/state.cc b/src/state.cc index 74cf4c1..d3a9e29 100644 --- a/src/state.cc +++ b/src/state.cc @@ -22,6 +22,7 @@ #include "metrics.h" #include "util.h" +using namespace std; void Pool::EdgeScheduled(const Edge& edge) { if (depth_ != 0) diff --git a/src/state.h b/src/state.h index 6fe886c..f553ed4 100644 --- a/src/state.h +++ b/src/state.h @@ -19,7 +19,6 @@ #include #include #include -using namespace std; #include "eval_env.h" #include "hash_map.h" @@ -38,13 +37,13 @@ struct Rule; /// the total scheduled weight diminishes enough (i.e. when a scheduled edge /// completes). struct Pool { - Pool(const string& name, int depth) + Pool(const std::string& name, int depth) : name_(name), current_use_(0), depth_(depth), delayed_(&WeightedEdgeCmp) {} // A depth of 0 is infinite bool is_valid() const { return depth_ >= 0; } int depth() const { return depth_; } - const string& name() const { return name_; } + const std::string& name() const { return name_; } int current_use() const { return current_use_; } /// true if the Pool might delay this edge @@ -62,13 +61,13 @@ struct Pool { void DelayEdge(Edge* edge); /// Pool will add zero or more edges to the ready_queue - void RetrieveReadyEdges(set* ready_queue); + void RetrieveReadyEdges(std::set* ready_queue); /// Dump the Pool and its edges (useful for debugging). void Dump() const; private: - string name_; + std::string name_; /// |current_use_| is the total of the weights of the edges which are /// currently scheduled in the Plan (i.e. the edges in Plan::ready_). @@ -77,7 +76,7 @@ struct Pool { static bool WeightedEdgeCmp(const Edge* a, const Edge* b); - typedef set DelayedEdges; + typedef std::set DelayedEdges; DelayedEdges delayed_; }; @@ -90,17 +89,17 @@ struct State { State(); void AddPool(Pool* pool); - Pool* LookupPool(const string& pool_name); + Pool* LookupPool(const std::string& pool_name); Edge* AddEdge(const Rule* rule); Node* GetNode(StringPiece path, uint64_t slash_bits); Node* LookupNode(StringPiece path) const; - Node* SpellcheckNode(const string& path); + Node* SpellcheckNode(const std::string& path); void AddIn(Edge* edge, StringPiece path, uint64_t slash_bits); bool AddOut(Edge* edge, StringPiece path, uint64_t slash_bits); - bool AddDefault(StringPiece path, string* error); + bool AddDefault(StringPiece path, std::string* error); /// Reset state. Keeps all nodes and edges, but restores them to the /// state where we haven't yet examined the disk for dirty state. @@ -111,21 +110,21 @@ struct State { /// @return the root node(s) of the graph. (Root nodes have no output edges). /// @param error where to write the error message if somethings went wrong. - vector RootNodes(string* error) const; - vector DefaultNodes(string* error) const; + std::vector RootNodes(std::string* error) const; + std::vector DefaultNodes(std::string* error) const; /// Mapping of path -> Node. typedef ExternalStringHashMap::Type Paths; Paths paths_; /// All the pools used in the graph. - map pools_; + std::map pools_; /// All the edges of the graph. - vector edges_; + std::vector edges_; BindingEnv bindings_; - vector defaults_; + std::vector defaults_; }; #endif // NINJA_STATE_H_ diff --git a/src/state_test.cc b/src/state_test.cc index 458b519..96469f9 100644 --- a/src/state_test.cc +++ b/src/state_test.cc @@ -16,6 +16,8 @@ #include "state.h" #include "test.h" +using namespace std; + namespace { TEST(State, Basic) { diff --git a/src/string_piece.h b/src/string_piece.h index 031bda4..1c0bee6 100644 --- a/src/string_piece.h +++ b/src/string_piece.h @@ -17,8 +17,6 @@ #include -using namespace std; - #include /// StringPiece represents a slice of a string whose memory is managed @@ -30,7 +28,7 @@ struct StringPiece { StringPiece() : str_(NULL), len_(0) {} /// The constructors intentionally allow for implicit conversions. - StringPiece(const string& str) : str_(str.data()), len_(str.size()) {} + StringPiece(const std::string& str) : str_(str.data()), len_(str.size()) {} StringPiece(const char* str) : str_(str), len_(strlen(str)) {} StringPiece(const char* str, size_t len) : str_(str), len_(len) {} @@ -38,14 +36,15 @@ struct StringPiece { bool operator==(const StringPiece& other) const { return len_ == other.len_ && memcmp(str_, other.str_, len_) == 0; } + bool operator!=(const StringPiece& other) const { return !(*this == other); } /// Convert the slice into a full-fledged std::string, copying the /// data into a new string. - string AsString() const { - return len_ ? string(str_, len_) : string(); + std::string AsString() const { + return len_ ? std::string(str_, len_) : std::string(); } const_iterator begin() const { diff --git a/src/string_piece_util.h b/src/string_piece_util.h index 2e40b9f..28470f1 100644 --- a/src/string_piece_util.h +++ b/src/string_piece_util.h @@ -19,11 +19,10 @@ #include #include "string_piece.h" -using namespace std; -vector SplitStringPiece(StringPiece input, char sep); +std::vector SplitStringPiece(StringPiece input, char sep); -string JoinStringPiece(const vector& list, char sep); +std::string JoinStringPiece(const std::vector& list, char sep); inline char ToLowerASCII(char c) { return (c >= 'A' && c <= 'Z') ? (c + ('a' - 'A')) : c; diff --git a/src/string_piece_util_test.cc b/src/string_piece_util_test.cc index 648c647..b77ae84 100644 --- a/src/string_piece_util_test.cc +++ b/src/string_piece_util_test.cc @@ -16,6 +16,8 @@ #include "test.h" +using namespace std; + TEST(StringPieceUtilTest, SplitStringPiece) { { string input("a:b:c"); diff --git a/src/subprocess-posix.cc b/src/subprocess-posix.cc index 74785d1..0c5f556 100644 --- a/src/subprocess-posix.cc +++ b/src/subprocess-posix.cc @@ -34,6 +34,8 @@ extern char** environ; #include "util.h" +using namespace std; + Subprocess::Subprocess(bool use_console) : fd_(-1), pid_(-1), use_console_(use_console) { } diff --git a/src/subprocess-win32.cc b/src/subprocess-win32.cc index d221476..ff3baac 100644 --- a/src/subprocess-win32.cc +++ b/src/subprocess-win32.cc @@ -21,6 +21,8 @@ #include "util.h" +using namespace std; + Subprocess::Subprocess(bool use_console) : child_(NULL) , overlapped_(), is_reading_(false), use_console_(use_console) { diff --git a/src/subprocess.h b/src/subprocess.h index b2d486c..9e3d2ee 100644 --- a/src/subprocess.h +++ b/src/subprocess.h @@ -18,7 +18,6 @@ #include #include #include -using namespace std; #ifdef _WIN32 #include @@ -49,14 +48,14 @@ struct Subprocess { bool Done() const; - const string& GetOutput() const; + const std::string& GetOutput() const; private: Subprocess(bool use_console); - bool Start(struct SubprocessSet* set, const string& command); + bool Start(struct SubprocessSet* set, const std::string& command); void OnPipeReady(); - string buf_; + std::string buf_; #ifdef _WIN32 /// Set up pipe_ as the parent-side pipe of the subprocess; return the @@ -84,13 +83,13 @@ struct SubprocessSet { SubprocessSet(); ~SubprocessSet(); - Subprocess* Add(const string& command, bool use_console = false); + Subprocess* Add(const std::string& command, bool use_console = false); bool DoWork(); Subprocess* NextFinished(); void Clear(); - vector running_; - queue finished_; + std::vector running_; + std::queue finished_; #ifdef _WIN32 static BOOL WINAPI NotifyInterrupted(DWORD dwCtrlType); diff --git a/src/subprocess_test.cc b/src/subprocess_test.cc index 6e487db..073fe86 100644 --- a/src/subprocess_test.cc +++ b/src/subprocess_test.cc @@ -24,6 +24,8 @@ #include #endif +using namespace std; + namespace { #ifdef _WIN32 diff --git a/src/test.cc b/src/test.cc index 021005e..11b1c9e 100644 --- a/src/test.cc +++ b/src/test.cc @@ -43,6 +43,8 @@ extern "C" { } #endif +using namespace std; + namespace { #ifdef _WIN32 diff --git a/src/test.h b/src/test.h index 6af17b3..4552c34 100644 --- a/src/test.h +++ b/src/test.h @@ -118,7 +118,7 @@ struct StateTestWithBuiltinRules : public testing::Test { void AddCatRule(State* state); /// Short way to get a Node by its path from state_. - Node* GetNode(const string& path); + Node* GetNode(const std::string& path); State state_; }; @@ -135,7 +135,7 @@ struct VirtualFileSystem : public DiskInterface { VirtualFileSystem() : now_(1) {} /// "Create" a file with contents. - void Create(const string& path, const string& contents); + void Create(const std::string& path, const std::string& contents); /// Tick "time" forwards; subsequent file operations will be newer than /// previous ones. @@ -144,25 +144,26 @@ struct VirtualFileSystem : public DiskInterface { } // DiskInterface - virtual TimeStamp Stat(const string& path, string* err) const; - virtual bool WriteFile(const string& path, const string& contents); - virtual bool MakeDir(const string& path); - virtual Status ReadFile(const string& path, string* contents, string* err); - virtual int RemoveFile(const string& path); + virtual TimeStamp Stat(const std::string& path, std::string* err) const; + virtual bool WriteFile(const std::string& path, const std::string& contents); + virtual bool MakeDir(const std::string& path); + virtual Status ReadFile(const std::string& path, std::string* contents, + std::string* err); + virtual int RemoveFile(const std::string& path); /// An entry for a single in-memory file. struct Entry { int mtime; - string stat_error; // If mtime is -1. - string contents; + std::string stat_error; // If mtime is -1. + std::string contents; }; - vector directories_made_; - vector files_read_; - typedef map FileMap; + std::vector directories_made_; + std::vector files_read_; + typedef std::map FileMap; FileMap files_; - set files_removed_; - set files_created_; + std::set files_removed_; + std::set files_created_; /// A simple fake timestamp for file operations. int now_; @@ -170,15 +171,15 @@ struct VirtualFileSystem : public DiskInterface { struct ScopedTempDir { /// Create a temporary directory and chdir into it. - void CreateAndEnter(const string& name); + void CreateAndEnter(const std::string& name); /// Clean up the temporary directory. void Cleanup(); /// The temp directory containing our dir. - string start_dir_; + std::string start_dir_; /// The subdirectory name for our dir, or empty if it hasn't been set up. - string temp_dir_name_; + std::string temp_dir_name_; }; #endif // NINJA_TEST_H_ diff --git a/src/util.cc b/src/util.cc index 4df2bb2..c76f730 100644 --- a/src/util.cc +++ b/src/util.cc @@ -54,6 +54,8 @@ #include "edit_distance.h" #include "metrics.h" +using namespace std; + void Fatal(const char* msg, ...) { va_list ap; fprintf(stderr, "ninja: fatal: "); diff --git a/src/util.h b/src/util.h index 6a4a7a9..4e6ebb8 100644 --- a/src/util.h +++ b/src/util.h @@ -23,7 +23,6 @@ #include #include -using namespace std; #ifdef _MSC_VER #define NORETURN __declspec(noreturn) @@ -57,29 +56,30 @@ void Error(const char* msg, ...); /// Canonicalize a path like "foo/../bar.h" into just "bar.h". /// |slash_bits| has bits set starting from lowest for a backslash that was /// normalized to a forward slash. (only used on Windows) -bool CanonicalizePath(string* path, uint64_t* slash_bits, string* err); +bool CanonicalizePath(std::string* path, uint64_t* slash_bits, + std::string* err); bool CanonicalizePath(char* path, size_t* len, uint64_t* slash_bits, - string* err); + std::string* err); /// Appends |input| to |*result|, escaping according to the whims of either /// Bash, or Win32's CommandLineToArgvW(). /// Appends the string directly to |result| without modification if we can /// determine that it contains no problematic characters. -void GetShellEscapedString(const string& input, string* result); -void GetWin32EscapedString(const string& input, string* result); +void GetShellEscapedString(const std::string& input, std::string* result); +void GetWin32EscapedString(const std::string& input, std::string* result); /// Read a file to a string (in text mode: with CRLF conversion /// on Windows). /// Returns -errno and fills in \a err on error. -int ReadFile(const string& path, string* contents, string* err); +int ReadFile(const std::string& path, std::string* contents, std::string* err); /// Mark a file descriptor to not be inherited on exec()s. void SetCloseOnExec(int fd); /// Given a misspelled string and a list of correct spellings, returns /// the closest match or NULL if there is no close enough match. -const char* SpellcheckStringV(const string& text, - const vector& words); +const char* SpellcheckStringV(const std::string& text, + const std::vector& words); /// Like SpellcheckStringV, but takes a NULL-terminated list. const char* SpellcheckString(const char* text, ...); @@ -87,7 +87,7 @@ const char* SpellcheckString(const char* text, ...); bool islatinalpha(int c); /// Removes all Ansi escape codes (http://www.termsys.demon.co.uk/vtansi.htm). -string StripAnsiEscapeCodes(const string& in); +std::string StripAnsiEscapeCodes(const std::string& in); /// @return the number of processors on the machine. Useful for an initial /// guess for how many jobs to run in parallel. @return 0 on error. @@ -99,10 +99,10 @@ double GetLoadAverage(); /// Elide the given string @a str with '...' in the middle if the length /// exceeds @a width. -string ElideMiddle(const string& str, size_t width); +std::string ElideMiddle(const std::string& str, size_t width); /// Truncates a file to the given size. -bool Truncate(const string& path, size_t size, string* err); +bool Truncate(const std::string& path, size_t size, std::string* err); #ifdef _MSC_VER #define snprintf _snprintf @@ -116,7 +116,7 @@ bool Truncate(const string& path, size_t size, string* err); #ifdef _WIN32 /// Convert the value returned by GetLastError() into a string. -string GetLastErrorString(); +std::string GetLastErrorString(); /// Calls Fatal() with a function name and GetLastErrorString. NORETURN void Win32Fatal(const char* function, const char* hint = NULL); diff --git a/src/util_test.cc b/src/util_test.cc index b43788d..1621c91 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -16,6 +16,8 @@ #include "test.h" +using namespace std; + namespace { bool CanonicalizePath(string* path, string* err) { diff --git a/src/version.cc b/src/version.cc index 9d27e87..f25a30a 100644 --- a/src/version.cc +++ b/src/version.cc @@ -18,6 +18,8 @@ #include "util.h" +using namespace std; + const char* kNinjaVersion = "1.10.1.git"; void ParseVersion(const string& version, int* major, int* minor) { diff --git a/src/version.h b/src/version.h index bd6b9ff..9d84ecb 100644 --- a/src/version.h +++ b/src/version.h @@ -16,17 +16,16 @@ #define NINJA_VERSION_H_ #include -using namespace std; /// The version number of the current Ninja release. This will always /// be "git" on trunk. extern const char* kNinjaVersion; /// Parse the major/minor components of a version string. -void ParseVersion(const string& version, int* major, int* minor); +void ParseVersion(const std::string& version, int* major, int* minor); /// Check whether \a version is compatible with the current Ninja version, /// aborting if not. -void CheckNinjaVersion(const string& required_version); +void CheckNinjaVersion(const std::string& required_version); #endif // NINJA_VERSION_H_