summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/Core/Transform.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-09-04 17:35:07 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-09-04 17:35:07 +0000
commitd9063c46f59f4bec47bcbeddca8ca2f789348c03 (patch)
tree76505542df7a05016dc71ffe44ed3ba264fb54be /clang-tools-extra/cpp11-migrate/Core/Transform.cpp
parent6a23d212897d5402035cfaea82260f6dae1c8f2a (diff)
downloadbcm5719-llvm-d9063c46f59f4bec47bcbeddca8ca2f789348c03.tar.gz
bcm5719-llvm-d9063c46f59f4bec47bcbeddca8ca2f789348c03.zip
Rename cpp11-migrate to clang-modernize.
There is no reason to expect this tool to be limited to C++11, it seems very likely to be of on-going interest. It seems likely to be useful for modernizing even as new libraries come out in TSes and other formats than a complete standard. Fundamentally, we need something a bit more general. After some discussion on the list, going with 'clang-modernize'. I've tried to do a reasonably comprehensive job of fixing up the names, but I may still have missed some. Feel free to poke me if you spot any fallout here. Things I've tried reasonably hard to find and fix: - cpp11-migrate -> clang-modernize - Migrator -> Modernizer - Clean up the introductory documentation that was C++11 specific. I'll also point out that this tool continues to delight me. =] Also, a huge thanks to those who have so carefully, thoroughly documented the tool. The docs here are simply phenomenal. Every tool should be this well documented. I hope I have updated the documentation reasonably well, but I'm not very good at documentation, so review much appreciated. llvm-svn: 189960
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Core/Transform.cpp')
-rw-r--r--clang-tools-extra/cpp11-migrate/Core/Transform.cpp172
1 files changed, 0 insertions, 172 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp b/clang-tools-extra/cpp11-migrate/Core/Transform.cpp
deleted file mode 100644
index cd76723d316..00000000000
--- a/clang-tools-extra/cpp11-migrate/Core/Transform.cpp
+++ /dev/null
@@ -1,172 +0,0 @@
-//===-- Core/Transform.cpp - Transform Base Class Def'n -------------------===//
-//
-// 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 definition for the base Transform class from
-/// which all transforms must subclass.
-///
-//===----------------------------------------------------------------------===//
-
-#include "Core/Transform.h"
-#include "Core/FileOverrides.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/STLExtras.h"
-
-using namespace clang;
-
-llvm::cl::OptionCategory TransformsOptionsCategory("Transforms' options");
-
-namespace {
-
-using namespace tooling;
-using namespace ast_matchers;
-
-/// \brief Custom FrontendActionFactory to produce FrontendActions that simply
-/// forward (Begin|End)SourceFileAction calls to a given Transform.
-class ActionFactory : public clang::tooling::FrontendActionFactory {
-public:
- ActionFactory(MatchFinder &Finder, Transform &Owner)
- : Finder(Finder), Owner(Owner) {}
-
- virtual FrontendAction *create() LLVM_OVERRIDE {
- return new FactoryAdaptor(Finder, Owner);
- }
-
-private:
- class FactoryAdaptor : public ASTFrontendAction {
- public:
- FactoryAdaptor(MatchFinder &Finder, Transform &Owner)
- : Finder(Finder), Owner(Owner) {}
-
- ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
- return Finder.newASTConsumer();
- }
-
- virtual bool BeginSourceFileAction(CompilerInstance &CI,
- StringRef Filename) LLVM_OVERRIDE {
- if (!ASTFrontendAction::BeginSourceFileAction(CI, Filename))
- return false;
-
- return Owner.handleBeginSource(CI, Filename);
- }
-
- virtual void EndSourceFileAction() LLVM_OVERRIDE {
- Owner.handleEndSource();
- return ASTFrontendAction::EndSourceFileAction();
- }
-
- private:
- MatchFinder &Finder;
- Transform &Owner;
- };
-
- MatchFinder &Finder;
- Transform &Owner;
-};
-} // namespace
-
-Transform::Transform(llvm::StringRef Name, const TransformOptions &Options)
- : Name(Name), GlobalOptions(Options), Overrides(0) {
- Reset();
-}
-
-Transform::~Transform() {}
-
-bool Transform::isFileModifiable(const SourceManager &SM,
- const SourceLocation &Loc) const {
- if (SM.isWrittenInMainFile(Loc))
- return true;
-
- if (!GlobalOptions.EnableHeaderModifications)
- return false;
-
- const FileEntry *FE = SM.getFileEntryForID(SM.getFileID(Loc));
- if (!FE)
- return false;
-
- return GlobalOptions.ModifiableHeaders.isFileIncluded(FE->getName());
-}
-
-bool Transform::handleBeginSource(CompilerInstance &CI, StringRef Filename) {
- assert(Overrides != 0 && "Subclass transform didn't provide InputState");
-
- Overrides->applyOverrides(CI.getSourceManager());
- CurrentSource = Filename;
-
- if (Options().EnableTiming) {
- Timings.push_back(std::make_pair(Filename.str(), llvm::TimeRecord()));
- Timings.back().second -= llvm::TimeRecord::getCurrentTime(true);
- }
- return true;
-}
-
-void Transform::handleEndSource() {
- CurrentSource.clear();
- if (Options().EnableTiming)
- Timings.back().second += llvm::TimeRecord::getCurrentTime(false);
-}
-
-void Transform::addTiming(llvm::StringRef Label, llvm::TimeRecord Duration) {
- Timings.push_back(std::make_pair(Label.str(), Duration));
-}
-
-bool
-Transform::addReplacementForCurrentTU(const clang::tooling::Replacement &R) {
- if (CurrentSource.empty())
- return false;
-
- TranslationUnitReplacements &TU = Replacements[CurrentSource];
- if (TU.MainSourceFile.empty())
- TU.MainSourceFile = CurrentSource;
- TU.Replacements.push_back(R);
-
- return true;
-}
-
-FrontendActionFactory *Transform::createActionFactory(MatchFinder &Finder) {
- return new ActionFactory(Finder, /*Owner=*/ *this);
-}
-
-Version Version::getFromString(llvm::StringRef VersionStr) {
- llvm::StringRef MajorStr, MinorStr;
- Version V;
-
- llvm::tie(MajorStr, MinorStr) = VersionStr.split('.');
- if (!MinorStr.empty()) {
- llvm::StringRef Ignore;
- llvm::tie(MinorStr, Ignore) = MinorStr.split('.');
- if (MinorStr.getAsInteger(10, V.Minor))
- return Version();
- }
- if (MajorStr.getAsInteger(10, V.Major))
- return Version();
- return V;
-}
-
-TransformFactory::~TransformFactory() {}
-
-namespace {
-bool versionSupported(Version Required, Version AvailableSince) {
- // null version, means no requirements, means supported
- if (Required.isNull())
- return true;
- return Required >= AvailableSince;
-}
-} // end anonymous namespace
-
-bool TransformFactory::supportsCompilers(CompilerVersions Required) const {
- return versionSupported(Required.Clang, Since.Clang) &&
- versionSupported(Required.Gcc, Since.Gcc) &&
- versionSupported(Required.Icc, Since.Icc) &&
- versionSupported(Required.Msvc, Since.Msvc);
-}
OpenPOWER on IntegriCloud