|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | +#include "clang/AST/ASTConsumer.h" |
| 5 | +#include "clang/AST/ASTContext.h" |
| 6 | +#include "clang/AST/RecursiveASTVisitor.h" |
| 7 | +#include "clang/Basic/Version.h" |
| 8 | +#include "clang/Frontend/CompilerInstance.h" |
| 9 | +#include "clang/Frontend/FrontendPluginRegistry.h" |
| 10 | +#include "clang/Sema/Sema.h" |
| 11 | + |
| 12 | +#define CLANG_VERSION_FULL (CLANG_VERSION_MAJOR * 100 + CLANG_VERSION_MINOR) |
| 13 | + |
| 14 | +using namespace llvm; |
| 15 | +using namespace clang; |
| 16 | + |
| 17 | +namespace { |
| 18 | +class MozChecker : public ASTConsumer, public RecursiveASTVisitor<MozChecker> { |
| 19 | + DiagnosticsEngine &Diag; |
| 20 | + const CompilerInstance &CI; |
| 21 | +public: |
| 22 | + MozChecker(const CompilerInstance &CI) : Diag(CI.getDiagnostics()), CI(CI) {} |
| 23 | + virtual void HandleTranslationUnit(ASTContext &ctx) { |
| 24 | + TraverseDecl(ctx.getTranslationUnitDecl()); |
| 25 | + } |
| 26 | +}; |
| 27 | + |
| 28 | +class MozCheckAction : public PluginASTAction { |
| 29 | +public: |
| 30 | + ASTConsumer *CreateASTConsumer(CompilerInstance &CI, StringRef fileName) { |
| 31 | + return new MozChecker(CI); |
| 32 | + } |
| 33 | + |
| 34 | + bool ParseArgs(const CompilerInstance &CI, |
| 35 | + const std::vector<std::string> &args) { |
| 36 | + return true; |
| 37 | + } |
| 38 | +}; |
| 39 | +} |
| 40 | + |
| 41 | +static FrontendPluginRegistry::Add<MozCheckAction> |
| 42 | +X("moz-check", "check moz action"); |
0 commit comments