1 ####################################################################
3 # This file was generated using Parse::Yapp version 1.05.
5 # Don't edit this file, use source file instead.
7 # ANY CHANGE MADE HERE WILL BE LOST !
9 ####################################################################
10 package Parse::Pidl::IDL;
14 @ISA= qw ( Parse::Yapp::Driver );
15 #Included Parse/Yapp/Driver.pm file----------------------------------------
18 # Module Parse::Yapp::Driver
20 # This module is part of the Parse::Yapp package available on your
23 # Any use of this module in a standalone parser make the included
24 # text under the same copyright as the Parse::Yapp module itself.
26 # This notice should remain unchanged.
28 # (c) Copyright 1998-2001 Francois Desarmenien, all rights reserved.
29 # (see the pod text in Parse::Yapp module for use and distribution rights)
32 package Parse::Yapp::Driver;
38 use vars qw ( $VERSION $COMPATIBLE $FILENAME );
46 #Known parameters, all starting with YY (leading YY will be discarded)
47 my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '',
48 YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => '');
50 my(@params)=('LEX','RULES','STATES');
54 my($errst,$nberr,$token,$value,$check,$dotpos);
55 my($self)={ ERROR => \&_Error,
65 _CheckParams( [], \%params, \@_, $self );
67 exists($$self{VERSION})
68 and $$self{VERSION} < $COMPATIBLE
69 and croak "Yapp driver version $VERSION ".
70 "incompatible with version $$self{VERSION}:\n".
71 "Please recompile parser module.";
74 and $class=ref($class);
83 _CheckParams( \@params, \%params, \@_, $self );
87 $retval = eval '$self->_DBParse()';#Do not create stab entry on compile
91 $retval = $self->_Parse();
122 ${$$self{ERRST}} != 0;
128 ${$$self{CHECK}}='ABORT';
135 ${$$self{CHECK}}='ACCEPT';
142 ${$$self{CHECK}}='ERROR';
148 my($index)= $_[0] - ${$$self{DOTPOS}} - 1;
151 and -$index <= @{$$self{STACK}}
152 and return $$self{STACK}[$index][1];
154 undef; #Invalid index
161 and ${$$self{TOKEN}}=$_[0];
169 and ${$$self{VALUE}}=$_[0];
176 keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
192 my($mandatory,$checklist,$inarray,$outhash)=@_;
196 while(($prm,$value)=splice(@$inarray,0,2)) {
198 exists($$checklist{$prm})
199 or croak("Unknow parameter '$prm'");
200 ref($value) eq $$checklist{$prm}
201 or croak("Invalid value for parameter '$prm'");
202 $prm=unpack('@2A*',$prm);
203 $$outhash{$prm}=$value;
206 exists($$outhash{$_})
207 or croak("Missing mandatory parameter '".lc($_)."'");
212 print "Parse error.\n";
219 exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
224 open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname";
226 /^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
238 #Note that for loading debugging version of the driver,
239 #this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
240 #So, DO NOT remove comment at end of sub !!!
244 my($rules,$states,$lex,$error)
245 = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
246 my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
247 = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };
249 #DBG> my($debug)=$$self{DEBUG};
250 #DBG> my($dbgerror)=0;
252 #DBG> my($ShowCurToken) = sub {
254 #DBG> for (split('',$$token)) {
255 #DBG> $tok.= (ord($_) < 32 or ord($_) > 126)
256 #DBG> ? sprintf('<%02X>',ord($_))
264 ($$token,$$value)=(undef,undef);
265 @$stack=( [ 0, undef ] );
269 my($actions,$act,$stateno);
271 $stateno=$$stack[-1][0];
272 $actions=$$states[$stateno];
274 #DBG> print STDERR ('-' x 40),"\n";
276 #DBG> and print STDERR "In state $stateno:\n";
278 #DBG> and print STDERR "Stack:[".
279 #DBG> join(',',map { $$_[0] } @$stack).
283 if (exists($$actions{ACTIONS})) {
287 ($$token,$$value)=&$lex($self);
289 #DBG> and print STDERR "Need token. Got ".&$ShowCurToken."\n";
292 $act= exists($$actions{ACTIONS}{$$token})
293 ? $$actions{ACTIONS}{$$token}
294 : exists($$actions{DEFAULT})
299 $act=$$actions{DEFAULT};
301 #DBG> and print STDERR "Don't need token.\n";
311 #DBG> and print STDERR "Shift and go to state $act.\n";
319 #DBG> and $$errstatus == 0
321 #DBG> print STDERR "**End of Error recovery.\n";
327 push(@$stack,[ $act, $$value ]);
329 $$token ne '' #Don't eat the eof
330 and $$token=$$value=undef;
335 my($lhs,$len,$code,@sempar,$semval);
336 ($lhs,$len,$code)=@{$$rules[-$act]};
340 #DBG> and print STDERR "Reduce using rule ".-$act." ($lhs,$len): ";
343 or $self->YYAccept();
347 unpack('A1',$lhs) eq '@' #In line rule
349 $lhs =~ /^\@[0-9]+\-([0-9]+)$/
350 or die "In line rule name '$lhs' ill formed: ".
351 "report it as a BUG.\n";
356 ? map { $$_[1] } @$stack[ -$$dotpos .. -1 ]
359 $semval = $code ? &$code( $self, @sempar )
360 : @sempar ? $sempar[0] : undef;
362 splice(@$stack,-$len,$len);
368 #DBG> and print STDERR "Accept.\n";
377 #DBG> and print STDERR "Abort.\n";
384 #DBG> and print STDERR "Back to state $$stack[-1][0], then ";
389 #DBG> and print STDERR
390 #DBG> "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n";
394 #DBG> and $$errstatus == 0
396 #DBG> print STDERR "**End of Error recovery.\n";
401 [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]);
407 #DBG> and print STDERR "Forced Error recovery.\n";
419 $$errstatus # if 0, then YYErrok has been called
420 or next; # so continue parsing
424 #DBG> print STDERR "**Entering Error recovery.\n";
432 $$errstatus == 3 #The next token is not valid: discard it
434 $$token eq '' # End of input: no hope
437 #DBG> and print STDERR "**At eof: aborting.\n";
442 #DBG> and print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n";
444 $$token=$$value=undef;
450 and ( not exists($$states[$$stack[-1][0]]{ACTIONS})
451 or not exists($$states[$$stack[-1][0]]{ACTIONS}{error})
452 or $$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) {
455 #DBG> and print STDERR "**Pop state $$stack[-1][0].\n";
464 #DBG> and print STDERR "**No state left on stack: aborting.\n";
469 #shift the error token
472 #DBG> and print STDERR "**Shift \$error token and go to state ".
473 #DBG> $$states[$$stack[-1][0]]{ACTIONS}{error}.
476 push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]);
481 croak("Error in driver logic. Please, report it as a BUG");
484 #DO NOT remove comment
489 #End of include--------------------------------------------------
497 and $class=ref($class);
499 my($self)=$class->SUPER::new( yyversion => '1.05',
590 'base_interface' => 20
596 'interface_names' => 21
706 'property_list' => 53,
722 'optional_semicolon' => 69
801 'commalisttext' => 76
844 'commalisttext' => 79
923 'property_list' => 85
932 'optional_identifier' => 87
955 'property_list' => 53,
996 'property_list' => 95
1022 'optional_identifier' => 97
1034 'optional_identifier' => 98
1043 'optional_identifier' => 99
1247 'optional_semicolon' => 106
1281 'decl_bitmap' => 109,
1364 'union_elements' => 121
1407 'element_list1' => 127
1415 'identifier' => 128,
1416 'enum_element' => 129,
1417 'enum_elements' => 130
1425 'identifier' => 133,
1426 'bitmap_elements' => 132,
1427 'bitmap_element' => 131
1487 'optional_base_element' => 137,
1488 'property_list' => 136
1499 'base_element' => 138,
1500 'element_list2' => 140,
1501 'property_list' => 139
1549 'base_element' => 148,
1550 'property_list' => 139
1596 'base_or_empty' => 156,
1597 'base_element' => 157,
1598 'empty_element' => 158,
1599 'property_list' => 159
1727 'identifier' => 128,
1728 'enum_element' => 169
1739 'identifier' => 133,
1740 'bitmap_element' => 170
1801 'base_element' => 175,
1802 'property_list' => 139
1939 #line 19 "build/pidl/idl.yp"
1940 { push(@{$_[1]}, $_[2]); $_[1] }
1945 #line 20 "build/pidl/idl.yp"
1946 { push(@{$_[1]}, $_[2]); $_[1] }
1951 #line 24 "build/pidl/idl.yp"
1953 "TYPE" => "COCLASS",
1954 "PROPERTIES" => $_[1],
1957 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
1958 "LINE" => $_[0]->YYData->{LINE},
1962 'interface_names', 0, undef
1965 'interface_names', 4,
1967 #line 36 "build/pidl/idl.yp"
1968 { push(@{$_[1]}, $_[2]); $_[1] }
1973 #line 40 "build/pidl/idl.yp"
1975 "TYPE" => "INTERFACE",
1976 "PROPERTIES" => $_[1],
1980 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
1981 "LINE" => $_[0]->YYData->{LINE},
1985 'base_interface', 0, undef
1988 'base_interface', 2,
1990 #line 53 "build/pidl/idl.yp"
1996 #line 57 "build/pidl/idl.yp"
2002 #line 58 "build/pidl/idl.yp"
2003 { push(@{$_[1]}, $_[2]); $_[1] }
2006 'definition', 1, undef
2009 'definition', 1, undef
2012 'definition', 1, undef
2015 'definition', 1, undef
2018 'definition', 1, undef
2023 #line 66 "build/pidl/idl.yp"
2029 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2030 "LINE" => $_[0]->YYData->{LINE},
2036 #line 75 "build/pidl/idl.yp"
2041 "ARRAY_LEN" => $_[4],
2043 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2044 "LINE" => $_[0]->YYData->{LINE},
2050 #line 88 "build/pidl/idl.yp"
2052 "TYPE" => "FUNCTION",
2054 "RETURN_TYPE" => $_[2],
2055 "PROPERTIES" => $_[1],
2056 "ELEMENTS" => $_[5],
2057 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2058 "LINE" => $_[0]->YYData->{LINE},
2064 #line 100 "build/pidl/idl.yp"
2066 "TYPE" => "DECLARE",
2067 "PROPERTIES" => $_[2],
2070 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2071 "LINE" => $_[0]->YYData->{LINE},
2075 'decl_type', 1, undef
2078 'decl_type', 1, undef
2083 #line 114 "build/pidl/idl.yp"
2091 #line 120 "build/pidl/idl.yp"
2099 #line 126 "build/pidl/idl.yp"
2101 "TYPE" => "TYPEDEF",
2102 "PROPERTIES" => $_[2],
2105 "ARRAY_LEN" => $_[5],
2106 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2107 "LINE" => $_[0]->YYData->{LINE},
2111 'usertype', 1, undef
2114 'usertype', 1, undef
2117 'usertype', 1, undef
2120 'usertype', 1, undef
2125 #line 139 "build/pidl/idl.yp"
2137 #line 142 "build/pidl/idl.yp"
2143 #line 146 "build/pidl/idl.yp"
2153 #line 154 "build/pidl/idl.yp"
2159 #line 155 "build/pidl/idl.yp"
2160 { push(@{$_[1]}, $_[3]); $_[1] }
2163 'enum_element', 1, undef
2168 #line 159 "build/pidl/idl.yp"
2169 { "$_[1]$_[2]$_[3]" }
2174 #line 163 "build/pidl/idl.yp"
2182 'bitmap_elements', 1,
2184 #line 171 "build/pidl/idl.yp"
2188 'bitmap_elements', 3,
2190 #line 172 "build/pidl/idl.yp"
2191 { push(@{$_[1]}, $_[3]); $_[1] }
2194 'bitmap_element', 3,
2196 #line 175 "build/pidl/idl.yp"
2197 { "$_[1] ( $_[3] )" }
2202 #line 179 "build/pidl/idl.yp"
2212 #line 187 "build/pidl/idl.yp"
2216 "PROPERTIES" => $_[1],
2219 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2220 "LINE" => $_[0]->YYData->{LINE},
2224 'base_or_empty', 2, undef
2227 'base_or_empty', 1, undef
2230 'optional_base_element', 2,
2232 #line 201 "build/pidl/idl.yp"
2233 { $_[2]->{PROPERTIES} = Parse::Pidl::Util::FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] }
2236 'union_elements', 0, undef
2239 'union_elements', 2,
2241 #line 206 "build/pidl/idl.yp"
2242 { push(@{$_[1]}, $_[2]); $_[1] }
2247 #line 210 "build/pidl/idl.yp"
2257 #line 218 "build/pidl/idl.yp"
2261 "PROPERTIES" => $_[1],
2262 "POINTERS" => $_[3],
2263 "ARRAY_LEN" => $_[5],
2264 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2265 "LINE" => $_[0]->YYData->{LINE},
2271 #line 232 "build/pidl/idl.yp"
2277 #line 233 "build/pidl/idl.yp"
2281 'element_list1', 0, undef
2286 #line 238 "build/pidl/idl.yp"
2287 { push(@{$_[1]}, $_[2]); $_[1] }
2290 'element_list2', 0, undef
2293 'element_list2', 1, undef
2298 #line 244 "build/pidl/idl.yp"
2304 #line 245 "build/pidl/idl.yp"
2305 { push(@{$_[1]}, $_[3]); $_[1] }
2308 'array_len', 0, undef
2313 #line 250 "build/pidl/idl.yp"
2314 { push(@{$_[3]}, "*"); $_[3] }
2319 #line 251 "build/pidl/idl.yp"
2320 { push(@{$_[4]}, "$_[2]"); $_[4] }
2323 'property_list', 0, undef
2328 #line 257 "build/pidl/idl.yp"
2329 { Parse::Pidl::Util::FlattenHash([$_[1],$_[3]]); }
2334 #line 260 "build/pidl/idl.yp"
2340 #line 261 "build/pidl/idl.yp"
2341 { Parse::Pidl::Util::FlattenHash([$_[1], $_[3]]); }
2346 #line 264 "build/pidl/idl.yp"
2347 {{ "$_[1]" => "1" }}
2352 #line 265 "build/pidl/idl.yp"
2353 {{ "$_[1]" => "$_[3]" }}
2356 'listtext', 1, undef
2361 #line 270 "build/pidl/idl.yp"
2365 'commalisttext', 1, undef
2370 #line 275 "build/pidl/idl.yp"
2376 #line 279 "build/pidl/idl.yp"
2391 #line 281 "build/pidl/idl.yp"
2392 { "$_[1]$_[2]$_[3]" }
2397 #line 282 "build/pidl/idl.yp"
2398 { "$_[1]$_[2]$_[3]" }
2403 #line 283 "build/pidl/idl.yp"
2404 { "$_[1]$_[2]$_[3]" }
2409 #line 284 "build/pidl/idl.yp"
2410 { "$_[1]$_[2]$_[3]" }
2415 #line 285 "build/pidl/idl.yp"
2416 { "$_[1]$_[2]$_[3]" }
2421 #line 286 "build/pidl/idl.yp"
2422 { "$_[1]$_[2]$_[3]" }
2427 #line 287 "build/pidl/idl.yp"
2428 { "$_[1]$_[2]$_[3]" }
2433 #line 288 "build/pidl/idl.yp"
2434 { "$_[1]$_[2]$_[3]" }
2439 #line 289 "build/pidl/idl.yp"
2440 { "$_[1]$_[2]$_[3]" }
2445 #line 290 "build/pidl/idl.yp"
2446 { "$_[1]$_[2]$_[3]" }
2451 #line 291 "build/pidl/idl.yp"
2452 { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
2457 #line 292 "build/pidl/idl.yp"
2458 { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
2461 'identifier', 1, undef
2464 'optional_identifier', 1, undef
2467 'optional_identifier', 0, undef
2470 'constant', 1, undef
2475 #line 306 "build/pidl/idl.yp"
2479 'optional_semicolon', 0, undef
2482 'optional_semicolon', 1, undef
2486 bless($self,$class);
2489 #line 317 "build/pidl/idl.yp"
2492 use Parse::Pidl::Util;
2494 #####################################################################
2495 # traverse a perl data structure removing any empty arrays or
2496 # hashes and any hash elements that map to undef
2501 if (ref($v) eq "ARRAY") {
2502 foreach my $i (0 .. $#{$v}) {
2503 CleanData($v->[$i]);
2504 if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) {
2509 # this removes any undefined elements from the array
2510 @{$v} = grep { defined $_ } @{$v};
2511 } elsif (ref($v) eq "HASH") {
2512 foreach my $x (keys %{$v}) {
2513 CleanData($v->{$x});
2514 if (!defined $v->{$x}) { delete($v->{$x}); next; }
2515 if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; }
2522 if (exists $_[0]->YYData->{ERRMSG}) {
2523 print $_[0]->YYData->{ERRMSG};
2524 delete $_[0]->YYData->{ERRMSG};
2527 my $line = $_[0]->YYData->{LINE};
2528 my $last_token = $_[0]->YYData->{LAST_TOKEN};
2529 my $file = $_[0]->YYData->{INPUT_FILENAME};
2531 print "$file:$line: Syntax error near '$last_token'\n";
2538 $parser->YYData->{INPUT} or return('',undef);
2541 $parser->YYData->{INPUT} =~ s/^[ \t]*//;
2543 for ($parser->YYData->{INPUT}) {
2545 if (s/^\# (\d+) \"(.*?)\"( \d+|)//) {
2546 $parser->YYData->{LINE} = $1-1;
2547 $parser->YYData->{INPUT_FILENAME} = $2;
2550 if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) {
2551 $parser->YYData->{LINE} = $1-1;
2552 $parser->YYData->{INPUT_FILENAME} = $2;
2555 if (s/^(\#.*)$//m) {
2560 $parser->YYData->{LINE}++;
2563 if (s/^\"(.*?)\"//) {
2564 $parser->YYData->{LAST_TOKEN} = $1;
2567 if (s/^(\d+)(\W|$)/$2/) {
2568 $parser->YYData->{LAST_TOKEN} = $1;
2569 return('CONSTANT',$1);
2571 if (s/^([\w_]+)//) {
2572 $parser->YYData->{LAST_TOKEN} = $1;
2574 /^(coclass|interface|const|typedef|declare|union
2575 |struct|enum|bitmap|void)$/x) {
2578 return('IDENTIFIER',$1);
2581 $parser->YYData->{LAST_TOKEN} = $1;
2589 my ($self,$filename) = @_;
2591 my $saved_delim = $/;
2593 my $cpp = $ENV{CPP};
2594 if (! defined $cpp) {
2597 my $data = `$cpp -D__PIDL__ -xc $filename`;
2600 $self->YYData->{INPUT} = $data;
2601 $self->YYData->{LINE} = 0;
2602 $self->YYData->{LAST_TOKEN} = "NONE";
2604 my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
2606 return CleanData($idl);