clang-tools 23.0.0git
Markdown.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Markdown.h"
10
12
13// TODO: print() currently outputs nodes flat with no indentation. Add
14// S-expression style formatting (as used by the Swift AST printer) to make
15// dumped trees easier to read.
16
17#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
18LLVM_DUMP_METHOD void InlineNode::dump() const { print(llvm::errs()); }
19#endif
20
21void TextNode::print(llvm::raw_ostream &OS) const {
22 OS << "TextNode: " << getText() << "\n";
23}
24
25void InlineCodeNode::print(llvm::raw_ostream &OS) const {
26 OS << "InlineCodeNode: " << getCode() << "\n";
27}
28
29void EmphasisNode::print(llvm::raw_ostream &OS) const {
30 OS << "EmphasisNode\n";
31 for (const auto &Child : children())
32 Child.print(OS);
33}
34
35void StrongNode::print(llvm::raw_ostream &OS) const {
36 OS << "StrongNode\n";
37 for (const auto &Child : children())
38 Child.print(OS);
39}
40
41#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
42LLVM_DUMP_METHOD void BlockNode::dump() const { print(llvm::errs()); }
43#endif
44
45void ParagraphNode::print(llvm::raw_ostream &OS) const {
46 OS << "ParagraphNode\n";
47 for (const auto &Child : children())
48 Child.print(OS);
49}
50
51void HeadingNode::print(llvm::raw_ostream &OS) const {
52 OS << "HeadingNode: level=" << getLevel() << "\n";
53 for (const auto &Child : children())
54 Child.print(OS);
55}
56
57void FencedCodeNode::print(llvm::raw_ostream &OS) const {
58 OS << "FencedCodeNode: lang=" << getLang() << "\n" << getCode() << "\n";
59}
60
61void ListItemNode::print(llvm::raw_ostream &OS) const {
62 OS << "ListItemNode\n";
63 for (const auto &Child : children())
64 Child.print(OS);
65}
66
67#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
68LLVM_DUMP_METHOD void ListItemNode::dump() const { print(llvm::errs()); }
69#endif
70
71void UnorderedListNode::print(llvm::raw_ostream &OS) const {
72 OS << "UnorderedListNode\n";
73 for (const auto &Item : items())
74 Item.print(OS);
75}
76
77void OrderedListNode::print(llvm::raw_ostream &OS) const {
78 OS << "OrderedListNode: start=" << getStart() << "\n";
79 for (const auto &Item : items())
80 Item.print(OS);
81}
82
83void BlockQuoteNode::print(llvm::raw_ostream &OS) const {
84 OS << "BlockQuoteNode\n";
85 for (const auto &Child : children())
86 Child.print(OS);
87}
88
89void ThematicBreakNode::print(llvm::raw_ostream &OS) const {
90 OS << "ThematicBreakNode\n";
91}
92
93void DocumentNode::print(llvm::raw_ostream &OS) const {
94 OS << "DocumentNode\n";
95 for (const auto &Child : children())
96 Child.print(OS);
97}
98
99} // namespace clang::doc::markdown
Defines the Markdown AST node hierarchy for the clang-doc Markdown parser.
LLVM_DUMP_METHOD void dump() const
Prints to llvm::errs(). Only available in assert builds.
Definition Markdown.cpp:42
virtual void print(llvm::raw_ostream &OS) const =0
Recursively prints the node and its children to OS.
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:83
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:93
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:29
llvm::StringRef getCode() const
Definition Markdown.h:198
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:57
llvm::StringRef getLang() const
Definition Markdown.h:197
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:51
llvm::StringRef getCode() const
Definition Markdown.h:89
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:25
LLVM_DUMP_METHOD void dump() const
Prints to llvm::errs(). Only available in assert builds.
Definition Markdown.cpp:18
virtual void print(llvm::raw_ostream &OS) const =0
Recursively prints the node and its children to OS.
void print(llvm::raw_ostream &OS) const
Definition Markdown.cpp:61
LLVM_DUMP_METHOD void dump() const
Prints to llvm::errs().
Definition Markdown.cpp:68
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:77
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:45
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:35
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:21
llvm::StringRef getText() const
Definition Markdown.h:74
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:89
void print(llvm::raw_ostream &OS) const override
Recursively prints the node and its children to OS.
Definition Markdown.cpp:71