1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
41 * Generates documentation from javadoc-style comments in XPIDL files.
45 doc_prolog(TreeState
*state
)
47 fprintf(state
->file
, "<html>\n");
48 fprintf(state
->file
, "<head>\n");
51 "<!-- this file is generated from %s.idl -->\n",
53 fprintf(state
->file
, "<title>documentation for %s.idl interfaces</title>\n",
55 fprintf(state
->file
, "</head>\n\n");
56 fprintf(state
->file
, "<body>\n");
62 doc_epilog(TreeState
*state
)
64 fprintf(state
->file
, "</body>\n");
65 fprintf(state
->file
, "</html>\n");
72 doc_list(TreeState
*state
)
75 for (iter
= state
->tree
; iter
; iter
= IDL_LIST(iter
).next
) {
76 state
->tree
= IDL_LIST(iter
).data
;
77 if (!xpidl_process_node(state
))
84 print_list(FILE *outfile
, IDL_tree list
)
89 fprintf(outfile
, "<ul>\n");
90 while (list
!= NULL
) {
91 fprintf(outfile
, " <li>%s\n",
92 IDL_IDENT(IDL_LIST(list
).data
).str
);
93 list
= IDL_LIST(list
).next
;
95 fprintf(outfile
, "</ul>\n");
100 doc_interface(TreeState
*state
)
102 IDL_tree iface
= state
->tree
;
105 char *classname
= IDL_IDENT(IDL_INTERFACE(iface
).ident
).str
;
106 GSList
*doc_comments
= IDL_IDENT(IDL_INTERFACE(iface
).ident
).comments
;
108 fprintf(state
->file
, "interface %s<br>\n", classname
);
110 /* Much more could happen at this step. */
112 * If parsing doc comments, you might need to take some care with line
113 * endings, as the xpidl frontend will return comments containing of /r,
114 * /n, /r/n depending on the platform. It's best to leave out platform
115 * #defines and just treat them all as equivalent.
117 if (doc_comments
!= NULL
) {
118 fprintf(state
->file
, "doc comments:<br>\n");
119 fprintf(state
->file
, "<pre>\n");
120 printlist(state
->file
, doc_comments
);
121 fprintf(state
->file
, "</pre>\n");
122 fprintf(state
->file
, "<br>\n");
127 * Note that we accept multiple inheritance here (for e.g. gnome idl)
128 * even though the header backend (specific to mozilla idl) rejects it.
130 if ((iter
= IDL_INTERFACE(iface
).inheritance_spec
)) {
131 fprintf(state
->file
, "%s inherits from:<br>\n", classname
);
132 print_list(state
->file
, iter
);
133 fprintf(state
->file
, "<br>\n");
137 * Call xpidl_process_node to recur through list of declarations in
138 * interface body; another option would be to explicitly iterate through
139 * the list. xpidl_process_node currently requires twiddling the state to
140 * get the right node; I'll fix that soon to just take the node. Makes it
141 * easier to follow what's going on, I think...
144 state
->tree
= IDL_INTERFACE(iface
).body
;
145 if (state
->tree
&& !xpidl_process_node(state
))
153 * Copied from xpidl_header.c. You'll probably want to change it; if you can
154 * use it verbatim or abstract it, we could move it to xpidl_util.c and share
158 write_type(IDL_tree type_tree
, FILE *outfile
)
161 fputs("void", outfile
);
165 switch (IDL_NODE_TYPE(type_tree
)) {
166 case IDLN_TYPE_INTEGER
: {
167 gboolean sign
= IDL_TYPE_INTEGER(type_tree
).f_signed
;
168 switch (IDL_TYPE_INTEGER(type_tree
).f_type
) {
169 case IDL_INTEGER_TYPE_SHORT
:
170 fputs(sign
? "PRInt16" : "PRUint16", outfile
);
172 case IDL_INTEGER_TYPE_LONG
:
173 fputs(sign
? "PRInt32" : "PRUint32", outfile
);
175 case IDL_INTEGER_TYPE_LONGLONG
:
176 fputs(sign
? "PRInt64" : "PRUint64", outfile
);
179 g_error("Unknown integer type %d\n",
180 IDL_TYPE_INTEGER(type_tree
).f_type
);
186 fputs("char", outfile
);
188 case IDLN_TYPE_WIDE_CHAR
:
189 fputs("PRUnichar", outfile
); /* wchar_t? */
191 case IDLN_TYPE_WIDE_STRING
:
192 fputs("PRUnichar *", outfile
);
194 case IDLN_TYPE_STRING
:
195 fputs("char *", outfile
);
197 case IDLN_TYPE_BOOLEAN
:
198 fputs("PRBool", outfile
);
200 case IDLN_TYPE_OCTET
:
201 fputs("PRUint8", outfile
);
203 case IDLN_TYPE_FLOAT
:
204 switch (IDL_TYPE_FLOAT(type_tree
).f_type
) {
205 case IDL_FLOAT_TYPE_FLOAT
:
206 fputs("float", outfile
);
208 case IDL_FLOAT_TYPE_DOUBLE
:
209 fputs("double", outfile
);
211 /* XXX 'long double' just ignored, or what? */
213 fprintf(outfile
, "unknown_type_%d", IDL_NODE_TYPE(type_tree
));
218 if (UP_IS_NATIVE(type_tree
)) {
219 fputs(IDL_NATIVE(IDL_NODE_UP(type_tree
)).user_type
, outfile
);
220 if (IDL_tree_property_get(type_tree
, "ptr")) {
221 fputs(" *", outfile
);
222 } else if (IDL_tree_property_get(type_tree
, "ref")) {
223 fputs(" &", outfile
);
226 fputs(IDL_IDENT(type_tree
).str
, outfile
);
228 if (UP_IS_AGGREGATE(type_tree
))
229 fputs(" *", outfile
);
232 fprintf(outfile
, "unknown_type_%d", IDL_NODE_TYPE(type_tree
));
238 /* handle ATTR_DCL (attribute declaration) nodes */
240 doc_attribute_declaration(TreeState
*state
)
242 IDL_tree attr
= state
->tree
;
244 if (!verify_attribute_declaration(attr
))
247 * Attribute idents can also take doc comments. They're ignored here;
251 if (IDL_ATTR_DCL(attr
).f_readonly
)
252 fprintf(state
->file
, "readonly ");
254 fprintf(state
->file
, "attribute ");
256 if (!write_type(IDL_ATTR_DCL(attr
).param_type_spec
, state
->file
))
259 fprintf(state
->file
, "\n");
260 print_list(state
->file
, IDL_ATTR_DCL(attr
).simple_declarations
);
261 fprintf(state
->file
, "<br>\n");
266 /* handle OP_DCL (method declaration) nodes */
268 doc_method_declaration(TreeState
*state
)
271 * Doc comment for attributes also applies here.
275 * Look at 'write_method_signature' in xpidl_header.c for an example of how
276 * to navigate parse trees for methods. For here, I just print the method
282 IDL_IDENT(IDL_OP_DCL(state
->tree
).ident
).str
);
288 xpidl_doc_dispatch(void)
290 static backend result
;
291 static nodeHandler table
[IDLN_LAST
];
292 static gboolean initialized
= FALSE
;
294 result
.emit_prolog
= doc_prolog
;
295 result
.emit_epilog
= doc_epilog
;
298 /* Initialize non-NULL elements */
300 /* I just handle a few... many still to be filled in! */
302 table
[IDLN_LIST
] = doc_list
;
303 table
[IDLN_INTERFACE
] = doc_interface
;
304 table
[IDLN_ATTR_DCL
] = doc_attribute_declaration
;
305 table
[IDLN_OP_DCL
] = doc_method_declaration
;
310 result
.dispatch_table
= table
;