brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · e25ab7a Raw
118 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "clang/AST/AST.h"10#include "clang/AST/ASTConsumer.h"11#include "clang/Frontend/FrontendPluginRegistry.h"12using namespace clang;13 14namespace {15 16class AlwaysBeforeConsumer : public ASTConsumer {17public:18  void HandleTranslationUnit(ASTContext &) override {19    llvm::errs() << "always-before\n";20  }21};22 23class AlwaysBeforeAction : public PluginASTAction {24public: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 40class AlwaysAfterConsumer : public ASTConsumer {41public:42  void HandleTranslationUnit(ASTContext &) override {43    llvm::errs() << "always-after\n";44  }45};46 47class AlwaysAfterAction : public PluginASTAction {48public: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 64class CmdAfterConsumer : public ASTConsumer {65public:66  void HandleTranslationUnit(ASTContext &) override {67    llvm::errs() << "cmd-after\n";68  }69};70 71class CmdAfterAction : public PluginASTAction {72public: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 88class CmdBeforeConsumer : public ASTConsumer {89public:90  void HandleTranslationUnit(ASTContext &) override {91    llvm::errs() << "cmd-before\n";92  }93};94 95class CmdBeforeAction : public PluginASTAction {96public: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} // namespace113 114static FrontendPluginRegistry::Add<CmdBeforeAction> X1("cmd-before", "");115static FrontendPluginRegistry::Add<CmdAfterAction> X2("cmd-after", "");116static FrontendPluginRegistry::Add<AlwaysBeforeAction> X3("always-before", "");117static FrontendPluginRegistry::Add<AlwaysAfterAction> X4("always-after", "");118