Reflection for RapidJSON
0.0.17
Reflection for serializing/deserializing with RapidJSON
Toggle main menu visibility
Loading...
Searching...
No Matches
consumer.cpp
Go to the documentation of this file.
1
#include "
./consumer.h
"
2
#include "
./codefactory.h
"
3
4
#include <clang/AST/ASTContext.h>
5
#include <clang/AST/DeclCXX.h>
6
#include <clang/AST/DeclGroup.h>
7
#include <clang/AST/DeclTemplate.h>
8
#include <clang/Basic/MacroBuilder.h>
9
#include <clang/Sema/Sema.h>
10
11
using namespace
std;
12
13
namespace
ReflectiveRapidJSON
{
14
15
bool
Consumer::shouldParseDecl
(clang::Decl *declaration)
16
{
17
const
clang::SourceManager &sourceManager = m_compilerInstance.getSourceManager();
18
return
sourceManager.getFileID(sourceManager.getExpansionLoc(declaration->getSourceRange().getBegin())) == sourceManager.getMainFileID();
19
}
20
21
bool
Consumer::HandleTopLevelDecl
(clang::DeclGroupRef groupRefDecl)
22
{
23
for
(clang::Decl *decl : groupRefDecl) {
24
if
(clang::NamespaceDecl *namespaceDecl = llvm::dyn_cast<clang::NamespaceDecl>(decl)) {
25
if
(!
shouldParseDecl
(namespaceDecl)) {
26
continue
;
27
}
28
}
29
}
30
return
clang::ASTConsumer::HandleTopLevelDecl(groupRefDecl);
31
}
32
33
void
Consumer::HandleTranslationUnit
(clang::ASTContext &context)
34
{
35
m_visitor.TraverseDecl(context.getTranslationUnitDecl());
36
m_factory.generate();
37
}
38
39
void
DiagConsumer::BeginSourceFile
(
const
clang::LangOptions &langOpts,
const
clang::Preprocessor *pp)
40
{
41
m_proxy->BeginSourceFile(langOpts, pp);
42
}
43
44
void
DiagConsumer::clear
()
45
{
46
m_proxy->clear();
47
}
48
49
void
DiagConsumer::EndSourceFile
()
50
{
51
m_proxy->EndSourceFile();
52
}
53
54
#if CLANG_VERSION_MAJOR <= 22
55
void
DiagConsumer::finish
()
56
{
57
m_proxy->finish();
58
}
59
#endif
60
64
void
DiagConsumer::HandleDiagnostic
(clang::DiagnosticsEngine::Level diagLevel,
const
clang::Diagnostic &info)
65
{
66
bool
shouldReset =
false
;
67
if
(m_errorResilient) {
68
const
auto
diagId = info.getID();
69
const
auto
category = info.getDiags()->getDiagnosticIDs()->getCategoryNumberForDiag(diagId);
70
71
if
(diagLevel >= clang::DiagnosticsEngine::Error) {
72
if
(category == 2
/* 2 means "Semantic Issue" */
) {
73
if
(!m_realErrorCount) {
74
shouldReset =
true
;
75
}
76
diagLevel = clang::DiagnosticsEngine::Warning;
77
}
else
{
78
++m_realErrorCount;
79
}
80
}
81
}
82
83
DiagnosticConsumer::HandleDiagnostic(diagLevel, info);
84
m_proxy->HandleDiagnostic(diagLevel, info);
85
86
if
(shouldReset) {
87
// FIXME: is there another way to ignore errors?
88
const_cast<
clang::DiagnosticsEngine *
>
(info.getDiags())->Reset();
89
}
90
}
91
92
}
// namespace ReflectiveRapidJSON
ReflectiveRapidJSON::Consumer::HandleTranslationUnit
void HandleTranslationUnit(clang::ASTContext &context) override
Definition
consumer.cpp:33
ReflectiveRapidJSON::Consumer::shouldParseDecl
bool shouldParseDecl(clang::Decl *declaration)
Definition
consumer.cpp:15
ReflectiveRapidJSON::Consumer::HandleTopLevelDecl
bool HandleTopLevelDecl(clang::DeclGroupRef groupRefDecl) override
Definition
consumer.cpp:21
ReflectiveRapidJSON::DiagConsumer::EndSourceFile
void EndSourceFile() override
Definition
consumer.cpp:49
ReflectiveRapidJSON::DiagConsumer::clear
void clear() override
Definition
consumer.cpp:44
ReflectiveRapidJSON::DiagConsumer::BeginSourceFile
void BeginSourceFile(const clang::LangOptions &langOpts, const clang::Preprocessor *pp=nullptr) override
Definition
consumer.cpp:39
ReflectiveRapidJSON::DiagConsumer::HandleDiagnostic
void HandleDiagnostic(clang::DiagnosticsEngine::Level diagLevel, const clang::Diagnostic &info) override
Turns most errors into warnings so the code generator can even work when parsing incomplete headers.
Definition
consumer.cpp:64
ReflectiveRapidJSON::DiagConsumer::finish
void finish() override
Definition
consumer.cpp:55
codefactory.h
consumer.h
ReflectiveRapidJSON
Definition
codegenerator.h:15
Generated on
for Reflection for RapidJSON by
1.18.0