1 //===- PluginsOrder.cpp ---------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "clang/AST/AST.h"
10 #include "clang/AST/ASTConsumer.h"
11 #include "clang/Frontend/FrontendPluginRegistry.h"
12 using namespace clang
;
16 class AlwaysBeforeConsumer
: public ASTConsumer
{
18 void HandleTranslationUnit(ASTContext
&) override
{
19 llvm::errs() << "always-before\n";
23 class AlwaysBeforeAction
: public PluginASTAction
{
25 std::unique_ptr
<ASTConsumer
> CreateASTConsumer(CompilerInstance
&CI
,
26 llvm::StringRef
) override
{
27 return std::make_unique
<AlwaysBeforeConsumer
>();
30 bool ParseArgs(const CompilerInstance
&CI
,
31 const std::vector
<std::string
> &args
) override
{
35 PluginASTAction::ActionType
getActionType() override
{
36 return AddBeforeMainAction
;
40 class AlwaysAfterConsumer
: public ASTConsumer
{
42 void HandleTranslationUnit(ASTContext
&) override
{
43 llvm::errs() << "always-after\n";
47 class AlwaysAfterAction
: public PluginASTAction
{
49 std::unique_ptr
<ASTConsumer
> CreateASTConsumer(CompilerInstance
&CI
,
50 llvm::StringRef
) override
{
51 return std::make_unique
<AlwaysAfterConsumer
>();
54 bool ParseArgs(const CompilerInstance
&CI
,
55 const std::vector
<std::string
> &args
) override
{
59 PluginASTAction::ActionType
getActionType() override
{
60 return AddAfterMainAction
;
64 class CmdAfterConsumer
: public ASTConsumer
{
66 void HandleTranslationUnit(ASTContext
&) override
{
67 llvm::errs() << "cmd-after\n";
71 class CmdAfterAction
: public PluginASTAction
{
73 std::unique_ptr
<ASTConsumer
> CreateASTConsumer(CompilerInstance
&CI
,
74 llvm::StringRef
) override
{
75 return std::make_unique
<CmdAfterConsumer
>();
78 bool ParseArgs(const CompilerInstance
&CI
,
79 const std::vector
<std::string
> &args
) override
{
83 PluginASTAction::ActionType
getActionType() override
{
84 return CmdlineAfterMainAction
;
88 class CmdBeforeConsumer
: public ASTConsumer
{
90 void HandleTranslationUnit(ASTContext
&) override
{
91 llvm::errs() << "cmd-before\n";
95 class CmdBeforeAction
: public PluginASTAction
{
97 std::unique_ptr
<ASTConsumer
> CreateASTConsumer(CompilerInstance
&CI
,
98 llvm::StringRef
) override
{
99 return std::make_unique
<CmdBeforeConsumer
>();
102 bool ParseArgs(const CompilerInstance
&CI
,
103 const std::vector
<std::string
> &args
) override
{
107 PluginASTAction::ActionType
getActionType() override
{
108 return CmdlineBeforeMainAction
;
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", "");