wineps: Don't use CDECL for private functions.
[wine.git] / tools / winapi / preprocessor.pm
blob796f7dfae2899a2fdd865b370d7d0d8412bcf285
2 # Copyright 1999, 2000, 2001 Patrik Stridvall
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 package preprocessor;
21 use strict;
22 use warnings 'all';
24 sub new($) {
25 my $proto = shift;
26 my $class = ref($proto) || $proto;
27 my $self = {};
28 bless ($self, $class);
30 my $state = \%{$self->{STATE}};
31 my $stack = \@{$self->{STACK}};
32 my $include_found = \${$self->{INCLUDE_FOUND}};
33 my $conditional_found = \${$self->{CONDITIONAL_FOUND}};
35 $$include_found = shift;
36 $$conditional_found = shift;
38 return $self;
41 sub include($$) {
42 my $self = shift;
43 my $include_found = \${$self->{INCLUDE_FOUND}};
45 my $argument = shift;
47 &$$include_found($argument);
50 sub define($$) {
51 my $self = shift;
52 my $state = \%{$self->{STATE}};
53 my $conditional_found = \${$self->{CONDITIONAL_FOUND}};
55 my $name = shift;
57 $$state{$name} = "def";
59 &$$conditional_found($name);
62 sub undefine($$) {
63 my $self = shift;
64 my $state = \%{$self->{STATE}};
65 my $conditional_found = \${$self->{CONDITIONAL_FOUND}};
67 my $name = shift;
69 $$state{$name} = "undef";
71 &$$conditional_found($name);
74 sub begin_if($$$) {
75 my $self = shift;
76 my $state = \%{$self->{STATE}};
77 my $stack = \@{$self->{STACK}};
79 my $directive = shift;
80 local $_ = shift;
82 while(!/^$/) {
83 if(/^0\s*\&\&/s) {
84 $_ = "0";
85 } elsif(/^1\s*\|\|/s) {
86 $_ = "1";
89 if (/^(!\s*)?defined\s*\(\s*(\w+)\s*\)\s*(?:(\&\&|\|\|)\s*)?/s ||
90 /^(!\s*)?defined\s*(\w+)\s*(?:(\&\&|\|\|)\s*)?/s)
92 $_ = $';
94 my $sign = $1;
95 my $var = $2;
97 if (defined($sign) && $sign eq "!") {
98 $self->undefine($var);
99 push @$stack, $var;
100 } else {
101 $self->define($var);
102 push @$stack, $var;
104 } elsif (/^(!\s*)?(\w+)\s*(?:(<|<=|==|!=|>=|>|\+|\-|\*\/)\s*(\w+)\s*)?(?:(\&\&|\|\|)\s*)?/s) {
105 $_ = $';
107 my $sign = $1;
108 my $var = $2;
110 if (defined($sign) && $sign eq "!") {
111 $self->undefine($var);
112 push @$stack, $var;
113 } else {
114 $self->define($var);
115 push @$stack, $var;
117 } elsif(/^(!\s*)?\(/s) {
118 $_ = "";
119 } else {
120 print "*** Can't parse '#$directive $_' ***\n";
121 $_ = "";
126 sub else_if($$) {
127 my $self = shift;
128 my $state = \%{$self->{STATE}};
129 my $stack = \@{$self->{STACK}};
131 my $argument = shift;
133 $self->end_if;
135 if(defined($argument)) {
136 $self->begin_if("elif", $argument);
140 sub end_if($) {
141 my $self = shift;
142 my $state = \%{$self->{STATE}};
143 my $stack = \@{$self->{STACK}};
145 my $macro = pop @$stack;
146 delete $$state{$macro} if defined($macro);
149 sub directive($$$) {
150 my $self = shift;
151 my $state = \%{$self->{STATE}};
152 my $stack = \@{$self->{STACK}};
154 my $directive = shift;
155 my $argument = shift;
157 local $_ = $directive;
158 if(/^if$/) {
159 $self->begin_if("if",$argument);
160 } elsif(/^ifdef$/) {
161 $self->begin_if("if", "defined($argument)");
162 } elsif(/^ifndef$/) {
163 $self->begin_if("if", "!defined($argument)");
164 push @$stack, $argument;
165 } elsif(/^elif$/) {
166 $self->else_if($argument);
167 } elsif(/^else$/) {
168 $self->else_if;
169 } elsif(/^endif$/) {
170 $self->end_if;
171 } elsif(/^include/) {
172 $self->include($argument);
176 sub is_def($$) {
177 my $self = shift;
178 my $state = \%{$self->{STATE}};
180 my $name = shift;
182 my $status = $$state{$name};
184 return defined($status) && $status eq "def";
187 sub is_undef($$) {
188 my $self = shift;
189 my $state = \%{$self->{STATE}};
191 my $name = shift;
193 my $status = $$state{$name};
195 return defined($status) && $status eq "undef";
198 sub is_unknown($$) {
199 my $self = shift;
200 my $state = \%{$self->{STATE}};
202 my $name = shift;
204 my $status = $$state{$name};
206 return !defined($status);