Revert "cp11-migrate: Integration with LibFormat"

This reverts commit r186866.

This breaks the build and the original author Guillaume Papin
<guillaume.papin@epitech.eu> asked me to revert so he could look at it more with
revane.

llvm-svn: 186873
This commit is contained in:
Michael Gottesman 2013-07-22 21:03:56 +00:00
parent 476f38a0c2
commit 29e449f222
14 changed files with 21 additions and 630 deletions

View File

@ -7,12 +7,9 @@ add_clang_library(migrateCore
Transform.cpp
IncludeExcludeInfo.cpp
PerfSupport.cpp
Reformatting.cpp
)
target_link_libraries(migrateCore
clangFormat
clangTooling
clangBasic
clangASTMatchers
clangRewriteFrontend
)

View File

@ -17,6 +17,8 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
#include "clang/Lex/Lexer.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/FileSystem.h"
@ -27,11 +29,10 @@
using namespace clang;
using namespace clang::tooling;
SourceOverrides::SourceOverrides(llvm::StringRef MainFileName,
bool TrackChanges)
: MainFileName(MainFileName), TrackChanges(TrackChanges) {}
SourceOverrides::SourceOverrides(llvm::StringRef MainFileName)
: MainFileName(MainFileName) {}
void SourceOverrides::applyReplacements(Replacements &Replaces) {
void SourceOverrides::applyReplacements(tooling::Replacements &Replaces) {
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts(
new DiagnosticOptions());
DiagnosticsEngine Diagnostics(
@ -56,8 +57,6 @@ void SourceOverrides::applyReplacements(tooling::Replacements &Replaces,
llvm::errs() << "error: failed to apply some replacements.";
applyRewrites(Rewrites);
if (TrackChanges)
adjustChangedRanges(Replaces);
}
void SourceOverrides::applyRewrites(Rewriter &Rewrites) {
@ -97,30 +96,6 @@ void SourceOverrides::applyRewrites(Rewriter &Rewrites) {
}
}
void SourceOverrides::adjustChangedRanges(const Replacements &Replaces) {
// Start by grouping replacements by file name
Replacements MainFileReplaces;
llvm::StringMap<Replacements> HeadersReplaces;
for (Replacements::iterator I = Replaces.begin(), E = Replaces.end(); I != E;
++I) {
llvm::StringRef ReplacementFileName = I->getFilePath();
if (ReplacementFileName == MainFileName)
MainFileReplaces.insert(*I);
else
HeadersReplaces[ReplacementFileName].insert(*I);
}
// Then adjust the changed ranges for each individual file
MainFileChanges.adjustChangedRanges(Replaces);
for (llvm::StringMap<Replacements>::iterator I = HeadersReplaces.begin(),
E = HeadersReplaces.end();
I != E; ++I) {
Headers[I->getKey()].Changes.adjustChangedRanges(I->getValue());
}
}
void SourceOverrides::applyOverrides(SourceManager &SM) const {
FileManager &FM = SM.getFileManager();
@ -179,109 +154,6 @@ SourceOverrides &FileOverrides::getOrCreate(llvm::StringRef Filename) {
SourceOverrides *&Override = Overrides[Filename];
if (Override == NULL)
Override = new SourceOverrides(Filename, TrackChanges);
Override = new SourceOverrides(Filename);
return *Override;
}
namespace {
/// \brief Comparator to be able to order tooling::Range based on their offset.
bool rangeLess(clang::tooling::Range A, clang::tooling::Range B) {
if (A.getOffset() == B.getOffset())
return A.getLength() < B.getLength();
return A.getOffset() < B.getOffset();
}
/// \brief Functor that returns the given range without its overlaps with the
/// replacement given in the constructor.
struct RangeReplacedAdjuster {
RangeReplacedAdjuster(const tooling::Replacement &Replace)
: Replace(Replace.getOffset(), Replace.getLength()),
ReplaceNewSize(Replace.getReplacementText().size()) {}
tooling::Range operator()(clang::tooling::Range Range) const {
if (!Range.overlapsWith(Replace))
return Range;
// range inside replacement -> make the range length null
if (Replace.contains(Range))
return tooling::Range(Range.getOffset(), 0);
// replacement inside range -> resize the range
if (Range.contains(Replace)) {
int Difference = ReplaceNewSize - Replace.getLength();
return tooling::Range(Range.getOffset(), Range.getLength() + Difference);
}
// beginning of the range replaced -> truncate range beginning
if (Range.getOffset() > Replace.getOffset()) {
unsigned ReplaceEnd = Replace.getOffset() + Replace.getLength();
unsigned RangeEnd = Range.getOffset() + Range.getLength();
return tooling::Range(ReplaceEnd, RangeEnd - ReplaceEnd);
}
// end of the range replaced -> truncate range end
if (Range.getOffset() < Replace.getOffset())
return tooling::Range(Range.getOffset(),
Replace.getOffset() - Range.getOffset());
llvm_unreachable("conditions not handled properly");
}
const tooling::Range Replace;
const unsigned ReplaceNewSize;
};
} // end anonymous namespace
void ChangedRanges::adjustChangedRanges(const tooling::Replacements &Replaces) {
// first adjust existing ranges in case they overlap with the replacements
for (Replacements::iterator I = Replaces.begin(), E = Replaces.end(); I != E;
++I) {
const tooling::Replacement &Replace = *I;
std::transform(Ranges.begin(), Ranges.end(), Ranges.begin(),
RangeReplacedAdjuster(Replace));
}
// then shift existing ranges to reflect the new positions
for (RangeVec::iterator I = Ranges.begin(), E = Ranges.end(); I != E; ++I) {
unsigned ShiftedOffset =
tooling::shiftedCodePosition(Replaces, I->getOffset());
*I = tooling::Range(ShiftedOffset, I->getLength());
}
// then generate the new ranges from the replacements
for (Replacements::iterator I = Replaces.begin(), E = Replaces.end(); I != E;
++I) {
const tooling::Replacement &R = *I;
unsigned Offset = tooling::shiftedCodePosition(Replaces, R.getOffset());
unsigned Length = R.getReplacementText().size();
Ranges.push_back(tooling::Range(Offset, Length));
}
// cleanups unecessary ranges to finish
coalesceRanges();
}
void ChangedRanges::coalesceRanges() {
// sort the ranges by offset and then for each group of adjacent/overlapping
// ranges the first one in the group is extended to cover the whole group.
std::sort(Ranges.begin(), Ranges.end(), &rangeLess);
RangeVec::iterator FirstInGroup = Ranges.begin();
assert(!Ranges.empty() && "unexpected empty vector");
for (RangeVec::iterator I = Ranges.begin() + 1, E = Ranges.end(); I != E;
++I) {
unsigned GroupEnd = FirstInGroup->getOffset() + FirstInGroup->getLength();
// no contact
if (I->getOffset() > GroupEnd)
FirstInGroup = I;
else {
unsigned GrpBegin = FirstInGroup->getOffset();
unsigned GrpEnd = std::max(GroupEnd, I->getOffset() + I->getLength());
*FirstInGroup = tooling::Range(GrpBegin, GrpEnd - GrpBegin);
}
}
// remove the ranges that are covered by the first member of the group
Ranges.erase(std::unique(Ranges.begin(), Ranges.end(),
std::mem_fun_ref(&Range::contains)),
Ranges.end());
}

View File

@ -29,34 +29,6 @@ class SourceManager;
class Rewriter;
} // namespace clang
/// \brief Class encapsulating a list of \c tooling::Range with some
/// convenience methods.
///
/// The ranges stored are used to keep track of the overriden parts of a file.
class ChangedRanges {
typedef std::vector<clang::tooling::Range> RangeVec;
public:
typedef RangeVec::const_iterator const_iterator;
/// \brief Create new ranges from the replacements and adjust existing one
/// to remove replaced parts.
///
/// Note that all replacements should come from the same file.
void adjustChangedRanges(const clang::tooling::Replacements &Replaces);
/// \brief Iterators.
/// @{
const_iterator begin() const { return Ranges.begin(); }
const_iterator end() const { return Ranges.end(); }
/// @}
private:
void coalesceRanges();
RangeVec Ranges;
};
/// \brief Container for storing override information for a single headers.
struct HeaderOverride {
HeaderOverride() {}
@ -64,7 +36,6 @@ struct HeaderOverride {
std::string FileName;
std::string FileOverride;
ChangedRanges Changes;
};
/// \brief Container mapping header file names to override information.
@ -75,18 +46,12 @@ typedef llvm::StringMap<HeaderOverride> HeaderOverrides;
/// which changes have been made.
class SourceOverrides {
public:
SourceOverrides(llvm::StringRef MainFileName, bool TrackChanges);
SourceOverrides(llvm::StringRef MainFileName);
/// \brief Accessors.
/// @{
llvm::StringRef getMainFileName() const { return MainFileName; }
llvm::StringRef getMainFileContent() const { return MainFileOverride; }
const ChangedRanges &getChangedRanges() const { return MainFileChanges; }
/// \brief Is file change tracking enabled?
///
/// Tracking file changes can be useful to reformat the code for example.
bool isTrackingFileChanges() const { return TrackChanges; }
/// @}
/// \brief Indicates if the source file has been overridden.
@ -122,14 +87,8 @@ private:
/// file content overrides.
void applyRewrites(clang::Rewriter &Rewrite);
/// \brief Adjust the changed ranges to reflect the parts of the files that
/// have been replaced.
void adjustChangedRanges(const clang::tooling::Replacements &Replaces);
const std::string MainFileName;
std::string MainFileOverride;
const bool TrackChanges;
ChangedRanges MainFileChanges;
HeaderOverrides Headers;
};
@ -139,11 +98,7 @@ public:
typedef llvm::StringMap<SourceOverrides *> SourceOverridesMap;
typedef SourceOverridesMap::const_iterator const_iterator;
/// \brief Construct the SourceOverrides manager.
///
/// \param TrackChanges Wether or not the \c SourceOverrides should keep track
/// of changes. See \c SourceOverrides::isTrackingFileChanges().
FileOverrides(bool TrackChanges) : TrackChanges(TrackChanges) {}
FileOverrides() {}
~FileOverrides();
const_iterator find(llvm::StringRef Filename) const {
@ -165,7 +120,6 @@ private:
FileOverrides &operator=(const FileOverrides &) LLVM_DELETED_FUNCTION;
SourceOverridesMap Overrides;
const bool TrackChanges;
};
/// \brief Generate a unique filename to store the replacements.

View File

@ -1,76 +0,0 @@
//===-- Core/Reformatting.cpp - LibFormat integration ---------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file provides the LibFormat integration used to reformat
/// migrated code.
///
//===----------------------------------------------------------------------===//
#include "Core/Reformatting.h"
#include "Core/FileOverrides.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
using namespace clang;
void Reformatter::reformatChanges(SourceOverrides &Overrides) {
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts(
new DiagnosticOptions());
DiagnosticsEngine Diagnostics(
llvm::IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()),
DiagOpts.getPtr());
FileManager Files((FileSystemOptions()));
SourceManager SM(Diagnostics, Files);
reformatChanges(Overrides, SM);
}
void Reformatter::reformatChanges(SourceOverrides &Overrides,
clang::SourceManager &SM) {
tooling::Replacements Replaces;
Overrides.applyOverrides(SM);
if (Overrides.isSourceOverriden())
Replaces = reformatSingleFile(Overrides.getMainFileName(),
Overrides.getChangedRanges(), SM);
for (HeaderOverrides::const_iterator I = Overrides.headers_begin(),
E = Overrides.headers_end();
I != E; ++I) {
const HeaderOverride &Header = I->getValue();
const tooling::Replacements &HeaderReplaces =
reformatSingleFile(Header.FileName, Header.Changes, SM);
Replaces.insert(HeaderReplaces.begin(), HeaderReplaces.end());
}
Overrides.applyReplacements(Replaces, SM);
}
tooling::Replacements Reformatter::reformatSingleFile(
llvm::StringRef FileName, const ChangedRanges &Changes, SourceManager &SM) {
const clang::FileEntry *Entry = SM.getFileManager().getFile(FileName);
assert(Entry && "expected an existing file");
FileID ID = SM.translateFile(Entry);
if (ID.isInvalid())
ID = SM.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User);
std::vector<CharSourceRange> ReformatRanges;
SourceLocation StartOfFile = SM.getLocForStartOfFile(ID);
for (ChangedRanges::const_iterator I = Changes.begin(), E = Changes.end();
I != E; ++I) {
SourceLocation Start = StartOfFile.getLocWithOffset(I->getOffset());
SourceLocation End = Start.getLocWithOffset(I->getLength());
ReformatRanges.push_back(CharSourceRange::getCharRange(Start, End));
}
Lexer Lex(ID, SM.getBuffer(ID), SM, getFormattingLangOpts(Style.Standard));
return format::reformat(Style, Lex, SM, ReformatRanges);
}

View File

@ -1,59 +0,0 @@
//===-- Core/Reformatting.h - LibFormat integration -------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// \brief This file provides the LibFormat integration used to reformat
/// migrated code.
///
//===----------------------------------------------------------------------===//
#ifndef CPP11_MIGRATE_REFORMATTING_H
#define CPP11_MIGRATE_REFORMATTING_H
#include "clang/Format/Format.h"
class SourceOverrides;
class ChangedRanges;
class Reformatter {
public:
Reformatter(const clang::format::FormatStyle &Style) : Style(Style) {}
/// \brief Reformat the changes made to the file overrides.
///
/// \param Overrides Overriden source files to reformat. Note that since only
/// the changes are reformatted, file change tracking has to be enabled.
/// \param SM A SourceManager where the overridens files can be found.
///
/// \sa \c SourceOverrides::isTrackingFileChanges()
void reformatChanges(SourceOverrides &Overrides, clang::SourceManager &SM);
/// \brief Overload of \c reformatChanges() providing it's own
/// \c SourceManager.
void reformatChanges(SourceOverrides &Overrides);
/// \brief Produce a list of replacements to apply on \p FileName, only the
/// ranges in \p Changes are replaced.
///
/// Since this routine use \c clang::format::reformat() the rules that applies
/// on the ranges are identical:
///
/// <blockquote> 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 formatting.
/// -- \c clang::format::reformat()</blockquote>
clang::tooling::Replacements reformatSingleFile(llvm::StringRef FileName,
const ChangedRanges &Changes,
clang::SourceManager &SM);
private:
clang::format::FormatStyle Style;
};
#endif // CPP11_MIGRATE_REFORMATTING_H

View File

@ -20,7 +20,6 @@
#include "Core/SyntaxCheck.h"
#include "Core/Transform.h"
#include "Core/Transforms.h"
#include "Core/Reformatting.h"
#include "LoopConvert/LoopConvert.h"
#include "UseNullptr/UseNullptr.h"
#include "UseAuto/UseAuto.h"
@ -29,7 +28,6 @@
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
namespace cl = llvm::cl;
@ -45,9 +43,9 @@ static cl::extrahelp MoreHelp(
" cpp11-migrate -use-auto path/to/file.cpp -- -Ipath/to/include/\n"
"\n"
"Convert for loops to the new ranged-based for loops on all files in a "
"subtree\nand reformat the code automatically using the LLVM style:\n\n"
"subtree:\n\n"
" find path/in/subtree -name '*.cpp' -exec \\\n"
" cpp11-migrate -p build/path -format-style=LLVM -loop-convert {} ';'\n"
" cpp11-migrate -p build/path -loop-convert {} ';'\n"
"\n"
"Make use of both nullptr and the override specifier, using git ls-files:\n"
"\n"
@ -72,14 +70,6 @@ static cl::opt<bool> FinalSyntaxCheck(
cl::desc("Check for correct syntax after applying transformations"),
cl::init(false));
static cl::opt<std::string> FormatStyleOpt(
"format-style",
cl::desc("Coding style to use on the replacements, either a builtin style\n"
"or a YAML config file (see: clang-format -dump-config).\n"
"Currently supports 4 builtins style:\n"
" LLVM, Google, Chromium, Mozilla.\n"),
cl::value_desc("string"));
static cl::opt<bool>
SummaryMode("summary", cl::desc("Print transform summary"),
cl::init(false));
@ -118,40 +108,6 @@ static cl::opt<bool, /*ExternalStorage=*/true> EnableHeaderModifications(
cl::location(GlobalOptions.EnableHeaderModifications),
cl::init(false));
/// \brief Creates the Reformatter if the format style option is provided,
/// return a null pointer otherwise.
///
/// \param ProgName The name of the program, \c argv[0], used to print errors.
/// \param Error If the \c -format-style is provided but with wrong parameters
/// this is parameter is set to \c true, left untouched otherwise. An error
/// message is printed with an explanation.
static Reformatter *handleFormatStyle(const char *ProgName, bool &Error) {
if (FormatStyleOpt.getNumOccurrences() > 0) {
format::FormatStyle Style;
if (!format::getPredefinedStyle(FormatStyleOpt, &Style)) {
llvm::StringRef ConfigFilePath = FormatStyleOpt;
llvm::OwningPtr<llvm::MemoryBuffer> Text;
llvm::error_code ec;
ec = llvm::MemoryBuffer::getFile(ConfigFilePath, Text);
if (!ec)
ec = parseConfiguration(Text->getBuffer(), &Style);
if (ec) {
llvm::errs() << ProgName << ": invalid format style " << FormatStyleOpt
<< ": " << ec.message() << "\n";
Error = true;
return 0;
}
}
// force mode to C++11
Style.Standard = clang::format::FormatStyle::LS_Cpp11;
return new Reformatter(Style);
}
return 0;
}
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
Transforms TransformManager;
@ -181,13 +137,6 @@ int main(int argc, const char **argv) {
// against the default value when the command line option is not specified.
GlobalOptions.EnableTiming = (TimingDirectoryName != NoTiming);
// Check the reformatting style option
bool BadStyle = false;
llvm::OwningPtr<Reformatter> ChangesReformatter(
handleFormatStyle(argv[0], BadStyle));
if (BadStyle)
return 1;
// Populate the ModifiableHeaders structure if header modifications are
// enabled.
if (GlobalOptions.EnableHeaderModifications) {
@ -204,10 +153,7 @@ int main(int argc, const char **argv) {
return 1;
}
// if reformatting is enabled we wants to track file changes so that it's
// possible to reformat them.
bool TrackReplacements = static_cast<bool>(ChangesReformatter);
FileOverrides FileStates(TrackReplacements);
FileOverrides FileStates;
SourcePerfData PerfData;
// Apply transforms.
@ -237,15 +183,6 @@ int main(int argc, const char **argv) {
}
}
// Reformat changes if a reformatter is provided.
if (ChangesReformatter)
for (FileOverrides::const_iterator I = FileStates.begin(),
E = FileStates.end();
I != E; ++I) {
SourceOverrides &Overrides = *I->second;
ChangesReformatter->reformatChanges(Overrides);
}
if (FinalSyntaxCheck)
if (!doSyntaxCheck(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList(), FileStates))

View File

@ -34,10 +34,10 @@ SOURCES += $(addprefix ../ReplaceAutoPtr/,$(notdir $(wildcard $(PROJ_SRC_DIR)/..
BUILT_SOURCES += $(ObjDir)/../ReplaceAutoPtr/.objdir
LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc mcparser option
USEDLIBS = migrateCore.a clangFormat.a clangTooling.a clangFrontend.a \
clangSerialization.a clangDriver.a clangRewriteFrontend.a \
clangRewriteCore.a clangParse.a clangSema.a clangAnalysis.a \
clangAST.a clangASTMatchers.a clangEdit.a clangLex.a clangBasic.a
USEDLIBS = migrateCore.a clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \
clangRewriteFrontend.a clangRewriteCore.a clangParse.a \
clangSema.a clangAnalysis.a \
clangAST.a clangASTMatchers.a clangEdit.a clangLex.a clangBasic.a
include $(CLANG_LEVEL)/Makefile

View File

@ -66,43 +66,6 @@ General Command Line Options
earlier transforms are already caught when subsequent transforms parse the
file.
.. option:: -format-style=<string>
After all transformations have been applied, reformat the changes using the
style ``string`` given as argument to the option. The style can be a builtin
style, one of LLVM, Google, Chromium, Mozilla; or a YAML configuration file.
If you want a place to start for using your own custom configuration file,
ClangFormat_ can generate a file with ``clang-format -dump-config``.
Example:
.. code-block:: c++
:emphasize-lines: 10-12,18
// file.cpp
for (std::vector<int>::const_iterator I = my_container.begin(),
E = my_container.end();
I != E; ++I) {
std::cout << *I << std::endl;
}
// No reformatting:
// cpp11-migrate -use-auto file.cpp --
for (auto I = my_container.begin(),
E = my_container.end();
I != E; ++I) {
std::cout << *I << std::endl;
}
// With reformatting enabled:
// cpp11-migrate -format-style=LLVM -use-auto file.cpp --
for (auto I = my_container.begin(), E = my_container.end(); I != E; ++I) {
std::cout << *I << std::endl;
}
.. _ClangFormat: http://clang.llvm.org/docs/ClangFormat.html
.. option:: -summary
Displays a summary of the number of changes each transform made or could have

View File

@ -1,42 +0,0 @@
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: not cpp11-migrate -format-style=FOO -use-auto %t.cpp -- -std=c++11
// RUN: not cpp11-migrate -format-style=/tmp/ -use-auto %t.cpp -- -std=c++11
// RUN: cpp11-migrate -format-style=LLVM -replace-auto_ptr -loop-convert \
// RUN: -use-auto -use-nullptr %t.cpp -- \
// RUN: -std=c++11
// RUN: FileCheck --strict-whitespace -input-file=%t.cpp %s
#include <iostream>
#include <memory>
#include <vector>
void take_auto_ptrs(std::auto_ptr<int>, std::auto_ptr<int>);
void f_1() {
std::auto_ptr<int> aaaaaaaa;
std::auto_ptr<int> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
// CHECK: {{^\ \ std::unique_ptr<int>\ aaaaaaaa;$}}
// CHECK-NEXT: std::unique_ptr<int>
// CHECK-NEXT: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
aaaaaaaa = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
// CHECK: aaaaaaaa =
// CHECK-Next: std::move(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
std::auto_ptr<int> cccccccccccccccccccccccccccc, dddddddddddddddddddddddddddd;
// CHECK: std::unique_ptr<int> cccccccccccccccccccccccccccc,
// CHECK-NEXT: dddddddddddddddddddddddddddd;
take_auto_ptrs(cccccccccccccccccccccccccccc, dddddddddddddddddddddddddddd);
// CHECK: take_auto_ptrs(std::move(cccccccccccccccccccccccccccc),
// CHECK-NEXT: std::move(dddddddddddddddddddddddddddd));
}
// Test loop-convert (and potentially use-auto)
void f_2(const std::vector<int> &Vect) {
for (std::vector<int>::const_iterator I = Vect.begin(), E = Vect.end();
I != E; ++I)
std::cout << *I << std::endl;
// CHECK: for (auto const &elem : Vect)
// CHECK-NEXT: std::cout << elem << std::endl;
}

View File

@ -8,7 +8,6 @@ include_directories(${CPP11_MIGRATE_SOURCE_DIR})
add_extra_unittest(Cpp11MigrateTests
FileOverridesTest.cpp
ReformattingTest.cpp
IncludeExcludeTest.cpp
PerfSupportTest.cpp
TransformTest.cpp
@ -17,9 +16,7 @@ add_extra_unittest(Cpp11MigrateTests
target_link_libraries(Cpp11MigrateTests
migrateCore
clangFormat
clangTooling
clangBasic
clangASTMatchers
clangRewriteFrontend
)

View File

@ -21,11 +21,10 @@ TEST(SourceOverridesTest, Interface) {
FileName,
"std::vector<such_a_long_name_for_a_type>::const_iterator long_type =\n"
" vec.begin();\n");
SourceOverrides Overrides(FileName, /*TrackFileChanges=*/false);
SourceOverrides Overrides(FileName);
EXPECT_EQ(FileName, Overrides.getMainFileName());
EXPECT_FALSE(Overrides.isSourceOverriden());
EXPECT_FALSE(Overrides.isTrackingFileChanges());
Replacements Replaces;
unsigned ReplacementLength =
@ -38,103 +37,3 @@ TEST(SourceOverridesTest, Interface) {
" vec.begin();\n";
EXPECT_EQ(ExpectedContent, Overrides.getMainFileContent());
}
namespace {
Replacement makeReplacement(unsigned Offset, unsigned Length,
unsigned ReplacementLength) {
return Replacement("", Offset, Length, std::string(ReplacementLength, '~'));
}
// generate a set of replacements containing one element
Replacements makeReplacements(unsigned Offset, unsigned Length,
unsigned ReplacementLength) {
Replacements Replaces;
Replaces.insert(makeReplacement(Offset, Length, ReplacementLength));
return Replaces;
}
bool equalRanges(Range A, Range B) {
return A.getOffset() == B.getOffset() && A.getLength() == B.getLength();
}
} // end anonymous namespace
TEST(ChangedRangesTest, adjustChangedRangesShrink) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(0, 0, 4));
EXPECT_NE(Changes.begin(), Changes.end());
EXPECT_TRUE(equalRanges(Range(0, 4), *Changes.begin()));
// create a replacement that cuts the end of the last insertion
Changes.adjustChangedRanges(makeReplacements(2, 4, 0));
Range ExpectedChanges[] = { Range(0, 2) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}
TEST(ChangedRangesTest, adjustChangedRangesExtend) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(1, 0, 4));
// cut the old one by a bigger one
Changes.adjustChangedRanges(makeReplacements(3, 4, 6));
Range ExpectedChanges[] = { Range(1, 8) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}
TEST(ChangedRangesTest, adjustChangedRangesNoOverlap) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(0, 0, 4));
Changes.adjustChangedRanges(makeReplacements(6, 0, 4));
Range ExpectedChanges[] = { Range(0, 4), Range(6, 4) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}
TEST(ChangedRangesTest, adjustChangedRangesNullRange) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(0, 4, 0));
Range ExpectedChanges[] = { Range(0, 0) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}
TEST(ChangedRangesTest, adjustChangedRangesExtendExisting) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(0, 0, 3));
Changes.adjustChangedRanges(makeReplacements(2, 5, 8));
Range ExpectedChanges[] = { Range(0, 10) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}
TEST(ChangedRangesTest, adjustChangedRangesSplit) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(0, 0, 3));
Changes.adjustChangedRanges(makeReplacements(1, 1, 0));
Range ExpectedChanges[] = { Range(0, 2) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}
TEST(ChangedRangesTest, adjustChangedRangesRangeContained) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(3, 0, 2));
Changes.adjustChangedRanges(makeReplacements(1, 4, 5));
Range ExpectedChanges[] = { Range(1, 5) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}
TEST(ChangedRangesTest, adjustChangedRangesRangeResized) {
ChangedRanges Changes;
Changes.adjustChangedRanges(makeReplacements(2, 0, 5));
// first make the range bigger
Changes.adjustChangedRanges(makeReplacements(4, 1, 3));
Range ExpectedChanges[] = { Range(2, 7) };
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
// then smaller
Changes.adjustChangedRanges(makeReplacements(3, 3, 1));
ExpectedChanges[0] = Range(2, 5);
EXPECT_TRUE(
std::equal(Changes.begin(), Changes.end(), ExpectedChanges, equalRanges));
}

View File

@ -12,11 +12,10 @@ include $(CLANG_LEVEL)/../../Makefile.config
TESTNAME = Cpp11MigrateTests
LINK_COMPONENTS := asmparser bitreader support MC MCParser option
USEDLIBS = migrateCore.a clangFormat.a clangTooling.a clangFrontend.a \
clangSerialization.a clangDriver.a clangRewriteFrontend.a \
clangRewriteCore.a clangParse.a clangSema.a clangAnalysis.a \
clangAST.a clangASTMatchers.a clangEdit.a clangLex.a \
clangBasic.a
USEDLIBS = migrateCore.a clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \
clangRewriteFrontend.a clangRewriteCore.a clangParse.a \
clangSema.a clangAnalysis.a \
clangAST.a clangASTMatchers.a clangEdit.a clangLex.a clangBasic.a
include $(CLANG_LEVEL)/Makefile
MAKEFILE_UNITTEST_NO_INCLUDE_COMMON := 1

View File

@ -1,50 +0,0 @@
//===- cpp11-migrate/ReformattingTest.cpp - Reformatting unit tests -------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Core/Reformatting.h"
#include "Core/FileOverrides.h"
#include "gtest/gtest.h"
#include "VirtualFileHelper.h"
using namespace clang;
using namespace clang::tooling;
namespace {
// convenience function to create a ChangedRanges containing one Range
ChangedRanges makeChangedRanges(unsigned Offset, unsigned Length) {
ChangedRanges Changes;
Replacements Replaces;
Replaces.insert(Replacement("", Offset, 0, std::string(Length, '~')));
Changes.adjustChangedRanges(Replaces);
return Changes;
}
} // end anonymous namespace
TEST(Reformatter, SingleReformat) {
VirtualFileHelper VFHelper;
llvm::StringRef FileName = "<test>";
VFHelper.mapFile(FileName, "int a;\n"
"int b;\n");
Reformatter ChangesReformatter(format::getLLVMStyle());
ChangedRanges Changes = makeChangedRanges(0, 6);
tooling::Replacements Replaces = ChangesReformatter.reformatSingleFile(
FileName, Changes, VFHelper.getNewSourceManager());
SourceOverrides Overrides(FileName, /*TrackChanges=*/false);
Overrides.applyReplacements(Replaces, VFHelper.getNewSourceManager());
std::string Expected, Result;
Expected = "int a;\n"
"int b;\n";
Result = Overrides.getMainFileContent();
EXPECT_EQ(Expected, Result);
}

View File

@ -161,7 +161,7 @@ TEST(Transform, Timings) {
// Transform's handle* functions require FileOverrides to be set, even if
// there aren't any.
FileOverrides Overrides(/*TrackFileChanges=*/false);
FileOverrides Overrides;
T.setOverrides(Overrides);
Tool.run(clang::tooling::newFrontendActionFactory(&Factory, &Callbacks));