1 | /**************************************************************************** |
2 | * Copyright (C) 2013-2016 Woboq GmbH |
3 | * Olivier Goffart <contact at woboq.com> |
4 | * https://woboq.com/ |
5 | * |
6 | * This program is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation, either version 3 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #pragma once |
21 | |
22 | #include <clang/Frontend/CompilerInstance.h> |
23 | #include <clang/AST/ASTConsumer.h> |
24 | |
25 | #include "mocng.h" |
26 | |
27 | class MocPPCallbacks; |
28 | |
29 | class MocASTConsumer : public clang::ASTConsumer |
30 | { |
31 | protected: |
32 | clang::CompilerInstance &ci; |
33 | clang::ASTContext *ctx = nullptr; |
34 | MocPPCallbacks *PPCallbacks = nullptr; |
35 | |
36 | std::vector<ClassDef> objects; |
37 | std::vector<NamespaceDef> namespaces; |
38 | MocNg Moc; |
39 | |
40 | public: |
41 | MocASTConsumer(clang::CompilerInstance &ci) :ci(ci) |
42 | { } |
43 | |
44 | void Initialize(clang::ASTContext& Ctx) override; |
45 | void HandleTagDeclDefinition(clang::TagDecl* D) override; |
46 | bool HandleTopLevelDecl(clang::DeclGroupRef D) override; |
47 | |
48 | virtual bool shouldParseDecl(clang::Decl *D) { return true; } |
49 | |
50 | private: |
51 | void HandleNamespaceDefinition(clang::NamespaceDecl *D); |
52 | }; |
53 | |
54 | |