summary refs log tree commit diff
path: root/goatc.hh
diff options
context:
space:
mode:
Diffstat (limited to 'goatc.hh')
-rw-r--r--goatc.hh55
1 files changed, 55 insertions, 0 deletions
diff --git a/goatc.hh b/goatc.hh
new file mode 100644
index 0000000..76e1525
--- /dev/null
+++ b/goatc.hh
@@ -0,0 +1,55 @@
+// Clang plugin declaration
+// Copyright (C) 2024  Nguyễn Gia Phong
+//
+// This file is part of GoatC.
+//
+// GoatC is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// GoatC is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with GoatC.  If not, see <https://www.gnu.org/licenses/>.
+
+#include <clang/AST/RecursiveASTVisitor.h>
+#include <clang/Frontend/FrontendPluginRegistry.h>
+
+class GoatCVisitor : public clang::RecursiveASTVisitor<GoatCVisitor> {
+  clang::ASTContext* ctx;
+
+public:
+  GoatCVisitor(clang::ASTContext* ctx) : ctx {ctx}
+  { }
+};
+
+class GoatCConsumer : public clang::ASTConsumer {
+  clang::CompilerInstance& ci;
+  /// Consuming source file that is not patched
+  bool noop;
+
+  bool HandleTopLevelDecl (clang::DeclGroupRef) override;
+
+public:
+  GoatCConsumer (clang::CompilerInstance& ci, bool noop) : ci {ci}, noop {noop}
+  { }
+};
+
+class GoatCAction : public clang::PluginASTAction {
+  std::string source_file;
+
+  std::unique_ptr <clang::ASTConsumer> CreateASTConsumer
+    (clang::CompilerInstance&, llvm::StringRef) override;
+
+  bool ParseArgs (const clang::CompilerInstance&,
+                  const std::vector <std::string>&) override;
+
+  clang::PluginASTAction::ActionType getActionType () override;
+};
+
+static clang::FrontendPluginRegistry::Add <GoatCAction>
+X {"goatc", "chimera breeder"};