Reflection for RapidJSON
0.0.17
Reflection for serializing/deserializing with RapidJSON
Toggle main menu visibility
Loading...
Searching...
No Matches
codefactory.cpp
Go to the documentation of this file.
1
#include "
./codefactory.h
"
2
#include "
./clangversionabstraction.h
"
3
#include "
./frontendaction.h
"
4
5
#include "resources/config.h"
6
7
#include <clang/Basic/FileManager.h>
8
#include <clang/Frontend/FrontendActions.h>
9
#include <clang/Tooling/Tooling.h>
10
11
#include <memory>
12
13
using namespace
std;
14
15
namespace
ReflectiveRapidJSON
{
16
17
struct
CodeFactory::ToolInvocation
{
18
ToolInvocation
(
CodeFactory
&factory);
19
20
clang::FileManager
fileManager
;
21
clang::tooling::ToolInvocation
invocation
;
22
};
23
24
CodeFactory::ToolInvocation::ToolInvocation
(
CodeFactory
&factory)
25
:
fileManager
({
"."
})
26
, invocation(factory.makeClangArgs(),
maybe_unique
(
new
FrontendAction
(factory)), &fileManager)
27
{
28
fileManager.Retain();
29
}
30
35
CodeFactory::CodeFactory
(std::string_view applicationPath,
const
std::vector<const char *> &sourceFiles,
36
const
std::vector<std::string_view> &clangOptions, std::ostream &os)
37
: m_applicationPath(applicationPath)
38
, m_sourceFiles(sourceFiles)
39
, m_clangOptions(clangOptions)
40
, m_os(os)
41
, m_compilerInstance(nullptr)
42
, m_errorResilient(true)
43
{
44
}
45
46
CodeFactory::~CodeFactory
()
47
{
48
}
49
53
std::vector<string> CodeFactory::makeClangArgs()
const
54
{
55
static
const
initializer_list<std::string_view> flags
56
= { m_applicationPath,
"-x"
,
"c++"
,
"-Wno-pragma-once-outside-header"
,
"-std=c++14"
,
"-fsyntax-only"
,
"-D"
PROJECT_VARNAME_UPPER };
57
vector<string> clangArgs;
58
clangArgs.reserve(flags.size() + m_clangOptions.size() + m_sourceFiles.size());
59
clangArgs.insert(clangArgs.end(), flags.begin(), flags.end());
60
clangArgs.insert(clangArgs.end(), m_clangOptions.cbegin(), m_clangOptions.cend());
61
clangArgs.insert(clangArgs.end(), m_sourceFiles.cbegin(), m_sourceFiles.cend());
62
return
clangArgs;
63
}
64
69
void
CodeFactory::addDeclaration(clang::Decl *decl)
70
{
71
for
(
const
auto
&generator : m_generators) {
72
generator->addDeclaration(decl);
73
}
74
}
75
79
bool
CodeFactory::generate()
const
80
{
81
for
(
const
auto
&generator : m_generators) {
82
generator->generate(m_os);
83
}
84
return
true
;
85
}
86
90
bool
CodeFactory::run
()
91
{
92
// lazy initialize Clang tool invocation
93
if
(!m_toolInvocation) {
94
m_toolInvocation = make_unique<ToolInvocation>(*
this
);
95
}
96
// run Clang
97
return
m_toolInvocation->invocation.run();
98
}
99
100
}
// namespace ReflectiveRapidJSON
clangversionabstraction.h
ReflectiveRapidJSON::CodeFactory::run
bool run()
Reads (relevant) AST elements using Clang and generates code.
Definition
codefactory.cpp:90
ReflectiveRapidJSON::CodeFactory::~CodeFactory
~CodeFactory()
Definition
codefactory.cpp:46
ReflectiveRapidJSON::CodeFactory::CodeFactory
CodeFactory(std::string_view applicationPath, const std::vector< const char * > &sourceFiles, const std::vector< std::string_view > &clangOptions, std::ostream &os)
Constructs a new instance.
Definition
codefactory.cpp:35
ReflectiveRapidJSON::FrontendAction::FrontendAction
FrontendAction(CodeFactory &factory)
Definition
frontendaction.h:27
codefactory.h
frontendaction.h
ReflectiveRapidJSON
Definition
codegenerator.h:15
ReflectiveRapidJSON::maybe_unique
MaybeUnique< T > maybe_unique(T *val)
Definition
clangversionabstraction.h:28
ReflectiveRapidJSON::CodeFactory::ToolInvocation
Definition
codefactory.cpp:17
ReflectiveRapidJSON::CodeFactory::ToolInvocation::fileManager
clang::FileManager fileManager
Definition
codefactory.cpp:20
ReflectiveRapidJSON::CodeFactory::ToolInvocation::invocation
clang::tooling::ToolInvocation invocation
Definition
codefactory.cpp:21
ReflectiveRapidJSON::CodeFactory::ToolInvocation::ToolInvocation
ToolInvocation(CodeFactory &factory)
Definition
codefactory.cpp:24
Generated on
for Reflection for RapidJSON by
1.18.0