Re: doxyparse addon - simple code parse based on doxyapp

Joenio Costa <[email protected]>
Newsgroups gmane.text.doxygen.devel
Message-ID <20090721042803.GA15078@debian>
ops!

I forgot the attachment.

-- 
Joenio Costa
- www.Colivre.coop.br
- www.Perl.org.br
- Salvador.pm.org

GNU/Linux User #431067 http://counter.li.org

On Tue, Jul 21, 2009 at 12:36:39AM -0300, Joenio Costa wrote:
> Hi Dimitri,
> 
> On Sat, Jul 18, 2009 at 04:54:16PM +0200, Dimitri Van Heesch wrote:
> > Sounds interesting.
> 
> Thanks!
> 
> > Can you give (a pointer to) more detailed information about
> > what the tool does? (i.e. the kind of dependencies it extracts, and the
> > form in which they presented)
> 
> Yes, sure!
> 
> Basically doxyparse extract informations about declarations and use of
> symbols found in source code. Follow a small example running doxyparse
> over addon/doxyapp sources:
> 
> ----------------------------------------------------
> ~/src/doxygen$ ./bin/doxyparse addon/doxyapp/
> module doxyapp.cpp
>    function findXRefSymbols in line 97
>    function listSymbol in line 120
>    function listSymbols in line 131
>       uses function listSymbol defined in doxyapp.cpp
>    function lookupSymbol in line 155
>    function lookupSymbols in line 204
>       uses function lookupSymbol defined in doxyapp.cpp
>    function main in line 233
>       uses function findXRefSymbols defined in doxyapp.cpp
>       uses function listSymbols defined in doxyapp.cpp
>       uses function lookupSymbols defined in doxyapp.cpp
> ----------------------------------------------------
> 
> Here doxyparse says for example:
> 
> "module doxyapp.cpp declares function findXRefSymbols"
> 
> > Can you make the changes available to developers that do not yet use
> > git (like myself)?
> > (i.e. as a tarball or as a patch on the current SVN repository)
> 
> Sorry!
> 
> I attach a diff in this email.
> 
> to compile:
> ./configure --with-doxyparse
> 
> > Regards,
> >  Dimitri
> 
> Best regards,
> -- 
> Joenio Costa
> - www.Colivre.coop.br
> - www.Perl.org.br
> - Salvador.pm.org
> 
> GNU/Linux User #431067 http://counter.li.org
> 
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge  
> This is your chance to win up to $100,000 in prizes! For a limited time, 
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize  
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Doxygen-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/doxygen-develop

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge

_______________________________________________
Doxygen-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/doxygen-develop
doxyparse.diff (text/x-diff, 13.4 KB)
diff --git a/Makefile.in b/Makefile.in
index 618fb05..d4669ca 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -27,6 +27,7 @@ distclean: clean
 	cd addon/doxmlparser/test ; $(MAKE) distclean
 	cd addon/doxmlparser/examples/metrics ; $(MAKE) distclean
 	cd addon/doxyapp ; $(MAKE) distclean
+	cd addon/doxyparse ; $(MAKE) distclean
 	-rm -f lib/lib*
 	-rm -f bin/doxy*
 	-rm -f html
@@ -42,6 +43,8 @@ distclean: clean
 	-rm -f src/version.cpp
 	-rm -r addon/doxywizard/Makefile
 	-rm -f addon/doxywizard/doxywizard.pro
+	-rm -r addon/doxyparse/Makefile
+	-rm -f addon/doxyparse/doxyparse.pro
 	-rm -f VERSION
 	-rm -f packages/rpm/doxygen.spec
 
@@ -53,13 +56,17 @@ install: doxywizard_install
 	$(INSTTOOL) -d $(DESTDIR)/$(INSTALL)/bin
 	$(INSTTOOL) -m 755 bin/doxygen    $(DESTDIR)/$(INSTALL)/bin
 	$(INSTTOOL) -m 755 bin/doxytag    $(DESTDIR)/$(INSTALL)/bin
+	$(INSTTOOL) -m 755 bin/doxyparse    $(DESTDIR)/$(INSTALL)/bin
 	$(INSTTOOL) -d $(DESTDIR)/$(INSTALL)/$(MAN1DIR)
 	cat doc/doxygen.1    | sed -e "s/DATE/$(DATE)/g" -e "s/VERSION/$(VERSION)/g" > doxygen.1 
 	$(INSTTOOL) -m 644 doxygen.1 $(DESTDIR)/$(INSTALL)/$(MAN1DIR)/doxygen.1
 	rm doxygen.1
 	cat doc/doxytag.1    | sed -e "s/DATE/$(DATE)/g" -e "s/VERSION/$(VERSION)/g" > doxytag.1
+	cat addon/doxyparse/doxyparse.1    | sed -e "s/DATE/$(DATE)/g" -e "s/VERSION/$(VERSION)/g" > doxyparse.1
 	$(INSTTOOL) -m 644 doxytag.1 $(DESTDIR)/$(INSTALL)/$(MAN1DIR)/doxytag.1
+	$(INSTTOOL) -m 644 doxyparse.1 $(DESTDIR)/$(INSTALL)/$(MAN1DIR)/doxyparse.1
 	rm doxytag.1
+	rm doxyparse.1
 
 install_docs: 
 	$(INSTTOOL) -d $(DESTDIR)/$(DOCDIR)
diff --git a/addon/doxyparse/Makefile.in b/addon/doxyparse/Makefile.in
new file mode 100644
index 0000000..b26f11c
--- /dev/null
+++ b/addon/doxyparse/Makefile.in
@@ -0,0 +1,17 @@
+
+all clean depend distclean: Makefile.doxyparse
+	$(MAKE) -f Makefile.doxyparse $@
+
+distclean: clean
+	$(RM) -rf Makefile doxyparse.pro Makefile.doxyparse
+
+tmake:
+	$(ENV) $(PERL) $(TMAKE) doxyparse.pro >Makefile.doxyparse
+
+strip:
+	strip doxyparse
+
+Makefile.doxyparse: doxyparse.pro
+	$(ENV) $(PERL) $(TMAKE) doxyparse.pro >Makefile.doxyparse
+
+install:
diff --git a/addon/doxyparse/README b/addon/doxyparse/README
new file mode 100644
index 0000000..e91da3d
--- /dev/null
+++ b/addon/doxyparse/README
@@ -0,0 +1,6 @@
+This directory contains an "source parsing engine" based on doxyapp code.
+
+More info and source code repository: http://gitorious.org/doxygen/
+
+---
+Joenio Costa <[email protected]>
diff --git a/addon/doxyparse/doxyparse.1 b/addon/doxyparse/doxyparse.1
new file mode 100644
index 0000000..d8530ab
--- /dev/null
+++ b/addon/doxyparse/doxyparse.1
@@ -0,0 +1,10 @@
+.TH DOXYPARSE "1" "DATE" "doxyparse VERSION" "User Commands"
+.SH NAME
+doxyparse \- parse and dumps informations about the code
+.SH SYNOPSIS
+.B doxyparse
+[\fIsource file\fR...]
+.SH DESCRIPTION
+Parses source code and dumps the dependencies between the code elements.
+.SH SEE ALSO
+doxygen(1), doxytag(1), doxywizard(1).
diff --git a/addon/doxyparse/doxyparse.cpp b/addon/doxyparse/doxyparse.cpp
new file mode 100644
index 0000000..06371b3
--- /dev/null
+++ b/addon/doxyparse/doxyparse.cpp
@@ -0,0 +1,217 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2009 by Joenio Costa.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation under the terms of the GNU General Public License is hereby
+ * granted. No representations are made about the suitability of this software
+ * for any purpose. It is provided "as is" without express or implied warranty.
+ * See the GNU General Public License for more details.
+ *
+ * Documents produced by Doxygen are derivative works derived from the
+ * input used in their production; they are not affected by this license.
+ *
+ */
+
+/** @file
+ *  @brief Code parse based on doxyapp by Dimitri van Heesch
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include "doxygen.h"
+#include "outputgen.h"
+#include "parserintf.h"
+
+class Doxyparse : public CodeOutputInterface
+{
+  public:
+    Doxyparse(FileDef *fd) : m_fd(fd) {}
+   ~Doxyparse() {}
+
+    // these are just null functions, they can be used to produce a syntax highlighted
+    // and cross-linked version of the source code, but who needs that anyway ;-)
+    void codify(const char *) {}
+    void writeCodeLink(const char *,const char *,const char *,const char *,const char *)  {}
+    void startCodeLine() {}
+    void endCodeLine() {}
+    void startCodeAnchor(const char *) {}
+    void endCodeAnchor() {}
+    void startFontClass(const char *) {}
+    void endFontClass() {}
+    void writeCodeAnchor(const char *) {}
+    void writeLineNumber(const char *,const char *,const char *,int) {}
+
+    void linkableSymbol(int l, const char *sym, Definition *symDef, Definition *context)
+    {
+      if (!symDef) {
+        // in this case we have a local or external symbol
+
+        // TODO record use of external symbols
+        // TODO must have a way to differentiate external symbols from local variables
+      }
+    }
+
+  private:
+    FileDef *m_fd;
+};
+
+static void findXRefSymbols(FileDef *fd)
+{
+  // get the interface to a parser that matches the file extension
+  ParserInterface *pIntf=Doxygen::parserManager->getParser(fd->getDefFileExtension());
+
+  // reset the parsers state
+  pIntf->resetCodeParserState();
+
+  // create a new backend object
+  Doxyparse *parse = new Doxyparse(fd);
+
+  // parse the source code
+  pIntf->parseCode(*parse, 0, fileToString(fd->absFilePath()), FALSE, 0, fd);
+
+  // dismiss the object.
+  delete parse;
+}
+
+static bool ignoreStaticExternalCall(MemberDef *context, MemberDef *md) {
+  if (md->isStatic()) {
+    if(md->getFileDef()) {
+      if(md->getFileDef()->getFileBase() == context->getFileDef()->getFileBase())
+        // TODO ignore prefix of file
+        return false;
+      else
+        return true;
+    }
+    else {
+      return false;
+    }
+  }
+  else {
+    return false;
+  }
+}
+
+static void printReferencesMembers(MemberDef *md) {
+  LockingPtr<MemberSDict> defDict = md->getReferencesMembers();
+  if (defDict != 0) {
+    MemberSDict::Iterator msdi(*defDict);
+    MemberDef *rmd;
+    for (msdi.toFirst(); (rmd=msdi.current()); ++msdi) {
+      if (rmd->definitionType() == Definition::TypeMember && !ignoreStaticExternalCall(md, rmd)) {
+        printf("      uses %s %s", rmd->memberTypeName().data(), rmd->name().data());
+        if (rmd->getFileDef())
+          printf(" defined in %s\n", rmd->getFileDef()->getFileBase().data());
+        else
+          printf("\n");
+      }
+    }
+  }
+}
+
+static void lookupSymbol(Definition *d) {
+  if (d->definitionType() == Definition::TypeMember) {
+    MemberDef *md = (MemberDef *)d;
+      printf("   %s %s in line %d\n", md->memberTypeName().data(), d->name().data(), d->getDefLine());
+      if (md->isFunction())
+        printReferencesMembers(md);
+  }
+}
+
+static void listSymbols() {
+  // iterate over the input files
+  FileNameListIterator fnli(*Doxygen::inputNameList);
+  FileName *fn;
+  // for each file with a certain name
+  for (fnli.toFirst(); (fn=fnli.current()); ++fnli) {
+    FileNameIterator fni(*fn);
+    FileDef *fd;
+    for (; (fd=fni.current()); ++fni) {
+      MemberList *ml = fd->getMemberList(MemberList::allMembersList);
+      if (ml && ml->count() > 0) {
+        printf("module %s\n", fd->getFileBase().data());
+        MemberListIterator mli(*ml);
+        MemberDef *md;
+        for (mli.toFirst(); (md=mli.current()); ++mli) {
+          lookupSymbol((Definition*) md);
+        }
+        printf("\n");
+      }
+    }
+  }
+  // TODO print external symbols referenced
+}
+
+int main(int argc,char **argv) {
+  if (argc < 2) {
+    printf("Usage: %s [source_file | source_dir]\n",argv[0]);
+    exit(1);
+  }
+
+  // initialize data structures
+  initDoxygen();
+
+  // setup the non-default configuration options
+
+  // we need a place to put intermediate files
+  Config_getString("OUTPUT_DIRECTORY")="/tmp/doxyparse";
+  // enable HTML (fake) output to omit warning about missing output format
+  Config_getBool("GENERATE_HTML")=TRUE;
+  // disable latex output
+  Config_getBool("GENERATE_LATEX")=FALSE;
+  // be quiet
+  Config_getBool("QUIET")=TRUE;
+  // turn off warnings
+  Config_getBool("WARNINGS")=FALSE;
+  Config_getBool("WARN_IF_UNDOCUMENTED")=FALSE;
+  Config_getBool("WARN_IF_DOC_ERROR")=FALSE;
+  // Extract as much as possible
+  Config_getBool("EXTRACT_ALL")=TRUE;
+  Config_getBool("EXTRACT_STATIC")=TRUE;
+  Config_getBool("EXTRACT_PRIVATE")=TRUE;
+  Config_getBool("EXTRACT_LOCAL_METHODS")=TRUE;
+  // Extract source browse information, needed
+  // to make doxygen gather the cross reference info
+  Config_getBool("SOURCE_BROWSER")=TRUE;
+  // find functions call between modules
+  Config_getBool("CALL_GRAPH")=TRUE;
+  // loop recursive over input files
+  Config_getBool("RECURSIVE")=TRUE;
+  // set the input
+  Config_getList("INPUT").clear();
+  for (int i = 1; i < argc; i++) {
+    Config_getList("INPUT").append(argv[i]);
+  }
+
+  // check and finalize the configuration
+  checkConfiguration();
+  adjustConfiguration();
+
+  // parse the files
+  parseInput();
+
+  // iterate over the input files
+  FileNameListIterator fnli(*Doxygen::inputNameList);
+  FileName *fn;
+  // for each file with a certain name
+  for (fnli.toFirst();(fn=fnli.current());++fnli) {
+    FileNameIterator fni(*fn);
+    FileDef *fd;
+    // for each file definition
+    for (;(fd=fni.current());++fni) {
+      // get the references (linked and unlinked) found in this file
+      findXRefSymbols(fd);
+    }
+  }
+
+  // remove temporary files
+  if (!Doxygen::objDBFileName.isEmpty()) unlink(Doxygen::objDBFileName);
+  if (!Doxygen::entryDBFileName.isEmpty()) unlink(Doxygen::entryDBFileName);
+  // clean up after us
+  rmdir(Config_getString("OUTPUT_DIRECTORY"));
+
+  listSymbols();
+
+  exit(0);
+}
diff --git a/addon/doxyparse/doxyparse.pro.in b/addon/doxyparse/doxyparse.pro.in
new file mode 100644
index 0000000..5342531
--- /dev/null
+++ b/addon/doxyparse/doxyparse.pro.in
@@ -0,0 +1,11 @@
+TEMPLATE     =	app.t
+CONFIG       =	console warn_on debug
+HEADERS      =
+SOURCES      =	doxyparse.cpp
+LIBS          += -L../../lib -L../../lib -ldoxygen -lqtools -lmd5 -ldoxycfg -lpng
+DESTDIR        =
+OBJECTS_DIR    = ../../objects
+TARGET         = ../../bin/doxyparse
+INCLUDEPATH   += ../../qtools ../../src
+DEPENDPATH    += ../../src
+TARGETDEPS     = ../../lib/libdoxygen.a
diff --git a/configure b/configure
index dc6bf06..ef9de89 100755
--- a/configure
+++ b/configure
@@ -35,6 +35,7 @@ f_insttool=NO
 f_english=NO
 f_wizard=NO
 f_app=NO
+f_parse=NO
 f_thread=NO
 f_flex=NO
 f_bison=NO
@@ -93,6 +94,9 @@ while test -n "$1";  do
     --with-doxyapp | -with-doxyapp)
        f_app=YES
        ;;
+    --with-doxyparse | -with-doxyparse)
+       f_parse=YES
+       ;;
     -h | -help | --help)
        f_help=y
        ;;
@@ -111,7 +115,7 @@ Usage: $0 [--help] [--shared] [--static] [--release] [--debug]
           [--perl name] [--flex name] [--bison name] [--make name] 
           [--dot name] [--platform target] [--prefix dir] [--docdir dir] 
           [--install name] [--english-only] [----enable-langs list] 
-          [--with-doxywizard] [--with-doxyapp]
+          [--with-doxywizard] [--with-doxyapp] [--with-doxyparse]
 
 Options: 
 
@@ -146,6 +150,7 @@ Options:
   --with-doxywizard     Build the GUI frontend for doxygen. This
                         requires Qt 3.3.x
   --with-doxyapp        Example showing how to embed doxygen in an application.
+  --with-doxyparse      Parses source code and dumps the dependencies between the code elements.
 
 EOF
   test "$f_error" = y && exit 1
@@ -575,7 +580,7 @@ TMAKE_CXXFLAGS += -DENGLISH_ONLY
 EOF
 fi
 
-f_inmakefiles="Makefile.in qtools/Makefile.in src/Makefile.in examples/Makefile.in doc/Makefile.in addon/doxywizard/Makefile.in addon/doxmlparser/src/Makefile.in addon/doxmlparser/test/Makefile.in addon/doxmlparser/examples/metrics/Makefile.in libpng/Makefile.in libmd5/Makefile.in addon/doxyapp/Makefile.in"
+f_inmakefiles="Makefile.in qtools/Makefile.in src/Makefile.in examples/Makefile.in doc/Makefile.in addon/doxywizard/Makefile.in addon/doxmlparser/src/Makefile.in addon/doxmlparser/test/Makefile.in addon/doxmlparser/examples/metrics/Makefile.in libpng/Makefile.in libmd5/Makefile.in addon/doxyapp/Makefile.in addon/doxyparse/Makefile.in"
 
 for i in $f_inmakefiles ; do
      SRC=$i
@@ -601,6 +606,9 @@ EOF
        if test $f_app = YES; then
          echo "	\$(MAKE) -C addon/doxyapp" >> $DST
        fi
+       if test $f_parse = YES; then
+         echo "	\$(MAKE) -C addon/doxyparse" >> $DST
+       fi
        echo "" >> $DST
        echo "doxywizard_install:" >> $DST
        if test $f_wizard = YES; then
@@ -616,7 +624,7 @@ EOF
      echo "  Created $DST from $SRC..."
 done
 
-f_inprofiles="qtools/qtools.pro.in src/libdoxygen.pro.in src/libdoxycfg.pro.in src/doxygen.pro.in src/doxytag.pro.in addon/doxywizard/doxywizard.pro.in addon/doxmlparser/src/doxmlparser.pro.in addon/doxmlparser/test/xmlparse.pro.in addon/doxmlparser/examples/metrics/metrics.pro.in libpng/libpng.pro.in libmd5/libmd5.pro.in addon/doxyapp/doxyapp.pro.in" 
+f_inprofiles="qtools/qtools.pro.in src/libdoxygen.pro.in src/libdoxycfg.pro.in src/doxygen.pro.in src/doxytag.pro.in addon/doxywizard/doxywizard.pro.in addon/doxmlparser/src/doxmlparser.pro.in addon/doxmlparser/test/xmlparse.pro.in addon/doxmlparser/examples/metrics/metrics.pro.in libpng/libpng.pro.in libmd5/libmd5.pro.in addon/doxyapp/doxyapp.pro.in addon/doxyparse/doxyparse.pro.in" 
 
 for i in $f_inprofiles ; do
      SRC=$i
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.