106
|
1 module dmd.ddoc.Sections;
|
0
|
2
|
114
|
3 import dmd.common;
|
106
|
4 import dmd.ddoc.DocComment;
|
153
|
5 import dmd.ddoc.Util;
|
106
|
6 import dmd.Array;
|
0
|
7 import dmd.Scope;
|
|
8 import dmd.Dsymbol;
|
153
|
9 import dmd.HdrGenState;
|
0
|
10 import dmd.OutBuffer;
|
|
11
|
106
|
12 //!
|
|
13 alias Vector!Section Sections;
|
|
14
|
|
15 //!
|
0
|
16 class Section
|
|
17 {
|
153
|
18 string name;
|
|
19 string body_;
|
106
|
20
|
153
|
21 int nooutput;
|
106
|
22
|
|
23 void write(DocComment dc, Scope sc, Dsymbol s, OutBuffer buf)
|
|
24 {
|
153
|
25 if (name.length)
|
106
|
26 {
|
153
|
27 static string[] table = [
|
|
28 "AUTHORS", "BUGS", "COPYRIGHT", "DATE",
|
|
29 "DEPRECATED", "EXAMPLES", "HISTORY", "LICENSE",
|
|
30 "RETURNS", "SEE_ALSO", "STANDARDS", "THROWS",
|
|
31 "VERSION"
|
|
32 ];
|
|
33
|
|
34 for (uint i = 0; i < table.length; i++)
|
106
|
35 {
|
153
|
36 if (icmp(table[i], name) == 0)
|
106
|
37 {
|
|
38 buf.printf("$(DDOC_%s ", table[i]);
|
|
39 goto L1;
|
|
40 }
|
|
41 }
|
0
|
42
|
106
|
43 buf.writestring("$(DDOC_SECTION ");
|
|
44 // Replace _ characters with spaces
|
|
45 buf.writestring("$(DDOC_SECTION_H ");
|
|
46 size_t o = buf.offset;
|
153
|
47 for (size_t u = 0; u < name.length; u++)
|
106
|
48 {
|
|
49 char c = name[u];
|
|
50 buf.writeByte((c == '_') ? ' ' : c);
|
|
51 }
|
|
52 escapeStrayParenthesis(buf, o, s.loc);
|
153
|
53 buf.writestring(":)\n");
|
106
|
54 }
|
|
55 else
|
|
56 {
|
|
57 buf.writestring("$(DDOC_DESCRIPTION ");
|
|
58 }
|
|
59 L1:
|
153
|
60 uint o = buf.offset;
|
|
61 buf.write(body_, body_.length);
|
106
|
62 escapeStrayParenthesis(buf, o, s.loc);
|
|
63 highlightText(sc, s, buf, o);
|
|
64 buf.writestring(")\n");
|
|
65 }
|
|
66 }
|
|
67
|
|
68 //!
|
|
69 class ParamSection : Section
|
|
70 {
|
|
71 override void write(DocComment dc, Scope sc, Dsymbol s, OutBuffer buf)
|
|
72 {
|
153
|
73 size_t i = 0;
|
|
74 string p = body_;
|
106
|
75
|
153
|
76 size_t tempstart, templen;
|
106
|
77
|
153
|
78 size_t namestart, namelen = 0; // !=0 if line continuation
|
106
|
79
|
153
|
80 size_t textstart, textlen;
|
106
|
81
|
153
|
82 uint o;
|
106
|
83 Parameter *arg;
|
|
84
|
|
85 buf.writestring("$(DDOC_PARAMS \n");
|
153
|
86 while (i < _body.length)
|
106
|
87 {
|
|
88 // Skip to start of macro
|
153
|
89 while (true)
|
106
|
90 {
|
153
|
91 switch (p[i])
|
106
|
92 {
|
|
93 case ' ':
|
|
94 case '\t':
|
153
|
95 i++;
|
106
|
96 continue;
|
|
97
|
|
98 case '\n':
|
153
|
99 i++;
|
106
|
100 goto Lcont;
|
0
|
101
|
106
|
102 default:
|
|
103 if (isIdStart(p))
|
|
104 break;
|
|
105 if (namelen)
|
|
106 goto Ltext; // continuation of prev macro
|
|
107 goto Lskipline;
|
|
108 }
|
|
109 break;
|
|
110 }
|
153
|
111 tempstart = i;
|
106
|
112
|
153
|
113 while (isIdTail(body_[i .. $]))
|
|
114 i += utfStride(body_[i .. $]);
|
|
115 templen = i - tempstart;
|
106
|
116
|
153
|
117 while (p[i] == ' ' || p[i] == '\t')
|
|
118 i++;
|
106
|
119
|
153
|
120 if (p[i] != '=')
|
106
|
121 { if (namelen)
|
|
122 goto Ltext; // continuation of prev macro
|
|
123 goto Lskipline;
|
|
124 }
|
153
|
125 i++;
|
106
|
126
|
|
127 if (namelen)
|
|
128 { // Output existing param
|
|
129
|
|
130 L1:
|
153
|
131 // writef("param '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart);
|
106
|
132 HdrGenState hgs;
|
|
133 buf.writestring("$(DDOC_PARAM_ROW ");
|
|
134 buf.writestring("$(DDOC_PARAM_ID ");
|
|
135 o = buf.offset;
|
|
136 arg = isFunctionParameter(s, namestart, namelen);
|
|
137 if (arg && arg.type && arg.ident)
|
|
138 arg.type.toCBuffer(buf, arg.ident, &hgs);
|
|
139 else
|
|
140 buf.write(namestart, namelen);
|
|
141 escapeStrayParenthesis(buf, o, s.loc);
|
|
142 highlightCode(sc, s, buf, o);
|
|
143 buf.writestring(")\n");
|
0
|
144
|
106
|
145 buf.writestring("$(DDOC_PARAM_DESC ");
|
|
146 o = buf.offset;
|
153
|
147 buf.write(&p[textstart], textlen);
|
106
|
148 escapeStrayParenthesis(buf, o, s.loc);
|
|
149 highlightText(sc, s, buf, o);
|
|
150 buf.writestring(")");
|
|
151 buf.writestring(")\n");
|
|
152 namelen = 0;
|
153
|
153 if (i >= p.length)
|
106
|
154 break;
|
|
155 }
|
|
156
|
|
157 namestart = tempstart;
|
|
158 namelen = templen;
|
|
159
|
153
|
160 while (p[i] == ' ' || p[i] == '\t')
|
|
161 i++;
|
|
162 textstart = i;
|
106
|
163
|
|
164 Ltext:
|
153
|
165 while (p[i] != '\n')
|
|
166 i++;
|
|
167 textlen = i - textstart;
|
|
168 i++;
|
106
|
169
|
|
170 Lcont:
|
|
171 continue;
|
|
172
|
|
173 Lskipline:
|
|
174 // Ignore this line
|
153
|
175 while (p[i++] != '\n') {}
|
106
|
176 }
|
|
177 if (namelen)
|
|
178 goto L1; // write out last one
|
|
179 buf.writestring(")\n");
|
|
180 }
|
|
181 }
|
|
182
|
|
183 //!
|
|
184 class MacroSection : Section
|
|
185 {
|
|
186 override void write(DocComment dc, Scope sc, Dsymbol s, OutBuffer buf)
|
0
|
187 {
|
106
|
188 // writef("MacroSection.write()\n");
|
153
|
189 DocComment.parseMacros(dc.pescapetable, dc.pmacrotable, body_, body_.length);
|
0
|
190 }
|
|
191 } |