Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
builder.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4
#
include
"builder.h"
5
6
#
include
"../atom.h"
7
#
include
"../pagenode.h"
8
#
include
"../text.h"
9
10
QT_BEGIN_NAMESPACE
11
12
using
namespace
Qt::Literals;
13
14
namespace
IR
{
15
16
/*!
17
\class IR::Builder
18
\internal
19
\brief Builds IR (Intermediate Representation) from QDoc's Node tree.
20
21
Builder is the "compiler" in QDoc's compile/link/render pipeline. It
22
transforms Node objects into format-agnostic IR structures that can be:
23
24
\list
25
\li Rendered to output formats (HTML, Markdown, DocBook) by generators.
26
\li Written to .index files for cross-module linking.
27
\li Consumed by other IR processors.
28
\endlist
29
30
\section1 Separation of Concerns
31
32
Builder handles all interaction with Node classes and Atom chains.
33
Generators receive pre-built IR and focus purely on formatting output.
34
This separation enables:
35
36
\list
37
\li Testing IR building independently from rendering.
38
\li Multiple output formats from the same IR.
39
\li Clear architectural boundaries.
40
\endlist
41
42
\section1 Link Resolution
43
44
During IR building, \b{local links} (within the same module) are resolved
45
immediately. \b{Cross-module links} are marked as external with an empty
46
href, to be resolved during the link phase when dependency .index files
47
are available.
48
49
\sa IR::Document, TemplateGenerator
50
*/
51
52
53
/*!
54
\internal
55
Build IR for a PageNode.
56
57
This method extracts documentation content from the node's atom chain.
58
The brief is stored separately via Doc::briefText(), while body content
59
is extracted by walking the atom chain and collecting text atoms that
60
are not within the brief section.
61
62
\note Currently handles basic text atoms (String, AutoLink, C) and
63
paragraph breaks. More complex atom types (lists, code blocks, images)
64
will be added as the IR layer matures.
65
*/
66
Document
Builder
::
buildPageIR
(
const
PageNode
*pn)
const
67
{
68
Document
ir;
69
70
// Classification
71
ir
.
nodeType
= pn
->
nodeType
();
72
ir
.
genus
= pn
->
genus
();
73
ir
.
status
= pn
->
status
();
74
ir
.
access
= pn
->
access
();
75
76
// Identity
77
ir.title = pn->title();
78
ir.fullTitle = pn->fullTitle();
79
ir.url = pn->url();
80
ir.since = pn->since();
81
ir.deprecatedSince = pn->deprecatedSince();
82
ir.brief = pn
->
doc
().briefText().toString();
83
84
QString bodyText;
85
const
Text
&body = pn
->
doc
().body();
86
const
Atom
*atom = body
.
firstAtom
(
)
;
87
bool
inBrief =
false
;
88
89
while
(atom) {
90
switch
(atom
->
type
(
)
) {
91
case
Atom
::
BriefLeft
:
92
inBrief =
true
;
93
break
;
94
case
Atom
::
BriefRight
:
95
inBrief =
false
;
96
break
;
97
case
Atom::ParaLeft:
98
if
(!inBrief && !bodyText.isEmpty())
99
bodyText +=
"\n\n"_L1
;
100
break
;
101
case
Atom
::
String
:
102
case
Atom
::
AutoLink
:
103
case
Atom
::
C
:
104
if
(!inBrief)
105
bodyText += atom->string();
106
break
;
107
default
:
108
break
;
109
}
110
atom = atom
->
next
(
)
;
111
}
112
113
ir.contentJson[
"text"_L1
] = bodyText.trimmed();
114
115
return
ir;
116
}
117
118
}
// namespace IR
119
120
QT_END_NAMESPACE
Atom
The Atom class is the fundamental unit for representing documents internally.
Definition
atom.h:19
Atom::type
AtomType type() const
Return the type of this atom.
Definition
atom.h:153
Atom::BriefRight
@ BriefRight
Definition
atom.h:27
Atom::String
@ String
Definition
atom.h:93
Atom::BriefLeft
@ BriefLeft
Definition
atom.h:26
Atom::C
@ C
Definition
atom.h:28
Atom::AutoLink
@ AutoLink
Definition
atom.h:23
Atom::next
const Atom * next() const
Return the next atom in the atom list.
Definition
atom.h:150
IR::Builder
Builds IR (Intermediate Representation) from QDoc's Node tree.
Definition
builder.h:16
IR::Builder::buildPageIR
Document buildPageIR(const PageNode *pn) const
Definition
builder.cpp:66
PageNode
A PageNode is a Node that generates a documentation page.
Definition
pagenode.h:19
Text
Definition
text.h:12
Text::firstAtom
const Atom * firstAtom() const
Definition
text.h:34
IR
Definition
builder.cpp:14
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
IR::Document
Intermediate representation for a documentation topic.
Definition
document.h:19
IR::Document::access
Access access
Definition
document.h:24
IR::Document::status
Status status
Definition
document.h:23
IR::Document::nodeType
NodeType nodeType
Definition
document.h:21
IR::Document::genus
Genus genus
Definition
document.h:22
Node::doc
const Doc & doc() const
Returns a reference to the node's Doc data member.
Definition
node.h:235
Node::nodeType
NodeType nodeType() const override
Returns this node's type.
Definition
node.h:82
Node::genus
Genus genus() const override
Returns this node's Genus.
Definition
node.h:85
Node::status
virtual Status status() const
Returns the node's status value.
Definition
node.h:239
Node::access
Access access() const
Returns the node's Access setting, which can be Public, Protected, or Private.
Definition
node.h:228
qttools
src
qdoc
qdoc
src
qdoc
ir
builder.cpp
Generated on
for Qt by
1.16.1