From 460e72183338efad84b08e5069176920a92a3f1e Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Mon, 20 Sep 2010 10:55:20 +0300 Subject: [PATCH] scan: attempt to handle skipping redeclarations of symbols This unfortunately does not work yet. If a header has multiple different declarations of a symbol, we would like to only use the first. --- gtkdoc-scan.in | 74 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/gtkdoc-scan.in b/gtkdoc-scan.in index da1111d..523daa8 100755 --- a/gtkdoc-scan.in +++ b/gtkdoc-scan.in @@ -354,7 +354,7 @@ sub ScanHeader { } } - # set global that affects AddSymbolToList + # set global that is used later when we do AddSymbolToList if ($deprecated_conditional_nest > 0) { $deprecated = "\n"; } else { @@ -480,8 +480,9 @@ sub ScanHeader { # will override this. my $structsym = uc $1; #print "DEBUG: $structsym typedef: $2\n"; - &AddSymbolToList (\$list, $2); - print DECL "<$structsym>\n$2\n$deprecated\n"; + if (&AddSymbolToList (\$list, $2)) { + print DECL "<$structsym>\n$2\n$deprecated\n"; + } } elsif (m/^\s*(?:struct|union)\s+_(\w+)\s*;/) { # Skip private structs/unions. @@ -493,8 +494,9 @@ sub ScanHeader { # can differentiate it from a typedef. my $structsym = uc $1; #print "DEBUG: $structsym: $2\n"; - &AddSymbolToList (\$list, $2); - print DECL "<$structsym>\n$2\n$_$deprecated\n"; + if (&AddSymbolToList (\$list, $2)) { + print DECL "<$structsym>\n$2\n$_$deprecated\n"; + } } elsif (m/^\s*typedef\s+(struct|union)\s*\w*\s*{/) { $symbol = ""; @@ -507,14 +509,16 @@ sub ScanHeader { } elsif (m/^\s*typedef\s+(?:struct|union)\s+\w+[\s\*]+(\w+)\s*;/) { #print "DEBUG: Found struct/union(*) typedef $1: $_"; - &AddSymbolToList (\$list, $1); - print DECL "\n$1\n$deprecated$_\n"; + if (&AddSymbolToList (\$list, $1)) { + print DECL "\n$1\n$deprecated$_\n"; + } } elsif (m/^\s*(G_GNUC_EXTENSION\s+)?typedef\s+(.+[\s\*])(\w+)(\s*\[[^\]]+\])*\s*;/) { if ($2 !~ m/^struct\s/ && $2 !~ m/^union\s/) { #print "DEBUG: Found typedef: $_"; - &AddSymbolToList (\$list, $3); - print DECL "\n$3\n$deprecated$_\n"; + if (&AddSymbolToList (\$list, $3)) { + print DECL "\n$3\n$deprecated$_\n"; + } } } elsif (m/^\s*typedef\s+/) { #print "DEBUG: Skipping typedef: $_"; @@ -526,8 +530,9 @@ sub ScanHeader { $symbol = $5; s/^\s*([A-Za-z_]+VAR)\b/extern/; #print "DEBUG: Possible extern: $_"; - &AddSymbolToList (\$list, $symbol); - print DECL "\n$symbol\n$deprecated$_\n"; + if (&AddSymbolToList (\$list, $symbol)) { + print DECL "\n$symbol\n$deprecated$_\n"; + } # FUNCTIONS @@ -706,13 +711,14 @@ sub ScanHeader { $decl =~ s/\s*\n\s*/ /gs; # consolidate whitespace at start # and end of lines. $ret_type =~ s%/\*.*?\*/%%g; # remove comments in ret type. - &AddSymbolToList (\$list, $symbol); - print DECL "\n$symbol\n$deprecated$ret_type\n$decl\n\n"; - if ($REBUILD_TYPES) { - # check if this looks like a get_type function and if so remember - if (($symbol =~ m/_get_type$/) && ($ret_type =~ m/GType/) && ($decl =~ m/(void|)/)) { - #print "Adding get-type: [$ret_type] [$symbol] [$decl]\tfrom $input_file\n"; - push (@get_types, $symbol); + if (&AddSymbolToList (\$list, $symbol)) { + print DECL "\n$symbol\n$deprecated$ret_type\n$decl\n\n"; + if ($REBUILD_TYPES) { + # check if this looks like a get_type function and if so remember + if (($symbol =~ m/_get_type$/) && ($ret_type =~ m/GType/) && ($decl =~ m/(void|)/)) { + #print "Adding get-type: [$ret_type] [$symbol] [$decl]\tfrom $input_file\n"; + push (@get_types, $symbol); + } } } } else { @@ -725,8 +731,9 @@ sub ScanHeader { if ($in_declaration eq 'user_function') { if ($decl =~ s/\).*$//) { - &AddSymbolToList (\$list, $symbol); - print DECL "\n$symbol\n$deprecated$ret_type\n$decl\n"; + if (&AddSymbolToList (\$list, $symbol)) { + print DECL "\n$symbol\n$deprecated$ret_type\n$decl\n"; + } $in_declaration = ""; } } @@ -734,8 +741,9 @@ sub ScanHeader { if ($in_declaration eq 'macro') { if ($decl !~ m/\\\s*$/) { if ($internal == 0) { - &AddSymbolToList (\$list, $symbol); - print DECL "\n$symbol\n$deprecated$decl\n"; + if (&AddSymbolToList (\$list, $symbol)) { + print DECL "\n$symbol\n$deprecated$decl\n"; + } } else { $internal = 0; } @@ -748,8 +756,9 @@ sub ScanHeader { if ($symbol eq "") { $symbol = $1; } - &AddSymbolToList (\$list, $symbol); - print DECL "\n$symbol\n$deprecated$decl\n"; + if (&AddSymbolToList (\$list, $symbol)) { + print DECL "\n$symbol\n$deprecated$decl\n"; + } $in_declaration = ""; } } @@ -769,10 +778,10 @@ sub ScanHeader { push (@objects, $objectname); } #print "Store struct: $symbol\n"; - &AddSymbolToList (\$list, $symbol); - - my $structsym = uc $in_declaration; - print DECL "<$structsym>\n$symbol\n$deprecated$decl\n"; + if (&AddSymbolToList (\$list, $symbol)) { + my $structsym = uc $in_declaration; + print DECL "<$structsym>\n$symbol\n$deprecated$decl\n"; + } $in_declaration = ""; } else { # We use tr to count the brackets in the line, and adjust @@ -841,8 +850,13 @@ sub AddSymbolToList { my ($list, $symbol) = @_; if ($$list =~ m/\b\Q$symbol\E\b/) { -# print "Symbol $symbol already in list. skipping\n"; - return; + #print "Symbol $symbol already in list. skipping\n"; + # FIXME: ideally we would like to return 0 to skip outputting another + # entry to -decl.txt to avoid redeclarations (e.g. in conditional + # sections). Unfortunately this does not work, because of forward + # declarations + return 1; } $$list .= "$symbol\n"; + return 1; } -- 2.11.4.GIT