Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/src/defgen.cpp

Source at commit 1322 created 9 years 5 months ago.
By meklort, Add doxygen to utils folder
1/******************************************************************************
2 *
3 * $Id: def.cpp,v 1.2 2001/01/01 10:15:18 root Exp $
4 *
5 *
6 * Copyright (C) 1997-2011 by Dimitri van Heesch.
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation under the terms of the GNU General Public License is hereby
10 * granted. No representations are made about the suitability of this software
11 * for any purpose. It is provided "as is" without express or implied warranty.
12 * See the GNU General Public License for more details.
13 *
14 * Documents produced by Doxygen are derivative works derived from the
15 * input used in their production; they are not affected by this license.
16 *
17 */
18
19#include <stdlib.h>
20
21#include "qtbc.h"
22#include "defgen.h"
23#include "doxygen.h"
24#include "message.h"
25#include "config.h"
26#include "classlist.h"
27#include "util.h"
28#include "defargs.h"
29#include "outputgen.h"
30#include "dot.h"
31
32#include <qdir.h>
33#include <qfile.h>
34#include <qtextstream.h>
35
36#define DEF_DB(x)
37
38inline void writeDEFString(FTextStream &t,const char *s)
39{
40 const char* p=s;
41 char c;
42
43 t << '\'';
44 while ((c = *(p++)))
45 {
46 if (c == '\'')
47 t << '\\';
48 t << c;
49 }
50 t << '\'';
51}
52
53void generateDEFForMember(MemberDef *md,
54 FTextStream &t,
55 Definition *def,
56 const char* Prefix)
57{
58 QCString memPrefix;
59
60 // + declaration
61 // - reimplements
62 // - reimplementedBy
63 // - exceptions
64 // - const/volatile specifiers
65 // - examples
66 // + source definition
67 // - source references
68 // - source referenced by
69 // - include code
70
71 if (md->memberType()==MemberDef::EnumValue) return;
72
73 QCString scopeName;
74 if (md->getClassDef())
75 scopeName=md->getClassDef()->name();
76 else if (md->getNamespaceDef())
77 scopeName=md->getNamespaceDef()->name();
78
79 t << " " << Prefix << "-member = {" << endl;
80 memPrefix = " ";
81 memPrefix.append( Prefix );
82 memPrefix.append( "-mem-" );
83
84 QCString memType;
85 bool isFunc=FALSE;
86 switch (md->memberType())
87 {
88 case MemberDef::Define: memType="define"; break;
89 case MemberDef::EnumValue: ASSERT(0); break;
90 case MemberDef::Property: memType="property"; break;
91 case MemberDef::Event: memType="event"; break;
92 case MemberDef::Variable: memType="variable"; break;
93 case MemberDef::Typedef: memType="typedef"; break;
94 case MemberDef::Enumeration: memType="enum"; break;
95 case MemberDef::Function: memType="function"; isFunc=TRUE; break;
96 case MemberDef::Signal: memType="signal"; isFunc=TRUE; break;
97 case MemberDef::Friend: memType="friend"; isFunc=TRUE; break;
98 case MemberDef::DCOP: memType="dcop"; isFunc=TRUE; break;
99 case MemberDef::Slot: memType="slot"; isFunc=TRUE; break;
100 }
101
102 t << memPrefix << "kind = '" << memType << "';" << endl;
103 t << memPrefix << "id = '"
104 << md->getOutputFileBase() << "_1" << md->anchor()
105 << "';" << endl;
106
107 t << memPrefix << "virt = ";
108 switch (md->virtualness())
109 {
110 case Normal: t << "normal;" << endl; break;
111 case Virtual: t << "virtual;" << endl; break;
112 case Pure: t << "pure-virtual;" << endl; break;
113 default: ASSERT(0);
114 }
115
116 t << memPrefix << "prot = ";
117 switch(md->protection())
118 {
119 case Public: t << "public;" << endl; break;
120 case Protected: t << "protected;" << endl; break;
121 case Private: t << "private;" << endl; break;
122 case Package: t << "package;" << endl; break;
123 }
124
125 if (md->memberType()!=MemberDef::Define &&
126 md->memberType()!=MemberDef::Enumeration
127 )
128 {
129 QCString typeStr = replaceAnonymousScopes(md->typeString());
130 t << memPrefix << "type = <<_EnD_oF_dEf_TeXt_" << endl << typeStr << endl
131 << "_EnD_oF_dEf_TeXt_;" << endl;
132 }
133
134 t << memPrefix << "name = '" << md->name() << "';" << endl;
135
136 if (isFunc) //function
137 {
138 ArgumentList *declAl = new ArgumentList;
139 LockingPtr<ArgumentList> defAl = md->argumentList();
140 stringToArgumentList(md->argsString(),declAl);
141 QCString fcnPrefix = " " + memPrefix + "param-";
142
143 if (declAl->count()>0)
144 {
145 ArgumentListIterator declAli(*declAl);
146 ArgumentListIterator defAli(*defAl);
147 Argument *a;
148 for (declAli.toFirst();(a=declAli.current());++declAli)
149 {
150 Argument *defArg = defAli.current();
151 t << memPrefix << "param = {" << endl;
152 if (!a->attrib.isEmpty())
153 {
154 t << fcnPrefix << "attributes = ";
155 writeDEFString(t,a->attrib);
156 t << ';' << endl;
157 }
158 if (!a->type.isEmpty())
159 {
160 t << fcnPrefix << "type = <<_EnD_oF_dEf_TeXt_" << endl
161 << a->type << endl << "_EnD_oF_dEf_TeXt_;" << endl;
162 }
163 if (!a->name.isEmpty())
164 {
165 t << fcnPrefix << "declname = ";
166 writeDEFString(t,a->name);
167 t << ';' << endl;
168 }
169 if (defArg && !defArg->name.isEmpty() && defArg->name!=a->name)
170 {
171 t << fcnPrefix << "defname = ";
172 writeDEFString(t,defArg->name);
173 t << ';' << endl;
174 }
175 if (!a->array.isEmpty())
176 {
177 t << fcnPrefix << "array = ";
178 writeDEFString(t,a->array);
179 t << ';' << endl;
180 }
181 if (!a->defval.isEmpty())
182 {
183 t << fcnPrefix << "defval = <<_EnD_oF_dEf_TeXt_" << endl
184 << a->defval << endl << "_EnD_oF_dEf_TeXt_;" << endl;
185 }
186 if (defArg) ++defAli;
187 t << " }; /*" << fcnPrefix << "-param */" << endl;
188 }
189 }
190 delete declAl;
191 }
192 else if ( md->memberType()==MemberDef::Define
193 && md->argsString()!=0)
194 {
195 ArgumentListIterator ali(*md->argumentList());
196 Argument *a;
197 QCString defPrefix = " " + memPrefix + "def-";
198
199 for (ali.toFirst();(a=ali.current());++ali)
200 {
201 t << memPrefix << "param = {" << endl;
202 t << defPrefix << "name = '" << a->type << "';" << endl;
203 t << " }; /*" << defPrefix << "-param */" << endl;
204 }
205 }
206
207 if (!md->initializer().isEmpty())
208 {
209 t << memPrefix << "initializer = <<_EnD_oF_dEf_TeXt_" << endl
210 << md->initializer() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
211 }
212 // TODO: exceptions, const volatile
213 if (md->memberType()==MemberDef::Enumeration) // enum
214 {
215 LockingPtr<MemberList> enumList = md->enumFieldList();
216 if (enumList!=0)
217 {
218 MemberListIterator emli(*enumList);
219 MemberDef *emd;
220 for (emli.toFirst();(emd=emli.current());++emli)
221 {
222 t << memPrefix << "enum = { enum-name = " << emd->name() << ';';
223 if (!emd->initializer().isEmpty())
224 {
225 t << " enum-value = ";
226 writeDEFString(t,emd->initializer());
227 t << ';';
228 }
229 t << " };" << endl;
230 }
231 }
232 }
233
234 t << memPrefix << "desc-file = '" << md->getDefFileName() << "';" << endl;
235 t << memPrefix << "desc-line = '" << md->getDefLine() << "';" << endl;
236 t << memPrefix << "briefdesc = <<_EnD_oF_dEf_TeXt_" << endl
237 << md->briefDescription() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
238 t << memPrefix << "documentation = <<_EnD_oF_dEf_TeXt_" << endl
239 << md->documentation() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
240
241 //printf("md->getReferencesMembers()=%p\n",md->getReferencesMembers());
242
243 LockingPtr<MemberSDict> mdict = md->getReferencesMembers();
244 if (!mdict.isNull())
245 {
246 MemberSDict::Iterator mdi(*mdict);
247 MemberDef *rmd;
248 QCString refPrefix = " " + memPrefix + "ref-";
249
250 for (mdi.toFirst();(rmd=mdi.current());++mdi)
251 {
252 if (rmd->getStartBodyLine()!=-1 && rmd->getBodyDef())
253 {
254 t << memPrefix << "referenceto = {" << endl;
255 t << refPrefix << "id = '"
256 << rmd->getBodyDef()->getOutputFileBase()
257 << "_1" // encoded `:' character (see util.cpp:convertNameToFile)
258 << rmd->anchor() << "';" << endl;
259
260 t << refPrefix << "line = '"
261 << rmd->getStartBodyLine() << "';" << endl;
262
263 QCString scope = rmd->getScopeString();
264 QCString name = rmd->name();
265 if (!scope.isEmpty() && scope!=def->name())
266 {
267 name.prepend(scope+"::");
268 }
269
270 t << refPrefix << "name = ";
271 writeDEFString(t,name);
272 t << ';' << endl << " };" << endl;
273 }
274 } /* for (mdi.toFirst...) */
275 }
276 mdict = md->getReferencedByMembers();
277 if (!mdict.isNull())
278 {
279 MemberSDict::Iterator mdi(*mdict);
280 MemberDef *rmd;
281 QCString refPrefix = " " + memPrefix + "ref-";
282
283 for (mdi.toFirst();(rmd=mdi.current());++mdi)
284 {
285 if (rmd->getStartBodyLine()!=-1 && rmd->getBodyDef())
286 {
287 t << memPrefix << "referenceby = {" << endl;
288 t << refPrefix << "id = '"
289 << rmd->getBodyDef()->getOutputFileBase()
290 << "_1" // encoded `:' character (see util.cpp:convertNameToFile)
291 << rmd->anchor() << "';" << endl;
292
293 t << refPrefix << "line = '"
294 << rmd->getStartBodyLine() << "';" << endl;
295
296 QCString scope = rmd->getScopeString();
297 QCString name = rmd->name();
298 if (!scope.isEmpty() && scope!=def->name())
299 {
300 name.prepend(scope+"::");
301 }
302
303 t << refPrefix << "name = ";
304 writeDEFString(t,name);
305 t << ';' << endl << " };" << endl;
306 }
307 } /* for (mdi.toFirst...) */
308 }
309
310 t << " }; /* " << Prefix << "-member */" << endl;
311}
312
313
314void generateDEFClassSection(ClassDef *cd,
315 FTextStream &t,
316 MemberList *ml,
317 const char *kind)
318{
319 if (cd && ml && ml->count()>0)
320 {
321 t << " cp-section = {" << endl;
322 t << " sec-kind = '" << kind << "';" << endl;
323
324 MemberListIterator mli(*ml);
325 MemberDef *md;
326 for (mli.toFirst();(md=mli.current());++mli)
327 {
328 generateDEFForMember(md,t,cd,"sec");
329 }
330 t << " }; /* cp-section */" << endl;
331 }
332}
333
334void generateDEFForClass(ClassDef *cd,FTextStream &t)
335{
336 // + brief description
337 // + detailed description
338 // - template arguments
339 // - include files
340 // + inheritance diagram
341 // + list of direct super classes
342 // + list of direct sub classes
343 // + collaboration diagram
344 // - list of all members
345 // + user defined member sections
346 // + standard member sections
347 // + detailed member documentation
348 // - examples
349
350 if (cd->isReference()) return; // skip external references.
351 if (cd->name().find('@')!=-1) return; // skip anonymous compounds.
352 if (cd->templateMaster()!=0) return; // skip generated template instances.
353
354 t << cd->compoundTypeString() << " = {" << endl;
355 t << " cp-id = '" << cd->getOutputFileBase() << "';" << endl;
356 t << " cp-name = '" << cd->name() << "';" << endl;
357
358 if (cd->baseClasses())
359 {
360 BaseClassListIterator bcli(*cd->baseClasses());
361 BaseClassDef *bcd;
362 for (bcli.toFirst();(bcd=bcli.current());++bcli)
363 {
364 t << " cp-ref = {" << endl << " ref-type = base;" << endl;
365 t << " ref-id = '"
366 << bcd->classDef->getOutputFileBase() << "';" << endl;
367 t << " ref-prot = ";
368 switch (bcd->prot)
369 {
370 case Public: t << "public;" << endl; break;
371 case Package: // package scope is not possible
372 case Protected: t << "protected;" << endl; break;
373 case Private: t << "private;" << endl; break;
374 }
375 t << " ref-virt = ";
376 switch(bcd->virt)
377 {
378 case Normal: t << "non-virtual;"; break;
379 case Virtual: t << "virtual;"; break;
380 case Pure: t << "pure-virtual;"; break;
381 }
382 t << endl << " };" << endl;
383 }
384 }
385
386 if (cd->subClasses())
387 {
388 BaseClassListIterator bcli(*cd->subClasses());
389 BaseClassDef *bcd;
390 for (bcli.toFirst();(bcd=bcli.current());++bcli)
391 {
392 t << " cp-ref = {" << endl << " ref-type = derived;" << endl;
393 t << " ref-id = '"
394 << bcd->classDef->getOutputFileBase() << "';" << endl;
395 t << " ref-prot = ";
396 switch (bcd->prot)
397 {
398 case Public: t << "public;" << endl; break;
399 case Package: // packet scope is not possible!
400 case Protected: t << "protected;" << endl; break;
401 case Private: t << "private;" << endl; break;
402 }
403 t << " ref-virt = ";
404 switch(bcd->virt)
405 {
406 case Normal: t << "non-virtual;"; break;
407 case Virtual: t << "virtual;"; break;
408 case Pure: t << "pure-virtual;"; break;
409 }
410 t << endl << " };" << endl;
411 }
412 }
413
414 int numMembers = 0;
415 QListIterator<MemberList> mli(cd->getMemberLists());
416 MemberList *ml;
417 for (mli.toFirst();(ml=mli.current());++mli)
418 {
419 if ((ml->listType()&MemberList::detailedLists)==0)
420 {
421 numMembers+=ml->count();
422 }
423 }
424 if (numMembers>0)
425 {
426 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::pubTypes),"public-type");
427 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::pubMethods),"public-func");
428 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::pubAttribs),"public-attrib");
429 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::pubSlots),"public-slot");
430 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::signals),"signal");
431 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::dcopMethods),"dcop-func");
432 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::properties),"property");
433 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::pubStaticMethods),"public-static-func");
434 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::pubStaticAttribs),"public-static-attrib");
435 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::proTypes),"protected-type");
436 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::proMethods),"protected-func");
437 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::proAttribs),"protected-attrib");
438 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::proSlots),"protected-slot");
439 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::proStaticMethods),"protected-static-func");
440 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::proStaticAttribs),"protected-static-attrib");
441 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::priTypes),"private-type");
442 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::priMethods),"private-func");
443 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::priAttribs),"private-attrib");
444 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::priSlots),"private-slot");
445 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::priStaticMethods),"private-static-func");
446 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::priStaticAttribs),"private-static-attrib");
447 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::friends),"signal");
448 generateDEFClassSection(cd,t,cd->getMemberList(MemberList::related),"related");
449 }
450
451 t << " cp-filename = '" << cd->getDefFileName() << "';" << endl;
452 t << " cp-fileline = '" << cd->getDefLine() << "';" << endl;
453 t << " cp-briefdesc = <<_EnD_oF_dEf_TeXt_" << endl
454 << cd->briefDescription() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
455
456 t << " cp-documentation = <<_EnD_oF_dEf_TeXt_" << endl
457 << cd->documentation() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
458
459 DotClassGraph inheritanceGraph(cd,DotNode::Inheritance);
460 if (!inheritanceGraph.isTrivial())
461 {
462 t << " cp-inheritancegraph = <<_EnD_oF_dEf_TeXt_" << endl;
463 inheritanceGraph.writeDEF(t);
464 t << endl << "_EnD_oF_dEf_TeXt_;" << endl;
465 }
466 DotClassGraph collaborationGraph(cd,DotNode::Collaboration);
467 if (!collaborationGraph.isTrivial())
468 {
469 t << " cp-collaborationgraph = <<_EnD_oF_dEf_TeXt_" << endl;
470 collaborationGraph.writeDEF(t);
471 t << endl << "_EnD_oF_dEf_TeXt_;" << endl;
472 }
473 t << "}; /* " << cd->compoundTypeString() << " */" << endl;
474}
475
476void generateDEFSection(Definition *d,
477 FTextStream &t,
478 MemberList *ml,
479 const char *kind)
480{
481 if (ml && ml->count()>0)
482 {
483 t << " " << kind << " = {" << endl;
484 MemberListIterator mli(*ml);
485 MemberDef *md;
486 for (mli.toFirst();(md=mli.current());++mli)
487 {
488 generateDEFForMember(md,t,d,kind);
489 }
490 t << " };" << endl;
491 }
492}
493
494void generateDEFForNamespace(NamespaceDef *nd,FTextStream &t)
495{
496 if (nd->isReference()) return; // skip external references
497 t << " namespace = {" << endl;
498 t << " ns-id = '" << nd->getOutputFileBase() << "';" << endl;
499 t << " ns-name = ";
500 writeDEFString(t,nd->name());
501 t << ';' << endl;
502
503 generateDEFSection(nd,t,nd->getMemberList(MemberList::decDefineMembers),"define");
504 generateDEFSection(nd,t,nd->getMemberList(MemberList::decProtoMembers),"prototype");
505 generateDEFSection(nd,t,nd->getMemberList(MemberList::decTypedefMembers),"typedef");
506 generateDEFSection(nd,t,nd->getMemberList(MemberList::decEnumMembers),"enum");
507 generateDEFSection(nd,t,nd->getMemberList(MemberList::decFuncMembers),"func");
508 generateDEFSection(nd,t,nd->getMemberList(MemberList::decVarMembers),"var");
509
510 t << " ns-filename = '" << nd->getDefFileName() << "';" << endl;
511 t << " ns-fileline = '" << nd->getDefLine() << "';" << endl;
512 t << " ns-briefdesc = <<_EnD_oF_dEf_TeXt_" << endl
513 << nd->briefDescription() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
514
515 t << " ns-documentation = <<_EnD_oF_dEf_TeXt_" << endl
516 << nd->documentation() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
517 t << " };" << endl;
518}
519
520void generateDEFForFile(FileDef *fd,FTextStream &t)
521{
522 if (fd->isReference()) return; // skip external references
523
524 t << "file = {" << endl;
525 t << " file-id = '" << fd->getOutputFileBase() << "';" << endl;
526 t << " file-name = ";
527 writeDEFString(t,fd->name());
528 t << ';' << endl;
529
530 generateDEFSection(fd,t,fd->getMemberList(MemberList::decDefineMembers),"define");
531 generateDEFSection(fd,t,fd->getMemberList(MemberList::decProtoMembers),"prototype");
532 generateDEFSection(fd,t,fd->getMemberList(MemberList::decTypedefMembers),"typedef");
533 generateDEFSection(fd,t,fd->getMemberList(MemberList::decEnumMembers),"enum");
534 generateDEFSection(fd,t,fd->getMemberList(MemberList::decFuncMembers),"func");
535 generateDEFSection(fd,t,fd->getMemberList(MemberList::decVarMembers),"var");
536
537 t << " file-full-name = '" << fd->getDefFileName() << "';" << endl;
538 t << " file-first-line = '" << fd->getDefLine() << "';" << endl;
539
540 t << " file-briefdesc = <<_EnD_oF_dEf_TeXt_" << endl
541 << fd->briefDescription() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
542
543 t << " file-documentation = <<_EnD_oF_dEf_TeXt_" << endl
544 << fd->documentation() << endl << "_EnD_oF_dEf_TeXt_;" << endl;
545
546 t << "}; /* file */" << endl;
547}
548
549
550void generateDEF()
551{
552 QCString outputDirectory = Config_getString("OUTPUT_DIRECTORY");
553 if (outputDirectory.isEmpty())
554 {
555 outputDirectory=QDir::currentDirPath();
556 }
557 else
558 {
559 QDir dir(outputDirectory);
560 if (!dir.exists())
561 {
562 dir.setPath(QDir::currentDirPath());
563 if (!dir.mkdir(outputDirectory))
564 {
565 err("error: tag OUTPUT_DIRECTORY: Output directory `%s' does not "
566 "exist and cannot be created\n",outputDirectory.data());
567 exit(1);
568 }
569 else if (!Config_getBool("QUIET"))
570 {
571 err("notice: Output directory `%s' does not exist. "
572 "I have created it for you.\n", outputDirectory.data());
573 }
574 dir.cd(outputDirectory);
575 }
576 outputDirectory=dir.absPath();
577 }
578
579 QDir dir(outputDirectory);
580 if (!dir.exists())
581 {
582 dir.setPath(QDir::currentDirPath());
583 if (!dir.mkdir(outputDirectory))
584 {
585 err("Cannot create directory %s\n",outputDirectory.data());
586 return;
587 }
588 }
589 QDir defDir(outputDirectory+"/def");
590 if (!defDir.exists() && !defDir.mkdir(outputDirectory+"/def"))
591 {
592 err("Could not create def directory in %s\n",outputDirectory.data());
593 return;
594 }
595
596 QCString fileName=outputDirectory+"/def/doxygen.def";
597 QFile f(fileName);
598 if (!f.open(IO_WriteOnly))
599 {
600 err("Cannot open file %s for writing!\n",fileName.data());
601 return;
602 }
603 FTextStream t(&f);
604 t << "AutoGen Definitions dummy;" << endl;
605
606 if (Doxygen::classSDict->count()+Doxygen::inputNameList->count()>0)
607 {
608 ClassSDict::Iterator cli(*Doxygen::classSDict);
609 ClassDef *cd;
610 for (cli.toFirst();(cd=cli.current());++cli)
611 {
612 generateDEFForClass(cd,t);
613 }
614 FileNameListIterator fnli(*Doxygen::inputNameList);
615 FileName *fn;
616 for (;(fn=fnli.current());++fnli)
617 {
618 FileNameIterator fni(*fn);
619 FileDef *fd;
620 for (;(fd=fni.current());++fni)
621 {
622 generateDEFForFile(fd,t);
623 }
624 }
625 }
626 else
627 {
628 t << "dummy_value = true;" << endl;
629 }
630}
631

Archive Download this file

Revision: 1322