Files
clang-p2996/clang-tools-extra/cpp11-migrate/Core/SyntaxCheck.cpp
Edwin Vane 62c013db6c cpp11-migrate: Transform now responsible for applying replacements
To make it possible for replacements made to headers as part of transforming
one translation unit to not be visible to the transform of other translation
units, Transform now handles replacement application as part of its
end-of-source handling. Several things were simplified as a result:

- The duplicated code in every transform for applying replacements is now gone
  and replaced with one location in Transform.
- RefactoringTool is no longer used since Transform houses the Replacements
  structure.
- RewriterContainer is now a private implementation detail of Transform (also
  renamed to RewriterManager since its behaviour is slightly different now with
  respect to lifetime of objects).
- There's now no distinction between input and output file state.

Misc notes:

- Interface changes reflected in unit tests.
- Replacements for files other than the main file are assumed to be for headers
  and stored as such.

llvm-svn: 184194
2013-06-18 15:31:01 +00:00

60 lines
1.8 KiB
C++

#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());
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;
}