[Doxygen-develop] [PATCH] multi-word type names are not recognized in prototypes
Brought to you by:
dimitri
From: Dave D. <do...@do...> - 2005-12-19 22:27:43
|
This fixes handling of multi-word types in prototypes Symptom: Function prototypes using multi-word C types such as "unsigned int", "long long", or "struct foo" with no explicit parameter name fail to be linked to the function definition. Cause: As an example: int foo(unsigned int); // prototype declaration in header int foo(unsigned int x) // definition in .c file In the declaration, Doxygen thinks that "unsigned" is the type and "int" is the parameter name. It fails to match this to the definition, which has type "unsigned int" and name "x". Solution: If the parameter name is one of the C keywords that can appear at the end of a multi-word type, the name is merged into the type. Likewise if the last word of the type is a C keyword that is normally followed by a tag, the name is assumed to be a tag and is merged into the type. Index: doxygen-1.4.5/src/util.cpp =================================================================== --- doxygen-1.4.5.orig/src/util.cpp 2005-11-11 12:08:21.000000000 -0500 +++ doxygen-1.4.5/src/util.cpp 2005-11-11 12:15:24.000000000 -0500 @@ -2832,7 +2832,7 @@ static QCString extractCanonicalType(Definition *d,FileDef *fs,const Argument *arg) { QCString type = arg->type.stripWhiteSpace(); - QCString name = arg->name; + QCString name = arg->name.stripWhiteSpace(); //printf("extractCanonicalType(type=%s,name=%s)\n",type.data(),name.data()); if ((type=="const" || type=="volatile") && !name.isEmpty()) { // name is part of type => correct @@ -2845,6 +2845,47 @@ type+=name; } + // If a multiword type name such as "unsigned int" or "long long" + // appears at the end of a parameter in a prototype with no + // parameter name identifier, the defargs parser may end up thinking + // the "int" or "long" is the name of the parameter. This tries to + // detect and fixup those cases. + if (!type.isEmpty() && !name.isEmpty()) + { + if (name=="long" || name=="int" || name=="short" || name=="char" + || name=="double" || name=="_Complex" || name=="_Imaginary") + { + //printf("extractCanonicalType: fixed multiword type %s << %s\n",type.data(),name.data()); + type+=" "; + type+=name; + } + } + + // If a tagged type name such as "struct foo" appears at the end of + // a parameter in a prototype with no parameter name identifier, the + // defargs parser may end up thinking the "foo" tag is the name of + // the parameter. This tries to detect and fixup those cases. + if (!type.isEmpty() && !name.isEmpty()) + { + // The old QRegExp shipped with Doxygen is a bit limited, so this + // requires a bunch of tests. + static QRegExp exprs[] = { + QRegExp("\\sstruct$"),QRegExp("^struct$"), + QRegExp("\\sunion$"),QRegExp("^union$"), + QRegExp("\\senum$"),QRegExp("^enum$")}; + + for (unsigned int i=0;i < (sizeof exprs)/(sizeof exprs[0]);i++) + { + if (exprs[i].match(type)!=-1) + { + //printf("extractCanonicalType: fixed tag %s << %s\n",type.data(),name.data()); + type+=" "; + type+=name; + break; + } + } + } + // strip const and volatile keywords that are not relatevant for the type stripIrrelevantConstVolatile(type); |