Thread: [Doxygen-develop] [PATCH] handling gcc attributes
Brought to you by:
dimitri
From: <de...@vt...> - 2006-01-14 13:14:22
|
The following patch allows doxygen to process C code which contains GCC attributes. http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Attribute-Syntax.html#Attribute-Syntax Symptom: Doxygen gets confused when trying to process C code that contains attributes, it usually throws off the parser causing everything from the start of the first attribute to the end of the file to be mis-processed. Cause: The scanner doesn't know to look for attributes. Index: doxygen-1.4.6/src/scanner.l =================================================================== --- doxygen-1.4.6/src/scanner.l 2005-12-27 13:04:40.000000000 -0500 +++ doxygen-1.4.6-tlw/src/scanner.l 2006-01-14 07:51:22.210391347 -0500 @@ -1195,7 +1195,7 @@ } } <FindMembers>{B}*(("typedef"{BN}+)?)("volatile"{BN}+)?"struct{" | -<FindMembers>{B}*(("typedef"{BN}+)?)("volatile"{BN}+)?"struct"/{BN}+ { +<FindMembers>{B}*(("typedef"{BN}+)?) ("volatile"{BN}+)?"struct"({BN}+"__attribute__"{BN}*"((".*"))")?/{BN}+ { isTypedef=((QCString)yytext).find("typedef")!=-1; current->section = Entry::STRUCT_SEC ; addType( current ) ; @@ -1233,6 +1233,8 @@ if (yytext[yyleng-1]=='{') unput('{'); BEGIN( CompoundName ) ; } +<FindMembers>"__attribute__"{BN}+"((".*"))"{BN}+ { + } <Operator>"("{BN}*")"({BN}*"<"[^>]*">"){BN}*/"(" { // A::operator()<int>(int arg) lineCount(); current->name += "()"; @@ -1874,7 +1876,8 @@ <FindMembers,FindFields,ReadInitializer>"//"([!/]?) {B}*{CMD}"}".*|"/*"([!*]?){B}*{CMD}"}".*"*/" { closeGroup(current,yyFileName,yyLineNr); } -<FindMembers>"=" { +<FindMembers>"=" | +<FindMember>({BN}+"__attribute__"{BN}*"((".*"))"{BN}+)?"=" { current->bodyLine = yyLineNr; lastInitializerContext = YY_START; initBracketCount=0; @@ -2202,7 +2205,9 @@ BEGIN( Array ) ; } } -<Array>"]" { current->args += *yytext ; +<Array>"]" | +<Array>"]"({BN}+"__attribute__"{BN}*"((".*"))")? { + current->args += *yytext ; if (--squareCount<=0) BEGIN( FindMembers ) ; } @@ -2211,7 +2216,8 @@ } <Array>. { current->args += *yytext ; } <SkipSquare>"[" { squareCount++; } -<SkipSquare>"]" { +<SkipSquare>"]" | +<SkipSquare>"]"({BN}+"__attribute__"{BN}*"((".*"))")? { if (--squareCount<=0) BEGIN( lastSquareContext ); } @@ -2238,7 +2244,7 @@ <FindFields>{ID} { current->name = yytext; } -<FindFields>"=" { +<FindFields>({BN}*"__attribute__"{BN}*"((".*"))"{BN}*)?"=" { lastInitializerContext = YY_START; initBracketCount=0; BEGIN(ReadInitializer); @@ -2443,7 +2449,7 @@ unput(';'); BEGIN( MemberSpec ) ; } -<MemberSpec>([*&]*{BN}*)*{ID}{BN}*("["[^\]\n]*"]")* { // the [] part could be improved. +<MemberSpec>([*&]*{BN}*)*{ID} {BN}*("["[^\]\n]*"]")*({BN}*"__attribute__"{BN}*"((".*"))")? { // the [] part could be improved. lineCount(); int i=0,l=yyleng,j; while (i<l && (!isId(yytext[i]))) i++; @@ -2574,7 +2580,7 @@ BEGIN( FindMembers ); } } -<MemberSpec>"=" { +<MemberSpec>({BN}*"__attribute__"{BN}*"((".*"))"{BN}*)?"=" { lastInitializerContext=YY_START; initBracketCount=0; BEGIN(ReadInitializer); |
From: Kevin M. <ke...@pl...> - 2006-01-14 17:01:41
|
Hello, 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 de...@vt... wrote: > The following patch allows doxygen to process C code which contains > GCC attributes. > http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gcc/Attribute-Syntax.html#Attribute-Syntax > > Symptom: Doxygen gets confused when trying to process C code that > contains attributes, it usually throws off the parser causing > everything from the start of the first attribute to the end of the > file to be mis-processed. > > Cause: The scanner doesn't know to look for attributes. > |
From: Dave D. <do...@do...> - 2006-01-15 01:54:39
|
On Sat, Jan 14, 2006 at 08:14:12AM -0500, de...@vt... wrote: > The following patch allows doxygen to process C code which contains GCC > attributes. Just FYI, a workaround for this is to make attributes conditionally disappear in the preprocessor. I usually do that anyway since I want to avoid tying code to gcc: #if defined ( __GNUC__ ) #define FUNC_MALLOC() __attribute__((__malloc__)) #else #define FUNC_MALLOC() #endif extern void * foo(int,int) FUNC_MALLOC(); Doxygen still doesn't like seeing that FUNC_MALLOC() there. That's fixed by telling the Doxygen config to remove it during preprocessing: PREDEFINED = \ "FUNC_MALLOC()=" -Dave Dodge |
From: <de...@vt...> - 2006-01-15 03:07:29
|
On Saturday 14 January 2006 20:55, Dave Dodge wrote: > On Sat, Jan 14, 2006 at 08:14:12AM -0500, de...@vt... wrote: > > The following patch allows doxygen to process C code which contains > > GCC attributes. > > Just FYI, a workaround for this is to make attributes conditionally > disappear in the preprocessor. I usually do that anyway since I want > to avoid tying code to gcc: Thanks for the tip, Dave. I much prefer this solution over hacking in support for arbitrary compilers into doxygen. |