-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathActionFactories.cpp
89 lines (68 loc) · 2.65 KB
/
ActionFactories.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "ActionFactories.h"
#include "Generators/GeneratorsFactory.h"
#include "Rules/Rule.h"
#include "Rules/RulesFactory.h"
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Lex/Preprocessor.h>
using namespace llvm;
using namespace clang;
using namespace clang::ast_matchers;
ColobotLintASTFrontendActionFactory::ColobotLintASTFrontendActionFactory(Context& context)
: m_context(context)
{}
FrontendAction* ColobotLintASTFrontendActionFactory::create()
{
return new ColobotLintASTFrontendAction(m_context);
}
///////////////////////////
ColobotLintASTFrontendAction::ColobotLintASTFrontendAction(Context& context)
: m_context(context),
m_beginSourceFileHandler(context),
m_exclusionZoneCommentHandler(context)
{}
bool ColobotLintASTFrontendAction::BeginSourceFileAction(CompilerInstance& ci, StringRef filename)
{
m_exclusionZoneCommentHandler.AtBeginOfMainFile();
return m_beginSourceFileHandler.BeginSourceFileAction(ci, filename);
}
std::unique_ptr<ASTConsumer> ColobotLintASTFrontendAction::CreateASTConsumer(CompilerInstance& compiler,
StringRef /*file*/)
{
std::vector<std::unique_ptr<ASTConsumer>> consumers;
auto finder = make_unique<MatchFinder>();
std::vector<std::unique_ptr<Rule>> rules;
std::unique_ptr<Generator> generator = CreateGenerator(m_context);
if (generator != nullptr)
{
generator->RegisterASTMatcherCallback(*finder.get());
}
else
{
m_exclusionZoneCommentHandler.RegisterPreProcessorCallbacks(compiler);
rules = CreateRules(m_context);
for (auto& rule : rules)
{
rule->RegisterASTMatcherCallback(*finder.get());
rule->RegisterPreProcessorCallbacks(compiler);
}
}
consumers.push_back(finder->newASTConsumer());
return make_unique<ColobotLintASTConsumer>(std::move(consumers),
std::move(finder),
std::move(rules),
std::move(generator));
}
///////////////////////////
ColobotLintASTConsumer::ColobotLintASTConsumer(
std::vector<std::unique_ptr<ASTConsumer>>&& consumers,
std::unique_ptr<MatchFinder>&& finder,
std::vector<std::unique_ptr<Rule>>&& rules,
std::unique_ptr<Generator>&& generator)
: MultiplexConsumer(std::move(consumers)),
m_finder(std::move(finder)),
m_rules(std::move(rules)),
m_generator(std::move(generator))
{}
ColobotLintASTConsumer::~ColobotLintASTConsumer()
{}