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
709 'property_list' => 56,
725 'optional_semicolon' => 72
832 'commalisttext' => 81
889 'commalisttext' => 85
968 'property_list' => 91
977 'optional_identifier' => 93
1000 'property_list' => 56,
1028 'existingtype' => 101,
1045 'property_list' => 105
1071 'optional_identifier' => 107
1083 'optional_identifier' => 108
1092 'optional_identifier' => 109
1371 'existingtype' => 101,
1391 'union_body' => 117,
1392 'opt_union_body' => 115
1401 'optional_semicolon' => 118
1453 'decl_bitmap' => 123,
1470 'struct_body' => 129,
1471 'opt_struct_body' => 131
1480 'opt_enum_body' => 134,
1490 'bitmap_body' => 137,
1491 'opt_bitmap_body' => 135
1553 'union_elements' => 142
1611 'element_list1' => 147
1622 'identifier' => 148,
1623 'enum_element' => 149,
1624 'enum_elements' => 150
1642 'identifier' => 153,
1643 'bitmap_element' => 152,
1644 'bitmap_elements' => 151,
1645 'opt_bitmap_elements' => 154
1717 'optional_base_element' => 159,
1718 'property_list' => 158
1729 'base_element' => 160,
1730 'element_list2' => 162,
1731 'property_list' => 161
1757 'base_element' => 168,
1758 'property_list' => 161
1824 'base_or_empty' => 178,
1825 'base_element' => 179,
1826 'empty_element' => 180,
1827 'property_list' => 181
1850 'existingtype' => 101,
1922 'identifier' => 148,
1923 'enum_element' => 189
1931 'identifier' => 153,
1932 'bitmap_element' => 190
2010 'existingtype' => 101,
2030 'base_element' => 197,
2031 'property_list' => 161
2209 { push(@{$_[1]}, $_[2]); $_[1] }
2215 { push(@{$_[1]}, $_[2]); $_[1] }
2222 "TYPE" => "COCLASS",
2223 "PROPERTIES" => $_[1],
2226 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2227 "LINE" => $_[0]->YYData->{LINE},
2231 'interface_names', 0, undef
2234 'interface_names', 4,
2237 { push(@{$_[1]}, $_[2]); $_[1] }
2244 "TYPE" => "INTERFACE",
2245 "PROPERTIES" => $_[1],
2249 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2250 "LINE" => $_[0]->YYData->{LINE},
2254 'base_interface', 0, undef
2257 'base_interface', 2,
2272 { push(@{$_[1]}, $_[2]); $_[1] }
2275 'definition', 1, undef
2278 'definition', 1, undef
2281 'definition', 1, undef
2284 'definition', 1, undef
2287 'definition', 1, undef
2296 "POINTERS" => $_[3],
2299 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2300 "LINE" => $_[0]->YYData->{LINE},
2310 "POINTERS" => $_[3],
2312 "ARRAY_LEN" => $_[5],
2314 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2315 "LINE" => $_[0]->YYData->{LINE},
2323 "TYPE" => "FUNCTION",
2325 "RETURN_TYPE" => $_[2],
2326 "PROPERTIES" => $_[1],
2327 "ELEMENTS" => $_[5],
2328 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2329 "LINE" => $_[0]->YYData->{LINE},
2337 "TYPE" => "DECLARE",
2338 "PROPERTIES" => $_[2],
2341 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2342 "LINE" => $_[0]->YYData->{LINE},
2346 'decl_type', 1, undef
2349 'decl_type', 1, undef
2352 'decl_type', 1, undef
2383 "TYPE" => "TYPEDEF",
2384 "PROPERTIES" => $_[2],
2387 "ARRAY_LEN" => $_[5],
2388 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2389 "LINE" => $_[0]->YYData->{LINE},
2393 'usertype', 1, undef
2396 'usertype', 1, undef
2399 'usertype', 1, undef
2402 'usertype', 1, undef
2417 'existingtype', 0, undef
2426 'existingtype', 1, undef
2447 'opt_enum_body', 0, undef
2450 'opt_enum_body', 1, undef
2472 { push(@{$_[1]}, $_[3]); $_[1] }
2475 'enum_element', 1, undef
2481 { "$_[1]$_[2]$_[3]" }
2490 'opt_bitmap_body', 0, undef
2493 'opt_bitmap_body', 1, undef
2506 'bitmap_elements', 1,
2512 'bitmap_elements', 3,
2515 { push(@{$_[1]}, $_[3]); $_[1] }
2518 'opt_bitmap_elements', 0, undef
2521 'opt_bitmap_elements', 1, undef
2524 'bitmap_element', 3,
2527 { "$_[1] ( $_[3] )" }
2536 'opt_struct_body', 0, undef
2539 'opt_struct_body', 1, undef
2558 "PROPERTIES" => $_[1],
2561 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2562 "LINE" => $_[0]->YYData->{LINE},
2566 'base_or_empty', 2, undef
2569 'base_or_empty', 1, undef
2572 'optional_base_element', 2,
2575 { $_[2]->{PROPERTIES} = FlattenHash([$_[1],$_[2]->{PROPERTIES}]); $_[2] }
2578 'union_elements', 0, undef
2581 'union_elements', 2,
2584 { push(@{$_[1]}, $_[2]); $_[1] }
2593 'opt_union_body', 0, undef
2596 'opt_union_body', 1, undef
2615 "PROPERTIES" => $_[1],
2616 "POINTERS" => $_[3],
2617 "ARRAY_LEN" => $_[5],
2618 "FILE" => $_[0]->YYData->{INPUT_FILENAME},
2619 "LINE" => $_[0]->YYData->{LINE},
2635 'element_list1', 0, undef
2641 { push(@{$_[1]}, $_[2]); $_[1] }
2644 'element_list2', 0, undef
2647 'element_list2', 1, undef
2659 { push(@{$_[1]}, $_[3]); $_[1] }
2662 'array_len', 0, undef
2668 { push(@{$_[3]}, "*"); $_[3] }
2674 { push(@{$_[4]}, "$_[2]"); $_[4] }
2677 'property_list', 0, undef
2683 { FlattenHash([$_[1],$_[3]]); }
2695 { FlattenHash([$_[1], $_[3]]); }
2701 {{ "$_[1]" => "1" }}
2707 {{ "$_[1]" => "$_[3]" }}
2710 'listtext', 1, undef
2719 'commalisttext', 1, undef
2746 { "$_[1]$_[2]$_[3]" }
2752 { "$_[1]$_[2]$_[3]" }
2758 { "$_[1]$_[2]$_[3]" }
2764 { "$_[1]$_[2]$_[3]" }
2770 { "$_[1]$_[2]$_[3]" }
2776 { "$_[1]$_[2]$_[3]" }
2782 { "$_[1]$_[2]$_[3]" }
2788 { "$_[1]$_[2]$_[3]" }
2794 { "$_[1]$_[2]$_[3]" }
2800 { "$_[1]$_[2]$_[3]" }
2806 { "$_[1]$_[2]$_[3]" }
2812 { "$_[1]$_[2]$_[3]" }
2818 { "$_[1]$_[2]$_[3]" }
2824 { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
2830 { "$_[1]$_[2]$_[3]$_[4]$_[5]" }
2833 'identifier', 1, undef
2836 'optional_identifier', 1, undef
2839 'optional_identifier', 0, undef
2842 'constant', 1, undef
2851 'optional_semicolon', 0, undef
2854 'optional_semicolon', 1, undef
2858 bless($self,$class);
2864 #####################################################################
2865 # flatten an array of hashes into a single hash
2871 for my $k (keys %{$d}) {
2880 #####################################################################
2881 # traverse a perl data structure removing any empty arrays or
2882 # hashes and any hash elements that map to undef
2887 return undef if (not defined($v));
2888 if (ref($v) eq "ARRAY") {
2889 foreach my $i (0 .. $#{$v}) {
2890 CleanData($v->[$i]);
2891 if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) {
2896 # this removes any undefined elements from the array
2897 @{$v} = grep { defined $_ } @{$v};
2898 } elsif (ref($v) eq "HASH") {
2899 foreach my $x (keys %{$v}) {
2900 CleanData($v->{$x});
2901 if (!defined $v->{$x}) { delete($v->{$x}); next; }
2902 if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; }
2909 if (exists $_[0]->YYData->{ERRMSG}) {
2910 print $_[0]->YYData->{ERRMSG};
2911 delete $_[0]->YYData->{ERRMSG};
2914 my $line = $_[0]->YYData->{LINE};
2915 my $last_token = $_[0]->YYData->{LAST_TOKEN};
2916 my $file = $_[0]->YYData->{INPUT_FILENAME};
2918 print "$file:$line: Syntax error near '$last_token'\n";
2925 $parser->YYData->{INPUT} or return('',undef);
2928 $parser->YYData->{INPUT} =~ s/^[ \t]*//;
2930 for ($parser->YYData->{INPUT}) {
2932 if (s/^\# (\d+) \"(.*?)\"( \d+|)//) {
2933 $parser->YYData->{LINE} = $1-1;
2934 $parser->YYData->{INPUT_FILENAME} = $2;
2937 if (s/^\#line (\d+) \"(.*?)\"( \d+|)//) {
2938 $parser->YYData->{LINE} = $1-1;
2939 $parser->YYData->{INPUT_FILENAME} = $2;
2942 if (s/^(\#.*)$//m) {
2947 $parser->YYData->{LINE}++;
2950 if (s/^\"(.*?)\"//) {
2951 $parser->YYData->{LAST_TOKEN} = $1;
2954 if (s/^(\d+)(\W|$)/$2/) {
2955 $parser->YYData->{LAST_TOKEN} = $1;
2956 return('CONSTANT',$1);
2958 if (s/^([\w_]+)//) {
2959 $parser->YYData->{LAST_TOKEN} = $1;
2961 /^(coclass|interface|const|typedef|declare|union
2962 |struct|enum|bitmap|void|unsigned|signed)$/x) {
2965 return('IDENTIFIER',$1);
2968 $parser->YYData->{LAST_TOKEN} = $1;
2976 my ($data,$filename) = @_;
2978 my $self = new Parse::Pidl::IDL;
2980 $self->YYData->{INPUT_FILENAME} = $filename;
2981 $self->YYData->{INPUT} = $data;
2982 $self->YYData->{LINE} = 0;
2983 $self->YYData->{LAST_TOKEN} = "NONE";
2985 my $idl = $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
2987 return CleanData($idl);
2992 my ($filename,$incdirs) = @_;
2994 my $saved_delim = $/;
2996 my $cpp = $ENV{CPP};
2997 if (! defined $cpp) {
3000 my $includes = map { " -I$_" } @$incdirs;
3001 my $data = `$cpp -D__PIDL__$includes -xc $filename`;
3004 return parse_string($data, $filename);