]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/newdoc.cxx
1 /*******************************************************************************
2 * Simplified Wrapper and Interface Generator (SWIG)
4 * Author : David Beazley
6 * Department of Computer Science
7 * University of Chicago
10 * beazley@cs.uchicago.edu
12 * Please read the file LICENSE for the copyright and terms by which SWIG
13 * can be used and distributed.
14 *******************************************************************************/
15 /***********************************************************************
20 * SWIG Documentation system. (2nd attempt)
22 * SWIG organizes documentation as a tree structure where each node is a
23 * documentation entry (DocEntry) of some kind. To generate documentation,
24 * we simply traverse the tree and call output methods.
26 * A sample documentation tree looks something like the following :
28 * TITLE ----> SECTION 1 ----> func1
31 * ----> class ---> func1
36 * ----> SECTION 2 ----> func1
41 * This structure makes it possible to organize C++ classes and more
42 * complicated structures. Hopefully this will provide enough structure
43 * for later versions of SWIG.
45 *************************************************************************/
50 extern char *get_time();
51 static char *last_name
= 0;
53 DocEntry
*DocEntry::dead_entries
= 0;
55 // Utility function for converting a string to upper case
57 static void str_toupper(char *str
) {
66 // --------------------------------------------------------------------
67 // DocEntry::~DocEntry
69 // Destroy a documentation entry. Destroys this entry and all of
71 // --------------------------------------------------------------------
73 DocEntry::~DocEntry() {
76 if (name
) delete name
;
78 // Now kill all of the children (well, figuratively speaking)
88 // --------------------------------------------------------------------
89 // void DocEntry::sort_children()
91 // Sort children by name (not height). This function gathers all
92 // of the children up into an array of pointers. Then we do an
93 // insertion sort on it and place the children back in order.
94 // --------------------------------------------------------------------
96 void DocEntry::sort_children() {
104 if (!child
) return; // Nothing to sort
112 // allocate a temporary array for sorting everything
114 list
= new DocEntry
*[count
+2];
116 // Now put pointers into list
126 // Do an insertion sort by name
128 for (i
= 1; i
< count
; i
++) {
131 while((j
> 0) && (strcmp(list
[j
-1]->name
,v
->name
) > 0)) {
138 // Now, we're going to reorganize the children in order
141 child
= list
[0]; // Our child is the first one in the list
143 for (i
= 0; i
< count
; i
++) {
150 // --------------------------------------------------------------------
151 // void DocEntry::output()
154 // --------------------------------------------------------------------
156 void DocEntry::output(Documentation
*) {
157 fprintf(stderr
,"SWIG (internal) : No output method defined for DocEntry.\n");
160 // --------------------------------------------------------------------
161 // DocEntry::add(DocEntry *de)
163 // Adds a new DocEntry as a sibling. Basically we just walk down the
164 // linked list and append ourselves to the end. The documentation
165 // Entry we're adding may, in fact, have siblings too, but this function
166 // Should still work.
167 // --------------------------------------------------------------------
169 void DocEntry::add(DocEntry
*de
) {
178 de
->previous
= d1
; // Set up the previous list member
182 // --------------------------------------------------------------------
183 // DocEntry::addchild(DocEntry *de)
185 // Adds a new DocEntry as a child. If we're in Ignore mode, the
186 // documentation entry is still created, but we simply abandon it.
187 // --------------------------------------------------------------------
189 void DocEntry::addchild(DocEntry
*de
) {
191 if (child
) child
->add(de
);
194 if (dead_entries
) dead_entries
->add(de
);
195 else dead_entries
= de
;
199 // -------------------------------------------------------------------
200 // DocEntry::remove()
202 // Removes a documentation entry from the tree and places it on
203 // the dead_entries list
204 // -------------------------------------------------------------------
206 void DocEntry::remove() {
210 previous
->next
= next
; // Take out of the linked list
213 } else { // Make sure our parent isn't pointing to us
215 parent
->child
= next
;
221 if (!dead_entries
) dead_entries
= this;
222 else dead_entries
->add(this);
226 // -------------------------------------------------------------------
227 // void DocEntry::style(char *name, char *value)
229 // Set style parameters of a documentation entry
230 // -------------------------------------------------------------------
232 void DocEntry::style(char *pname
, char *) {
233 if (strcmp(pname
,"sort") == 0) {
235 } else if (strcmp(pname
,"nosort") == 0) {
237 } else if (strcmp(pname
,"info") == 0) {
239 } else if (strcmp(pname
,"noinfo") == 0) {
241 } else if (strcmp(pname
,"pre") == 0) {
243 } else if (strcmp(pname
,"format") == 0) {
248 // -------------------------------------------------------------------
249 // void DocEntry::parse_args(int argc, char **argv)
251 // Take command line options and process them. This really only
252 // applies to the top-level documentation entry.
253 // -------------------------------------------------------------------
255 static char *doc_usage
= "\
256 Documentation Processing : \n\
257 -Sformat - Reformat comment text\n\
258 -Sinfo - Print C formatting information (the default)\n\
259 -Snoinfo - Omit C formatting information.\n\
260 -Snosort - Print everything in order (the default)\n\
261 -Spre - Assume comments are pre-formatted (the default)\n\
262 -Ssort - Sort documentation alphabetically\n\n";
264 void DocEntry::parse_args(int argc
, char **argv
) {
266 for (i
= 1; i
< argc
; i
++) {
268 if (strcmp(argv
[i
],"-Ssort") == 0) {
269 this->style("sort",0);
271 } else if (strcmp(argv
[i
],"-Snosort") == 0) {
272 this->style("nosort",0);
274 } else if (strcmp(argv
[i
],"-Sinfo") == 0) {
275 this->style("info",0);
277 } else if (strcmp(argv
[i
],"-Snoinfo") == 0) {
278 this->style("noinfo",0);
280 } else if (strcmp(argv
[i
],"-Spre") == 0) {
281 this->style("pre",0);
283 } else if (strcmp(argv
[i
],"-Sformat") == 0) {
284 this->style("format",0);
286 } else if (strcmp(argv
[i
],"-help") == 0) {
287 fputs(doc_usage
,stderr
);
294 // -------------------------------------------------------------------
295 // DocTitle::DocTitle(char *title, DocEntry *_parent);
297 // Create a new title documentation entry. The name of the entry
300 // The body text is optional, but may be filled in with a description
302 // -------------------------------------------------------------------
304 DocTitle::DocTitle(char *title
, DocEntry
*_parent
) {
305 name
= copy_string(title
);
311 usage
<< title
<< "\n";
314 line_number
= ::start_line
;
315 end_line
= ::line_number
;
316 file
= copy_string(input_file
);
318 sorted
= _parent
->sorted
;
319 format
= _parent
->format
;
320 print_info
= _parent
->print_info
;
322 sorted
= SWIGDEFAULT_SORT
;
323 format
= SWIGDEFAULT_FORMAT
;
324 print_info
= SWIGDEFAULT_INFO
;
326 comment_handler
->set_entry(this);
327 if (last_name
) delete last_name
;
330 // --------------------------------------------------------------------
331 // DocTitle::output(Documentation *d)
333 // Output a title to the Documentation module
334 // --------------------------------------------------------------------
336 void DocTitle::output(Documentation
*d
) {
344 // Now output my children
353 // -------------------------------------------------------------------
354 // DocSection::DocSection(char *section, DocEntry *_parent);
356 // Create a new documentation section. The name and description is
357 // set to the name of the section. The text field is optional
358 // but could contain a more complete description.
360 // The sorted field indicates whether members of this section are
362 // -------------------------------------------------------------------
364 DocSection::DocSection(char *section
, DocEntry
*_parent
) {
365 name
= copy_string(section
);
374 if (_parent
) _parent
->addchild(this);
375 line_number
= ::start_line
;
376 end_line
= ::line_number
;
377 file
= copy_string(input_file
);
379 sorted
= _parent
->sorted
;
380 format
= _parent
->format
;
381 print_info
= _parent
->print_info
;
383 sorted
= SWIGDEFAULT_SORT
;
384 format
= SWIGDEFAULT_FORMAT
;
385 print_info
= SWIGDEFAULT_INFO
;
387 comment_handler
->set_entry(this);
388 if (last_name
) delete last_name
;
392 // --------------------------------------------------------------------
393 // DocSection::output(Documentation *d)
395 // Output a section to the documentation module
396 // --------------------------------------------------------------------
398 void DocSection::output(Documentation
*d
) {
401 // Make a new section
403 d
->newsection(this,this->parent
->counter
++); // Make a new section
405 // Sort the children if necessary
411 // Now output my children
426 // -------------------------------------------------------------------
427 // DocDecl::DocDecl(char *fname, DocEntry *_parent);
429 // Create documentation for a function declaration.
430 // -------------------------------------------------------------------
432 DocDecl::DocDecl(char *fname
, DocEntry
*_parent
) {
433 name
= copy_string(fname
);
440 if (_parent
) _parent
->addchild(this);
441 line_number
= ::start_line
;
442 end_line
= ::line_number
;
443 file
= copy_string(input_file
);
445 sorted
= _parent
->sorted
;
446 format
= _parent
->format
;
447 print_info
= _parent
->print_info
;
449 sorted
= SWIGDEFAULT_SORT
;
450 format
= SWIGDEFAULT_FORMAT
;
451 print_info
= SWIGDEFAULT_INFO
;
453 comment_handler
->set_entry(this);
454 if (last_name
) delete last_name
;
455 last_name
= copy_string(name
);
459 // --------------------------------------------------------------------
460 // DocDecl::DocDecl(DocEntry *de, DocEntry *_parent)
462 // Make a new declaration entry, but copy attributes from someone else
463 // --------------------------------------------------------------------
465 DocDecl::DocDecl(DocEntry
*de
, DocEntry
*_parent
) {
466 name
= copy_string(de
->name
);
467 usage
= de
->usage
.get();
468 cinfo
= de
->cinfo
.get();
469 text
= de
->text
.get();
470 line_number
= de
->line_number
;
471 end_line
= de
->end_line
;
472 file
= copy_string(de
->file
);
473 print_info
= de
->print_info
;
476 _parent
->addchild(this);
480 // --------------------------------------------------------------------
481 // DocDecl::output(Documentation *d)
483 // Output a function to the documentation module
484 // --------------------------------------------------------------------
486 void DocDecl::output(Documentation
*d
) {
490 // -------------------------------------------------------------------
491 // DocClass::DocClass(char *classname, DocEntry *_parent);
493 // Create a new class section. Classes are created as funny sorts of
496 // The sorted field indicates whether members of this section are
498 // -------------------------------------------------------------------
500 DocClass::DocClass(char *classname
, DocEntry
*_parent
) {
501 name
= copy_string(classname
);
507 usage
<< classname
<< "\n";
510 if (_parent
) _parent
->addchild(this);
511 line_number
= ::start_line
;
512 end_line
= ::line_number
;
513 file
= copy_string(input_file
);
515 sorted
= _parent
->sorted
;
516 format
= _parent
->format
;
517 print_info
= _parent
->print_info
;
519 sorted
= SWIGDEFAULT_SORT
;
520 format
= SWIGDEFAULT_FORMAT
;
521 print_info
= SWIGDEFAULT_INFO
;
523 comment_handler
->set_entry(this);
524 if (last_name
) delete last_name
;
525 last_name
= copy_string(name
);
529 // --------------------------------------------------------------------
530 // DocClass::output(Documentation *d)
532 // Output a section to the documentation module
533 // --------------------------------------------------------------------
535 void DocClass::output(Documentation
*d
) {
538 // Make a new section
540 d
->newsection(this,this->parent
->counter
++); // Make a subsection for this
542 // Sort the children if necessary
548 // Now output my children
560 // We now check to see if the next thing is a separator. If not, we'll
564 if (!next
->is_separator
)
569 // -------------------------------------------------------------------
570 // DocText::DocText(char *_text, DocEntry *_parent);
572 // Create documentation for a function declaration.
573 // -------------------------------------------------------------------
575 DocText::DocText(char *_text
, DocEntry
*_parent
) {
577 name
= copy_string(""); // There is no name for text
579 name
= copy_string(last_name
);
586 if (_parent
) _parent
->addchild(this);
588 sorted
= _parent
->sorted
;
589 format
= _parent
->format
;
590 print_info
= _parent
->print_info
;
592 sorted
= SWIGDEFAULT_SORT
;
593 format
= SWIGDEFAULT_FORMAT
;
594 print_info
= SWIGDEFAULT_INFO
;
598 // --------------------------------------------------------------------
599 // DocText::output(Documentation *d)
601 // Output a function to the documentation module
602 // --------------------------------------------------------------------
604 void DocText::output(Documentation
*d
) {