[llvm-branch-commits] [cfe-branch] r157324 - in /cfe/branches/tooling: include/clang/Tooling/Refactoring.h lib/Tooling/Refactoring.cpp unittests/Tooling/RefactoringTest.cpp

Manuel Klimek klimek at google.com
Wed May 23 07:58:08 PDT 2012


Author: klimek
Date: Wed May 23 09:58:08 2012
New Revision: 157324

URL: http://llvm.org/viewvc/llvm-project?rev=157324&view=rev
Log:
Addresses Dougs review comments.


Modified:
    cfe/branches/tooling/include/clang/Tooling/Refactoring.h
    cfe/branches/tooling/lib/Tooling/Refactoring.cpp
    cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp

Modified: cfe/branches/tooling/include/clang/Tooling/Refactoring.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/include/clang/Tooling/Refactoring.h?rev=157324&r1=157323&r2=157324&view=diff
==============================================================================
--- cfe/branches/tooling/include/clang/Tooling/Refactoring.h (original)
+++ cfe/branches/tooling/include/clang/Tooling/Refactoring.h Wed May 23 09:58:08 2012
@@ -105,12 +105,6 @@
 /// Apply operations.
 bool applyAllReplacements(Replacements &Replaces, Rewriter &Rewrite);
 
-/// \brief Saves all changed files in the Rewriter to disk.
-///
-/// \returns True On Success.
-/// FIXME: Put into Rewriter.
-bool saveRewrittenFiles(Rewriter &Rewrite);
-
 /// \brief A tool to run refactorings.
 ///
 /// This is a refactoring specific version of \see ClangTool.
@@ -136,11 +130,6 @@
   Replacements Replace;
 };
 
-/// \brief Returns the length of the given range.
-///
-/// FIXME: Put into  SourceManager.
-int getRangeSize(SourceManager &Sources, const CharSourceRange &Range);
-
 template <typename Node>
 Replacement::Replacement(SourceManager &Sources, const Node &NodeToReplace,
                          llvm::StringRef ReplacementText) {

Modified: cfe/branches/tooling/lib/Tooling/Refactoring.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/lib/Tooling/Refactoring.cpp?rev=157324&r1=157323&r2=157324&view=diff
==============================================================================
--- cfe/branches/tooling/lib/Tooling/Refactoring.cpp (original)
+++ cfe/branches/tooling/lib/Tooling/Refactoring.cpp Wed May 23 09:58:08 2012
@@ -23,7 +23,7 @@
 namespace clang {
 namespace tooling {
 
-static const char * const InvalidLocation = "invalid-location";
+static const char * const InvalidLocation = "";
 
 Replacement::Replacement()
   : FilePath(InvalidLocation), Offset(0), Length(0) {}
@@ -91,6 +91,21 @@
   this->ReplacementText = ReplacementText;
 }
 
+// FIXME: This should go into the Lexer, but we need to figure out how
+// to handle ranges for refactoring in general first - there is no obvious
+// good way how to integrate this into the Lexer yet.
+static int getRangeSize(SourceManager &Sources, const CharSourceRange &Range) {
+  SourceLocation SpellingBegin = Sources.getSpellingLoc(Range.getBegin());
+  SourceLocation SpellingEnd = Sources.getSpellingLoc(Range.getEnd());
+  std::pair<FileID, unsigned> Start = Sources.getDecomposedLoc(SpellingBegin);
+  std::pair<FileID, unsigned> End = Sources.getDecomposedLoc(SpellingEnd);
+  if (Start.first != End.first) return -1;
+  if (Range.isTokenRange())
+    End.second += Lexer::MeasureTokenLength(SpellingEnd, Sources,
+                                            LangOptions());
+  return End.second - Start.second;
+}
+
 void Replacement::setFromSourceRange(SourceManager &Sources,
                                      const CharSourceRange &Range,
                                      llvm::StringRef ReplacementText) {
@@ -132,19 +147,6 @@
   return true;
 }
 
-int getRangeSize(SourceManager &Sources, const CharSourceRange &Range) {
-  SourceLocation SpellingBegin = Sources.getSpellingLoc(Range.getBegin());
-  SourceLocation SpellingEnd = Sources.getSpellingLoc(Range.getEnd());
-  std::pair<FileID, unsigned> Start = Sources.getDecomposedLoc(SpellingBegin);
-  std::pair<FileID, unsigned> End = Sources.getDecomposedLoc(SpellingEnd);
-  if (Start.first != End.first) return -1;
-  if (Range.isTokenRange())
-    // FIXME: Bring in the correct LangOptions.
-    End.second += Lexer::MeasureTokenLength(SpellingEnd, Sources,
-                                            LangOptions());
-  return End.second - Start.second;
-}
-
 RefactoringTool::RefactoringTool(const CompilationDatabase &Compilations,
                                  ArrayRef<std::string> SourcePaths)
   : Tool(Compilations, SourcePaths) {}

Modified: cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp?rev=157324&r1=157323&r2=157324&view=diff
==============================================================================
--- cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp (original)
+++ cfe/branches/tooling/unittests/Tooling/RefactoringTest.cpp Wed May 23 09:58:08 2012
@@ -143,10 +143,10 @@
 
 TEST_F(ReplacementTest, ReturnsInvalidPath) {
   Replacement Replace1(Context.Sources, SourceLocation(), 0, "");
-  EXPECT_EQ("invalid-location", Replace1.getFilePath());
+  EXPECT_TRUE(Replace1.getFilePath().empty());
 
   Replacement Replace2;
-  EXPECT_EQ("invalid-location", Replace2.getFilePath());
+  EXPECT_TRUE(Replace2.getFilePath().empty());
 }
 
 TEST_F(ReplacementTest, CanApplyReplacements) {
@@ -241,7 +241,7 @@
   Replaces.insert(Replacement(Context.Sources, Context.getLocation(ID, 2, 1),
                               5, "replaced"));
   EXPECT_TRUE(applyAllReplacements(Replaces, Context.Rewrite));
-  EXPECT_TRUE(saveRewrittenFiles(Context.Rewrite));
+  EXPECT_FALSE(Context.Rewrite.overwriteChangedFiles());
   EXPECT_EQ("line1\nreplaced\nline3\nline4",
             getFileContentFromDisk("input.cpp"));
 }





More information about the llvm-branch-commits mailing list