]> granicus.if.org Git - clang/commitdiff
[clang-format] Remove (SourceManager, FileID) variants
authorDaniel Jasper <djasper@google.com>
Tue, 8 Nov 2016 16:11:33 +0000 (16:11 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 8 Nov 2016 16:11:33 +0000 (16:11 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286243 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Format/Format.h
lib/Format/Format.cpp
lib/Index/CommentToXML.cpp

index 338092c2af185119402155c2c783d01e0cddc0ec..2c1eb947ae18946ea611193c20a6249832ebe730 100644 (file)
@@ -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, 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<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>");
index 99a192341c6cbd44a17b9f789564dfd9ccd9d0d7..e1f991a9bf645ee36046de0adc1e948053a39781 100644 (file)
@@ -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<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 FormatStyle &Style, StringRef Code,
   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) {
index c4beef2494667a00736693bfc26f4e1eac66b0d9..4210b897c3a4dff9c3d9c5ade87012007851b0be 100644 (file)
@@ -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<bool>(FormattedStringDecl)) {
+    Declaration = *FormattedStringDecl;
+  }
 }
 
 } // end unnamed namespace
@@ -1159,4 +1160,3 @@ void CommentToXMLConverter::convertCommentToXML(const FullComment *FC,
                                      FormatInMemoryUniqueId++);
   Converter.visit(FC);
 }
-