diff options
author | Damon Chaplin <damon@gnome.org> | 2004-10-15 22:12:11 +0000 |
---|---|---|
committer | Damon Chaplin <damon@src.gnome.org> | 2004-10-15 22:12:11 +0000 |
commit | 4be26ba63fc175dbf7e05d2b3662e5d9b251d5cc (patch) | |
tree | b2499edc4f0fefb309654611de82f6e0dec12465 /gtkdoc-mktmpl.in | |
parent | d875a2cf68112d3862a2ba6d50cd4f5979362068 (diff) | |
download | gtk-doc-4be26ba63fc175dbf7e05d2b3662e5d9b251d5cc.tar.gz |
moved these here, rather than have 2 copies in gtkdoc-mkdb.in and
2004-10-15 Damon Chaplin <damon@gnome.org>
* gtkdoc-common.pl.in (ParseStructDeclaration)
(ParseEnumDeclaration): moved these here, rather than have 2 copies
in gtkdoc-mkdb.in and gtkdoc-mktmpl.in.
* gtkdoc-common.pl.in (ParseStructDeclaration): handle struct fields
better. We can now handle things like *foo, ***bar, *baz[12][23],
foo : 25 all on one line. Fixes part of #151219.
Also support the 'short' modifier to fix #90565.
And use $nbsp; rather than spaces to try to avoid splitting
declarations in the output.
Also take an extra arg specifying whether to include parameters in
the function pointer fields.
* gtkdoc-scan.in (ScanHeader): Deal with array types in typedefs.
(Eg, "typedef unsigned char MD5Digest[16];") From Dan Winship.
Last bit of #151219.
Diffstat (limited to 'gtkdoc-mktmpl.in')
-rwxr-xr-x | gtkdoc-mktmpl.in | 190 |
1 files changed, 1 insertions, 189 deletions
diff --git a/gtkdoc-mktmpl.in b/gtkdoc-mktmpl.in index 4d29397..635bf61 100755 --- a/gtkdoc-mktmpl.in +++ b/gtkdoc-mktmpl.in @@ -442,7 +442,7 @@ EOF if ($type eq "STRUCT") { my $is_object_struct = CheckIsObject ($symbol); - my @fields = ParseStructDeclaration($declaration, $is_object_struct); + my @fields = ParseStructDeclaration($declaration, $is_object_struct, 1); for (my $i = 0; $i <= $#fields; $i += 2) { my $field_name = $fields[$i]; @@ -1225,191 +1225,3 @@ sub CheckIsObject { return 0; } - -############################################################################# -# Function : ParseStructDeclaration -# Description : This function takes a structure declaration and -# breaks it into individual type declarations. -# Arguments : $declaration - the declaration to parse -# $is_object - true if this is an object structure -# $typefunc - function reference to apply to type -# $namefunc - function reference to apply to name -############################################################################# - -sub ParseStructDeclaration { - my ($declaration, $is_object, $typefunc, $namefunc) = @_; - - # Remove all private parts of the declaration - - # For objects, assume private - if ($is_object) { - $declaration =~ s!(struct\s+\w*\s*\{) - .*? - (?:/\*\s*<\s*public\s*>\s*\*/|(?=\}))!$1!msgx; - } - - # Assume end of declaration if line begins with '}' - $declaration =~ s!\n?[ \t]*/\*\s*<\s*(private|protected)\s*>\s*\*/ - .*? - (?:/\*\s*<\s*public\s*>\s*\*/|(?=^\}))!!msgx; - - # Remove all other comments; - $declaration =~ s@/\*([^*]+|\*(?!/))*\*/@ @g; - - my @result = (); - - if ($declaration =~ /^\s*$/) { - return @result; - } - - # Prime match after "struct {" declaration - if (!scalar($declaration =~ m/struct\s+\w*\s*\{/msg)) { - die "Structure declaration '$declaration' does not begin with struct [NAME] {\n"; - } - - # Treat lines in sequence, allowing singly nested anonymous structs - # and unions. - while ($declaration =~ m/\s*([^{;]+(\{[^\}]*\}[^{;]+)?);/msg) { - my $line = $1; - - last if $line =~ /^\s*\}\s*\w*\s*$/; - - # FIXME: Just ignore nested structs and unions for now - next if $line =~ /{/; - - # FIXME: The regexes here are the same as in OutputFunction; - # this functionality should be separated out. - - if ($line =~ m/^ - (const\s+|unsigned\s+|volatile\s+)*(struct\s+)? # mod1 - (\w+)\s* # type - (\**)\s* # ptr1 - (const\s+)? # mod2 - (\**)?\s* # ptr2 - (\w+(?:\s*,\s*\w+)*)\s* # name - (?:((?:\[[^\]]*\]\s*)+) | # array - (:\s*\d+))?\s* # bits - $/x) { - my $mod1 = defined($1) ? $1 : ""; - if (defined($2)) { $mod1 .= $2; } - my $type = $3; - my $ptr1 = $4; - my $mod2 = defined($5) ? $5 : ""; - my $ptr2 = $6; - my $name = $7; - $ptr1 = " " . $ptr1; - my $array = defined($8) ? $8 : ""; - my $bits = defined($9) ? " $9" : ""; - my $ptype = defined $typefunc ? $typefunc->($type) : $type; - - # FIXME: - # As a hack, we allow the "name" to be of the form - # "a, b, c". This isn't the correct C syntax, but - # at least we get "gint16 x, y" right. Such constructs - # should really be completely removed from the source. - # Or we should really try to understand the C syntax - # here... - - my @names = split /\s*,\s*/, $name; - for my $n (@names) { - push @result, $n; - if (defined $namefunc) { - $n = $namefunc->($n); - } - push @result, "$mod1$ptype$ptr1$mod2$ptr2$n$array$bits"; - } - - # Try to match structure members which are functions - } elsif ($line =~ m/^ - (const\s+|G_CONST_RETURN\s+|unsigned\s+)*(struct\s+)? # mod1 - (\w+)\s* # type - (\**)\s* # ptr1 - (const\s+)? # mod2 - \(\s*\*\s*(\w+)\s*\)\s* # name - \(([^)]*)\)\s* # func_params - $/x) { - - my $mod1 = defined($1) ? $1 : ""; - if (defined($2)) { $mod1 .= $2; } - my $type = $3; - my $ptr1 = $4; - my $mod2 = defined($5) ? $5 : ""; - my $name = $6; - my $func_params = $7; - my $ptype = defined $typefunc ? $typefunc->($type) : $type; - my $pname = defined $namefunc ? $namefunc->($name) : $name; - - push @result, $name; - push @result, "$mod1$ptype$ptr1$mod2 (*$pname) ($func_params)"; - - } else { - warn "Cannot parse structure field \"$line\""; - } - } - - return @result; -} - - -############################################################################# -# Function : ParseEnumDeclaration -# Description : This function takes a enumeration declaration and -# breaks it into individual enum member declarations. -# Arguments : $declaration - the declaration to parse -############################################################################# - -sub ParseEnumDeclaration { - my ($declaration, $is_object) = @_; - - # Remove comments; - $declaration =~ s@/\*([^*]+|\*(?!/))*\*/@ @g; - - my @result = (); - - if ($declaration =~ /^\s*$/) { - return @result; - } - - # Remove parenthesized expressions (in macros like GTK_BLAH = BLAH(1,3)) - # to avoid getting confused by commas they might contain. This - # doesn't handle nested parentheses correctly. - - $declaration =~ s/\([^)]*\)//g; - - # Remove comma from comma - possible whitespace - closing brace sequence - # since it is legal in GNU C and C99 to have a trailing comma but doesn't - # result in an actual enum member - - $declaration =~ s/,(\s*})/$1/g; - - # Prime match after "typedef enum {" declaration - if (!scalar($declaration =~ m/typedef\s+enum\s*\{/msg)) { - die "Enum declaration '$declaration' does not begin with typedef enum {\n"; - } - - # Treat lines in sequence. - while ($declaration =~ m/\s*([^,\}]+)([,\}])/msg) { - my $line = $1; - my $terminator = $2; - - if ($line =~ m/^(\w+)\s*(=.*)?$/msg) { - push @result, $1; - - # Special case for GIOCondition, where the values are specified by - # macros which expand to include the equal sign like '=1'. - } elsif ($line =~ m/^(\w+)\s*GLIB_SYSDEF_POLL/msg) { - push @result, $1; - - # Special case include of <gdk/gdkcursors.h>, just ignore it - } elsif ($line =~ m/^#include/) { - last; - - } else { - warn "Cannot parse enumeration member \"$line\""; - } - - last if $terminator eq '}'; - } - - return @result; -} |