forked from jmah/Clang-KeyPathValidator
/
ValidateKeyPathsAction.cpp
57 lines (43 loc) · 1.45 KB
/
ValidateKeyPathsAction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// ValidateKeyPathsAction.cpp
// Created by Jonathon Mah on 2014-01-24.
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "KeyPathValidationConsumer.h"
#include "ValueForKeyVisitor.h"
#include "KeyPathsAffectingVisitor.h"
#include "FitbitFBBinderVisitor.h"
using namespace clang;
void KeyPathValidationConsumer::HandleTranslationUnit(ASTContext &Context) {
cacheNSTypes();
ValueForKeyVisitor(this, Compiler).TraverseDecl(Context.getTranslationUnitDecl());
KeyPathsAffectingVisitor(this, Compiler).TraverseDecl(Context.getTranslationUnitDecl());
FBBinderVisitor(this, Compiler).TraverseDecl(Context.getTranslationUnitDecl());
}
namespace {
class NullConsumer : public ASTConsumer {
public:
NullConsumer()
: ASTConsumer()
{ }
};
class ValidateKeyPathsAction : public PluginASTAction {
protected:
ASTConsumer *CreateASTConsumer(CompilerInstance &compiler, llvm::StringRef) {
LangOptions const opts = compiler.getLangOpts();
if (opts.ObjC1 || opts.ObjC2)
return new KeyPathValidationConsumer(compiler);
else
return new NullConsumer();
}
bool ParseArgs(const CompilerInstance &compiler,
const std::vector<std::string>& args) {
return true;
}
};
}
static FrontendPluginRegistry::Add<ValidateKeyPathsAction>
X("validate-key-paths", "warn if static key paths seem invalid");