LILAC
Language to language Interop LAyer Compiler
Loading...
Searching...
No Matches
pluginaction.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Yeong-won Seo
3 *
4 * This file is part of LILAC.
5 *
6 * LILAC is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3, or (at your option) any later
9 * version.
10 *
11 * LILAC is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "pch.h"
23
24namespace lilac::cxx
25{
26 frxml::dom& GetDOMRoot();
27
31 class LilacAction final : public clang::ASTFrontendAction
32 {
33 public:
34 std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef) override;
35 };
36
45 class LilacASTConsumer final : public clang::SemaConsumer
46 {
47 clang::Sema* m_Sema = nullptr;
48 frxml::dom& m_Root;
49
50 public:
51 explicit LilacASTConsumer(frxml::dom& dom);
52
53 void InitializeSema(clang::Sema& sema) override;
54
55 void HandleTranslationUnit(clang::ASTContext& context) override;
56 };
57
64 class LilacASTVisitor final : public clang::RecursiveASTVisitor<LilacASTVisitor>
65 {
66 using Level = clang::DiagnosticsEngine::Level;
67
68 clang::Sema& m_Sema;
69 clang::DiagnosticsEngine& m_Diag;
70
71 frxml::dom& m_Root;
72
73 frxml::dom* GetNamespaceDOM(clang::NamedDecl* decl) const;
74
75 bool IsDuplicated(clang::NamedDecl* decl, const std::string& tag);
76
77 public:
78 LilacASTVisitor(clang::Sema& sema, frxml::dom& dom);
79
80 bool TraverseEnumDecl(clang::EnumDecl* decl);
81
82 bool TraverseCXXRecordDecl(clang::CXXRecordDecl* decl);
83
84 bool TraverseFunctionDecl(clang::FunctionDecl* decl);
85
86
94 class EnumVisitor : public RecursiveASTVisitor<EnumVisitor>
95 {
96 std::function<void(clang::EnumConstantDecl*)> m_Delegate;
97
98 public:
99 EnumVisitor(std::function<void(clang::EnumConstantDecl* constant)>);
100
101 bool TraverseEnumConstantDecl(clang::EnumConstantDecl* decl);
102 };
103
110 class CXXRecordVisitor : public RecursiveASTVisitor<CXXRecordVisitor>
111 {
112 std::function<void(clang::CXXMethodDecl*)> m_Delegate;
113
114 public:
115 CXXRecordVisitor(std::function<void(clang::CXXMethodDecl*)> delegate);
116
117 bool TraverseCXXMethodDecl(clang::CXXMethodDecl* decl);
118 };
119 };
120}
An ASTConsumer that creates lilac::cxx::LilacASTVisitor to traverse AST.
void InitializeSema(clang::Sema &sema) override
LilacASTConsumer(frxml::dom &dom)
void HandleTranslationUnit(clang::ASTContext &context) override
A recursive AST visitor that traverses AST of an enumeration.
bool TraverseCXXMethodDecl(clang::CXXMethodDecl *decl)
CXXRecordVisitor(std::function< void(clang::CXXMethodDecl *)> delegate)
A recursive AST visitor that traverses AST of an enumeration.
EnumVisitor(std::function< void(clang::EnumConstantDecl *constant)>)
bool TraverseEnumConstantDecl(clang::EnumConstantDecl *decl)
A recursive AST visitor that serializes C/C++ interface data into DOM object.
bool TraverseCXXRecordDecl(clang::CXXRecordDecl *decl)
bool TraverseEnumDecl(clang::EnumDecl *decl)
LilacASTVisitor(clang::Sema &sema, frxml::dom &dom)
bool TraverseFunctionDecl(clang::FunctionDecl *decl)
A frontend action that creates lilac::cxx::LilacASTConsumer to traverse AST.
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &, llvm::StringRef) override
frxml::dom & GetDOMRoot()