summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-02-28 16:29:24 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-02-28 16:29:24 +0000
commit266b625ca90de49dac72022232deac1a59f09ccd (patch)
treec1d3ec4cf38c7f06d5205ee702e0f5c4d85e09a6 /clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp
parent3305b177e6b62e54efb3fa92b5cafbc0c58df981 (diff)
downloadbcm5719-llvm-266b625ca90de49dac72022232deac1a59f09ccd.tar.gz
bcm5719-llvm-266b625ca90de49dac72022232deac1a59f09ccd.zip
Introducing Use-Auto transform for cpp11-migrate
The new Use-Auto transform replaces the type specifier for variable declarations with the special C++11 'auto' type specifier. For now, the replacement is done only for variables that are iterators of any of the std containers and only if the type used is one of those explicitly allowed by the standard (i.e. not an implementation-specific type). Reviewers: gribozavr, silvas, klimek llvm-svn: 176266
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp')
-rw-r--r--clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp b/clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp
new file mode 100644
index 00000000000..00723cab218
--- /dev/null
+++ b/clang-tools-extra/cpp11-migrate/UseAuto/UseAuto.cpp
@@ -0,0 +1,58 @@
+//===-- UseAuto/UseAuto.cpp - Use auto type specifier ---------------------===//
+//
+// 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 implementation of the UseAutoTransform class.
+///
+//===----------------------------------------------------------------------===//
+
+#include "UseAuto.h"
+#include "UseAutoActions.h"
+#include "UseAutoMatchers.h"
+
+using clang::ast_matchers::MatchFinder;
+using namespace clang;
+using namespace clang::tooling;
+
+int UseAutoTransform::apply(const FileContentsByPath &InputStates,
+ RiskLevel MaxRisk,
+ const clang::tooling::CompilationDatabase &Database,
+ const std::vector<std::string> &SourcePaths,
+ FileContentsByPath &ResultStates) {
+ RefactoringTool UseAutoTool(Database, SourcePaths);
+
+ for (FileContentsByPath::const_iterator I = InputStates.begin(),
+ E = InputStates.end();
+ I != E; ++I)
+ UseAutoTool.mapVirtualFile(I->first, I->second);
+
+ unsigned AcceptedChanges = 0;
+
+ MatchFinder Finder;
+ UseAutoFixer Fixer(UseAutoTool.getReplacements(), AcceptedChanges, MaxRisk);
+
+ Finder.addMatcher(makeIteratorMatcher(), &Fixer);
+
+ if (int Result = UseAutoTool.run(newFrontendActionFactory(&Finder))) {
+ llvm::errs() << "Error encountered during translation.\n";
+ return Result;
+ }
+
+ RewriterContainer Rewrite(UseAutoTool.getFiles(), InputStates);
+
+ // FIXME: Do something if some replacements didn't get applied?
+ UseAutoTool.applyAllReplacements(Rewrite.getRewriter());
+
+ collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
+
+ if (AcceptedChanges > 0)
+ setChangesMade();
+
+ return 0;
+}
OpenPOWER on IntegriCloud