winapi: Introduce a pseudo-loop in parse_c_variable() to get rid of the $finished variable.

Francois Gouget fgouget at free.fr
Thu Jul 9 02:52:08 CDT 2009


---
 tools/winapi/c_parser.pm |  212 ++++++++++++++++++++++------------------------
 1 files changed, 103 insertions(+), 109 deletions(-)

diff --git a/tools/winapi/c_parser.pm b/tools/winapi/c_parser.pm
index d5832b9..28617f3 100644
--- a/tools/winapi/c_parser.pm
+++ b/tools/winapi/c_parser.pm
@@ -1692,126 +1692,120 @@ sub parse_c_variable($$$$$$$)
 	}
     }
 
-    my $finished = 0;
+    return 0 if(/^$/);
 
-    if($finished) {
-	# Nothing
-    } elsif(/^$/) {
-	return 0;
-    } elsif (s/^(enum\s+|interface\s+|struct\s+|union\s+)((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
-	my $kind = $1;
-	my $_name = $2;
-	$self->_update_c_position($&, \$line, \$column);
-
-	if(defined($_name)) {
-	    $type = "$kind $_name { }";
-	} else {
-	    $type = "$kind { }";
-	}
-
-	$finished = 1;
-    } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s+DECLSPEC_ALIGN\(.*?\)|\s*(?:const\s*|volatile\s*)?\*)*)\s*(\w+)\s*(\[.*?\]$|:\s*(\d+)$|\{)?//s) {
-	$type = "$sign$1";
-	$name = $2;
-
-	if (defined($3)) {
-	    my $bits = $4;
-	    local $_ = $3;
-	    if (/^\[/) {
-		$type .= $_;
-	    } elsif (/^:/) {
-		$type .= ":$bits";
-	    } elsif (/^\{/) {
-		# Nothing
-	    }
-	}
-
-	$type = $self->_format_c_type($type);
-
-	$finished = 1;
-    } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*)\s*:\s*(\d+)$//s) {
-	$type = "$sign$1:$2";
-	$name = "";
-	$type = $self->_format_c_type($type);
-
-	$finished = 1;
-    } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*\s*\(\s*(?:$CALL_CONVENTION)?(?:\s*\*)*)\s*(\w+)\s*(\)\s*\(.*?\))$//s) {
-	$type = $self->_format_c_type("$sign$1$3");
-	$name = $2;
-
-	$finished = 1;
-    } elsif($self->_parse_c('DEFINE_GUID', \$_, \$line, \$column, \$match)) { # Windows specific
-	$type = $match;
-	$finished = 1;
-    } else {
-	$self->_parse_c_warning($_, $line, $column, "variable", "'$_'");
-	$finished = 1;
-    }
-
-    if($finished) {
-	# Nothing
-    } elsif($self->_parse_c('SEQ_DEFINEBUF', \$_, \$line, \$column, \$match)) { # Linux specific
-	$type = $match;
-	$finished = 1;
-    } elsif($self->_parse_c('DEFINE_REGS_ENTRYPOINT_\w+|DPQ_DECL_\w+|HANDLER_DEF|IX86_ONLY', # Wine specific
-			    \$_, \$line, \$column, \$match))
+  finished: while (1)
     {
-	$type = $match;
-	$finished = 1;
-    } elsif($self->_parse_c('(?:struct\s+)?ICOM_VTABLE\s*\(\w+\)', \$_, \$line, \$column, \$match)) {
-	$type = $match;
-	$finished = 1;
-    } elsif(s/^(enum|interface|struct|union)(?:\s+(\w+))?\s*\{.*?\}\s*//s) {
-	my $kind = $1;
-	my $_name = $2;
-	$self->_update_c_position($&, \$line, \$column);
+        if (s/^(enum\s+|interface\s+|struct\s+|union\s+)((?:MSVCRT|WS)\(\s*\w+\s*\)|\w+)?\s*\{\s*//s) {
+            my $kind = $1;
+            my $_name = $2;
+            $self->_update_c_position($&, \$line, \$column);
+
+            if(defined($_name)) {
+                $type = "$kind $_name { }";
+            } else {
+                $type = "$kind { }";
+            }
 
-	if(defined($_name)) {
-	    $type = "struct $_name { }";
-	} else {
-	    $type = "struct { }";
-	}
-    } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+)\s*(?:\*\s*)*//s) {
-	$type = $&;
-	$type =~ s/\s//g;
-    } else {
-	return 0;
-    }
+            last finished;
+        } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s+DECLSPEC_ALIGN\(.*?\)|\s*(?:const\s*|volatile\s*)?\*)*)\s*(\w+)\s*(\[.*?\]$|:\s*(\d+)$|\{)?//s) {
+            $type = "$sign$1";
+            $name = $2;
+
+            if (defined($3)) {
+                my $bits = $4;
+                local $_ = $3;
+                if (/^\[/) {
+                    $type .= $_;
+                } elsif (/^:/) {
+                    $type .= ":$bits";
+                } elsif (/^\{/) {
+                    # Nothing
+                }
+            }
 
-    # $output->write("*** $type: '$_'\n");
+            $type = $self->_format_c_type($type);
+
+            last finished;
+        } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*)\s*:\s*(\d+)$//s) {
+            $type = "$sign$1:$2";
+            $name = "";
+            $type = $self->_format_c_type($type);
+
+            last finished;
+        } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+\b(?:\s*\*)*\s*\(\s*(?:$CALL_CONVENTION)?(?:\s*\*)*)\s*(\w+)\s*(\)\s*\(.*?\))$//s) {
+            $type = $self->_format_c_type("$sign$1$3");
+            $name = $2;
+
+            last finished;
+        } elsif($self->_parse_c('DEFINE_GUID', \$_, \$line, \$column, \$match)) { # Windows specific
+            $type = $match;
+            last finished;
+        } else {
+            $self->_parse_c_warning($_, $line, $column, "variable", "'$_'");
+            last finished;
+        }
 
-    # $self->_parse_c_warning($_, $line, $column, "variable2", "");
+        if($self->_parse_c('SEQ_DEFINEBUF', \$_, \$line, \$column, \$match)) { # Linux specific
+            $type = $match;
+            last finished;
+        } elsif($self->_parse_c('DEFINE_REGS_ENTRYPOINT_\w+|DPQ_DECL_\w+|HANDLER_DEF|IX86_ONLY', # Wine specific
+                                \$_, \$line, \$column, \$match))
+        {
+            $type = $match;
+            last finished;
+        } elsif($self->_parse_c('(?:struct\s+)?ICOM_VTABLE\s*\(\w+\)', \$_, \$line, \$column, \$match)) {
+            $type = $match;
+            last finished;
+        } elsif(s/^(enum|interface|struct|union)(?:\s+(\w+))?\s*\{.*?\}\s*//s) {
+            my $kind = $1;
+            my $_name = $2;
+            $self->_update_c_position($&, \$line, \$column);
+
+            if(defined($_name)) {
+                $type = "struct $_name { }";
+            } else {
+                $type = "struct { }";
+            }
+        } elsif(s/^((?:enum\s+|interface\s+|struct\s+|union\s+)?\w+)\s*(?:\*\s*)*//s) {
+            $type = $&;
+            $type =~ s/\s//g;
+        } else {
+            return 0;
+        }
 
-    if($finished) {
-	# Nothing
-    } elsif(s/^WINAPI\s*//) {
-	$self->_update_c_position($&, \$line, \$column);
-    }
+        # $output->write("*** $type: '$_'\n");
 
-    if($finished) {
-	# Nothing
-    } elsif(s/^(\((?:$CALL_CONVENTION)?\s*\*?\s*(?:$CALL_CONVENTION)?\w+\s*(?:\[[^\]]*\]\s*)*\))\s*\(//) {
-	$self->_update_c_position($&, \$line, \$column);
+        # $self->_parse_c_warning($_, $line, $column, "variable2", "");
 
-	$name = $1;
-	$name =~ s/\s//g;
+        if(s/^WINAPI\s*//) {
+            $self->_update_c_position($&, \$line, \$column);
+        }
 
-	$self->_parse_c_until_one_of("\\)", \$_, \$line, \$column);
-	if(s/^\)//) { $column++; }
-	$self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
+        if(s/^(\((?:$CALL_CONVENTION)?\s*\*?\s*(?:$CALL_CONVENTION)?\w+\s*(?:\[[^\]]*\]\s*)*\))\s*\(//) {
+            $self->_update_c_position($&, \$line, \$column);
 
-        if(!s/^(?:=\s*|,\s*|$)//) {
-	    return 0;
-	}
-    } elsif(s/^(?:\*\s*)*(?:const\s+|volatile\s+)?(\w+)\s*(?:\[[^\]]*\]\s*)*\s*(?:=\s*|,\s*|$)//) {
-	$self->_update_c_position($&, \$line, \$column);
+            $name = $1;
+            $name =~ s/\s//g;
 
-	$name = $1;
-	$name =~ s/\s//g;
-    } elsif(/^$/) {
-	$name = "";
-    } else {
-	return 0;
+            $self->_parse_c_until_one_of("\\)", \$_, \$line, \$column);
+            if(s/^\)//) { $column++; }
+            $self->_parse_c_until_one_of("\\S", \$_, \$line, \$column);
+
+            if(!s/^(?:=\s*|,\s*|$)//) {
+                return 0;
+            }
+        } elsif(s/^(?:\*\s*)*(?:const\s+|volatile\s+)?(\w+)\s*(?:\[[^\]]*\]\s*)*\s*(?:=\s*|,\s*|$)//) {
+            $self->_update_c_position($&, \$line, \$column);
+
+            $name = $1;
+            $name =~ s/\s//g;
+        } elsif(/^$/) {
+            $name = "";
+        } else {
+            return 0;
+        }
+        last finished;
     }
 
     # $output->write("$type: $name: '$_'\n");
-- 
1.6.3.1




More information about the wine-patches mailing list