Reflection for RapidJSON 0.0.17
Reflection for serializing/deserializing with RapidJSON
Loading...
Searching...
No Matches
consumer.h
Go to the documentation of this file.
1#ifndef REFLECTIVE_RAPIDJSON_CONSUMER_H
2#define REFLECTIVE_RAPIDJSON_CONSUMER_H
3
4#include "./visitor.h"
5
6#include <clang/AST/ASTConsumer.h>
7#include <clang/AST/Decl.h>
8#include <clang/Basic/DiagnosticIDs.h>
9#include <clang/Basic/Version.h>
10#include <clang/Frontend/CompilerInstance.h>
11#include <clang/Lex/LexDiagnostic.h>
12
13namespace ReflectiveRapidJSON {
14
15class CodeFactory;
16
24class Consumer : public clang::ASTConsumer {
25public:
26 Consumer(CodeFactory &factory, clang::CompilerInstance &compilerInstance);
27
28 bool HandleTopLevelDecl(clang::DeclGroupRef groupRefDecl) override;
29 void HandleTranslationUnit(clang::ASTContext &context) override;
30
31 bool shouldParseDecl(clang::Decl *declaration);
32
33private:
34 void handleNamespaceDefinition(clang::NamespaceDecl *nsDecl);
35
36 CodeFactory &m_factory;
37 clang::CompilerInstance &m_compilerInstance;
38 Visitor m_visitor;
39};
40
41inline Consumer::Consumer(CodeFactory &factory, clang::CompilerInstance &compilerInstance)
42 : m_factory(factory)
43 , m_compilerInstance(compilerInstance)
44 , m_visitor(factory)
45{
46}
47
52class DiagConsumer : public clang::DiagnosticConsumer {
53public:
54 DiagConsumer(std::unique_ptr<DiagnosticConsumer> previous, bool errorResilient);
55 unsigned int realErrorCount() const;
56
57 void BeginSourceFile(const clang::LangOptions &langOpts, const clang::Preprocessor *pp = nullptr) override;
58 void clear() override;
59 void EndSourceFile() override;
60#if CLANG_VERSION_MAJOR <= 22
61 void finish() override;
62#endif
63 void HandleDiagnostic(clang::DiagnosticsEngine::Level diagLevel, const clang::Diagnostic &info) override;
64
65private:
66 std::unique_ptr<DiagnosticConsumer> m_proxy;
67 unsigned int m_realErrorCount;
68 bool m_errorResilient;
69};
70
71inline DiagConsumer::DiagConsumer(std::unique_ptr<clang::DiagnosticConsumer> previous, bool errorResilient)
72 : m_proxy(std::move(previous))
73 , m_realErrorCount(0)
74 , m_errorResilient(errorResilient)
75{
76}
77
81inline unsigned int DiagConsumer::realErrorCount() const
82{
83 return m_realErrorCount;
84}
85
86} // namespace ReflectiveRapidJSON
87
88#endif // REFLECTIVE_RAPIDJSON_CONSUMER_H
The CodeFactory class produces additional (reflection) code for a specified list of C++ source files.
Definition codefactory.h:27
void HandleTranslationUnit(clang::ASTContext &context) override
Definition consumer.cpp:33
bool shouldParseDecl(clang::Decl *declaration)
Definition consumer.cpp:15
Consumer(CodeFactory &factory, clang::CompilerInstance &compilerInstance)
Definition consumer.h:41
bool HandleTopLevelDecl(clang::DeclGroupRef groupRefDecl) override
Definition consumer.cpp:21
unsigned int realErrorCount() const
Returns the number of errors which actually would have been occurred if we would not turn most errors...
Definition consumer.h:81
void BeginSourceFile(const clang::LangOptions &langOpts, const clang::Preprocessor *pp=nullptr) override
Definition consumer.cpp:39
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
DiagConsumer(std::unique_ptr< DiagnosticConsumer > previous, bool errorResilient)
Definition consumer.h:71
The Visitor class is used to traverse the elements of a translation unit.
Definition visitor.h:15