forked from mrriddler/Sherlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSherlock.hpp
executable file
·87 lines (70 loc) · 3.12 KB
/
Sherlock.hpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Sherlock.hpp
// Sherlock
//
// Created by Robbie on 2017/1/29.
//
//
#ifndef Sherlock_hpp
#define Sherlock_hpp
#include "clang/AST/AST.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/FrontEnd/FrontEndPluginRegistry.h"
#include "SherlockObservePairing.hpp"
#include "SherlockInitDesign.hpp"
using namespace clang;
using namespace llvm;
using namespace std;
namespace Sherlock
{
class SherlockASTVisitor : public RecursiveASTVisitor<SherlockASTVisitor>
{
public:
void setContext(ASTContext &context);
bool VisitStmt(Stmt *S);
bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID);
bool VisitObjCImplementationDecl(ObjCImplementationDecl *IMPD);
bool VisitObjCCategoryDecl(ObjCCategoryDecl *CD);
bool VisitObjCPropertyDecl(ObjCPropertyDecl *PD);
bool VisitObjCMethodDecl(ObjCMethodDecl *MD);
private:
ASTContext *context;
void checkInterfacePrefix(ObjCInterfaceDecl *ID);
void checkInterfaceIllegalCharacters(ObjCInterfaceDecl *ID);
void checkCopyProperty(ObjCPropertyDecl *PD, string typeStr, ObjCPropertyDecl::PropertyAttributeKind attKin);
void checkMutableProperty(ObjCPropertyDecl *PD, string typeStr, ObjCPropertyDecl::PropertyAttributeKind attKin);
void checkDelegateProperty(ObjCPropertyDecl *PD, string typeStr, ObjCPropertyDecl::PropertyAttributeKind attKin);
void checkAtomicProperty(ObjCPropertyDecl *PD, string typeStr, ObjCPropertyDecl::PropertyAttributeKind attKin);
void checkUnsafeProperty(ObjCPropertyDecl *PD, string typeStr, ObjCPropertyDecl::PropertyAttributeKind attKin);
void checkTimerAndDisplayer(ObjCMessageExpr *ME);
void checkSuperMethod(ObjCMessageExpr *ME);
void checkObservePairing(ObjCImplementationDecl *IMPD);
void checkInitDesign(ObjCMethodDecl *MD);
void checkCategoryMethodNaming(ObjCCategoryDecl *CD);
bool checkIsSourceInBlackList(SourceLocation SL, string name);
bool checkIsInBlackListPath(SourceLocation SL);
bool checkIsNameInBlackList(SourceLocation SL, string name);
bool checkIsInSystemHeader(SourceLocation SL);
bool isBuildInBaseRuleEnable(size_t idx);
bool isForceError();
bool isForceWarning();
DiagnosticsEngine::Level decideReportType(DiagnosticsEngine::Level level);
bool isSubclassOf(const char *name, ObjCInterfaceDecl *ID);
};
class SherlockASTConsumer : public ASTConsumer
{
private:
SherlockASTVisitor visitor;
void HandleTranslationUnit(ASTContext &context);
};
class SherlockASTAction : public PluginASTAction
{
public:
unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,StringRef InFile);
bool ParseArgs(const CompilerInstance &CI, const vector<string>& args);
};
}
static clang::FrontendPluginRegistry::Add<Sherlock::SherlockASTAction> X("SherlockPlugin", "SherlockPlugin");
#endif /* Sherlock_hpp */