doxygen  1.8.18
About: Doxygen is a source code documentation generator tool for C++, C, Objective-C, C#, PHP, Java, Python, IDL (diverse flavors), Fortran, VHDL, Tcl, and to some extent D. Different output formats are supported.
  Fossies Dox: doxygen-1.8.18.src.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

doxyapp.cpp
Go to the documentation of this file.
1 
28 #include <stdlib.h>
29 #include <qfile.h>
30 #include <qdir.h>
31 #include "doxygen.h"
32 #include "outputgen.h"
33 #include "parserintf.h"
34 #include "classdef.h"
35 #include "namespacedef.h"
36 #include "filedef.h"
37 #include "util.h"
38 #include "classlist.h"
39 #include "config.h"
40 #include "filename.h"
41 
43 {
44  public:
47 
48  // these are just null functions, they can be used to produce a syntax highlighted
49  // and cross-linked version of the source code, but who needs that anyway ;-)
50  void codify(const char *) {}
51  void writeCodeLink(const char *,const char *,const char *,const char *,const char *) {}
52  void writeLineNumber(const char *,const char *,const char *,int) {}
53  virtual void writeTooltip(const char *,const DocLinkInfo &,
54  const char *,const char *,const SourceLinkInfo &,
55  const SourceLinkInfo &) {}
56  void startCodeLine(bool) {}
57  void endCodeLine() {}
58  void startCodeAnchor(const char *) {}
59  void endCodeAnchor() {}
60  void startFontClass(const char *) {}
61  void endFontClass() {}
62  void writeCodeAnchor(const char *) {}
63  void setCurrentDoc(const Definition *,const char *,bool) {}
64  void addWord(const char *,bool) {}
65 
66  // here we are presented with the symbols found by the code parser
67  void linkableSymbol(int l, const char *sym,Definition *symDef,Definition *context)
68  {
69  QCString ctx;
70  if (context) // the context of the symbol is known
71  {
72  if (context->definitionType()==Definition::TypeMember) // it is inside a member
73  {
74  Definition *parentContext = context->getOuterScope();
75  if (parentContext && parentContext->definitionType()==Definition::TypeClass)
76  // it is inside a member of a class
77  {
78  ctx.sprintf("inside %s %s of %s %s",
79  (dynamic_cast<MemberDef*>(context))->memberTypeName().data(),
80  context->name().data(),
81  (dynamic_cast<ClassDef*>(parentContext))->compoundTypeString().data(),
82  parentContext->name().data());
83  }
84  else if (parentContext==Doxygen::globalScope) // it is inside a global member
85  {
86  ctx.sprintf("inside %s %s",
87  (dynamic_cast<MemberDef*>(context))->memberTypeName().data(),
88  context->name().data());
89  }
90  }
91  if (ctx.isEmpty()) // it is something else (class, or namespace member, ...)
92  {
93  ctx.sprintf("in %s",context->name().data());
94  }
95  }
96  printf("Found symbol %s at line %d of %s %s\n",
97  sym,l,m_fd->getDefFileName().data(),ctx.data());
98  if (symDef && context) // in this case the definition of the symbol is
99  // known to doxygen.
100  {
101  printf("-> defined at line %d of %s\n",
102  symDef->getDefLine(),symDef->getDefFileName().data());
103  }
104  }
105  private:
107 };
108 
109 static void findXRefSymbols(FileDef *fd)
110 {
111  // get the interface to a parser that matches the file extension
113 
114  // get the programming language from the file name
116 
117  // reset the parsers state
118  intf.resetCodeParserState();
119 
120  // create a new backend object
122 
123  // parse the source code
124  intf.parseCode(*xrefGen,
125  0,
126  fileToString(fd->absFilePath()),
127  lang,
128  FALSE,
129  0,
130  fd);
131 
132  // dismiss the object.
133  delete xrefGen;
134 }
135 
136 static void listSymbol(Definition *d)
137 {
138  if (d!=Doxygen::globalScope && // skip the global namespace symbol
139  d->name().at(0)!='@' // skip anonymous stuff
140  )
141  {
142  printf("%s\n",
143  d->name().data());
144  }
145 }
146 
147 static void listSymbols()
148 {
150  DefinitionIntf *di;
151  for (sli.toFirst();(di=sli.current());++sli)
152  {
153  if (di->definitionType()==DefinitionIntf::TypeSymbolList) // list of symbols
154  // with same name
155  {
157  Definition *d;
158  // for each symbol
159  for (dli.toFirst();(d=dli.current());++dli)
160  {
161  listSymbol(d);
162  }
163  }
164  else // single symbol
165  {
166  listSymbol((Definition*)di);
167  }
168  }
169 }
170 
171 static void lookupSymbol(Definition *d)
172 {
173  if (d!=Doxygen::globalScope && // skip the global namespace symbol
174  d->name().at(0)!='@' // skip anonymous stuff
175  )
176  {
177  printf("Symbol info\n");
178  printf("-----------\n");
179  printf("Name: %s\n",d->name().data());
180  printf("File: %s\n",d->getDefFileName().data());
181  printf("Line: %d\n",d->getDefLine());
182  // depending on the definition type we can case to the appropriate
183  // derived to get additional information
184  switch (d->definitionType())
185  {
187  {
188  ClassDef *cd = dynamic_cast<ClassDef*>(d);
189  printf("Kind: %s\n",cd->compoundTypeString().data());
190  }
191  break;
193  {
194  FileDef *fd = dynamic_cast<FileDef*>(d);
195  printf("Kind: File: #includes %d other files\n",
196  fd->includeFileList() ? fd->includeFileList()->count() : 0);
197  }
198  break;
200  {
201  NamespaceDef *nd = dynamic_cast<NamespaceDef*>(d);
202  printf("Kind: Namespace: contains %d classes and %d namespaces\n",
203  nd->getClassSDict() ? nd->getClassSDict()->count() : 0,
204  nd->getNamespaceSDict() ? nd->getNamespaceSDict()->count() : 0);
205  }
206  break;
208  {
209  MemberDef *md = dynamic_cast<MemberDef*>(d);
210  printf("Kind: %s\n",md->memberTypeName().data());
211  }
212  break;
213  default:
214  // ignore groups/pages/packages/dirs for now
215  break;
216  }
217  }
218 }
219 
220 static void lookupSymbols(const QCString &sym)
221 {
222  if (!sym.isEmpty())
223  {
224  DefinitionIntf *di = Doxygen::symbolMap->find(sym);
225  if (di)
226  {
228  {
230  Definition *d;
231  // for each symbol with the given name
232  for (dli.toFirst();(d=dli.current());++dli)
233  {
234  lookupSymbol(d);
235  }
236  }
237  else
238  {
239  lookupSymbol((Definition*)di);
240  }
241  }
242  else
243  {
244  printf("Unknown symbol\n");
245  }
246  }
247 }
248 
249 int main(int argc,char **argv)
250 {
251  char cmd[256];
252 
253  if (argc<2)
254  {
255  printf("Usage: %s [source_file | source_dir]\n",argv[0]);
256  exit(1);
257  }
258 
259  // initialize data structures
260  initDoxygen();
261 
262  // setup the non-default configuration options
263 
266  // we need a place to put intermediate files
267  Config_getString(OUTPUT_DIRECTORY)="/tmp/doxygen";
268  // disable html output
269  Config_getBool(GENERATE_HTML)=FALSE;
270  // disable latex output
271  Config_getBool(GENERATE_LATEX)=FALSE;
272  // be quiet
273  Config_getBool(QUIET)=TRUE;
274  // turn off warnings
275  Config_getBool(WARNINGS)=FALSE;
276  Config_getBool(WARN_IF_UNDOCUMENTED)=FALSE;
277  Config_getBool(WARN_IF_DOC_ERROR)=FALSE;
278  // Extract as much as possible
279  Config_getBool(EXTRACT_ALL)=TRUE;
280  Config_getBool(EXTRACT_STATIC)=TRUE;
281  Config_getBool(EXTRACT_PRIVATE)=TRUE;
282  Config_getBool(EXTRACT_LOCAL_METHODS)=TRUE;
283  // Extract source browse information, needed
284  // to make doxygen gather the cross reference info
285  Config_getBool(SOURCE_BROWSER)=TRUE;
286  // In case of a directory take all files on directory and its subdirectories
287  Config_getBool(RECURSIVE)=TRUE;
288 
289  // set the input
290  Config_getList(INPUT).clear();
291  Config_getList(INPUT).append(argv[1]);
292 
293  // parse the files
294  parseInput();
295 
296  // iterate over the input files
297  for (const auto &fn : *Doxygen::inputNameLinkedMap)
298  {
299  for (const auto &fd : *fn)
300  {
301  // get the references (linked and unlinked) found in this file
302  findXRefSymbols(fd.get());
303  }
304  }
305 
306  // remove temporary files
309  // clean up after us
310  QDir().rmdir("/tmp/doxygen");
311 
312  while (1)
313  {
314  printf("> Type a symbol name or\n> .list for a list of symbols or\n> .quit to exit\n> ");
315  fgets(cmd,256,stdin);
316  QCString s(cmd);
317  if (s.at(s.length()-1)=='\n') s=s.left(s.length()-1); // strip trailing \n
318  if (s==".list")
319  listSymbols();
320  else if (s==".quit")
321  exit(0);
322  else
323  lookupSymbols(s);
324  }
325 }
326 
listSymbols
static void listSymbols()
Definition: doxyapp.cpp:147
qfile.h
NamespaceDef::getClassSDict
virtual ClassSDict * getClassSDict() const =0
QDictIterator
The QDictIterator class provides an iterator for QDict collections.
getLanguageFromFileName
SrcLangExt getLanguageFromFileName(const QCString &fileName)
Definition: util.cpp:6876
findXRefSymbols
static void findXRefSymbols(FileDef *fd)
Definition: doxyapp.cpp:109
QCString::isEmpty
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition: qcstring.h:191
XRefDummyCodeGenerator::XRefDummyCodeGenerator
XRefDummyCodeGenerator(FileDef *fd)
Definition: doxyapp.cpp:45
Doxygen::parserManager
static ParserManager * parserManager
Definition: doxygen.h:130
ClassDef
A abstract class representing of a compound symbol.
Definition: classdef.h:61
XRefDummyCodeGenerator::startCodeAnchor
void startCodeAnchor(const char *)
Definition: doxyapp.cpp:58
MemberDef::memberTypeName
virtual QCString memberTypeName() const =0
Definition::getDefLine
virtual int getDefLine() const =0
XRefDummyCodeGenerator::endFontClass
void endFontClass()
Definition: doxyapp.cpp:61
lookupSymbols
static void lookupSymbols(const QCString &sym)
Definition: doxyapp.cpp:220
namespacedef.h
checkConfiguration
void checkConfiguration()
check and resolve config options
Definition: doxygen.cpp:10214
SrcLangExt
SrcLangExt
Language as given by extension.
Definition: types.h:43
Doxygen::entryDBFileName
static QCString entryDBFileName
Definition: doxygen.h:134
data
const char *const void * data
Definition: iconv.h:120
Definition::getDefFileExtension
virtual QCString getDefFileExtension() const =0
QCString::length
uint length() const
Returns the length of the string, excluding the 0-terminator.
Definition: qcstring.h:197
FileDef::includeFileList
virtual QList< IncludeInfo > * includeFileList() const =0
languages.l
l
Definition: languages.py:75
XRefDummyCodeGenerator::codify
void codify(const char *)
Definition: doxyapp.cpp:50
DocLinkInfo
Definition: outputgen.h:41
Doxygen::inputNameLinkedMap
static FileNameLinkedMap * inputNameLinkedMap
Definition: doxygen.h:103
filename.h
initDoxygen
void initDoxygen()
Definition: doxygen.cpp:9669
config.h
FileDef::name
virtual QCString name() const =0
DefinitionList
A list of Definition objects.
Definition: definition.h:379
XRefDummyCodeGenerator::setCurrentDoc
void setCurrentDoc(const Definition *, const char *, bool)
Definition: doxyapp.cpp:63
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:134
DefinitionIntf
Abstract interface for a Definition or DefinitionList.
Definition: definition.h:73
DefinitionIntf::TypeMember
@ TypeMember
Definition: definition.h:83
FileDef
A model of a file symbol.
Definition: filedef.h:65
ParserManager::getCodeParser
CodeParserInterface & getCodeParser(const char *extension)
Gets the interface to the parser associated with given extension.
Definition: parserintf.h:227
Config_getString
#define Config_getString(val)
Definition: config.h:34
MemberDef
A model of a class/file/namespace member symbol.
Definition: memberdef.h:45
XRefDummyCodeGenerator::startCodeLine
void startCodeLine(bool)
Definition: doxyapp.cpp:56
TRUE
@ TRUE
Definition: mscgen_bool.h:29
outputgen.h
FALSE
@ FALSE
Definition: mscgen_bool.h:28
classlist.h
Definition::getOuterScope
virtual Definition * getOuterScope() const =0
ClassDef::compoundTypeString
virtual QCString compoundTypeString() const =0
Returns the type of compound as a string.
XRefDummyCodeGenerator::linkableSymbol
void linkableSymbol(int l, const char *sym, Definition *symDef, Definition *context)
Definition: doxyapp.cpp:67
XRefDummyCodeGenerator::writeCodeLink
void writeCodeLink(const char *, const char *, const char *, const char *, const char *)
Definition: doxyapp.cpp:51
listSymbol
static void listSymbol(Definition *d)
Definition: doxyapp.cpp:136
QCString::at
char & at(uint i) const
Returns a reference to the character at index i.
Definition: qcstring.h:329
Config_getList
#define Config_getList(val)
Definition: config.h:38
DefinitionIntf::TypeFile
@ TypeFile
Definition: definition.h:81
NamespaceDef
An abstract interface of a namespace symbol.
Definition: namespacedef.h:38
Doxygen::globalScope
static NamespaceDef * globalScope
Definition: doxygen.h:118
CodeParserInterface::parseCode
virtual void parseCode(CodeOutputInterface &codeOutIntf, const char *scopeName, const QCString &input, SrcLangExt lang, bool isExampleBlock, const char *exampleName=0, FileDef *fileDef=0, int startLine=-1, int endLine=-1, bool inlineFragment=FALSE, const MemberDef *memberDef=0, bool showLineNumbers=TRUE, const Definition *searchCtx=0, bool collectXRefs=TRUE)=0
Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.
doxygen.h
XRefDummyCodeGenerator::writeTooltip
virtual void writeTooltip(const char *, const DocLinkInfo &, const char *, const char *, const SourceLinkInfo &, const SourceLinkInfo &)
Definition: doxyapp.cpp:53
QDir
Implementation of QDir class.
Definition: qdir.h:53
parserintf.h
XRefDummyCodeGenerator
Definition: doxyapp.cpp:43
main
int main(int argc, char **argv)
Definition: doxyapp.cpp:249
XRefDummyCodeGenerator::m_fd
FileDef * m_fd
Definition: doxyapp.cpp:106
CodeParserInterface::resetCodeParserState
virtual void resetCodeParserState()=0
Resets the state of the code parser.
DefinitionIntf::TypeClass
@ TypeClass
Definition: definition.h:80
XRefDummyCodeGenerator::startFontClass
void startFontClass(const char *)
Definition: doxyapp.cpp:60
QList::count
uint count() const
Definition: qlist.h:66
DefinitionIntf::definitionType
virtual DefType definitionType() const =0
QListIterator::current
type * current() const
Definition: qlist.h:147
CodeOutputInterface
Output interface for code parser.
Definition: outputgen.h:60
Definition
The common base class of all entity definitions found in the sources.
Definition: definition.h:100
filedef.h
QCString::left
QCString left(uint len) const
Definition: qcstring.cpp:241
Definition::getDefFileName
virtual QCString getDefFileName() const =0
XRefDummyCodeGenerator::writeCodeAnchor
void writeCodeAnchor(const char *)
Definition: doxyapp.cpp:62
DefinitionIntf::TypeSymbolList
@ TypeSymbolList
Definition: definition.h:88
NamespaceDef::getNamespaceSDict
virtual const NamespaceSDict * getNamespaceSDict() const =0
Doxygen::symbolMap
static QDict< DefinitionIntf > * symbolMap
Definition: doxygen.h:123
XRefDummyCodeGenerator::endCodeLine
void endCodeLine()
Definition: doxyapp.cpp:57
QListIterator::toFirst
type * toFirst()
Definition: qlist.h:136
DefinitionListIterator
An iterator for Definition objects in a DefinitionList.
Definition: definition.h:392
adjustConfiguration
void adjustConfiguration()
adjust globals that depend on configuration settings.
Definition: doxygen.cpp:10223
classdef.h
parseInput
void parseInput()
Definition: doxygen.cpp:10642
QCString::data
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition: qcstring.h:209
SDict::count
uint count() const
Definition: sortdict.h:280
XRefDummyCodeGenerator::~XRefDummyCodeGenerator
~XRefDummyCodeGenerator()
Definition: doxyapp.cpp:46
CodeParserInterface
Abstract interface for code parsers.
Definition: parserintf.h:101
SourceLinkInfo
Definition: outputgen.h:49
Config_getBool
#define Config_getBool(val)
Definition: config.h:35
QDir::rmdir
virtual bool rmdir(const QString &dirName, bool acceptAbsPath=TRUE) const
Definition: qdir_unix.cpp:104
qdir.h
QFile::remove
bool remove()
Definition: qfile.cpp:205
XRefDummyCodeGenerator::addWord
void addWord(const char *, bool)
Definition: doxyapp.cpp:64
Definition::name
virtual QCString name() const =0
XRefDummyCodeGenerator::endCodeAnchor
void endCodeAnchor()
Definition: doxyapp.cpp:59
util.h
Copyright (C) 1997-2015 by Dimitri van Heesch.
lookupSymbol
static void lookupSymbol(Definition *d)
Definition: doxyapp.cpp:171
XRefDummyCodeGenerator::writeLineNumber
void writeLineNumber(const char *, const char *, const char *, int)
Definition: doxyapp.cpp:52
QCString::sprintf
QCString & sprintf(const char *format,...)
Copyright (C) 1997-2015 by Dimitri van Heesch.
Definition: qcstring.cpp:28
fileToString
QCString fileToString(const char *name, bool filter, bool isSourceCode)
Definition: util.cpp:2506
FileDef::absFilePath
virtual QCString absFilePath() const =0
Doxygen::objDBFileName
static QCString objDBFileName
Definition: doxygen.h:133
DefinitionIntf::TypeNamespace
@ TypeNamespace
Definition: definition.h:82