Thread: [Doxygen-develop] [PATCH] [1/2] prototype mistaken as class constructor: recognize pointers
Brought to you by:
dimitri
From: Dave D. <do...@do...> - 2005-12-19 22:30:18
|
Symptom: Some function prototypes end up being treated as constructor calls. Example: /** \brief something */ typedef struct { int x; } t; extern t foo(struct t *); // declaration /** \brief something */ t foo(struct t * x) // definition Doxygen thinks that the declaration is actually a variable being created with a call to a constructor for type t. It ends up putting it in the "Variables" section. This patch adds a check of the arguments being passed to the function that might be a constructor. If any argument ends in an asterisk, it must be a bare pointer type with no parameter name and therefore this must be a function prototype instead of a constructor call. Index: doxygen-1.4.5/src/doxygen.cpp =================================================================== --- doxygen-1.4.5.orig/src/doxygen.cpp 2005-11-11 12:07:22.000000000 -0500 +++ doxygen-1.4.5/src/doxygen.cpp 2005-11-11 12:20:06.000000000 -0500 @@ -1972,6 +1972,13 @@ result=FALSE; // arg type is a known type goto done; } + // If the argument is a pointer type, then this is a function prototype. + if (a->type.find('*',a->type.length()-1)!=-1) + { + //printf("%s:%d: false (arg is a pointer)\n",__FILE__,__LINE__); + result=FALSE; + goto done; + } if (a->type.find(initChars)==0) { result=TRUE; // argument type starts with typical initializer char |
From: Dave D. <do...@do...> - 2005-12-19 22:35:11
|
Symptom: Some function prototypes end up being treated as constructor calls. Example: /** \brief something */ typedef struct { int x; } t1; /** \brief something */ typedef int t2; extern t1 foo(t2); // declaration /** \brief something */ t1 foo(t2 x) // definition Doxygen thinks that the declaration is actually a variable being created with a call to a constructor for type t. It ends up putting it in the "Variables" section. This patch adds a check to the arguments being passed to the function that might be a constructor. If any argument consists entirely of a typedef name, it must be a bare type with no parameter name and therefore this must be a function prototype instead of a constructor call. Index: doxygen-1.4.5/src/doxygen.cpp =================================================================== --- doxygen-1.4.5.orig/src/doxygen.cpp 2005-11-11 12:20:37.000000000 -0500 +++ doxygen-1.4.5/src/doxygen.cpp 2005-11-11 12:25:40.000000000 -0500 @@ -1972,6 +1972,13 @@ result=FALSE; // arg type is a known type goto done; } + // If the parameter is just a typedef, then this is a function prototype. + if(checkIfTypedef(ctx,fd,a->type)) + { + //printf("%s:%d: false (arg is typedef)\n",__FILE__,__LINE__); + result=FALSE; // argument is a typedef + goto done; + } // If the argument is a pointer type, then this is a function prototype. if (a->type.find('*',a->type.length()-1)!=-1) { Index: doxygen-1.4.5/src/util.h =================================================================== --- doxygen-1.4.5.orig/src/util.h 2005-11-11 12:06:59.000000000 -0500 +++ doxygen-1.4.5/src/util.h 2005-11-11 12:25:40.000000000 -0500 @@ -153,6 +153,7 @@ QCString *pTemplSpec=0, bool mayBeUnlinkable=FALSE, bool mayBeHidden=FALSE); +bool checkIfTypedef(Definition *scope,FileDef *fileScope,const char *n); NamespaceDef *getResolvedNamespace(const char *key); FileDef *findFileDef(const FileNameDict *fnDict,const char *n, bool &ambig); Index: doxygen-1.4.5/src/util.cpp =================================================================== --- doxygen-1.4.5.orig/src/util.cpp 2005-11-11 12:15:24.000000000 -0500 +++ doxygen-1.4.5/src/util.cpp 2005-11-11 12:25:40.000000000 -0500 @@ -1310,6 +1310,61 @@ return result; } +/*! Returns true iff the given name string appears to be a typedef in scope. */ +bool checkIfTypedef(Definition *scope,FileDef *fileScope,const char *n) +{ + if (scope==0 || + (scope->definitionType()!=Definition::TypeClass && + scope->definitionType()!=Definition::TypeNamespace + ) + ) + { + scope=Doxygen::globalScope; + } + + QCString name = n; + if (name.isEmpty()) + return false; // no name was given + + DefinitionList *dl = Doxygen::symbolMap->find(name); + if (dl==0) + return false; // could not find any matching symbols + + // mostly copied from getResolvedClassRec() + QCString explicitScopePart; + int qualifierIndex = computeQualifiedIndex(name); + if (qualifierIndex!=-1) + { + explicitScopePart = name.left(qualifierIndex); + replaceNamespaceAliases(explicitScopePart,explicitScopePart.length()); + name = name.mid(qualifierIndex+2); + } + + // find the closest closest matching definition + DefinitionListIterator dli(*dl); + Definition *d; + int minDistance = 10000; + MemberDef *bestMatch = 0; + for (dli.toFirst();(d=dli.current());++dli) + { + if (d->definitionType()==Definition::TypeMember) + { + g_visitedNamespaces.clear(); + int distance = isAccessibleFromWithExpScope(scope,fileScope,d,explicitScopePart); + if (distance!=-1 && distance<minDistance) + { + minDistance = distance; + bestMatch = (MemberDef *)d; + } + } + } + + if (bestMatch && bestMatch->isTypedef()) + return true; // closest matching symbol is a typedef + else + return false; +} + //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- |
Re: [Doxygen-develop] [PATCH] [2/2] prototype mistaken as class constructor:
recognize typedef names
From: Kevin M. <ke...@pl...> - 2005-12-20 01:09:58
|
Hello Dave. It's a good thing that you are submitting patches to the developer list, and we appreciate you submitting your patches. However, we prefer all bugs to be filed within the bugzilla, even if you have the patches to fix the bugs. Doing so makes it easier for us to add fixed bugs to the ChangeLogs. :) Thank you, - KJM |
Re: [Doxygen-develop] [PATCH] [2/2] prototype mistaken as class constructor: recognize typedef names
From: Dave D. <do...@do...> - 2005-12-20 05:48:00
|
On Mon, Dec 19, 2005 at 08:13:26PM -0500, Kevin McBride wrote: > It's a good thing that you are submitting patches to the developer list, > and we appreciate you submitting your patches. However, we prefer all > bugs to be filed within the bugzilla, even if you have the patches to > fix the bugs. Okay. I've submitted them as bugs 324565, 324566, and 324568. BTW: On this page: http://www.stack.nl/~dimitri/doxygen/trouble.html#bug_reports it says "please use PATCH as a keyword in the bug report", but note that: - The Bugzilla "new patch" forms never ask you for keywords, which was confusing at first. - If you view the bug after submitting it, there is a keywords field. But when I try to put PATCH in there, Bugzilla complains that "PATCH" is not a valid keyword. I notice that if I get Bugzilla to list all valid keywords, "PATCH" is not listed, but some of the keyword descriptions mention it. So I'm guessing that it used to be a valid keyword but was later deprecated. -Dave Dodge |
Re: [Doxygen-develop] [PATCH] [2/2] prototype mistaken as class constructor:
recognize typedef names
From: Kevin M. <ke...@pl...> - 2005-12-20 05:59:13
|
Dimitri, we need to correct the information regarding the PATCH keyword - GNOME bugzilla doesn't have it anymore! Excerpt from #bugs: epn: bugzilla didn't use to be able to track or search for patches in any special way epn: so, we manually had volunteers try to mark all of them with the PATCH keyword epn: we couldn't ever really keep up epn: then, bugzilla got the abilities to search for it, and we eventually nuked the keyword Dave Dodge wrote: > BTW: On this page: > > http://www.stack.nl/~dimitri/doxygen/trouble.html#bug_reports > > it says "please use PATCH as a keyword in the bug report", but note > that: > > - The Bugzilla "new patch" forms never ask you for keywords, which > was confusing at first. > > - If you view the bug after submitting it, there is a keywords field. > But when I try to put PATCH in there, Bugzilla complains that > "PATCH" is not a valid keyword. I notice that if I get Bugzilla to > list all valid keywords, "PATCH" is not listed, but some of the > keyword descriptions mention it. So I'm guessing that it used to be > a valid keyword but was later deprecated. > > -Dave Dodge > > > ------------------------------------------------------- This SF.net > email is sponsored by: Splunk Inc. Do you grep through log files for > problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD > SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click > _______________________________________________ Doxygen-develop > mailing list Dox...@li... > https://lists.sourceforge.net/lists/listinfo/doxygen-develop > |