Author: Owen Pan Date: 2024-05-20T20:32:18-07:00 New Revision: 1c58208d899285318c89e069268145c85ec33368
URL: https://github.com/llvm/llvm-project/commit/1c58208d899285318c89e069268145c85ec33368 DIFF: https://github.com/llvm/llvm-project/commit/1c58208d899285318c89e069268145c85ec33368.diff LOG: [clang-format][NFC] Remove redundnat llvm::, clang::, etc. Added: Modified: clang/include/clang/Format/Format.h clang/lib/Format/Format.cpp clang/lib/Format/FormatTokenSource.h clang/lib/Format/MacroExpander.cpp clang/lib/Format/Macros.h clang/lib/Format/SortJavaScriptImports.cpp clang/tools/clang-format/ClangFormat.cpp clang/unittests/Format/CleanupTest.cpp clang/unittests/Format/DefinitionBlockSeparatorTest.cpp clang/unittests/Format/FormatTestBase.h clang/unittests/Format/FormatTestCSharp.cpp clang/unittests/Format/FormatTestJS.cpp clang/unittests/Format/FormatTestJson.cpp clang/unittests/Format/FormatTestProto.cpp clang/unittests/Format/FormatTestRawStrings.cpp clang/unittests/Format/FormatTestSelective.cpp clang/unittests/Format/FormatTestTableGen.cpp clang/unittests/Format/FormatTestUtils.h clang/unittests/Format/FormatTestVerilog.cpp clang/unittests/Format/FormatTokenSourceTest.cpp clang/unittests/Format/MacroCallReconstructorTest.cpp clang/unittests/Format/MacroExpanderTest.cpp clang/unittests/Format/MatchFilePathTest.cpp clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp clang/unittests/Format/QualifierFixerTest.cpp clang/unittests/Format/SortImportsTestJS.cpp clang/unittests/Format/SortImportsTestJava.cpp clang/unittests/Format/SortIncludesTest.cpp clang/unittests/Format/TestLexer.h clang/unittests/Format/TokenAnnotatorTest.cpp clang/unittests/Format/UsingDeclarationsSorterTest.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 74893f23210cd..274b45d1bc586 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -5239,7 +5239,7 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, /// Returns the replacements corresponding to applying and formatting /// \p Replaces on success; otheriwse, return an llvm::Error carrying /// llvm::StringError. -llvm::Expected<tooling::Replacements> +Expected<tooling::Replacements> formatReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style); @@ -5256,7 +5256,7 @@ formatReplacements(StringRef Code, const tooling::Replacements &Replaces, /// The include manipulation is done via ``tooling::HeaderInclude``, see its /// documentation for more details on how include insertion points are found and /// what edits are produced. -llvm::Expected<tooling::Replacements> +Expected<tooling::Replacements> cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style); @@ -5381,11 +5381,10 @@ extern const char *DefaultFallbackStyle; /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is /// "file" and no file is found, returns ``FallbackStyle``. If no style could be /// determined, returns an Error. -llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName, - StringRef FallbackStyle, - StringRef Code = "", - llvm::vfs::FileSystem *FS = nullptr, - bool AllowUnknownOptions = false); +Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName, + StringRef FallbackStyle, StringRef Code = "", + llvm::vfs::FileSystem *FS = nullptr, + bool AllowUnknownOptions = false); // Guesses the language from the ``FileName`` and ``Code`` to be formatted. // Defaults to FormatStyle::LK_Cpp. diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 52005a6c881f3..9cba0c2614eef 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -28,7 +28,7 @@ using clang::format::FormatStyle; -LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat) +LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat) namespace llvm { namespace yaml { @@ -1235,7 +1235,7 @@ std::error_code make_error_code(ParseError e) { return std::error_code(static_cast<int>(e), getParseCategory()); } -inline llvm::Error make_string_error(const llvm::Twine &Message) { +inline llvm::Error make_string_error(const Twine &Message) { return llvm::make_error<llvm::StringError>(Message, llvm::inconvertibleErrorCode()); } @@ -2361,7 +2361,7 @@ class JavaScriptRequoter : public TokenAnalyzer { // FIXME: handle error. For now, print error message and skip the // replacement for release version. if (Err) { - llvm::errs() << llvm::toString(std::move(Err)) << "\n"; + llvm::errs() << toString(std::move(Err)) << "\n"; assert(false); } }; @@ -2802,7 +2802,7 @@ class Cleaner : public TokenAnalyzer { // FIXME: better error handling. for now just print error message and skip // for the release version. if (Err) { - llvm::errs() << llvm::toString(std::move(Err)) << "\n"; + llvm::errs() << toString(std::move(Err)) << "\n"; assert(false && "Fixes must not conflict!"); } Idx = End + 1; @@ -3074,7 +3074,7 @@ static void sortCppIncludes(const FormatStyle &Style, llvm::to_vector<16>(llvm::seq<unsigned>(0, Includes.size())); if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive) { - llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { + stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { const auto LHSFilenameLower = Includes[LHSI].Filename.lower(); const auto RHSFilenameLower = Includes[RHSI].Filename.lower(); return std::tie(Includes[LHSI].Priority, LHSFilenameLower, @@ -3083,7 +3083,7 @@ static void sortCppIncludes(const FormatStyle &Style, Includes[RHSI].Filename); }); } else { - llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { + stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { return std::tie(Includes[LHSI].Priority, Includes[LHSI].Filename) < std::tie(Includes[RHSI].Priority, Includes[RHSI].Filename); }); @@ -3115,7 +3115,7 @@ static void sortCppIncludes(const FormatStyle &Style, // enough as additional newlines might be added or removed across #include // blocks. This we handle below by generating the updated #include blocks and // comparing it to the original. - if (Indices.size() == Includes.size() && llvm::is_sorted(Indices) && + if (Indices.size() == Includes.size() && is_sorted(Indices) && Style.IncludeStyle.IncludeBlocks == tooling::IncludeStyle::IBS_Preserve) { return; } @@ -3154,7 +3154,7 @@ static void sortCppIncludes(const FormatStyle &Style, // FIXME: better error handling. For now, just skip the replacement for the // release version. if (Err) { - llvm::errs() << llvm::toString(std::move(Err)) << "\n"; + llvm::errs() << toString(std::move(Err)) << "\n"; assert(false); } } @@ -3307,7 +3307,7 @@ static void sortJavaImports(const FormatStyle &Style, bool StaticImportAfterNormalImport = Style.SortJavaStaticImport == FormatStyle::SJSIO_After; - llvm::sort(Indices, [&](unsigned LHSI, unsigned RHSI) { + sort(Indices, [&](unsigned LHSI, unsigned RHSI) { // Negating IsStatic to push static imports above non-static imports. return std::make_tuple(!Imports[LHSI].IsStatic ^ StaticImportAfterNormalImport, @@ -3357,7 +3357,7 @@ static void sortJavaImports(const FormatStyle &Style, // FIXME: better error handling. For now, just skip the replacement for the // release version. if (Err) { - llvm::errs() << llvm::toString(std::move(Err)) << "\n"; + llvm::errs() << toString(std::move(Err)) << "\n"; assert(false); } } @@ -3451,7 +3451,7 @@ tooling::Replacements sortIncludes(const FormatStyle &Style, StringRef Code, } template <typename T> -static llvm::Expected<tooling::Replacements> +static Expected<tooling::Replacements> processReplacements(T ProcessFunc, StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style) { @@ -3470,7 +3470,7 @@ processReplacements(T ProcessFunc, StringRef Code, return Replaces.merge(FormatReplaces); } -llvm::Expected<tooling::Replacements> +Expected<tooling::Replacements> formatReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style) { // We need to use lambda function here since there are two versions of @@ -3515,13 +3515,13 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, return Replaces; tooling::Replacements HeaderInsertions; - std::set<llvm::StringRef> HeadersToDelete; + std::set<StringRef> HeadersToDelete; tooling::Replacements Result; for (const auto &R : Replaces) { if (isHeaderInsertion(R)) { // Replacements from \p Replaces must be conflict-free already, so we can // simply consume the error. - llvm::consumeError(HeaderInsertions.add(R)); + consumeError(HeaderInsertions.add(R)); } else if (isHeaderDeletion(R)) { HeadersToDelete.insert(R.getReplacementText()); } else if (R.getOffset() == UINT_MAX) { @@ -3529,7 +3529,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, "not supported! " << R.getReplacementText() << "\n"; } else { - llvm::consumeError(Result.add(R)); + consumeError(Result.add(R)); } } if (HeaderInsertions.empty() && HeadersToDelete.empty()) @@ -3546,13 +3546,12 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, if (Err) { // Ignore the deletion on conflict. llvm::errs() << "Failed to add header deletion replacement for " - << Header << ": " << llvm::toString(std::move(Err)) - << "\n"; + << Header << ": " << toString(std::move(Err)) << "\n"; } } } - llvm::SmallVector<StringRef, 4> Matches; + SmallVector<StringRef, 4> Matches; for (const auto &R : HeaderInsertions) { auto IncludeDirective = R.getReplacementText(); bool Matched = @@ -3567,7 +3566,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, if (Replace) { auto Err = Result.add(*Replace); if (Err) { - llvm::consumeError(std::move(Err)); + consumeError(std::move(Err)); unsigned NewOffset = Result.getShiftedCodePosition(Replace->getOffset()); auto Shifted = tooling::Replacement(FileName, NewOffset, 0, @@ -3581,7 +3580,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces, } // anonymous namespace -llvm::Expected<tooling::Replacements> +Expected<tooling::Replacements> cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style) { // We need to use lambda function here since there are two versions of @@ -3774,7 +3773,7 @@ reformat(const FormatStyle &Style, StringRef Code, auto Err = NonNoOpFixes.add(Fix); if (Err) { llvm::errs() << "Error adding replacements : " - << llvm::toString(std::move(Err)) << "\n"; + << toString(std::move(Err)) << "\n"; } } } @@ -3956,17 +3955,16 @@ loadAndParseConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS, return Text; } -llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName, - StringRef FallbackStyleName, - StringRef Code, llvm::vfs::FileSystem *FS, - bool AllowUnknownOptions) { +Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName, + StringRef FallbackStyleName, StringRef Code, + llvm::vfs::FileSystem *FS, + bool AllowUnknownOptions) { FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code)); FormatStyle FallbackStyle = getNoStyle(); if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle)) return make_string_error("Invalid fallback style: " + FallbackStyleName); - llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 1> - ChildFormatTextToApply; + SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 1> ChildFormatTextToApply; if (StyleName.starts_with("{")) { // Parse YAML/JSON style from the command line. @@ -4041,7 +4039,7 @@ llvm::Expected<FormatStyle> getStyle(StringRef StyleName, StringRef FileName, }; // Look for .clang-format/_clang-format file in the file's parent directories. - llvm::SmallVector<std::string, 2> FilesToLookFor; + SmallVector<std::string, 2> FilesToLookFor; FilesToLookFor.push_back(".clang-format"); FilesToLookFor.push_back("_clang-format"); diff --git a/clang/lib/Format/FormatTokenSource.h b/clang/lib/Format/FormatTokenSource.h index 2b93f302d3603..8f00e5f4582c6 100644 --- a/clang/lib/Format/FormatTokenSource.h +++ b/clang/lib/Format/FormatTokenSource.h @@ -173,7 +173,7 @@ class IndexedTokenSource : public FormatTokenSource { return Next; } - void dbgToken(int Position, llvm::StringRef Indent = "") { + void dbgToken(int Position, StringRef Indent = "") { FormatToken *Tok = Tokens[Position]; llvm::dbgs() << Indent << "[" << Position << "] Token: " << Tok->Tok.getName() << " / " << Tok->TokenText diff --git a/clang/lib/Format/MacroExpander.cpp b/clang/lib/Format/MacroExpander.cpp index 5a1cdd884c5e6..5768ff37fefcd 100644 --- a/clang/lib/Format/MacroExpander.cpp +++ b/clang/lib/Format/MacroExpander.cpp @@ -119,7 +119,7 @@ class MacroExpander::DefinitionParser { }; MacroExpander::MacroExpander( - const std::vector<std::string> &Macros, clang::SourceManager &SourceMgr, + const std::vector<std::string> &Macros, SourceManager &SourceMgr, const FormatStyle &Style, llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator, IdentifierTable &IdentTable) @@ -134,7 +134,7 @@ MacroExpander::~MacroExpander() = default; void MacroExpander::parseDefinition(const std::string &Macro) { Buffers.push_back( llvm::MemoryBuffer::getMemBufferCopy(Macro, "<scratch space>")); - clang::FileID FID = SourceMgr.createFileID(Buffers.back()->getMemBufferRef()); + FileID FID = SourceMgr.createFileID(Buffers.back()->getMemBufferRef()); FormatTokenLexer Lex(SourceMgr, FID, 0, Style, encoding::Encoding_UTF8, Allocator, IdentTable); const auto Tokens = Lex.lex(); @@ -150,20 +150,20 @@ void MacroExpander::parseDefinition(const std::string &Macro) { } } -bool MacroExpander::defined(llvm::StringRef Name) const { +bool MacroExpander::defined(StringRef Name) const { return FunctionLike.contains(Name) || ObjectLike.contains(Name); } -bool MacroExpander::objectLike(llvm::StringRef Name) const { +bool MacroExpander::objectLike(StringRef Name) const { return ObjectLike.contains(Name); } -bool MacroExpander::hasArity(llvm::StringRef Name, unsigned Arity) const { +bool MacroExpander::hasArity(StringRef Name, unsigned Arity) const { auto it = FunctionLike.find(Name); return it != FunctionLike.end() && it->second.contains(Arity); } -llvm::SmallVector<FormatToken *, 8> +SmallVector<FormatToken *, 8> MacroExpander::expand(FormatToken *ID, std::optional<ArgsList> OptionalArgs) const { if (OptionalArgs) diff --git a/clang/lib/Format/Macros.h b/clang/lib/Format/Macros.h index fb12d22299dea..e05f734b0db8a 100644 --- a/clang/lib/Format/Macros.h +++ b/clang/lib/Format/Macros.h @@ -79,7 +79,7 @@ struct UnwrappedLineNode; /// class MacroExpander { public: - using ArgsList = llvm::ArrayRef<llvm::SmallVector<FormatToken *, 8>>; + using ArgsList = ArrayRef<SmallVector<FormatToken *, 8>>; /// Construct a macro expander from a set of macro definitions. /// Macro definitions must be encoded as UTF-8. @@ -95,27 +95,27 @@ class MacroExpander { /// Macros that cannot be parsed will be silently discarded. /// MacroExpander(const std::vector<std::string> &Macros, - clang::SourceManager &SourceMgr, const FormatStyle &Style, + SourceManager &SourceMgr, const FormatStyle &Style, llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator, IdentifierTable &IdentTable); ~MacroExpander(); /// Returns whether any macro \p Name is defined, regardless of overloads. - bool defined(llvm::StringRef Name) const; + bool defined(StringRef Name) const; /// Returns whetherh there is an object-like overload, i.e. where the macro /// has no arguments and should not consume subsequent parentheses. - bool objectLike(llvm::StringRef Name) const; + bool objectLike(StringRef Name) const; /// Returns whether macro \p Name provides an overload with the given arity. - bool hasArity(llvm::StringRef Name, unsigned Arity) const; + bool hasArity(StringRef Name, unsigned Arity) const; /// Returns the expanded stream of format tokens for \p ID, where /// each element in \p Args is a positional argument to the macro call. /// If \p Args is not set, the object-like overload is used. /// If \p Args is set, the overload with the arity equal to \c Args.size() is /// used. - llvm::SmallVector<FormatToken *, 8> + SmallVector<FormatToken *, 8> expand(FormatToken *ID, std::optional<ArgsList> OptionalArgs) const; private: @@ -124,7 +124,7 @@ class MacroExpander { void parseDefinition(const std::string &Macro); - clang::SourceManager &SourceMgr; + SourceManager &SourceMgr; const FormatStyle &Style; llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator; IdentifierTable &IdentTable; @@ -260,7 +260,7 @@ class MacroCallReconstructor { LineNode() = default; LineNode(FormatToken *Tok) : Tok(Tok) {} FormatToken *Tok = nullptr; - llvm::SmallVector<std::unique_ptr<ReconstructedLine>> Children; + SmallVector<std::unique_ptr<ReconstructedLine>> Children; }; // Line in which we build up the resulting unwrapped line. @@ -269,7 +269,7 @@ class MacroCallReconstructor { struct ReconstructedLine { explicit ReconstructedLine(unsigned Level) : Level(Level) {} unsigned Level; - llvm::SmallVector<std::unique_ptr<LineNode>> Tokens; + SmallVector<std::unique_ptr<LineNode>> Tokens; }; // The line in which we collect the resulting reconstructed output. @@ -285,7 +285,7 @@ class MacroCallReconstructor { // Stack of currently "open" lines, where each line's predecessor's last // token is the parent token for that line. - llvm::SmallVector<ReconstructedLine *> ActiveReconstructedLines; + SmallVector<ReconstructedLine *> ActiveReconstructedLines; // Maps from the expanded token to the token that takes its place in the // reconstructed token stream in terms of parent-child relationships. @@ -325,7 +325,7 @@ class MacroCallReconstructor { }; // Stack of macro calls for which we're in the middle of an expansion. - llvm::SmallVector<Expansion> ActiveExpansions; + SmallVector<Expansion> ActiveExpansions; struct MacroCallState { MacroCallState(ReconstructedLine *Line, FormatToken *ParentLastToken, @@ -368,7 +368,7 @@ class MacroCallReconstructor { // |- , // | \- <argument> // \- ) - llvm::SmallVector<MacroCallState> MacroCallStructure; + SmallVector<MacroCallState> MacroCallStructure; // Maps from identifier of the macro call to an unwrapped line containing // all tokens of the macro call. diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index 1a6a1b19e7022..1acce26ff2795 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/clang/lib/Format/SortJavaScriptImports.cpp @@ -34,8 +34,6 @@ namespace format { class FormatTokenLexer; -using clang::format::FormatStyle; - // An imported symbol in a JavaScript ES6 import/export, possibly aliased. struct JsImportedSymbol { StringRef Symbol; @@ -178,7 +176,7 @@ class JavaScriptImportSorter : public TokenAnalyzer { } } } - llvm::StringRef PreviousText = getSourceText(InsertionPoint); + StringRef PreviousText = getSourceText(InsertionPoint); if (ReferencesText == PreviousText) return {Result, 0}; @@ -209,7 +207,7 @@ class JavaScriptImportSorter : public TokenAnalyzer { // FIXME: better error handling. For now, just print error message and skip // the replacement for the release version. if (Err) { - llvm::errs() << llvm::toString(std::move(Err)) << "\n"; + llvm::errs() << toString(std::move(Err)) << "\n"; assert(false); } @@ -276,7 +274,7 @@ class JavaScriptImportSorter : public TokenAnalyzer { SortChunk.push_back(*Start); ++Start; } - llvm::stable_sort(SortChunk); + stable_sort(SortChunk); mergeModuleReferences(SortChunk); ReferencesSorted.insert(ReferencesSorted.end(), SortChunk.begin(), SortChunk.end()); @@ -334,10 +332,10 @@ class JavaScriptImportSorter : public TokenAnalyzer { // Sort the individual symbols within the import. // E.g. `import {b, a} from 'x';` -> `import {a, b} from 'x';` SmallVector<JsImportedSymbol, 1> Symbols = Reference.Symbols; - llvm::stable_sort( - Symbols, [&](const JsImportedSymbol &LHS, const JsImportedSymbol &RHS) { - return LHS.Symbol.compare_insensitive(RHS.Symbol) < 0; - }); + stable_sort(Symbols, + [&](const JsImportedSymbol &LHS, const JsImportedSymbol &RHS) { + return LHS.Symbol.compare_insensitive(RHS.Symbol) < 0; + }); if (!Reference.SymbolsMerged && Symbols == Reference.Symbols) { // Symbols didn't change, just emit the entire module reference. StringRef ReferenceStmt = getSourceText(Reference.Range); @@ -349,7 +347,7 @@ class JavaScriptImportSorter : public TokenAnalyzer { // ... then the references in order ... if (!Symbols.empty()) { Buffer += getSourceText(Symbols.front().Range); - for (const JsImportedSymbol &Symbol : llvm::drop_begin(Symbols)) { + for (const JsImportedSymbol &Symbol : drop_begin(Symbols)) { Buffer += ","; Buffer += getSourceText(Symbol.Range); } diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 3fa5f81a35768..50dd073c41255 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -352,7 +352,7 @@ emitReplacementWarnings(const Replacements &Replaces, StringRef AssumedFileName, unsigned Errors = 0; if (WarnFormat && !NoWarnFormat) { - llvm::SourceMgr Mgr; + SourceMgr Mgr; const char *StartBuf = Code->getBufferStart(); Mgr.AddNewSourceBuffer( @@ -447,11 +447,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) { return true; } - llvm::Expected<FormatStyle> FormatStyle = + Expected<FormatStyle> FormatStyle = getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer(), nullptr, WNoErrorList.isSet(WNoError::Unknown)); if (!FormatStyle) { - llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n"; + llvm::errs() << toString(FormatStyle.takeError()) << "\n"; return true; } @@ -497,7 +497,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) { auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces); if (!ChangedCode) { - llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n"; + llvm::errs() << toString(ChangedCode.takeError()) << "\n"; return true; } // Get new affected ranges after sorting `#includes`. @@ -567,14 +567,12 @@ static int dumpConfig() { } Code = std::move(CodeOrErr.get()); } - llvm::Expected<clang::format::FormatStyle> FormatStyle = - clang::format::getStyle(Style, - FileNames.empty() || FileNames[0] == "-" - ? AssumeFileName - : FileNames[0], - FallbackStyle, Code ? Code->getBuffer() : ""); + Expected<clang::format::FormatStyle> FormatStyle = clang::format::getStyle( + Style, + FileNames.empty() || FileNames[0] == "-" ? AssumeFileName : FileNames[0], + FallbackStyle, Code ? Code->getBuffer() : ""); if (!FormatStyle) { - llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n"; + llvm::errs() << toString(FormatStyle.takeError()) << "\n"; return 1; } std::string Config = clang::format::configurationAsText(*FormatStyle); @@ -671,7 +669,7 @@ static bool isIgnored(StringRef FilePath) { } int main(int argc, const char **argv) { - llvm::InitLLVM X(argc, argv); + InitLLVM X(argc, argv); cl::HideUnrelatedOptions(ClangFormatCategory); diff --git a/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp index dc149b502bc52..a3801106e1ceb 100644 --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/unittests/Format/CleanupTest.cpp @@ -20,10 +20,9 @@ namespace clang { namespace format { namespace { -class CleanupTest : public ::testing::Test { +class CleanupTest : public testing::Test { protected: - std::string cleanup(llvm::StringRef Code, - const std::vector<tooling::Range> &Ranges, + std::string cleanup(StringRef Code, const std::vector<tooling::Range> &Ranges, const FormatStyle &Style = getLLVMStyle()) { tooling::Replacements Replaces = format::cleanup(Style, Code, Ranges); @@ -33,8 +32,7 @@ class CleanupTest : public ::testing::Test { } // Returns code after cleanup around \p Offsets. - std::string cleanupAroundOffsets(llvm::ArrayRef<unsigned> Offsets, - llvm::StringRef Code, + std::string cleanupAroundOffsets(ArrayRef<unsigned> Offsets, StringRef Code, const FormatStyle &Style = getLLVMStyle()) { std::vector<tooling::Range> Ranges; for (auto Offset : Offsets) @@ -332,7 +330,7 @@ class CleanUpReplacementsTest : public ReplacementTest { const tooling::Replacements &Replaces) { auto CleanReplaces = cleanupAroundReplacements(Code, Replaces, Style); EXPECT_TRUE(static_cast<bool>(CleanReplaces)) - << llvm::toString(CleanReplaces.takeError()) << "\n"; + << toString(CleanReplaces.takeError()) << "\n"; auto Result = applyAllReplacements(Code, *CleanReplaces); EXPECT_TRUE(static_cast<bool>(Result)); return *Result; @@ -342,10 +340,10 @@ class CleanUpReplacementsTest : public ReplacementTest { const tooling::Replacements &Replaces) { auto CleanReplaces = cleanupAroundReplacements(Code, Replaces, Style); EXPECT_TRUE(static_cast<bool>(CleanReplaces)) - << llvm::toString(CleanReplaces.takeError()) << "\n"; + << toString(CleanReplaces.takeError()) << "\n"; auto FormattedReplaces = formatReplacements(Code, *CleanReplaces, Style); EXPECT_TRUE(static_cast<bool>(FormattedReplaces)) - << llvm::toString(FormattedReplaces.takeError()) << "\n"; + << toString(FormattedReplaces.takeError()) << "\n"; auto Result = applyAllReplacements(Code, *FormattedReplaces); EXPECT_TRUE(static_cast<bool>(Result)); return *Result; diff --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp index 7a120935cfa96..b26b9f4f4ff62 100644 --- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp +++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp @@ -18,10 +18,10 @@ namespace clang { namespace format { namespace { -class DefinitionBlockSeparatorTest : public ::testing::Test { +class DefinitionBlockSeparatorTest : public testing::Test { protected: static std::string - separateDefinitionBlocks(llvm::StringRef Code, + separateDefinitionBlocks(StringRef Code, const std::vector<tooling::Range> &Ranges, const FormatStyle &Style = getLLVMStyle()) { LLVM_DEBUG(llvm::errs() << "---\n"); @@ -34,18 +34,17 @@ class DefinitionBlockSeparatorTest : public ::testing::Test { } static std::string - separateDefinitionBlocks(llvm::StringRef Code, + separateDefinitionBlocks(StringRef Code, const FormatStyle &Style = getLLVMStyle()) { return separateDefinitionBlocks( Code, /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style); } - static void _verifyFormat(const char *File, int Line, llvm::StringRef Code, + static void _verifyFormat(const char *File, int Line, StringRef Code, const FormatStyle &Style = getLLVMStyle(), - llvm::StringRef ExpectedCode = "", - bool Inverse = true) { - ::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str()); + StringRef ExpectedCode = "", bool Inverse = true) { + testing::ScopedTrace t(File, Line, testing::Message() << Code.str()); bool HasOriginalCode = true; if (ExpectedCode == "") { ExpectedCode = Code; @@ -70,7 +69,7 @@ class DefinitionBlockSeparatorTest : public ::testing::Test { EXPECT_EQ(ExpectedCode, Result) << "Test failed. Formatted:\n" << Result; } - static std::string removeEmptyLines(llvm::StringRef Code) { + static std::string removeEmptyLines(StringRef Code) { std::string Result = ""; for (auto Char : Code.str()) { if (Result.size()) { @@ -165,13 +164,13 @@ TEST_F(DefinitionBlockSeparatorTest, Basic) { TEST_F(DefinitionBlockSeparatorTest, FormatConflict) { FormatStyle Style = getLLVMStyle(); Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always; - llvm::StringRef Code = "class Test {\n" - "public:\n" - " static void foo() {\n" - " int t;\n" - " return 1;\n" - " }\n" - "};"; + StringRef Code = "class Test {\n" + "public:\n" + " static void foo() {\n" + " int t;\n" + " return 1;\n" + " }\n" + "};"; std::vector<tooling::Range> Ranges = {1, tooling::Range(0, Code.size())}; EXPECT_EQ(reformat(Style, Code, Ranges, "<stdin>").size(), 0u); } diff --git a/clang/unittests/Format/FormatTestBase.h b/clang/unittests/Format/FormatTestBase.h index eaadb1c9f83e5..33110ca5d9edf 100644 --- a/clang/unittests/Format/FormatTestBase.h +++ b/clang/unittests/Format/FormatTestBase.h @@ -25,17 +25,17 @@ namespace test { #define DEBUG_TYPE "format-test-base" -class FormatTestBase : public ::testing::Test { +class FormatTestBase : public testing::Test { protected: enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck }; virtual FormatStyle getDefaultStyle() const { return getLLVMStyle(); } - virtual std::string messUp(llvm::StringRef Code) const { + virtual std::string messUp(StringRef Code) const { return test::messUp(Code); } - std::string format(llvm::StringRef Code, + std::string format(StringRef Code, const std::optional<FormatStyle> &Style = {}, StatusCheck CheckComplete = SC_ExpectComplete, const std::vector<tooling::Range> &Ranges = {}) { @@ -80,11 +80,11 @@ class FormatTestBase : public ::testing::Test { return Style; } - bool _verifyFormat(const char *File, int Line, llvm::StringRef Expected, - llvm::StringRef Code, + bool _verifyFormat(const char *File, int Line, StringRef Expected, + StringRef Code, const std::optional<FormatStyle> &Style = {}, const std::vector<tooling::Range> &Ranges = {}) { - testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str()); + testing::ScopedTrace t(File, Line, testing::Message() << Code.str()); const auto ExpectedCode{Expected.str()}; auto FormattedCode{format(Code, Style, SC_ExpectComplete, Ranges)}; EXPECT_EQ(ExpectedCode, FormattedCode); @@ -111,7 +111,7 @@ class FormatTestBase : public ::testing::Test { return true; } - void _verifyFormat(const char *File, int Line, llvm::StringRef Code, + void _verifyFormat(const char *File, int Line, StringRef Code, const std::optional<FormatStyle> &Style = {}) { if (!_verifyFormat(File, Line, Code, Code, Style)) return; @@ -119,27 +119,26 @@ class FormatTestBase : public ::testing::Test { _verifyFormat(File, Line, Code, MessedUpCode, Style); } - void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code, + void _verifyIncompleteFormat(const char *File, int Line, StringRef Code, const std::optional<FormatStyle> &Style = {}) { - testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str()); + testing::ScopedTrace t(File, Line, testing::Message() << Code.str()); EXPECT_EQ(Code.str(), format(messUp(Code), Style, SC_ExpectIncomplete)); } void - _verifyIndependentOfContext(const char *File, int Line, llvm::StringRef Text, + _verifyIndependentOfContext(const char *File, int Line, StringRef Text, const std::optional<FormatStyle> &Style = {}) { _verifyFormat(File, Line, Text, Style); - _verifyFormat(File, Line, llvm::Twine("void f() { " + Text + " }").str(), - Style); + _verifyFormat(File, Line, Twine("void f() { " + Text + " }").str(), Style); } - void _verifyNoChange(const char *File, int Line, llvm::StringRef Code, + void _verifyNoChange(const char *File, int Line, StringRef Code, const std::optional<FormatStyle> &Style = {}) { _verifyFormat(File, Line, Code, Code, Style); } /// \brief Verify that clang-format does not crash on the given input. - void verifyNoCrash(llvm::StringRef Code, + void verifyNoCrash(StringRef Code, const std::optional<FormatStyle> &Style = {}) { format(Code, Style, SC_DoNotCheck); } diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index de261c0948308..7166e4ec4de30 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -21,8 +21,8 @@ class FormatTestCSharp : public test::FormatTestBase { return getMicrosoftStyle(FormatStyle::LK_CSharp); } - static std::string format(llvm::StringRef Code, unsigned Offset, - unsigned Length, const FormatStyle &Style) { + static std::string format(StringRef Code, unsigned Offset, unsigned Length, + const FormatStyle &Style) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); @@ -34,7 +34,7 @@ class FormatTestCSharp : public test::FormatTestBase { } static std::string - format(llvm::StringRef Code, + format(StringRef Code, const FormatStyle &Style = getMicrosoftStyle(FormatStyle::LK_CSharp)) { return format(Code, 0, Code.size(), Style); } diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 3aded8f3726d8..b910ce620de7a 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -16,10 +16,10 @@ namespace clang { namespace format { -class FormatTestJS : public ::testing::Test { +class FormatTestJS : public testing::Test { protected: - static std::string format(llvm::StringRef Code, unsigned Offset, - unsigned Length, const FormatStyle &Style) { + static std::string format(StringRef Code, unsigned Offset, unsigned Length, + const FormatStyle &Style) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); @@ -34,7 +34,7 @@ class FormatTestJS : public ::testing::Test { } static std::string format( - llvm::StringRef Code, + StringRef Code, const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { return format(Code, 0, Code.size(), Style); } @@ -46,7 +46,7 @@ class FormatTestJS : public ::testing::Test { } static void verifyFormat( - llvm::StringRef Code, + StringRef Code, const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable"; std::string Result = format(test::messUp(Code), Style); @@ -54,7 +54,7 @@ class FormatTestJS : public ::testing::Test { } static void verifyFormat( - llvm::StringRef Expected, llvm::StringRef Code, + StringRef Expected, StringRef Code, const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { EXPECT_EQ(Expected.str(), format(Expected, Style)) << "Expected code is not stable"; diff --git a/clang/unittests/Format/FormatTestJson.cpp b/clang/unittests/Format/FormatTestJson.cpp index 3254802dc0d60..60e9f17855f72 100644 --- a/clang/unittests/Format/FormatTestJson.cpp +++ b/clang/unittests/Format/FormatTestJson.cpp @@ -16,10 +16,10 @@ namespace clang { namespace format { -class FormatTestJson : public ::testing::Test { +class FormatTestJson : public testing::Test { protected: - static std::string format(llvm::StringRef Code, unsigned Offset, - unsigned Length, const FormatStyle &Style) { + static std::string format(StringRef Code, unsigned Offset, unsigned Length, + const FormatStyle &Style) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); @@ -47,7 +47,7 @@ class FormatTestJson : public ::testing::Test { } static std::string - format(llvm::StringRef Code, + format(StringRef Code, const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Json)) { return format(Code, 0, Code.size(), Style); } @@ -58,13 +58,12 @@ class FormatTestJson : public ::testing::Test { return Style; } - static void verifyFormatStable(llvm::StringRef Code, - const FormatStyle &Style) { + static void verifyFormatStable(StringRef Code, const FormatStyle &Style) { EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable"; } static void - verifyFormat(llvm::StringRef Code, + verifyFormat(StringRef Code, const FormatStyle &Style = getLLVMStyle(FormatStyle::LK_Json)) { verifyFormatStable(Code, Style); EXPECT_EQ(Code.str(), format(test::messUp(Code), Style)); diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index 4a2d2d68248d3..5adb532ae4a41 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -16,10 +16,10 @@ namespace clang { namespace format { -class FormatTestProto : public ::testing::Test { +class FormatTestProto : public testing::Test { protected: - static std::string format(llvm::StringRef Code, unsigned Offset, - unsigned Length, const FormatStyle &Style) { + static std::string format(StringRef Code, unsigned Offset, unsigned Length, + const FormatStyle &Style) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); @@ -30,13 +30,13 @@ class FormatTestProto : public ::testing::Test { return *Result; } - static std::string format(llvm::StringRef Code) { + static std::string format(StringRef Code) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto); Style.ColumnLimit = 60; // To make writing tests easier. return format(Code, 0, Code.size(), Style); } - static void verifyFormat(llvm::StringRef Code) { + static void verifyFormat(StringRef Code) { EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable"; EXPECT_EQ(Code.str(), format(test::messUp(Code))); } diff --git a/clang/unittests/Format/FormatTestRawStrings.cpp b/clang/unittests/Format/FormatTestRawStrings.cpp index 10f341cc8f799..0615fb1fad4c5 100644 --- a/clang/unittests/Format/FormatTestRawStrings.cpp +++ b/clang/unittests/Format/FormatTestRawStrings.cpp @@ -21,12 +21,11 @@ namespace clang { namespace format { namespace { -class FormatTestRawStrings : public ::testing::Test { +class FormatTestRawStrings : public testing::Test { protected: enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck }; - std::string format(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle(), + std::string format(StringRef Code, const FormatStyle &Style = getLLVMStyle(), StatusCheck CheckComplete = SC_ExpectComplete) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); diff --git a/clang/unittests/Format/FormatTestSelective.cpp b/clang/unittests/Format/FormatTestSelective.cpp index c21c9bfe60790..3ae70a15d359b 100644 --- a/clang/unittests/Format/FormatTestSelective.cpp +++ b/clang/unittests/Format/FormatTestSelective.cpp @@ -17,9 +17,9 @@ namespace clang { namespace format { namespace { -class FormatTestSelective : public ::testing::Test { +class FormatTestSelective : public testing::Test { protected: - std::string format(llvm::StringRef Code, unsigned Offset, unsigned Length) { + std::string format(StringRef Code, unsigned Offset, unsigned Length) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); diff --git a/clang/unittests/Format/FormatTestTableGen.cpp b/clang/unittests/Format/FormatTestTableGen.cpp index 79b6961b00b42..7771f6a109a9a 100644 --- a/clang/unittests/Format/FormatTestTableGen.cpp +++ b/clang/unittests/Format/FormatTestTableGen.cpp @@ -16,10 +16,10 @@ namespace clang { namespace format { -class FormatTestTableGen : public ::testing::Test { +class FormatTestTableGen : public testing::Test { protected: - static std::string format(llvm::StringRef Code, unsigned Offset, - unsigned Length, const FormatStyle &Style) { + static std::string format(StringRef Code, unsigned Offset, unsigned Length, + const FormatStyle &Style) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); @@ -30,22 +30,22 @@ class FormatTestTableGen : public ::testing::Test { return *Result; } - static std::string format(llvm::StringRef Code) { + static std::string format(StringRef Code) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_TableGen); Style.ColumnLimit = 60; // To make writing tests easier. return format(Code, 0, Code.size(), Style); } - static void verifyFormat(llvm::StringRef Code) { + static void verifyFormat(StringRef Code) { EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable"; EXPECT_EQ(Code.str(), format(test::messUp(Code))); } - static void verifyFormat(llvm::StringRef Result, llvm::StringRef MessedUp) { + static void verifyFormat(StringRef Result, StringRef MessedUp) { EXPECT_EQ(Result, format(MessedUp)); } - static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) { + static void verifyFormat(StringRef Code, const FormatStyle &Style) { EXPECT_EQ(Code.str(), format(Code, 0, Code.size(), Style)) << "Expected code is not stable"; auto MessUp = test::messUp(Code); diff --git a/clang/unittests/Format/FormatTestUtils.h b/clang/unittests/Format/FormatTestUtils.h index fa42b61c547d5..cb55b2d747b62 100644 --- a/clang/unittests/Format/FormatTestUtils.h +++ b/clang/unittests/Format/FormatTestUtils.h @@ -27,7 +27,7 @@ inline FormatStyle getGoogleStyle() { // When HandleHash is false, preprocessor directives starting with hash will not // be on separate lines. This is needed because Verilog uses hash for other // purposes. -inline std::string messUp(llvm::StringRef Code, bool HandleHash = true) { +inline std::string messUp(StringRef Code, bool HandleHash = true) { std::string MessedUp(Code.str()); bool InComment = false; bool InPreprocessorDirective = false; diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp index abebf9f7d4c78..b5241a4e0d6ae 100644 --- a/clang/unittests/Format/FormatTestVerilog.cpp +++ b/clang/unittests/Format/FormatTestVerilog.cpp @@ -19,7 +19,7 @@ class FormatTestVerilog : public test::FormatTestBase { FormatStyle getDefaultStyle() const override { return getLLVMStyle(FormatStyle::LK_Verilog); } - std::string messUp(llvm::StringRef Code) const override { + std::string messUp(StringRef Code) const override { return test::messUp(Code, /*HandleHash=*/false); } }; diff --git a/clang/unittests/Format/FormatTokenSourceTest.cpp b/clang/unittests/Format/FormatTokenSourceTest.cpp index 74de93057df6a..4f19e255004fc 100644 --- a/clang/unittests/Format/FormatTokenSourceTest.cpp +++ b/clang/unittests/Format/FormatTokenSourceTest.cpp @@ -15,10 +15,9 @@ namespace clang { namespace format { namespace { -class IndexedTokenSourceTest : public ::testing::Test { +class IndexedTokenSourceTest : public testing::Test { protected: - TokenList lex(llvm::StringRef Code, - const FormatStyle &Style = getLLVMStyle()) { + TokenList lex(StringRef Code, const FormatStyle &Style = getLLVMStyle()) { return TestLexer(Allocator, Buffers, Style).lex(Code); } llvm::SpecificBumpPtrAllocator<FormatToken> Allocator; diff --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp b/clang/unittests/Format/MacroCallReconstructorTest.cpp index 9df21eae70cb7..acef5e79eaaea 100644 --- a/clang/unittests/Format/MacroCallReconstructorTest.cpp +++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp @@ -30,15 +30,14 @@ class Expansion { // Appends the token stream obtained from expanding the macro Name given // the provided arguments, to be later retrieved with getTokens(). // Returns the list of tokens making up the unexpanded macro call. - TokenList - expand(llvm::StringRef Name, - const SmallVector<llvm::SmallVector<FormatToken *, 8>, 1> &Args) { + TokenList expand(StringRef Name, + const SmallVector<SmallVector<FormatToken *, 8>, 1> &Args) { return expandInternal(Name, Args); } - TokenList expand(llvm::StringRef Name) { return expandInternal(Name, {}); } + TokenList expand(StringRef Name) { return expandInternal(Name, {}); } - TokenList expand(llvm::StringRef Name, const std::vector<std::string> &Args) { + TokenList expand(StringRef Name, const std::vector<std::string> &Args) { return expandInternal(Name, lexArgs(Args)); } @@ -48,8 +47,8 @@ class Expansion { private: TokenList expandInternal( - llvm::StringRef Name, - const std::optional<SmallVector<llvm::SmallVector<FormatToken *, 8>, 1>> + StringRef Name, + const std::optional<SmallVector<SmallVector<FormatToken *, 8>, 1>> &Args) { auto *ID = Lex.id(Name); auto UnexpandedLine = std::make_unique<UnwrappedLine>(); @@ -75,26 +74,25 @@ class Expansion { return UnexpandedTokens; } - llvm::SmallVector<TokenList, 1> - lexArgs(const std::vector<std::string> &Args) { - llvm::SmallVector<TokenList, 1> Result; + SmallVector<TokenList, 1> lexArgs(const std::vector<std::string> &Args) { + SmallVector<TokenList, 1> Result; for (const auto &Arg : Args) Result.push_back(uneof(Lex.lex(Arg))); return Result; } llvm::DenseMap<FormatToken *, std::unique_ptr<UnwrappedLine>> Unexpanded; - llvm::SmallVector<FormatToken *, 8> Tokens; + SmallVector<FormatToken *, 8> Tokens; TestLexer &Lex; MacroExpander &Macros; }; struct Chunk { - Chunk(llvm::ArrayRef<FormatToken *> Tokens) + Chunk(ArrayRef<FormatToken *> Tokens) : Tokens(Tokens.begin(), Tokens.end()) {} - Chunk(llvm::ArrayRef<UnwrappedLine> Children) + Chunk(ArrayRef<UnwrappedLine> Children) : Children(Children.begin(), Children.end()) {} - llvm::SmallVector<UnwrappedLineNode, 1> Tokens; - llvm::SmallVector<UnwrappedLine, 0> Children; + SmallVector<UnwrappedLineNode, 1> Tokens; + SmallVector<UnwrappedLine, 0> Children; }; // Allows to produce chunks of a token list by typing the code of equal tokens. @@ -140,7 +138,7 @@ UnexpandedMap mergeUnexpanded(const UnexpandedMap &M1, return Result; } -class MacroCallReconstructorTest : public ::testing::Test { +class MacroCallReconstructorTest : public testing::Test { public: MacroCallReconstructorTest() : Lex(Allocator, Buffers) {} @@ -151,7 +149,7 @@ class MacroCallReconstructorTest : public ::testing::Test { Lex.Allocator, Lex.IdentTable); } - UnwrappedLine line(llvm::ArrayRef<FormatToken *> Tokens, unsigned Level = 0) { + UnwrappedLine line(ArrayRef<FormatToken *> Tokens, unsigned Level = 0) { UnwrappedLine Result; Result.Level = Level; for (FormatToken *Tok : Tokens) @@ -159,11 +157,11 @@ class MacroCallReconstructorTest : public ::testing::Test { return Result; } - UnwrappedLine line(llvm::StringRef Text, unsigned Level = 0) { + UnwrappedLine line(StringRef Text, unsigned Level = 0) { return line({lex(Text)}, Level); } - UnwrappedLine line(llvm::ArrayRef<Chunk> Chunks, unsigned Level = 0) { + UnwrappedLine line(ArrayRef<Chunk> Chunks, unsigned Level = 0) { UnwrappedLine Result; Result.Level = Level; for (const Chunk &Chunk : Chunks) { @@ -176,13 +174,11 @@ class MacroCallReconstructorTest : public ::testing::Test { return Result; } - TokenList lex(llvm::StringRef Text) { return uneof(Lex.lex(Text)); } + TokenList lex(StringRef Text) { return uneof(Lex.lex(Text)); } - Chunk tokens(llvm::StringRef Text) { return Chunk(lex(Text)); } + Chunk tokens(StringRef Text) { return Chunk(lex(Text)); } - Chunk children(llvm::ArrayRef<UnwrappedLine> Children) { - return Chunk(Children); - } + Chunk children(ArrayRef<UnwrappedLine> Children) { return Chunk(Children); } llvm::SpecificBumpPtrAllocator<FormatToken> Allocator; std::vector<std::unique_ptr<llvm::MemoryBuffer>> Buffers; diff --git a/clang/unittests/Format/MacroExpanderTest.cpp b/clang/unittests/Format/MacroExpanderTest.cpp index 72302aa0cea7e..e001c986dc2b8 100644 --- a/clang/unittests/Format/MacroExpanderTest.cpp +++ b/clang/unittests/Format/MacroExpanderTest.cpp @@ -9,7 +9,7 @@ namespace format { namespace { -class MacroExpanderTest : public ::testing::Test { +class MacroExpanderTest : public testing::Test { public: MacroExpanderTest() : Lex(Allocator, Buffers) {} std::unique_ptr<MacroExpander> @@ -19,33 +19,32 @@ class MacroExpanderTest : public ::testing::Test { Lex.Allocator, Lex.IdentTable); } - std::string expand(MacroExpander &Macros, llvm::StringRef Name) { + std::string expand(MacroExpander &Macros, StringRef Name) { EXPECT_TRUE(Macros.defined(Name)) << "Macro not defined: \"" << Name << "\""; return text(Macros.expand(Lex.id(Name), {})); } - std::string expand(MacroExpander &Macros, llvm::StringRef Name, + std::string expand(MacroExpander &Macros, StringRef Name, const std::vector<std::string> &Args) { EXPECT_TRUE(Macros.defined(Name)) << "Macro not defined: \"" << Name << "\""; return text(Macros.expand(Lex.id(Name), lexArgs(Args))); } - llvm::SmallVector<TokenList, 1> - lexArgs(const std::vector<std::string> &Args) { - llvm::SmallVector<TokenList, 1> Result; + SmallVector<TokenList, 1> lexArgs(const std::vector<std::string> &Args) { + SmallVector<TokenList, 1> Result; for (const auto &Arg : Args) Result.push_back(uneof(Lex.lex(Arg))); return Result; } struct MacroAttributes { - clang::tok::TokenKind Kind; + tok::TokenKind Kind; MacroRole Role; unsigned Start; unsigned End; - llvm::SmallVector<FormatToken *, 1> ExpandedFrom; + SmallVector<FormatToken *, 1> ExpandedFrom; }; void expectAttributes(const TokenList &Tokens, @@ -56,8 +55,8 @@ class MacroExpanderTest : public ::testing::Test { if (I >= Attributes.size()) continue; std::string Context = - ("for token " + llvm::Twine(I) + ": " + Tokens[I]->Tok.getName() + - " / " + Tokens[I]->TokenText) + ("for token " + Twine(I) + ": " + Tokens[I]->Tok.getName() + " / " + + Tokens[I]->TokenText) .str(); EXPECT_TRUE(Tokens[I]->is(Attributes[I].Kind)) << Context << " in " << text(Tokens) << " at " << File << ":" << Line; diff --git a/clang/unittests/Format/MatchFilePathTest.cpp b/clang/unittests/Format/MatchFilePathTest.cpp index 55723584ddc80..f41cf7f971596 100644 --- a/clang/unittests/Format/MatchFilePathTest.cpp +++ b/clang/unittests/Format/MatchFilePathTest.cpp @@ -13,7 +13,7 @@ namespace clang { namespace format { namespace { -class MatchFilePathTest : public ::testing::Test { +class MatchFilePathTest : public testing::Test { protected: bool match(llvm::StringRef FilePath, llvm::StringRef Pattern) { return matchFilePath(Pattern, FilePath); diff --git a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp index fe097e9961e2e..2c45ad1cbe1c8 100644 --- a/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ b/clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -17,16 +17,16 @@ namespace clang { namespace format { namespace { -class NamespaceEndCommentsFixerTest : public ::testing::Test { +class NamespaceEndCommentsFixerTest : public testing::Test { protected: std::string - fixNamespaceEndComments(llvm::StringRef Code, + fixNamespaceEndComments(StringRef Code, const std::vector<tooling::Range> &Ranges, const FormatStyle &Style = getLLVMStyle()) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); tooling::Replacements Replaces = - clang::format::fixNamespaceEndComments(Style, Code, Ranges, "<stdin>"); + format::fixNamespaceEndComments(Style, Code, Ranges, "<stdin>"); auto Result = applyAllReplacements(Code, Replaces); EXPECT_TRUE(static_cast<bool>(Result)); LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); @@ -34,7 +34,7 @@ class NamespaceEndCommentsFixerTest : public ::testing::Test { } std::string - fixNamespaceEndComments(llvm::StringRef Code, + fixNamespaceEndComments(StringRef Code, const FormatStyle &Style = getLLVMStyle()) { return fixNamespaceEndComments( Code, @@ -43,8 +43,7 @@ class NamespaceEndCommentsFixerTest : public ::testing::Test { bool isFormatted(StringRef Code, const std::vector<tooling::Range> &Ranges, const FormatStyle &Style = getLLVMStyle()) const { - return clang::format::fixNamespaceEndComments(Style, Code, Ranges, - "<stdin>") + return format::fixNamespaceEndComments(Style, Code, Ranges, "<stdin>") .empty(); } diff --git a/clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp b/clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp index 79ded66735916..9f852e4768b12 100644 --- a/clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp +++ b/clang/unittests/Format/ObjCPropertyAttributeOrderFixerTest.cpp @@ -28,7 +28,7 @@ namespace { class ObjCPropertyAttributeOrderFixerTest : public FormatTestBase { protected: - TokenList annotate(llvm::StringRef Code, + TokenList annotate(StringRef Code, const FormatStyle &Style = getLLVMStyle()) { return TestLexer(Allocator, Buffers, Style).annotate(Code); } diff --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp index 1f21fc0e0b42f..3a5f63e5de65b 100644 --- a/clang/unittests/Format/QualifierFixerTest.cpp +++ b/clang/unittests/Format/QualifierFixerTest.cpp @@ -28,7 +28,7 @@ namespace { class QualifierFixerTest : public FormatTestBase { protected: - TokenList annotate(llvm::StringRef Code, + TokenList annotate(StringRef Code, const FormatStyle &Style = getLLVMStyle()) { return TestLexer(Allocator, Buffers, Style).annotate(Code); } diff --git a/clang/unittests/Format/SortImportsTestJS.cpp b/clang/unittests/Format/SortImportsTestJS.cpp index f423cdd21d1ac..59ce62117d4a1 100644 --- a/clang/unittests/Format/SortImportsTestJS.cpp +++ b/clang/unittests/Format/SortImportsTestJS.cpp @@ -17,7 +17,7 @@ namespace clang { namespace format { namespace { -class SortImportsTestJS : public ::testing::Test { +class SortImportsTestJS : public testing::Test { protected: std::string sort(StringRef Code, unsigned Offset = 0, unsigned Length = 0) { StringRef FileName = "input.js"; @@ -33,10 +33,9 @@ class SortImportsTestJS : public ::testing::Test { return *Formatted; } - void _verifySort(const char *File, int Line, llvm::StringRef Expected, - llvm::StringRef Code, unsigned Offset = 0, - unsigned Length = 0) { - ::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str()); + void _verifySort(const char *File, int Line, StringRef Expected, + StringRef Code, unsigned Offset = 0, unsigned Length = 0) { + testing::ScopedTrace t(File, Line, testing::Message() << Code.str()); std::string Result = sort(Code, Offset, Length); EXPECT_EQ(Expected.str(), Result) << "Expected:\n" << Expected << "\nActual:\n" diff --git a/clang/unittests/Format/SortImportsTestJava.cpp b/clang/unittests/Format/SortImportsTestJava.cpp index 98a6826b1ff58..d577efa34f86e 100644 --- a/clang/unittests/Format/SortImportsTestJava.cpp +++ b/clang/unittests/Format/SortImportsTestJava.cpp @@ -7,7 +7,7 @@ namespace clang { namespace format { namespace { -class SortImportsTestJava : public ::testing::Test { +class SortImportsTestJava : public testing::Test { protected: std::vector<tooling::Range> GetCodeRange(StringRef Code) { return std::vector<tooling::Range>(1, tooling::Range(0, Code.size())); diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp index 52ba19627182b..2eeb16b4ab9f5 100644 --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -43,7 +43,7 @@ class SortIncludesTest : public test::FormatTestBase { return sort(Code, GetCodeRange(Code), FileName, ExpectedNumRanges); } - unsigned newCursor(llvm::StringRef Code, unsigned Cursor) { + unsigned newCursor(StringRef Code, unsigned Cursor) { sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.cpp", &Cursor); return Cursor; } @@ -644,7 +644,7 @@ TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveSorting) { "#include \"A/b.h\"", "a.h")); - Style.IncludeBlocks = clang::tooling::IncludeStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; Style.IncludeCategories = { {"^\"", 1, 0, false}, {"^<.*\\.h>$", 2, 0, false}, {"^<", 3, 0, false}}; @@ -694,7 +694,7 @@ TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) { } TEST_F(SortIncludesTest, SupportOptionalCaseSensitiveMachting) { - Style.IncludeBlocks = clang::tooling::IncludeStyle::IBS_Regroup; + Style.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup; Style.IncludeCategories = {{"^\"", 1, 0, false}, {"^<.*\\.h>$", 2, 0, false}, {"^<Q[A-Z][^\\.]*>", 3, 0, false}, diff --git a/clang/unittests/Format/TestLexer.h b/clang/unittests/Format/TestLexer.h index 8b5949b32fc9e..294d0106dbe2c 100644 --- a/clang/unittests/Format/TestLexer.h +++ b/clang/unittests/Format/TestLexer.h @@ -28,7 +28,7 @@ namespace clang { namespace format { -typedef llvm::SmallVector<FormatToken *, 8> TokenList; +typedef SmallVector<FormatToken *, 8> TokenList; inline std::ostream &operator<<(std::ostream &Stream, const FormatToken &Tok) { Stream << "(" << Tok.Tok.getName() << ", \"" << Tok.TokenText.str() << "\" , " @@ -48,7 +48,7 @@ inline TokenList uneof(const TokenList &Tokens) { return TokenList(Tokens.begin(), std::prev(Tokens.end())); } -inline std::string text(llvm::ArrayRef<FormatToken *> Tokens) { +inline std::string text(ArrayRef<FormatToken *> Tokens) { return std::accumulate(Tokens.begin(), Tokens.end(), std::string(), [](const std::string &R, FormatToken *Tok) { return (R + Tok->TokenText).str(); @@ -63,13 +63,13 @@ class TestLexer : public UnwrappedLineConsumer { : Allocator(Allocator), Buffers(Buffers), Style(Style), SourceMgr("test.cpp", ""), IdentTable(getFormattingLangOpts(Style)) {} - TokenList lex(llvm::StringRef Code) { + TokenList lex(StringRef Code) { FormatTokenLexer Lex = getNewLexer(Code); ArrayRef<FormatToken *> Result = Lex.lex(); return TokenList(Result.begin(), Result.end()); } - TokenList annotate(llvm::StringRef Code) { + TokenList annotate(StringRef Code) { FormatTokenLexer Lex = getNewLexer(Code); auto Tokens = Lex.lex(); UnwrappedLineParser Parser(SourceMgr.get(), Style, Lex.getKeywords(), 0, @@ -85,7 +85,7 @@ class TestLexer : public UnwrappedLineConsumer { return TokenList(Tokens.begin(), Tokens.end()); } - FormatToken *id(llvm::StringRef Code) { + FormatToken *id(StringRef Code) { auto Result = uneof(lex(Code)); assert(Result.size() == 1U && "Code must expand to 1 token."); return Result[0]; @@ -100,7 +100,7 @@ class TestLexer : public UnwrappedLineConsumer { FormatTokenLexer getNewLexer(StringRef Code) { Buffers.push_back( llvm::MemoryBuffer::getMemBufferCopy(Code, "<scratch space>")); - clang::FileID FID = + FileID FID = SourceMgr.get().createFileID(Buffers.back()->getMemBufferRef()); return FormatTokenLexer(SourceMgr.get(), FID, 0, Style, Encoding, Allocator, IdentTable); @@ -111,7 +111,7 @@ class TestLexer : public UnwrappedLineConsumer { std::vector<std::unique_ptr<llvm::MemoryBuffer>> &Buffers; FormatStyle Style; encoding::Encoding Encoding = encoding::Encoding_UTF8; - clang::SourceManagerForFile SourceMgr; + SourceManagerForFile SourceMgr; IdentifierTable IdentTable; SmallVector<UnwrappedLine, 16> UnwrappedLines; }; diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index aadfa6dc0165c..7528675753047 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -24,9 +24,9 @@ static bool operator==(const FormatToken &LHS, namespace { -class TokenAnnotatorTest : public ::testing::Test { +class TokenAnnotatorTest : public testing::Test { protected: - TokenList annotate(llvm::StringRef Code, + TokenList annotate(StringRef Code, const FormatStyle &Style = getLLVMStyle()) { return TestLexer(Allocator, Buffers, Style).annotate(Code); } @@ -2097,7 +2097,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacrosOnObjCProperty) { } TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) { - auto Annotate = [this](llvm::StringRef Code) { + auto Annotate = [this](StringRef Code) { return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog)); }; // Test that unary operators get labeled as such and that operators like '++' @@ -2279,9 +2279,7 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) { TestLexer Lexer(Allocator, Buffers, Style); AdditionalKeywords Keywords(Lexer.IdentTable); - auto Annotate = [&Lexer](llvm::StringRef Code) { - return Lexer.annotate(Code); - }; + auto Annotate = [&Lexer](StringRef Code) { return Lexer.annotate(Code); }; // Additional keywords representation test. auto Tokens = Annotate("def foo : Bar<1>;"); @@ -2357,7 +2355,7 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) { Tokens = Annotate("!cond"); EXPECT_TOKEN(Tokens[0], tok::identifier, TT_TableGenCondOperator); - auto AnnotateValue = [this, &Style](llvm::StringRef Code) { + auto AnnotateValue = [this, &Style](StringRef Code) { // Values are annotated only in specific context. auto Result = annotate(("def X { let V = " + Code + "; }").str(), Style); return decltype(Result){Result.begin() + 6, Result.end() - 3}; @@ -2649,7 +2647,7 @@ TEST_F(TokenAnnotatorTest, UnderstandDesignatedInitializers) { } TEST_F(TokenAnnotatorTest, UnderstandsJavaScript) { - auto Annotate = [this](llvm::StringRef Code) { + auto Annotate = [this](StringRef Code) { return annotate(Code, getLLVMStyle(FormatStyle::LK_JavaScript)); }; diff --git a/clang/unittests/Format/UsingDeclarationsSorterTest.cpp b/clang/unittests/Format/UsingDeclarationsSorterTest.cpp index c0c0de7076fe6..ddcecc0208b0c 100644 --- a/clang/unittests/Format/UsingDeclarationsSorterTest.cpp +++ b/clang/unittests/Format/UsingDeclarationsSorterTest.cpp @@ -17,22 +17,22 @@ namespace clang { namespace format { namespace { -class UsingDeclarationsSorterTest : public ::testing::Test { +class UsingDeclarationsSorterTest : public testing::Test { protected: - std::string sortUsingDeclarations(llvm::StringRef Code, + std::string sortUsingDeclarations(StringRef Code, const std::vector<tooling::Range> &Ranges, const FormatStyle &Style = getLLVMStyle()) { LLVM_DEBUG(llvm::errs() << "---\n"); LLVM_DEBUG(llvm::errs() << Code << "\n\n"); tooling::Replacements Replaces = - clang::format::sortUsingDeclarations(Style, Code, Ranges, "<stdin>"); + format::sortUsingDeclarations(Style, Code, Ranges, "<stdin>"); auto Result = applyAllReplacements(Code, Replaces); EXPECT_TRUE(static_cast<bool>(Result)); LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); return *Result; } - std::string sortUsingDeclarations(llvm::StringRef Code, + std::string sortUsingDeclarations(StringRef Code, const FormatStyle &Style = getLLVMStyle()) { return sortUsingDeclarations(Code, /*Ranges=*/{1, tooling::Range(0, Code.size())}, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits