Author: djasper Date: Tue Nov 8 10:11:33 2016 New Revision: 286243 URL: http://llvm.org/viewvc/llvm-project?rev=286243&view=rev Log: [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. Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/lib/Index/CommentToXML.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=286243&r1=286242&r2=286243&view=diff ============================================================================== --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Tue Nov 8 10:11:33 2016 @@ -794,7 +794,7 @@ llvm::Expected<tooling::Replacements> 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 /// 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<CharSourceRange> 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<tooling::Range> Ranges, StringRef FileName = "<stdin>", 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<CharSourceRange> 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<tooling::Range> Ranges, StringRef FileName = "<stdin>"); Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=286243&r1=286242&r2=286243&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Tue Nov 8 10:11:33 2016 @@ -1719,18 +1719,6 @@ cleanupAroundReplacements(StringRef Code return processReplacements(Cleanup, Code, NewReplaces, Style); } -tooling::Replacements reformat(const FormatStyle &Style, SourceManager &SM, - FileID ID, ArrayRef<CharSourceRange> 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<tooling::Range> Ranges, StringRef FileName, bool *IncompleteFormat) { @@ -1760,13 +1748,6 @@ tooling::Replacements reformat(const For return Format.process(); } -tooling::Replacements cleanup(const FormatStyle &Style, SourceManager &SM, - FileID ID, ArrayRef<CharSourceRange> Ranges) { - Environment Env(SM, ID, Ranges); - Cleaner Clean(Env, Style); - return Clean.process(); -} - tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef<tooling::Range> Ranges, StringRef FileName) { Modified: cfe/trunk/lib/Index/CommentToXML.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/CommentToXML.cpp?rev=286243&r1=286242&r2=286243&view=diff ============================================================================== --- cfe/trunk/lib/Index/CommentToXML.cpp (original) +++ cfe/trunk/lib/Index/CommentToXML.cpp Tue Nov 8 10:11:33 2016 @@ -597,20 +597,21 @@ void CommentASTToXMLConverter::formatTex // 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<bool>(FormattedStringDecl)) { + Declaration = *FormattedStringDecl; + } } } // end unnamed namespace @@ -1159,4 +1160,3 @@ void CommentToXMLConverter::convertComme FormatInMemoryUniqueId++); Converter.visit(FC); } - _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits