summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-06-13 16:00:46 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-06-13 16:00:46 +0000
commite0a7d9cefffeea97c2d922afdd8a373b329135e3 (patch)
tree38c2dbd6eaf429248430775b1aaffe8986cf9ccf /clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp
parentc0bbe36245df1b4feaee6239f344738bea31d244 (diff)
downloadbcm5719-llvm-e0a7d9cefffeea97c2d922afdd8a373b329135e3.tar.gz
bcm5719-llvm-e0a7d9cefffeea97c2d922afdd8a373b329135e3.zip
cpp11-migrate: Replace file override container
A more flexible container for storing overrides is required for headers. Before a source goes through the transform pipeline, any headers it references will be in their original state and unaffected by transforms applied to other sources. Therefore overrides for headers need to be kept separate for each source file. This patch doesn't introduce support for storing header overrides yet. It only replaces the existing structure and makes any necessary changes to support it. llvm-svn: 183910
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp')
-rw-r--r--clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp b/clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp
new file mode 100644
index 00000000000..65877668ee4
--- /dev/null
+++ b/clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp
@@ -0,0 +1,59 @@
+#include "SyntaxCheck.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/Tooling.h"
+
+using namespace clang;
+using namespace tooling;
+
+class SyntaxCheck : public SyntaxOnlyAction {
+public:
+ SyntaxCheck(const FileOverrides &Overrides) : Overrides(Overrides) {}
+
+ virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) {
+ if (!SyntaxOnlyAction::BeginSourceFileAction(CI, Filename))
+ return false;
+
+ FileOverrides::const_iterator I = Overrides.find(Filename);
+ if (I != Overrides.end())
+ I->second.applyOverrides(CI.getSourceManager(), CI.getFileManager());
+
+ return true;
+ }
+
+private:
+ const FileOverrides &Overrides;
+};
+
+class SyntaxCheckFactory : public FrontendActionFactory {
+public:
+ SyntaxCheckFactory(const FileOverrides &Overrides)
+ : Overrides(Overrides) {}
+
+ virtual FrontendAction *create() { return new SyntaxCheck(Overrides); }
+
+private:
+ const FileOverrides &Overrides;
+};
+
+class SyntaxArgumentsAdjuster : public ArgumentsAdjuster {
+ CommandLineArguments Adjust(const CommandLineArguments &Args) {
+ CommandLineArguments AdjustedArgs = Args;
+ AdjustedArgs.push_back("-fsyntax-only");
+ AdjustedArgs.push_back("-std=c++11");
+ return AdjustedArgs;
+ }
+};
+
+bool doSyntaxCheck(const CompilationDatabase &Database,
+ const std::vector<std::string> &SourcePaths,
+ const FileOverrides &Overrides) {
+ ClangTool SyntaxTool(Database, SourcePaths);
+
+ // Ensure C++11 support is enabled.
+ // FIXME: This isn't necessary anymore since the Migrator requires C++11
+ // to be enabled in the CompilationDatabase. Remove later.
+ SyntaxTool.setArgumentsAdjuster(new SyntaxArgumentsAdjuster);
+
+ return SyntaxTool.run(new SyntaxCheckFactory(Overrides)) == 0;
+}
OpenPOWER on IntegriCloud