From: Daniel Jasper Date: Tue, 8 Nov 2016 16:11:33 +0000 (+0000) Subject: [clang-format] Remove (SourceManager, FileID) variants X-Git-Tag: llvmorg-4.0.0-rc1~5239 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=528d682ff6f5180360b978a93ea0d49ebb758d5c;p=platform%2Fupstream%2Fllvm.git [clang-format] Remove (SourceManager, FileID) variants In Format, remove the reformat() and clean() functions taking a SourceManager and a FileID. Keep the versions taking StringRef Code. - there was duplicated functionality - the FileID versions were harder to use - the clean() version is dead code anyways Patch by Krasimir Georgiev. Thank you. llvm-svn: 286243 --- diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 338092c..2c1eb94 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -794,7 +794,7 @@ llvm::Expected cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, const FormatStyle &Style); -/// \brief Reformats the given \p Ranges in the file \p ID. +/// \brief Reformats the given \p Ranges in \p Code. /// /// Each range is extended on either end to its next bigger logic unit, i.e. /// everything that might influence its formatting or might be influenced by its @@ -806,31 +806,15 @@ cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, /// If ``IncompleteFormat`` is non-null, its value will be set to true if any /// of the affected ranges were not formatted due to a non-recoverable syntax /// error. -tooling::Replacements reformat(const FormatStyle &Style, - SourceManager &SourceMgr, FileID ID, - ArrayRef Ranges, - bool *IncompleteFormat = nullptr); - -/// \brief Reformats the given \p Ranges in \p Code. -/// -/// Otherwise identical to the reformat() function using a file ID. tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, ArrayRef Ranges, StringRef FileName = "", bool *IncompleteFormat = nullptr); -/// \brief Clean up any erroneous/redundant code in the given \p Ranges in the -/// file \p ID. -/// -/// Returns the ``Replacements`` that clean up all \p Ranges in the file \p ID. -tooling::Replacements cleanup(const FormatStyle &Style, - SourceManager &SourceMgr, FileID ID, - ArrayRef Ranges); - /// \brief Clean up any erroneous/redundant code in the given \p Ranges in \p /// Code. /// -/// Otherwise identical to the cleanup() function using a file ID. +/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code. tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef Ranges, StringRef FileName = ""); diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 99a1923..e1f991a 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1719,18 +1719,6 @@ cleanupAroundReplacements(StringRef Code, const tooling::Replacements &Replaces, return processReplacements(Cleanup, Code, NewReplaces, Style); } -tooling::Replacements reformat(const FormatStyle &Style, SourceManager &SM, - FileID ID, ArrayRef Ranges, - bool *IncompleteFormat) { - FormatStyle Expanded = expandPresets(Style); - if (Expanded.DisableFormat) - return tooling::Replacements(); - - Environment Env(SM, ID, Ranges); - Formatter Format(Env, Expanded, IncompleteFormat); - return Format.process(); -} - tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, ArrayRef Ranges, StringRef FileName, bool *IncompleteFormat) { @@ -1760,13 +1748,6 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, return Format.process(); } -tooling::Replacements cleanup(const FormatStyle &Style, SourceManager &SM, - FileID ID, ArrayRef Ranges) { - Environment Env(SM, ID, Ranges); - Cleaner Clean(Env, Style); - return Clean.process(); -} - tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef Ranges, StringRef FileName) { diff --git a/clang/lib/Index/CommentToXML.cpp b/clang/lib/Index/CommentToXML.cpp index c4beef2..4210b89 100644 --- a/clang/lib/Index/CommentToXML.cpp +++ b/clang/lib/Index/CommentToXML.cpp @@ -597,20 +597,21 @@ void CommentASTToXMLConverter::formatTextOfDeclaration( // Formatter specific code. // Form a unique in memory buffer name. - SmallString<128> filename; - filename += "xmldecl"; - filename += llvm::utostr(FormatInMemoryUniqueId); - filename += ".xd"; - FileID ID = FormatRewriterContext.createInMemoryFile(filename, StringDecl); - SourceLocation Start = FormatRewriterContext.Sources.getLocForStartOfFile(ID) - .getLocWithOffset(0); + SmallString<128> Filename; + Filename += "xmldecl"; + Filename += llvm::utostr(FormatInMemoryUniqueId); + Filename += ".xd"; + unsigned Offset = 0; unsigned Length = Declaration.size(); - tooling::Replacements Replace = reformat( - format::getLLVMStyle(), FormatRewriterContext.Sources, ID, - CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length))); - applyAllReplacements(Replace, FormatRewriterContext.Rewrite); - Declaration = FormatRewriterContext.getRewrittenText(ID); + bool IncompleteFormat = false; + tooling::Replacements Replaces = + reformat(format::getLLVMStyle(), StringDecl, + tooling::Range(Offset, Length), Filename, &IncompleteFormat); + auto FormattedStringDecl = applyAllReplacements(StringDecl, Replaces); + if (static_cast(FormattedStringDecl)) { + Declaration = *FormattedStringDecl; + } } } // end unnamed namespace @@ -1159,4 +1160,3 @@ void CommentToXMLConverter::convertCommentToXML(const FullComment *FC, FormatInMemoryUniqueId++); Converter.visit(FC); } -