[clang-tools-extra] [clang-doc] Add Markdown AST node type definitions (PR #205609)
Neil Nair via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 27 11:52:21 PDT 2026
================
@@ -0,0 +1,269 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SUPPORT_MARKDOWN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SUPPORT_MARKDOWN_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/simple_ilist.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/StringSaver.h"
+#include "llvm/Support/raw_ostream.h"
+#include <type_traits>
+
+namespace clang::doc::markdown {
+
+enum class NodeKind {
+ // Inline nodes
+ NK_Text,
+ NK_InlineCode,
+ NK_Emphasis,
+ NK_Strong,
+ // Block nodes
+ NK_Paragraph,
+ NK_Heading,
+ NK_FencedCode,
+ NK_Table,
+ NK_UnorderedList,
+ NK_OrderedList,
+ NK_ListItem,
+ NK_BlockQuote,
+ NK_ThematicBreak,
+ NK_Document,
+};
+
+// Forward declarations
+struct InlineNode;
+struct BlockNode;
+
+//===----------------------------------------------------------------------===//
+// Inline nodes
+//===----------------------------------------------------------------------===//
+
+struct InlineNode
+ : llvm::ilist_node<InlineNode, llvm::ilist_sentinel_tracking<true>> {
+ NodeKind Kind;
+ explicit InlineNode(NodeKind K) : Kind(K) {}
+ void dump(llvm::raw_ostream &OS = llvm::errs()) const;
+};
+
+struct TextNode : InlineNode {
+private:
+ llvm::StringRef Text;
+
+public:
+ explicit TextNode(llvm::StringRef T)
+ : InlineNode(NodeKind::NK_Text), Text(T) {}
+ llvm::StringRef getText() const { return Text; }
+ void dump(llvm::raw_ostream &OS = llvm::errs()) const {
+ OS << "TextNode: " << Text << "\n";
+ }
+ static bool classof(const InlineNode *N) {
+ return N->Kind == NodeKind::NK_Text;
+ }
+};
+static_assert(std::is_trivially_destructible_v<TextNode>);
+
+struct InlineCodeNode : InlineNode {
+private:
+ llvm::StringRef Code;
+
+public:
+ explicit InlineCodeNode(llvm::StringRef C)
+ : InlineNode(NodeKind::NK_InlineCode), Code(C) {}
+ llvm::StringRef getCode() const { return Code; }
+ void dump(llvm::raw_ostream &OS = llvm::errs()) const {
+ OS << "InlineCodeNode: " << Code << "\n";
+ }
+ static bool classof(const InlineNode *N) {
+ return N->Kind == NodeKind::NK_InlineCode;
+ }
+};
+static_assert(std::is_trivially_destructible_v<InlineCodeNode>);
+
+struct EmphasisNode : InlineNode {
+ llvm::simple_ilist<InlineNode, llvm::ilist_sentinel_tracking<true>> Children;
+ EmphasisNode() : InlineNode(NodeKind::NK_Emphasis) {}
+ void dump(llvm::raw_ostream &OS = llvm::errs()) const {
+ OS << "EmphasisNode\n";
+ }
+ static bool classof(const InlineNode *N) {
+ return N->Kind == NodeKind::NK_Emphasis;
+ }
+};
+
+struct StrongNode : InlineNode {
+ llvm::simple_ilist<InlineNode, llvm::ilist_sentinel_tracking<true>> Children;
+ StrongNode() : InlineNode(NodeKind::NK_Strong) {}
+ void dump(llvm::raw_ostream &OS = llvm::errs()) const {
+ OS << "StrongNode\n";
+ }
+ static bool classof(const InlineNode *N) {
+ return N->Kind == NodeKind::NK_Strong;
+ }
+};
+
+//===----------------------------------------------------------------------===//
+// Block nodes
+//===----------------------------------------------------------------------===//
+
+struct BlockNode
+ : llvm::ilist_node<BlockNode, llvm::ilist_sentinel_tracking<true>> {
+ NodeKind Kind;
+ explicit BlockNode(NodeKind K) : Kind(K) {}
+ void dump(llvm::raw_ostream &OS = llvm::errs()) const;
+};
+
+using InlineList =
+ llvm::simple_ilist<InlineNode, llvm::ilist_sentinel_tracking<true>>;
+using BlockList =
+ llvm::simple_ilist<BlockNode, llvm::ilist_sentinel_tracking<true>>;
+
+struct ParagraphNode : BlockNode {
+ InlineList Children;
+ ParagraphNode() : BlockNode(NodeKind::NK_Paragraph) {}
+ void dump(llvm::raw_ostream &OS = llvm::errs()) const {
+ OS << "ParagraphNode\n";
+ }
----------------
Neil-N4 wrote:
Moved implementations to Markdown.cpp using LLVM_DUMP_METHOD and a separate print() that recurses into children
https://github.com/llvm/llvm-project/pull/205609
More information about the cfe-commits
mailing list