2002-03-10 00:29:33 +01:00
|
|
|
#
|
|
|
|
# Copyright 1999, 2000, 2001 Patrik Stridvall
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
#
|
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
package winapi_parser;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2001-07-24 01:20:56 +02:00
|
|
|
use output qw($output);
|
2001-07-26 23:42:12 +02:00
|
|
|
use options qw($options);
|
2001-07-11 19:27:45 +02:00
|
|
|
|
2006-05-12 00:19:54 +02:00
|
|
|
# Defined a couple common regexp tidbits
|
|
|
|
my $CALL_CONVENTION="__cdecl|__stdcall|" .
|
|
|
|
"__RPC_API|__RPC_STUB|__RPC_USER|RPC_ENTRY|" .
|
|
|
|
"RPC_VAR_ENTRY|STDMETHODCALLTYPE|NET_API_FUNCTION|" .
|
|
|
|
"CALLBACK|CDECL|NTAPI|PASCAL|APIENTRY|" .
|
2017-01-07 14:55:14 +01:00
|
|
|
"SEC_ENTRY|VFWAPI|VFWAPIV|WINGDIPAPI|WMIAPI|WINAPI|WINAPIV|";
|
2006-05-12 00:19:54 +02:00
|
|
|
|
2004-10-07 20:53:56 +02:00
|
|
|
sub parse_c_file($$) {
|
1999-09-23 17:14:20 +02:00
|
|
|
my $file = shift;
|
2002-04-29 20:45:12 +02:00
|
|
|
my $callbacks = shift;
|
|
|
|
|
|
|
|
my $empty_callback = sub { };
|
|
|
|
|
|
|
|
my $c_comment_found_callback = $$callbacks{c_comment_found} || $empty_callback;
|
|
|
|
my $cplusplus_comment_found_callback = $$callbacks{cplusplus_comment_found} || $empty_callback;
|
|
|
|
my $function_create_callback = $$callbacks{function_create} || $empty_callback;
|
|
|
|
my $function_found_callback = $$callbacks{function_found} || $empty_callback;
|
|
|
|
my $type_create_callback = $$callbacks{type_create} || $empty_callback;
|
|
|
|
my $type_found_callback = $$callbacks{type_found} || $empty_callback;
|
|
|
|
my $preprocessor_found_callback = $$callbacks{preprocessor_found} || $empty_callback;
|
1999-10-24 23:45:39 +02:00
|
|
|
|
2001-06-11 22:13:21 +02:00
|
|
|
# global
|
|
|
|
my $debug_channels = [];
|
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
my $in_function = 0;
|
|
|
|
my $function_begin;
|
|
|
|
my $function_end;
|
|
|
|
{
|
|
|
|
my $documentation_line;
|
|
|
|
my $documentation;
|
|
|
|
my $function_line;
|
|
|
|
my $linkage;
|
|
|
|
my $return_type;
|
|
|
|
my $calling_convention;
|
|
|
|
my $internal_name = "";
|
|
|
|
my $argument_types;
|
|
|
|
my $argument_names;
|
|
|
|
my $argument_documentations;
|
2001-08-09 23:35:38 +02:00
|
|
|
my $statements_line;
|
2001-07-26 23:42:12 +02:00
|
|
|
my $statements;
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
$function_begin = sub {
|
|
|
|
$documentation_line = shift;
|
|
|
|
$documentation = shift;
|
|
|
|
$function_line = shift;
|
|
|
|
$linkage = shift;
|
|
|
|
$return_type= shift;
|
|
|
|
$calling_convention = shift;
|
|
|
|
$internal_name = shift;
|
|
|
|
$argument_types = shift;
|
|
|
|
$argument_names = shift;
|
|
|
|
$argument_documentations = shift;
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
if(defined($argument_names) && defined($argument_types) &&
|
|
|
|
$#$argument_names == -1)
|
|
|
|
{
|
|
|
|
foreach my $n (0..$#$argument_types) {
|
|
|
|
push @$argument_names, "";
|
|
|
|
}
|
2000-05-11 23:46:17 +02:00
|
|
|
}
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
if(defined($argument_documentations) &&
|
|
|
|
$#$argument_documentations == -1)
|
|
|
|
{
|
|
|
|
foreach my $n (0..$#$argument_documentations) {
|
|
|
|
push @$argument_documentations, "";
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
$in_function = 1;
|
|
|
|
};
|
1999-10-24 23:45:39 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
$function_end = sub {
|
2001-08-09 23:35:38 +02:00
|
|
|
$statements_line = shift;
|
2001-07-26 23:42:12 +02:00
|
|
|
$statements = shift;
|
|
|
|
|
|
|
|
my $function = &$function_create_callback();
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
if(!defined($documentation_line)) {
|
|
|
|
$documentation_line = 0;
|
2000-11-30 02:31:44 +01:00
|
|
|
}
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
$function->file($file);
|
|
|
|
$function->debug_channels([@$debug_channels]);
|
|
|
|
$function->documentation_line($documentation_line);
|
|
|
|
$function->documentation($documentation);
|
|
|
|
$function->function_line($function_line);
|
|
|
|
$function->linkage($linkage);
|
2002-06-01 04:55:48 +02:00
|
|
|
$function->return_type($return_type);
|
2001-07-26 23:42:12 +02:00
|
|
|
$function->calling_convention($calling_convention);
|
|
|
|
$function->internal_name($internal_name);
|
|
|
|
if(defined($argument_types)) {
|
|
|
|
$function->argument_types([@$argument_types]);
|
|
|
|
}
|
|
|
|
if(defined($argument_names)) {
|
|
|
|
$function->argument_names([@$argument_names]);
|
|
|
|
}
|
|
|
|
if(defined($argument_documentations)) {
|
|
|
|
$function->argument_documentations([@$argument_documentations]);
|
|
|
|
}
|
2001-08-09 23:35:38 +02:00
|
|
|
$function->statements_line($statements_line);
|
2001-07-26 23:42:12 +02:00
|
|
|
$function->statements($statements);
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
&$function_found_callback($function);
|
2000-11-30 02:31:44 +01:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
$in_function = 0;
|
|
|
|
};
|
|
|
|
}
|
2001-07-11 19:27:45 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
my $in_type = 0;
|
|
|
|
my $type_begin;
|
|
|
|
my $type_end;
|
|
|
|
{
|
|
|
|
my $type;
|
2001-07-14 02:48:41 +02:00
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
$type_begin = sub {
|
|
|
|
$type = shift;
|
|
|
|
$in_type = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$type_end = sub {
|
|
|
|
my $names = shift;
|
|
|
|
|
|
|
|
foreach my $name (@$names) {
|
2005-12-02 11:27:13 +01:00
|
|
|
if($type =~ /^(?:enum|interface|struct|union)/) {
|
2001-07-26 23:42:12 +02:00
|
|
|
# $output->write("typedef $type {\n");
|
|
|
|
# $output->write("} $name;\n");
|
|
|
|
} else {
|
|
|
|
# $output->write("typedef $type $name;\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$in_type = 0;
|
|
|
|
};
|
|
|
|
}
|
2001-07-11 19:27:45 +02:00
|
|
|
|
1999-12-12 00:01:45 +01:00
|
|
|
my %regs_entrypoints;
|
2001-07-02 03:21:48 +02:00
|
|
|
my @comment_lines = ();
|
1999-10-31 03:08:38 +01:00
|
|
|
my @comments = ();
|
2001-08-09 23:35:38 +02:00
|
|
|
my $statements_line;
|
2001-07-26 23:42:12 +02:00
|
|
|
my $statements;
|
1999-09-23 17:14:20 +02:00
|
|
|
my $level = 0;
|
2000-04-06 22:11:04 +02:00
|
|
|
my $extern_c = 0;
|
1999-09-23 17:14:20 +02:00
|
|
|
my $again = 0;
|
|
|
|
my $lookahead = 0;
|
|
|
|
my $lookahead_count = 0;
|
|
|
|
|
|
|
|
print STDERR "Processing file '$file' ... " if $options->verbose;
|
|
|
|
open(IN, "< $file") || die "<internal>: $file: $!\n";
|
2002-10-02 03:23:55 +02:00
|
|
|
local $_ = "";
|
2004-10-21 21:56:04 +02:00
|
|
|
readmore: while($again || defined(my $line = <IN>)) {
|
2002-10-02 03:23:55 +02:00
|
|
|
$_ = "" if !defined($_);
|
1999-09-23 17:14:20 +02:00
|
|
|
if(!$again) {
|
|
|
|
chomp $line;
|
|
|
|
|
|
|
|
if($lookahead) {
|
|
|
|
$lookahead = 0;
|
|
|
|
$_ .= "\n" . $line;
|
2001-07-02 03:21:48 +02:00
|
|
|
$lookahead_count++;
|
1999-09-23 17:14:20 +02:00
|
|
|
} else {
|
|
|
|
$_ = $line;
|
|
|
|
$lookahead_count = 0;
|
|
|
|
}
|
2002-10-02 03:23:55 +02:00
|
|
|
$output->write(" $level($lookahead_count): $line\n") if $options->debug >= 2;
|
|
|
|
$output->write("*** $_\n") if $options->debug >= 3;
|
1999-09-23 17:14:20 +02:00
|
|
|
} else {
|
|
|
|
$lookahead_count = 0;
|
|
|
|
$again = 0;
|
|
|
|
}
|
1999-10-31 03:08:38 +01:00
|
|
|
|
2001-07-11 19:27:45 +02:00
|
|
|
# CVS merge conflicts in file?
|
1999-10-31 03:08:38 +01:00
|
|
|
if(/^(<<<<<<<|=======|>>>>>>>)/) {
|
|
|
|
$output->write("$file: merge conflicts in file\n");
|
|
|
|
last;
|
|
|
|
}
|
2002-06-01 04:55:48 +02:00
|
|
|
|
2004-10-21 21:56:04 +02:00
|
|
|
my $prefix="";
|
|
|
|
while ($_ ne "")
|
|
|
|
{
|
|
|
|
if (s/^([^\"\/]+|\"(?:[^\\\"]*|\\.)*\")//)
|
|
|
|
{
|
|
|
|
$prefix.=$1;
|
|
|
|
}
|
|
|
|
elsif (/^\/\*/)
|
|
|
|
{
|
|
|
|
# remove C comments
|
|
|
|
if(s/^(\/\*.*?\*\/)//s) {
|
|
|
|
my @lines = split(/\n/, $1);
|
|
|
|
push @comment_lines, $.;
|
|
|
|
push @comments, $1;
|
|
|
|
&$c_comment_found_callback($. - $#lines, $., $1);
|
|
|
|
if($#lines <= 0) {
|
|
|
|
$_ = "$prefix $_";
|
|
|
|
} else {
|
|
|
|
$_ = $prefix . ("\n" x $#lines) . $_;
|
|
|
|
}
|
|
|
|
$again = 1;
|
|
|
|
} else {
|
|
|
|
$_ = "$prefix$_";
|
|
|
|
$lookahead = 1;
|
|
|
|
}
|
|
|
|
next readmore;
|
|
|
|
}
|
|
|
|
elsif (s/^(\/\/.*)$//)
|
|
|
|
{
|
|
|
|
# remove C++ comments
|
|
|
|
&$cplusplus_comment_found_callback($., $1);
|
|
|
|
$again = 1;
|
|
|
|
}
|
|
|
|
elsif (s/^(.)//)
|
|
|
|
{
|
|
|
|
$prefix.=$1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$_=$prefix;
|
2000-05-18 02:07:31 +02:00
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
# remove preprocessor directives
|
2001-08-09 23:35:38 +02:00
|
|
|
if(s/^\s*\#/\#/s) {
|
2020-04-14 16:57:12 +02:00
|
|
|
if (/^#\s*if\s+0\s*$/ms) {
|
|
|
|
# Skip #if 0 ... #endif sections entirely.
|
|
|
|
# They are typically used as 'super comments' and may not
|
|
|
|
# contain C code. This totally ignores nesting.
|
|
|
|
if(s/^(\s*#\s*if\s+0\s*\n.*?\n\s*#\s*endif\s*)\n//s) {
|
|
|
|
my @lines = split(/\n/, $1);
|
|
|
|
$_ = "\n" x $#lines;
|
|
|
|
&$preprocessor_found_callback("if", "0");
|
|
|
|
$again = 1;
|
|
|
|
} else {
|
|
|
|
$lookahead = 1;
|
|
|
|
}
|
|
|
|
next readmore;
|
|
|
|
}
|
|
|
|
elsif(/^(\#.*?)\\$/s) {
|
2003-08-08 23:04:17 +02:00
|
|
|
$_ = "$1\n";
|
1999-10-24 23:45:39 +02:00
|
|
|
$lookahead = 1;
|
|
|
|
next;
|
2001-08-09 23:35:38 +02:00
|
|
|
} elsif(s/^\#\s*(\w+)((?:\s+(.*?))?\s*)$//s) {
|
|
|
|
my @lines = split(/\n/, $2);
|
|
|
|
if($#lines > 0) {
|
|
|
|
$_ = "\n" x $#lines;
|
|
|
|
}
|
1999-10-24 23:45:39 +02:00
|
|
|
if(defined($3)) {
|
|
|
|
&$preprocessor_found_callback($1, $3);
|
|
|
|
} else {
|
|
|
|
&$preprocessor_found_callback($1, "");
|
|
|
|
}
|
2001-08-09 23:35:38 +02:00
|
|
|
$again = 1;
|
1999-10-24 23:45:39 +02:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
1999-09-23 17:14:20 +02:00
|
|
|
|
2000-04-06 22:11:04 +02:00
|
|
|
# Remove extern "C"
|
2002-06-01 04:55:48 +02:00
|
|
|
if(s/^\s*extern\s+"C"\s+\{//m) {
|
2000-04-06 22:11:04 +02:00
|
|
|
$extern_c = 1;
|
|
|
|
$again = 1;
|
2002-06-01 04:55:48 +02:00
|
|
|
next;
|
2000-04-06 22:11:04 +02:00
|
|
|
}
|
|
|
|
|
2001-07-02 03:21:48 +02:00
|
|
|
my $documentation_line;
|
2000-11-30 02:31:44 +01:00
|
|
|
my $documentation;
|
2000-12-02 00:51:33 +01:00
|
|
|
my @argument_documentations = ();
|
1999-10-31 03:08:38 +01:00
|
|
|
{
|
|
|
|
my $n = $#comments;
|
2000-11-30 02:31:44 +01:00
|
|
|
while($n >= 0 && ($comments[$n] !~ /^\/\*\*/ ||
|
2002-06-01 04:55:48 +02:00
|
|
|
$comments[$n] =~ /^\/\*\*+\/$/))
|
2000-11-30 02:31:44 +01:00
|
|
|
{
|
|
|
|
$n--;
|
|
|
|
}
|
|
|
|
|
1999-10-31 03:08:38 +01:00
|
|
|
if(defined($comments[$n]) && $n >= 0) {
|
2001-07-02 03:21:48 +02:00
|
|
|
my @lines = split(/\n/, $comments[$n]);
|
|
|
|
|
|
|
|
$documentation_line = $comment_lines[$n] - scalar(@lines) + 1;
|
1999-10-31 03:08:38 +01:00
|
|
|
$documentation = $comments[$n];
|
2001-07-02 03:21:48 +02:00
|
|
|
|
2000-11-30 02:31:44 +01:00
|
|
|
for(my $m=$n+1; $m <= $#comments; $m++) {
|
2001-01-20 03:16:31 +01:00
|
|
|
if($comments[$m] =~ /^\/\*\*+\/$/ ||
|
|
|
|
$comments[$m] =~ /^\/\*\s*(?:\!)?defined/) # FIXME: Kludge
|
|
|
|
{
|
2000-12-02 00:51:33 +01:00
|
|
|
@argument_documentations = ();
|
|
|
|
next;
|
|
|
|
}
|
2000-11-30 02:31:44 +01:00
|
|
|
push @argument_documentations, $comments[$m];
|
|
|
|
}
|
1999-10-31 03:08:38 +01:00
|
|
|
} else {
|
|
|
|
$documentation = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
if($level > 0)
|
|
|
|
{
|
2000-03-24 21:39:51 +01:00
|
|
|
my $line = "";
|
|
|
|
while(/^[^\{\}]/) {
|
|
|
|
s/^([^\{\}\'\"]*)//s;
|
1999-10-24 23:45:39 +02:00
|
|
|
$line .= $1;
|
2000-03-24 21:39:51 +01:00
|
|
|
if(s/^\'//) {
|
|
|
|
$line .= "\'";
|
|
|
|
while(/^./ && !s/^\'//) {
|
|
|
|
s/^([^\'\\]*)//s;
|
|
|
|
$line .= $1;
|
|
|
|
if(s/^\\//) {
|
|
|
|
$line .= "\\";
|
|
|
|
if(s/^(.)//s) {
|
|
|
|
$line .= $1;
|
|
|
|
if($1 eq "0") {
|
|
|
|
s/^(\d{0,3})//s;
|
|
|
|
$line .= $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$line .= "\'";
|
|
|
|
} elsif(s/^\"//) {
|
|
|
|
$line .= "\"";
|
|
|
|
while(/^./ && !s/^\"//) {
|
|
|
|
s/^([^\"\\]*)//s;
|
|
|
|
$line .= $1;
|
|
|
|
if(s/^\\//) {
|
|
|
|
$line .= "\\";
|
|
|
|
if(s/^(.)//s) {
|
|
|
|
$line .= $1;
|
|
|
|
if($1 eq "0") {
|
|
|
|
s/^(\d{0,3})//s;
|
|
|
|
$line .= $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$line .= "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s/^\{//) {
|
|
|
|
$_ = $'; $again = 1;
|
|
|
|
$line .= "{";
|
|
|
|
print "+1: \{$_\n" if $options->debug >= 2;
|
1999-09-23 17:14:20 +02:00
|
|
|
$level++;
|
2001-08-09 23:35:38 +02:00
|
|
|
$statements .= $line;
|
2000-03-24 21:39:51 +01:00
|
|
|
} elsif(s/^\}//) {
|
1999-09-23 17:14:20 +02:00
|
|
|
$_ = $'; $again = 1;
|
2000-03-24 21:39:51 +01:00
|
|
|
$line .= "}" if $level > 1;
|
2002-06-01 04:55:48 +02:00
|
|
|
print "-1: \}$_\n" if $options->debug >= 2;
|
1999-09-23 17:14:20 +02:00
|
|
|
$level--;
|
2000-04-06 22:11:04 +02:00
|
|
|
if($level == -1 && $extern_c) {
|
|
|
|
$extern_c = 0;
|
|
|
|
$level = 0;
|
|
|
|
}
|
2001-08-09 23:35:38 +02:00
|
|
|
$statements .= $line;
|
|
|
|
} else {
|
1999-10-24 23:45:39 +02:00
|
|
|
$statements .= "$line\n";
|
2000-03-24 21:39:51 +01:00
|
|
|
}
|
|
|
|
|
2001-07-26 23:42:12 +02:00
|
|
|
if($level == 0) {
|
|
|
|
if($in_function) {
|
2001-08-09 23:35:38 +02:00
|
|
|
&$function_end($statements_line, $statements);
|
2001-07-26 23:42:12 +02:00
|
|
|
$statements = undef;
|
|
|
|
} elsif($in_type) {
|
2005-08-08 13:06:24 +02:00
|
|
|
if(/^\s*((?:(?:FAR\s*)?\*\s*(?:RESTRICTED_POINTER\s+)?)?
|
2005-11-04 12:39:58 +01:00
|
|
|
(?:volatile\s+)?
|
2005-08-08 13:06:24 +02:00
|
|
|
(?:\w+|WS\(\w+\))\s*
|
2005-11-04 12:39:58 +01:00
|
|
|
(?:\s*,\s*(?:(?:FAR\s*)?\*+\s*(?:RESTRICTED_POINTER\s+)?)?(?:volatile\s+)?(?:\w+|WS\(\w+\)))*\s*);/sx) {
|
2001-07-26 23:42:12 +02:00
|
|
|
my @parts = split(/\s*,\s*/, $1);
|
|
|
|
&$type_end([@parts]);
|
|
|
|
} elsif(/;/s) {
|
|
|
|
die "$file: $.: syntax error: '$_'\n";
|
|
|
|
} else {
|
|
|
|
$lookahead = 1;
|
|
|
|
}
|
|
|
|
}
|
1999-10-24 23:45:39 +02:00
|
|
|
}
|
2001-07-18 22:09:12 +02:00
|
|
|
next;
|
2005-12-02 11:27:13 +01:00
|
|
|
} elsif(/(extern\s+|static\s+)?((interface\s+|struct\s+|union\s+|enum\s+|signed\s+|unsigned\s+)?\w+((\s*\*)+\s*|\s+))
|
2006-05-12 00:19:54 +02:00
|
|
|
(($CALL_CONVENTION)\s+)?
|
2017-01-07 14:37:23 +01:00
|
|
|
(?:DECLSPEC_HOTPATCH\s+)?
|
2004-05-17 22:50:24 +02:00
|
|
|
(\w+(\(\w+\))?)\s*\((.*?)\)\s*(\{|\;)/sx)
|
2000-06-11 22:02:29 +02:00
|
|
|
{
|
2001-07-02 03:21:48 +02:00
|
|
|
my @lines = split(/\n/, $&);
|
|
|
|
my $function_line = $. - scalar(@lines) + 1;
|
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
$_ = $'; $again = 1;
|
2001-07-02 03:21:48 +02:00
|
|
|
|
2000-03-24 21:39:51 +01:00
|
|
|
if($11 eq "{") {
|
1999-09-23 17:14:20 +02:00
|
|
|
$level++;
|
2000-03-24 21:39:51 +01:00
|
|
|
}
|
2000-04-15 22:39:55 +02:00
|
|
|
|
2000-03-24 21:39:51 +01:00
|
|
|
my $linkage = $1;
|
|
|
|
my $return_type = $2;
|
|
|
|
my $calling_convention = $7;
|
|
|
|
my $name = $8;
|
|
|
|
my $arguments = $10;
|
|
|
|
|
|
|
|
if(!defined($linkage)) {
|
|
|
|
$linkage = "";
|
|
|
|
}
|
1999-10-24 23:45:39 +02:00
|
|
|
|
|
|
|
if(!defined($calling_convention)) {
|
|
|
|
$calling_convention = "";
|
|
|
|
}
|
1999-09-23 17:14:20 +02:00
|
|
|
|
2000-03-24 21:39:51 +01:00
|
|
|
$linkage =~ s/\s*$//;
|
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
$return_type =~ s/\s*$//;
|
|
|
|
$return_type =~ s/\s*\*\s*/*/g;
|
|
|
|
$return_type =~ s/(\*+)/ $1/g;
|
|
|
|
|
1999-12-12 00:01:45 +01:00
|
|
|
if($regs_entrypoints{$name}) {
|
|
|
|
$name = $regs_entrypoints{$name};
|
2002-06-01 04:55:48 +02:00
|
|
|
}
|
1999-09-23 17:14:20 +02:00
|
|
|
|
|
|
|
$arguments =~ y/\t\n/ /;
|
|
|
|
$arguments =~ s/^\s*(.*?)\s*$/$1/;
|
2001-06-19 05:34:52 +02:00
|
|
|
if($arguments eq "") { $arguments = "..." }
|
2000-11-30 02:31:44 +01:00
|
|
|
|
2000-05-11 23:46:17 +02:00
|
|
|
my @argument_types;
|
|
|
|
my @argument_names;
|
2004-05-17 22:50:24 +02:00
|
|
|
my @arguments;
|
|
|
|
my $n = 0;
|
|
|
|
while ($arguments =~ s/^((?:[^,\(\)]*|(?:\([^\)]*\))?)+)(?:,|$)// && $1) {
|
|
|
|
my $argument = $1;
|
|
|
|
push @arguments, $argument;
|
|
|
|
|
2000-05-11 23:46:17 +02:00
|
|
|
my $argument_type = "";
|
|
|
|
my $argument_name = "";
|
2004-05-17 22:50:24 +02:00
|
|
|
|
1999-09-23 17:14:20 +02:00
|
|
|
$argument =~ s/^\s*(.*?)\s*$/$1/;
|
2000-05-11 23:46:17 +02:00
|
|
|
# print " " . ($n + 1) . ": '$argument'\n";
|
2006-05-10 18:53:41 +02:00
|
|
|
$argument =~ s/^(?:IN OUT|IN|OUT)?\s+//;
|
2007-06-21 11:15:26 +02:00
|
|
|
$argument =~ s/^(?:const|CONST|GDIPCONST|volatile)?\s+//;
|
2000-04-29 16:24:11 +02:00
|
|
|
if($argument =~ /^\.\.\.$/) {
|
2000-05-11 23:46:17 +02:00
|
|
|
$argument_type = "...";
|
|
|
|
$argument_name = "...";
|
2000-11-30 02:31:44 +01:00
|
|
|
} elsif($argument =~ /^
|
2006-05-10 18:53:41 +02:00
|
|
|
((?:interface\s+|struct\s+|union\s+|enum\s+|register\s+|(?:signed\s+|unsigned\s+)?
|
2005-08-08 13:06:24 +02:00
|
|
|
(?:short\s+(?=int)|long\s+(?=int))?)?(?:\w+|ElfW\(\w+\)|WS\(\w+\)))\s*
|
2007-06-21 11:15:26 +02:00
|
|
|
((?:__RPC_FAR|const|CONST|GDIPCONST|volatile)?\s*(?:\*\s*(?:__RPC_FAR|const|CONST|volatile)?\s*?)*)\s*
|
2005-08-08 13:06:24 +02:00
|
|
|
(\w*)\s*(\[\])?(?:\s+OPTIONAL)?$/x)
|
2000-11-30 02:31:44 +01:00
|
|
|
{
|
2004-05-17 22:50:24 +02:00
|
|
|
$argument_type = $1;
|
|
|
|
if ($2) {
|
2000-05-11 23:46:17 +02:00
|
|
|
$argument_type .= " $2";
|
1999-09-23 17:14:20 +02:00
|
|
|
}
|
2005-08-08 13:06:24 +02:00
|
|
|
if ($4) {
|
|
|
|
$argument_type .= "$4";
|
|
|
|
}
|
2000-05-11 23:46:17 +02:00
|
|
|
$argument_name = $3;
|
2004-05-17 22:50:24 +02:00
|
|
|
} elsif ($argument =~ /^
|
2006-05-10 18:53:41 +02:00
|
|
|
((?:interface\s+|struct\s+|union\s+|enum\s+|register\s+|(?:signed\s+|unsigned\s+)?
|
2004-05-17 22:50:24 +02:00
|
|
|
(?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
|
2005-09-06 11:23:46 +02:00
|
|
|
((?:const|volatile)?\s*(?:\*\s*(?:const|volatile)?\s*?)*)\s*
|
2006-05-12 00:19:54 +02:00
|
|
|
(?:(?:$CALL_CONVENTION)\s+)?
|
|
|
|
\(\s*(?:$CALL_CONVENTION)?\s*\*\s*((?:\w+)?)\s*\)\s*
|
2004-05-17 22:50:24 +02:00
|
|
|
\(\s*(.*?)\s*\)$/x)
|
|
|
|
{
|
|
|
|
my $return_type = $1;
|
|
|
|
if($2) {
|
|
|
|
$return_type .= " $2";
|
|
|
|
}
|
|
|
|
$argument_name = $3;
|
|
|
|
my $arguments = $4;
|
|
|
|
|
|
|
|
$return_type =~ s/\s+/ /g;
|
|
|
|
$arguments =~ s/\s*,\s*/,/g;
|
|
|
|
|
|
|
|
$argument_type = "$return_type (*)($arguments)";
|
|
|
|
} elsif ($argument =~ /^
|
2005-12-02 11:27:13 +01:00
|
|
|
((?:interface\s+|struct\s+|union\s+|enum\s+|register\s+|(?:signed\s+|unsigned\s+)
|
2004-05-17 22:50:24 +02:00
|
|
|
(?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
|
2005-09-06 11:23:46 +02:00
|
|
|
((?:const|volatile)?\s*(?:\*\s*(?:const|volatile)?\s*?)*)\s*
|
2004-05-17 22:50:24 +02:00
|
|
|
(\w+)\s*\[\s*(.*?)\s*\](?:\[\s*(.*?)\s*\])?$/x)
|
|
|
|
{
|
|
|
|
my $return_type = $1;
|
|
|
|
if($2) {
|
|
|
|
$return_type .= " $2";
|
|
|
|
}
|
|
|
|
$argument_name = $3;
|
2000-05-11 23:46:17 +02:00
|
|
|
|
2004-05-17 22:50:24 +02:00
|
|
|
$argument_type = "$return_type\[$4\]";
|
|
|
|
|
|
|
|
if (defined($5)) {
|
|
|
|
$argument_type .= "\[$5\]";
|
|
|
|
}
|
2000-05-11 23:46:17 +02:00
|
|
|
|
2004-05-17 22:50:24 +02:00
|
|
|
# die "$file: $.: syntax error: '$argument_type':'$argument_name'\n";
|
1999-09-23 17:14:20 +02:00
|
|
|
} else {
|
2020-04-14 16:57:00 +02:00
|
|
|
# This is either a complex argument type, typically
|
|
|
|
# involving parentheses, or a macro argument. This is rare
|
|
|
|
# so just ignore the 'function' declaration.
|
|
|
|
print STDERR "$file: $.: cannot parse declaration argument (ignoring): '$argument'\n";
|
|
|
|
next readmore;
|
1999-09-23 17:14:20 +02:00
|
|
|
}
|
2004-05-17 22:50:24 +02:00
|
|
|
|
2005-09-06 11:23:46 +02:00
|
|
|
$argument_type =~ s/\s*(?:const|volatile)\s*/ /g; # Remove const/volatile
|
2004-05-17 22:50:24 +02:00
|
|
|
$argument_type =~ s/([^\*\(\s])\*/$1 \*/g; # Assure whitespace between non-* and *
|
|
|
|
$argument_type =~ s/,([^\s])/, $1/g; # Assure whitespace after ,
|
|
|
|
$argument_type =~ s/\*\s+\*/\*\*/g; # Remove whitespace between * and *
|
|
|
|
$argument_type =~ s/([\(\[])\s+/$1/g; # Remove whitespace after ( and [
|
|
|
|
$argument_type =~ s/\s+([\)\]])/$1/g; # Remove whitespace before ] and )
|
|
|
|
$argument_type =~ s/\s+/ /; # Remove multiple whitespace
|
|
|
|
$argument_type =~ s/^\s*(.*?)\s*$/$1/; # Remove leading and trailing whitespace
|
|
|
|
|
|
|
|
$argument_name =~ s/^\s*(.*?)\s*$/$1/; # Remove leading and trailing whitespace
|
|
|
|
|
2000-05-11 23:46:17 +02:00
|
|
|
$argument_types[$n] = $argument_type;
|
|
|
|
$argument_names[$n] = $argument_name;
|
|
|
|
# print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
|
2004-05-17 22:50:24 +02:00
|
|
|
|
|
|
|
$n++;
|
2000-05-11 23:46:17 +02:00
|
|
|
}
|
|
|
|
if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
|
|
|
|
$#argument_types = -1;
|
2002-06-01 04:55:48 +02:00
|
|
|
$#argument_names = -1;
|
1999-09-23 17:14:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if($options->debug) {
|
|
|
|
print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
|
|
|
|
}
|
2001-07-11 19:27:45 +02:00
|
|
|
|
|
|
|
&$function_begin($documentation_line, $documentation,
|
|
|
|
$function_line, $linkage, $return_type, $calling_convention, $name,
|
|
|
|
\@argument_types,\@argument_names,\@argument_documentations);
|
2000-03-24 21:39:51 +01:00
|
|
|
if($level == 0) {
|
2001-08-09 23:35:38 +02:00
|
|
|
&$function_end(undef, undef);
|
2000-03-24 21:39:51 +01:00
|
|
|
}
|
2001-08-09 23:35:38 +02:00
|
|
|
$statements_line = $.;
|
2001-07-30 20:49:10 +02:00
|
|
|
$statements = "";
|
2001-02-12 04:44:41 +01:00
|
|
|
} elsif(/__ASM_GLOBAL_FUNC\(\s*(.*?)\s*,/s) {
|
2001-07-24 01:20:56 +02:00
|
|
|
my @lines = split(/\n/, $&);
|
|
|
|
my $function_line = $. - scalar(@lines) + 1;
|
|
|
|
|
2001-02-12 04:44:41 +01:00
|
|
|
$_ = $'; $again = 1;
|
2001-07-24 01:20:56 +02:00
|
|
|
|
2001-07-11 19:27:45 +02:00
|
|
|
&$function_begin($documentation_line, $documentation,
|
2001-07-24 01:20:56 +02:00
|
|
|
$function_line, "", "void", "__asm", $1);
|
2001-08-09 23:35:38 +02:00
|
|
|
&$function_end($., "");
|
2004-02-20 20:57:42 +01:00
|
|
|
} elsif(/DEFINE_THISCALL_WRAPPER\((\S*)\)/s) {
|
|
|
|
my @lines = split(/\n/, $&);
|
|
|
|
my $function_line = $. - scalar(@lines) + 1;
|
|
|
|
|
|
|
|
$_ = $'; $again = 1;
|
|
|
|
|
|
|
|
&$function_begin($documentation_line, $documentation,
|
|
|
|
$function_line, "", "void", "", "__thiscall_" . $1, \());
|
|
|
|
&$function_end($function_line, "");
|
1999-12-12 00:01:45 +01:00
|
|
|
} elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
|
|
|
|
$_ = $'; $again = 1;
|
|
|
|
$regs_entrypoints{$2} = $1;
|
2001-06-11 22:13:21 +02:00
|
|
|
} elsif(/DEFAULT_DEBUG_CHANNEL\s*\((\S+)\)/s) {
|
|
|
|
$_ = $'; $again = 1;
|
|
|
|
unshift @$debug_channels, $1;
|
|
|
|
} elsif(/(DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\((\S+)\)/s) {
|
|
|
|
$_ = $'; $again = 1;
|
|
|
|
push @$debug_channels, $1;
|
2020-04-14 16:55:44 +02:00
|
|
|
} elsif(/typedef\s+(enum|interface|struct|union)(?:\s+DECLSPEC_ALIGN\(\d+\))?(?:\s+(\w+))?\s*\{/s) {
|
2001-07-26 23:42:12 +02:00
|
|
|
$_ = $'; $again = 1;
|
|
|
|
$level++;
|
|
|
|
my $type = $1;
|
|
|
|
if(defined($2)) {
|
|
|
|
$type .= " $2";
|
|
|
|
}
|
|
|
|
&$type_begin($type);
|
|
|
|
} elsif(/typedef\s+
|
2005-12-02 11:27:13 +01:00
|
|
|
((?:const\s+|CONST\s+|enum\s+|interface\s+|long\s+|signed\s+|short\s+|struct\s+|union\s+|unsigned\s+|volatile\s+)*?)
|
2001-07-26 23:42:12 +02:00
|
|
|
(\w+)
|
2005-09-06 11:23:46 +02:00
|
|
|
(?:\s+const|\s+volatile)?
|
2005-08-08 13:06:24 +02:00
|
|
|
((?:\s*(?:(?:FAR|__RPC_FAR|TW_HUGE)?\s*)?\*+\s*|\s+)(?:volatile\s+|DECLSPEC_ALIGN\(\d+\)\s+)?\w+\s*(?:\[[^\]]*\])*
|
2005-07-24 19:09:37 +02:00
|
|
|
(?:\s*,\s*(?:\s*(?:(?:FAR|__RPC_FAR|TW_HUGE)?\s*)?\*+\s*|\s+)\w+\s*(?:\[[^\]]*\])?)*)
|
2002-06-01 04:55:48 +02:00
|
|
|
\s*;/sx)
|
2001-07-26 23:42:12 +02:00
|
|
|
{
|
|
|
|
$_ = $'; $again = 1;
|
|
|
|
|
|
|
|
my $type = "$1 $2";
|
|
|
|
|
|
|
|
my @names;
|
|
|
|
my @parts = split(/\s*,\s*/, $2);
|
|
|
|
foreach my $part (@parts) {
|
2005-07-24 19:09:37 +02:00
|
|
|
if($part =~ /(?:\s*((?:(?:FAR|__RPC_FAR|TW_HUGE)?\s*)?\*+)\s*|\s+)(\w+)\s*(\[[^\]]*\])?/) {
|
2001-07-26 23:42:12 +02:00
|
|
|
my $name = $2;
|
|
|
|
if(defined($1)) {
|
|
|
|
$name = "$1$2";
|
|
|
|
}
|
|
|
|
if(defined($3)) {
|
|
|
|
$name .= $3;
|
|
|
|
}
|
|
|
|
push @names, $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&$type_begin($type);
|
|
|
|
&$type_end([@names]);
|
|
|
|
} elsif(/typedef\s+
|
2005-12-02 11:27:13 +01:00
|
|
|
(?:(?:const\s+|enum\s+|interface\s+|long\s+|signed\s+|short\s+|struct\s+|union\s+|unsigned\s+|volatile\s+)*?)
|
2005-08-08 13:06:24 +02:00
|
|
|
(\w+(?:\s*\*+\s*)?)\s*
|
2001-07-26 23:42:12 +02:00
|
|
|
(?:(\w+)\s*)?
|
2005-08-08 13:06:24 +02:00
|
|
|
\((?:(\w+)\s*)?\s*(?:\*\s*(\w+)|_ATL_CATMAPFUNC)\s*\)\s*
|
2002-06-01 04:55:48 +02:00
|
|
|
(?:\(([^\)]*)\)|\[([^\]]*)\])\s*;/sx)
|
2001-07-26 23:42:12 +02:00
|
|
|
{
|
2002-06-01 04:55:48 +02:00
|
|
|
$_ = $'; $again = 1;
|
2001-07-26 23:42:12 +02:00
|
|
|
my $type;
|
|
|
|
if(defined($2) || defined($3)) {
|
|
|
|
my $cc = $2 || $3;
|
|
|
|
if(defined($5)) {
|
|
|
|
$type = "$1 ($cc *)($5)";
|
|
|
|
} else {
|
|
|
|
$type = "$1 ($cc *)[$6]";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(defined($5)) {
|
|
|
|
$type = "$1 (*)($5)";
|
|
|
|
} else {
|
|
|
|
$type = "$1 (*)[$6]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $name = $4;
|
|
|
|
&$type_begin($type);
|
|
|
|
&$type_end([$name]);
|
|
|
|
} elsif(/typedef[^\{;]*;/s) {
|
|
|
|
$_ = $'; $again = 1;
|
2020-04-14 16:55:27 +02:00
|
|
|
$output->write("$file: $.: could not parse typedef: '$&'\n");
|
2001-07-26 23:42:12 +02:00
|
|
|
} elsif(/typedef[^\{]*\{[^\}]*\}[^;];/s) {
|
|
|
|
$_ = $'; $again = 1;
|
2020-04-14 16:55:27 +02:00
|
|
|
$output->write("$file: $.: could not parse multi-line typedef: '$&'\n");
|
2000-03-24 21:39:51 +01:00
|
|
|
} elsif(/\'[^\']*\'/s) {
|
1999-09-23 17:14:20 +02:00
|
|
|
$_ = $'; $again = 1;
|
2004-10-21 21:56:04 +02:00
|
|
|
} elsif(/\"(?:[^\\\"]*|\\.)*\"/s) {
|
2000-03-24 21:39:51 +01:00
|
|
|
$_ = $'; $again = 1;
|
|
|
|
} elsif(/;/s) {
|
1999-09-23 17:14:20 +02:00
|
|
|
$_ = $'; $again = 1;
|
2000-04-06 22:11:04 +02:00
|
|
|
} elsif(/extern\s+"C"\s+{/s) {
|
|
|
|
$_ = $'; $again = 1;
|
2000-03-24 21:39:51 +01:00
|
|
|
} elsif(/\{/s) {
|
|
|
|
$_ = $'; $again = 1;
|
|
|
|
print "+1: $_\n" if $options->debug >= 2;
|
|
|
|
$level++;
|
1999-09-23 17:14:20 +02:00
|
|
|
} else {
|
|
|
|
$lookahead = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
print STDERR "done\n" if $options->verbose;
|
1999-10-31 03:08:38 +01:00
|
|
|
$output->write("$file: not at toplevel at end of file\n") unless $level == 0;
|
1999-09-23 17:14:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|