comparison dmd/ddoc/Sections.d @ 149:78bf0fe43974

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