comparison dmd/ddoc/Sections.d @ 153:560eaedcb7a2

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