From 1201117e604bb46087788bbebae401d9a4187df1 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Thu, 6 Oct 2016 05:11:48 +0000 Subject: [PATCH] Taking StringRef in Driver.h APIs instead of raw pointers (NFC) llvm-svn: 283417 --- clang/include/clang/Driver/Driver.h | 15 ++++----- clang/lib/Driver/Driver.cpp | 66 ++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index 1d83075..be79bdc 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -223,7 +223,7 @@ private: // Before executing jobs, sets up response files for commands that need them. void setUpResponseFiles(Compilation &C, Command &Cmd); - void generatePrefixedToolNames(const char *Tool, const ToolChain &TC, + void generatePrefixedToolNames(StringRef Tool, const ToolChain &TC, SmallVectorImpl &Names) const; public: @@ -369,7 +369,7 @@ public: /// directories to search. // // FIXME: This should be in CompilationInfo. - std::string GetFilePath(const char *Name, const ToolChain &TC) const; + std::string GetFilePath(StringRef Name, const ToolChain &TC) const; /// GetProgramPath - Lookup \p Name in the list of program search paths. /// @@ -377,7 +377,7 @@ public: /// directories to search. // // FIXME: This should be in CompilationInfo. - std::string GetProgramPath(const char *Name, const ToolChain &TC) const; + std::string GetProgramPath(StringRef Name, const ToolChain &TC) const; /// HandleImmediateArgs - Handle any arguments which should be /// treated before building actions or binding tools. @@ -427,7 +427,7 @@ public: /// as part of compilation; the file will have the given prefix and suffix. /// /// GCC goes to extra lengths here to be a bit more robust. - std::string GetTemporaryPath(StringRef Prefix, const char *Suffix) const; + std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const; /// Return the pathname of the pch file in clang-cl mode. std::string GetClPchPath(Compilation &C, StringRef BaseName) const; @@ -483,9 +483,8 @@ public: /// \return True if the entire string was parsed (9.2), or all /// groups were parsed (10.3.5extrastuff). HadExtra is true if all /// groups were parsed but extra characters remain at the end. - static bool GetReleaseVersion(const char *Str, unsigned &Major, - unsigned &Minor, unsigned &Micro, - bool &HadExtra); + static bool GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor, + unsigned &Micro, bool &HadExtra); /// Parse digits from a string \p Str and fulfill \p Digits with /// the parsed numbers. This method assumes that the max number of @@ -493,7 +492,7 @@ public: /// /// \return True if the entire string was parsed and there are /// no extra characters remaining at the end. - static bool GetReleaseVersion(const char *Str, + static bool GetReleaseVersion(StringRef Str, MutableArrayRef Digits); }; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 565eb09..1a6f27d 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2908,7 +2908,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, } } -std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { +std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const { // Respect a limited subset of the '-Bprefix' functionality in GCC by // attempting to use this prefix when looking for file paths. for (const std::string &Dir : PrefixDirs) { @@ -2938,16 +2938,16 @@ std::string Driver::GetFilePath(const char *Name, const ToolChain &TC) const { } void Driver::generatePrefixedToolNames( - const char *Tool, const ToolChain &TC, + StringRef Tool, const ToolChain &TC, SmallVectorImpl &Names) const { // FIXME: Needs a better variable than DefaultTargetTriple - Names.emplace_back(DefaultTargetTriple + "-" + Tool); + Names.emplace_back((DefaultTargetTriple + "-" + Tool).str()); Names.emplace_back(Tool); // Allow the discovery of tools prefixed with LLVM's default target triple. std::string LLVMDefaultTargetTriple = llvm::sys::getDefaultTargetTriple(); if (LLVMDefaultTargetTriple != DefaultTargetTriple) - Names.emplace_back(LLVMDefaultTargetTriple + "-" + Tool); + Names.emplace_back((LLVMDefaultTargetTriple + "-" + Tool).str()); } static bool ScanDirForExecutable(SmallString<128> &Dir, @@ -2961,8 +2961,7 @@ static bool ScanDirForExecutable(SmallString<128> &Dir, return false; } -std::string Driver::GetProgramPath(const char *Name, - const ToolChain &TC) const { +std::string Driver::GetProgramPath(StringRef Name, const ToolChain &TC) const { SmallVector TargetSpecificExecutables; generatePrefixedToolNames(Name, TC, TargetSpecificExecutables); @@ -2974,7 +2973,7 @@ std::string Driver::GetProgramPath(const char *Name, if (ScanDirForExecutable(P, TargetSpecificExecutables)) return P.str(); } else { - SmallString<128> P(PrefixDir + Name); + SmallString<128> P((PrefixDir + Name).str()); if (llvm::sys::fs::can_execute(Twine(P))) return P.str(); } @@ -2996,8 +2995,7 @@ std::string Driver::GetProgramPath(const char *Name, return Name; } -std::string Driver::GetTemporaryPath(StringRef Prefix, - const char *Suffix) const { +std::string Driver::GetTemporaryPath(StringRef Prefix, StringRef Suffix) const { SmallString<128> Path; std::error_code EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, Path); if (EC) { @@ -3165,36 +3163,35 @@ bool Driver::ShouldUseClangCompiler(const JobAction &JA) const { /// /// \return True if the entire string was parsed (9.2), or all groups were /// parsed (10.3.5extrastuff). -bool Driver::GetReleaseVersion(const char *Str, unsigned &Major, - unsigned &Minor, unsigned &Micro, - bool &HadExtra) { +bool Driver::GetReleaseVersion(StringRef Str, unsigned &Major, unsigned &Minor, + unsigned &Micro, bool &HadExtra) { HadExtra = false; Major = Minor = Micro = 0; - if (*Str == '\0') + if (Str.empty()) return false; - char *End; - Major = (unsigned)strtol(Str, &End, 10); - if (*Str != '\0' && *End == '\0') + if (Str.consumeInteger(10, Major)) + return false; + if (Str.empty()) return true; - if (*End != '.') + if (Str[0] != '.') return false; - Str = End + 1; - Minor = (unsigned)strtol(Str, &End, 10); - if (*Str != '\0' && *End == '\0') + Str = Str.drop_front(1); + + if (Str.consumeInteger(10, Minor)) + return false; + if (Str.empty()) return true; - if (*End != '.') + if (Str[0] != '.') return false; + Str = Str.drop_front(1); - Str = End + 1; - Micro = (unsigned)strtol(Str, &End, 10); - if (*Str != '\0' && *End == '\0') - return true; - if (Str == End) + if (Str.consumeInteger(10, Micro)) return false; - HadExtra = true; + if (!Str.empty()) + HadExtra = true; return true; } @@ -3204,21 +3201,22 @@ bool Driver::GetReleaseVersion(const char *Str, unsigned &Major, /// /// \return True if the entire string was parsed and there are /// no extra characters remaining at the end. -bool Driver::GetReleaseVersion(const char *Str, +bool Driver::GetReleaseVersion(StringRef Str, MutableArrayRef Digits) { - if (*Str == '\0') + if (Str.empty()) return false; - char *End; unsigned CurDigit = 0; while (CurDigit < Digits.size()) { - unsigned Digit = (unsigned)strtol(Str, &End, 10); + unsigned Digit; + if (Str.consumeInteger(10, Digit)) + return false; Digits[CurDigit] = Digit; - if (*Str != '\0' && *End == '\0') + if (Str.empty()) return true; - if (*End != '.' || Str == End) + if (Str[0] != '.') return false; - Str = End + 1; + Str = Str.drop_front(1); CurDigit++; } -- 2.7.4