xaizek / self-inc-first (License: GPLv2+) (since 2018-12-07)
Clang-based standalone tool that checks for first included file being self include.
Commit 05d0449507bfb4e9dcf749d0881c0f27a5da69c9

Style fixes for IncludeFinderAction.cpp
Author: xaizek
Author date (UTC): 2014-04-08 18:51
Committer name: xaizek
Committer date (UTC): 2014-04-08 18:51
Parent(s): e6533f89e5d9369436b573412223c74bb178cb37
Signing key:
Tree: b8bc23465639428715dee14237cc3d56d8293f8a
File Lines added Lines deleted
src/IncludeFinderAction.cpp 78 47
File src/IncludeFinderAction.cpp changed (mode: 100644) (index 4a75e3b..a67d4a3)
30 30 namespace namespace
31 31 { {
32 32
33 class Callbacks : public clang::PPCallbacks
33 class CallbacksProxy : public clang::PPCallbacks
34 34 { {
35 35 public: public:
36 Callbacks(clang::PPCallbacks &master)
37 : master(master)
38 {
39 }
36 inline CallbacksProxy(clang::PPCallbacks &master);
40 37
41 38 public: public:
42 virtual void InclusionDirective(clang::SourceLocation hashLoc,
43 const clang::Token &includeTok,
44 clang::StringRef fileName,
45 bool isAngled,
46 clang::CharSourceRange filenameRange,
47 const clang::FileEntry *file,
48 clang::StringRef searchPath,
49 clang::StringRef relativePath,
50 const clang::Module *imported)
51 {
52 master.InclusionDirective(hashLoc,
53 includeTok,
54 fileName,
55 isAngled,
56 filenameRange,
57 file,
58 searchPath,
59 relativePath,
60 imported);
61 }
39 virtual inline void InclusionDirective(clang::SourceLocation hashLoc,
40 const clang::Token &includeTok,
41 clang::StringRef fileName,
42 bool isAngled,
43 clang::CharSourceRange filenameRange,
44 const clang::FileEntry *file,
45 clang::StringRef searchPath,
46 clang::StringRef relativePath,
47 const clang::Module *imported);
62 48
63 49 private: private:
64 50 clang::PPCallbacks &master; clang::PPCallbacks &master;
65 51 }; };
66 52
53 inline
54 CallbacksProxy::CallbacksProxy(clang::PPCallbacks &master)
55 : master(master)
56 {
57 }
58
59 inline void
60 CallbacksProxy::InclusionDirective(clang::SourceLocation hashLoc,
61 const clang::Token &includeTok,
62 clang::StringRef fileName,
63 bool isAngled,
64 clang::CharSourceRange filenameRange,
65 const clang::FileEntry *file,
66 clang::StringRef searchPath,
67 clang::StringRef relativePath,
68 const clang::Module *imported)
69 {
70 master.InclusionDirective(hashLoc,
71 includeTok,
72 fileName,
73 isAngled,
74 filenameRange,
75 file,
76 searchPath,
77 relativePath,
78 imported);
79 }
80
67 81 class IncludeFinder : private clang::PPCallbacks class IncludeFinder : private clang::PPCallbacks
68 82 { {
69 83 public: public:
70 explicit IncludeFinder(const clang::CompilerInstance &compiler)
71 : compiler(compiler)
72 {
73 }
84 explicit inline IncludeFinder(const clang::CompilerInstance &compiler);
74 85
75 86 public: public:
76 clang::PPCallbacks * createPreprocessorCallbacks()
77 {
78 return new Callbacks(*this);
79 }
87 inline clang::PPCallbacks * createPreprocessorCallbacks();
80 88
81 virtual void InclusionDirective(clang::SourceLocation hashLoc,
82 const clang::Token &includeTok,
83 clang::StringRef fileName,
84 bool isAngled,
85 clang::CharSourceRange filenameRange,
86 const clang::FileEntry *file,
87 clang::StringRef searchPath,
88 clang::StringRef relativePath,
89 const clang::Module *imported)
90 {
91 if (compiler.getSourceManager().isInMainFile(hashLoc)) {
92 std::cout << fileName.str() << std::endl;
93 }
94 }
89 virtual inline void InclusionDirective(clang::SourceLocation hashLoc,
90 const clang::Token &includeTok,
91 clang::StringRef fileName,
92 bool isAngled,
93 clang::CharSourceRange filenameRange,
94 const clang::FileEntry *file,
95 clang::StringRef searchPath,
96 clang::StringRef relativePath,
97 const clang::Module *imported);
95 98
96 99 private: private:
97 100 const clang::CompilerInstance &compiler; const clang::CompilerInstance &compiler;
98 101 }; };
99 102
103 inline
104 IncludeFinder::IncludeFinder(const clang::CompilerInstance &compiler)
105 : compiler(compiler)
106 {
107 }
108
109 inline clang::PPCallbacks *
110 IncludeFinder::createPreprocessorCallbacks()
111 {
112 return new CallbacksProxy(*this);
113 }
114
115 inline void
116 IncludeFinder::InclusionDirective(clang::SourceLocation hashLoc,
117 const clang::Token &includeTok,
118 clang::StringRef fileName,
119 bool isAngled,
120 clang::CharSourceRange filenameRange,
121 const clang::FileEntry *file,
122 clang::StringRef searchPath,
123 clang::StringRef relativePath,
124 const clang::Module *imported)
125 {
126 if (compiler.getSourceManager().isInMainFile(hashLoc)) {
127 std::cout << fileName.str() << std::endl;
128 }
129 }
130
100 131 } }
101 132
102 133 void void
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/self-inc-first

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/self-inc-first

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master