Debian Codegraph @

llvm-project/clang/examples/PluginsOrder/PluginsOrder.cpp

raw
1 //===- PluginsOrder.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "clang/AST/AST.h"
10 #include "clang/AST/ASTConsumer.h"
11 #include "clang/Frontend/FrontendPluginRegistry.h"
12 using namespace clang;
13
14 namespace {
15
16 class AlwaysBeforeConsumer : public ASTConsumer {
17 public:
18 void HandleTranslationUnit(ASTContext &) override {
19 llvm::errs() << "always-before\n";
20 }
21 };
22
23 class AlwaysBeforeAction : public PluginASTAction {
24 public:
25 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
26 llvm::StringRef) override {
27 return std::make_unique<AlwaysBeforeConsumer>();
28 }
29
30 bool ParseArgs(const CompilerInstance &CI,
31 const std::vector<std::string> &args) override {
32 return true;
33 }
34
35 PluginASTAction::ActionType getActionType() override {
36 return AddBeforeMainAction;
37 }
38 };
39
40 class AlwaysAfterConsumer : public ASTConsumer {
41 public:
42 void HandleTranslationUnit(ASTContext &) override {
43 llvm::errs() << "always-after\n";
44 }
45 };
46
47 class AlwaysAfterAction : public PluginASTAction {
48 public:
49 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
50 llvm::StringRef) override {
51 return std::make_unique<AlwaysAfterConsumer>();
52 }
53
54 bool ParseArgs(const CompilerInstance &CI,
55 const std::vector<std::string> &args) override {
56 return true;
57 }
58
59 PluginASTAction::ActionType getActionType() override {
60 return AddAfterMainAction;
61 }
62 };
63
64 class CmdAfterConsumer : public ASTConsumer {
65 public:
66 void HandleTranslationUnit(ASTContext &) override {
67 llvm::errs() << "cmd-after\n";
68 }
69 };
70
71 class CmdAfterAction : public PluginASTAction {
72 public:
73 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
74 llvm::StringRef) override {
75 return std::make_unique<CmdAfterConsumer>();
76 }
77
78 bool ParseArgs(const CompilerInstance &CI,
79 const std::vector<std::string> &args) override {
80 return true;
81 }
82
83 PluginASTAction::ActionType getActionType() override {
84 return CmdlineAfterMainAction;
85 }
86 };
87
88 class CmdBeforeConsumer : public ASTConsumer {
89 public:
90 void HandleTranslationUnit(ASTContext &) override {
91 llvm::errs() << "cmd-before\n";
92 }
93 };
94
95 class CmdBeforeAction : public PluginASTAction {
96 public:
97 std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
98 llvm::StringRef) override {
99 return std::make_unique<CmdBeforeConsumer>();
100 }
101
102 bool ParseArgs(const CompilerInstance &CI,
103 const std::vector<std::string> &args) override {
104 return true;
105 }
106
107 PluginASTAction::ActionType getActionType() override {
108 return CmdlineBeforeMainAction;
109 }
110 };
111
112 } // namespace
113
114 static FrontendPluginRegistry::Add<CmdBeforeAction> X1("cmd-before", "");
115 static FrontendPluginRegistry::Add<CmdAfterAction> X2("cmd-after", "");
116 static FrontendPluginRegistry::Add<AlwaysBeforeAction> X3("always-before", "");
117 static FrontendPluginRegistry::Add<AlwaysAfterAction> X4("always-after", "");