Changeset 740 for vendor/current/pidl/lib/Parse/Pidl/NDR.pm
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified vendor/current/pidl/lib/Parse/Pidl/NDR.pm ¶
r414 r740 35 35 $VERSION = '0.01'; 36 36 @ISA = qw(Exporter); 37 @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred Contains String);37 @EXPORT = qw(GetPrevLevel GetNextLevel ContainsDeferred ContainsPipe ContainsString); 38 38 @EXPORT_OK = qw(GetElementLevelTable ParseElement ValidElement align_type mapToScalar ParseType can_contain_deferred is_charset_array); 39 39 40 40 use strict; 41 41 use Parse::Pidl qw(warning fatal); 42 use Parse::Pidl::Typelist qw(hasType getType expandAlias);42 use Parse::Pidl::Typelist qw(hasType getType typeIs expandAlias mapScalarType is_fixed_size_scalar); 43 43 use Parse::Pidl::Util qw(has_property property_matches); 44 44 … … 55 55 'int32' => 4, 56 56 'uint32' => 4, 57 'int3264' => 5, 58 'uint3264' => 5, 57 59 'hyper' => 8, 58 60 'double' => 8, … … 65 67 'string_array' => 4, #??? 66 68 'time_t' => 4, 69 'uid_t' => 8, 70 'gid_t' => 8, 67 71 'NTTIME' => 4, 68 72 'NTTIME_1sec' => 4, … … 71 75 'NTSTATUS' => 4, 72 76 'COMRESULT' => 4, 77 'dns_string' => 4, 73 78 'nbt_string' => 4, 74 79 'wrepl_nbt_name' => 4, 75 'ipv4address' => 4 80 'ipv4address' => 4, 81 'ipv6address' => 4, #16? 82 'dnsp_name' => 1, 83 'dnsp_string' => 1 76 84 }; 77 85 78 sub GetElementLevelTable($$ )79 { 80 my ($e, $pointer_default ) = @_;86 sub GetElementLevelTable($$$) 87 { 88 my ($e, $pointer_default, $ms_union) = @_; 81 89 82 90 my $order = []; … … 102 110 my $needptrs = 1; 103 111 104 if (has_property($e, "string") ) { $needptrs++; }112 if (has_property($e, "string") and not has_property($e, "in")) { $needptrs++; } 105 113 if ($#bracket_array >= 0) { $needptrs = 0; } 106 114 107 115 warning($e, "[out] argument `$e->{NAME}' not a pointer") if ($needptrs > $e->{POINTERS}); 116 } 117 118 my $allow_pipe = ($e->{PARENT}->{TYPE} eq "FUNCTION"); 119 my $is_pipe = typeIs($e->{TYPE}, "PIPE"); 120 121 if ($is_pipe) { 122 if (not $allow_pipe) { 123 fatal($e, "argument `$e->{NAME}' is a pipe and not allowed on $e->{PARENT}->{TYPE}"); 124 } 125 126 if ($e->{POINTERS} > 1) { 127 fatal($e, "$e->{POINTERS} are not allowed on pipe element $e->{NAME}"); 128 } 129 130 if ($e->{POINTERS} < 0) { 131 fatal($e, "pipe element $e->{NAME} needs pointer"); 132 } 133 134 if ($e->{POINTERS} == 1 and pointer_type($e) ne "ref") { 135 fatal($e, "pointer should be 'ref' on pipe element $e->{NAME}"); 136 } 137 138 if (scalar(@size_is) > 0) { 139 fatal($e, "size_is() on pipe element"); 140 } 141 142 if (scalar(@length_is) > 0) { 143 fatal($e, "length_is() on pipe element"); 144 } 145 146 if (scalar(@bracket_array) > 0) { 147 fatal($e, "brackets on pipe element"); 148 } 149 150 if (defined(has_property($e, "subcontext"))) { 151 fatal($e, "subcontext on pipe element"); 152 } 153 154 if (has_property($e, "switch_is")) { 155 fatal($e, "switch_is on pipe element"); 156 } 157 158 if (can_contain_deferred($e->{TYPE})) { 159 fatal($e, "$e->{TYPE} can_contain_deferred - not allowed on pipe element"); 160 } 108 161 } 109 162 … … 123 176 $is_conformant = 1; 124 177 if ($size = shift @size_is) { 178 if ($e->{POINTERS} < 1 and has_property($e, "string")) { 179 $is_string = 1; 180 delete($e->{PROPERTIES}->{string}); 181 } 125 182 } elsif ((scalar(@size_is) == 0) and has_property($e, "string")) { 126 183 $is_string = 1; … … 248 305 } 249 306 307 if ($is_pipe) { 308 push (@$order, { 309 TYPE => "PIPE", 310 IS_DEFERRED => 0, 311 CONTAINS_DEFERRED => 0, 312 }); 313 314 my $i = 0; 315 foreach (@$order) { $_->{LEVEL_INDEX} = $i; $i+=1; } 316 317 return $order; 318 } 319 250 320 if (defined(has_property($e, "subcontext"))) { 251 321 my $hdr_size = has_property($e, "subcontext"); … … 298 368 } 299 369 300 sub GetTypedefLevelTable($$$ )301 { 302 my ($e, $data, $pointer_default ) = @_;370 sub GetTypedefLevelTable($$$$) 371 { 372 my ($e, $data, $pointer_default, $ms_union) = @_; 303 373 304 374 my $order = []; … … 350 420 return "unique" if (has_property($e, "unique")); 351 421 return "relative" if (has_property($e, "relative")); 422 return "relative_short" if (has_property($e, "relative_short")); 352 423 return "ignore" if (has_property($e, "ignore")); 353 424 … … 407 478 if ($dt->{TYPE} eq "TYPEDEF") { 408 479 return align_type($dt->{DATA}); 480 } elsif ($dt->{TYPE} eq "CONFORMANCE") { 481 return $dt->{DATA}->{ALIGN}; 409 482 } elsif ($dt->{TYPE} eq "ENUM") { 410 483 return align_type(Parse::Pidl::Typelist::enum_type_fn($dt)); … … 415 488 return 4 unless (defined($dt->{ELEMENTS})); 416 489 return find_largest_alignment($dt); 490 } elsif (($dt->{TYPE} eq "PIPE")) { 491 return 5; 417 492 } 418 493 … … 420 495 } 421 496 422 sub ParseElement($$ )423 { 424 my ($e, $pointer_default ) = @_;497 sub ParseElement($$$) 498 { 499 my ($e, $pointer_default, $ms_union) = @_; 425 500 426 501 $e->{TYPE} = expandAlias($e->{TYPE}); 427 502 428 503 if (ref($e->{TYPE}) eq "HASH") { 429 $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default );504 $e->{TYPE} = ParseType($e->{TYPE}, $pointer_default, $ms_union); 430 505 } 431 506 … … 434 509 TYPE => $e->{TYPE}, 435 510 PROPERTIES => $e->{PROPERTIES}, 436 LEVELS => GetElementLevelTable($e, $pointer_default ),511 LEVELS => GetElementLevelTable($e, $pointer_default, $ms_union), 437 512 REPRESENTATION_TYPE => ($e->{PROPERTIES}->{represent_as} or $e->{TYPE}), 438 513 ALIGN => align_type($e->{TYPE}), … … 441 516 } 442 517 443 sub ParseStruct($$ )444 { 445 my ($struct, $pointer_default ) = @_;518 sub ParseStruct($$$) 519 { 520 my ($struct, $pointer_default, $ms_union) = @_; 446 521 my @elements = (); 447 522 my $surrounding = undef; … … 461 536 foreach my $x (@{$struct->{ELEMENTS}}) 462 537 { 463 my $e = ParseElement($x, $pointer_default );538 my $e = ParseElement($x, $pointer_default, $ms_union); 464 539 if ($x != $struct->{ELEMENTS}[-1] and 465 540 $e->{LEVELS}[0]->{IS_SURROUNDING}) { … … 498 573 sub ParseUnion($$) 499 574 { 500 my ($e, $pointer_default ) = @_;575 my ($e, $pointer_default, $ms_union) = @_; 501 576 my @elements = (); 577 my $is_ms_union = $ms_union; 578 $is_ms_union = 1 if has_property($e, "ms_union"); 502 579 my $hasdefault = 0; 503 580 my $switch_type = has_property($e, "switch_type"); … … 512 589 PROPERTIES => $e->{PROPERTIES}, 513 590 HAS_DEFAULT => $hasdefault, 591 IS_MS_UNION => $is_ms_union, 514 592 ORIGINAL => $e, 515 593 ALIGN => undef … … 524 602 $t = { TYPE => "EMPTY" }; 525 603 } else { 526 $t = ParseElement($x, $pointer_default );604 $t = ParseElement($x, $pointer_default, $ms_union); 527 605 } 528 606 if (has_property($x, "default")) { … … 549 627 PROPERTIES => $e->{PROPERTIES}, 550 628 HAS_DEFAULT => $hasdefault, 629 IS_MS_UNION => $is_ms_union, 551 630 ORIGINAL => $e, 552 631 ALIGN => $align … … 556 635 sub ParseEnum($$) 557 636 { 558 my ($e, $pointer_default ) = @_;637 my ($e, $pointer_default, $ms_union) = @_; 559 638 560 639 return { … … 568 647 } 569 648 570 sub ParseBitmap($$ )571 { 572 my ($e, $pointer_default ) = @_;649 sub ParseBitmap($$$) 650 { 651 my ($e, $pointer_default, $ms_union) = @_; 573 652 574 653 return { … … 582 661 } 583 662 584 sub ParseType($$) 585 { 586 my ($d, $pointer_default) = @_; 663 sub ParsePipe($$$) 664 { 665 my ($pipe, $pointer_default, $ms_union) = @_; 666 667 my $pname = $pipe->{NAME}; 668 $pname = $pipe->{PARENT}->{NAME} unless defined $pname; 669 670 if (not defined($pipe->{PROPERTIES}) 671 and defined($pipe->{PARENT}->{PROPERTIES})) { 672 $pipe->{PROPERTIES} = $pipe->{PARENT}->{PROPERTIES}; 673 } 674 675 if (ref($pipe->{DATA}) eq "HASH") { 676 if (not defined($pipe->{DATA}->{PROPERTIES}) 677 and defined($pipe->{PROPERTIES})) { 678 $pipe->{DATA}->{PROPERTIES} = $pipe->{PROPERTIES}; 679 } 680 } 681 682 my $struct = ParseStruct($pipe->{DATA}, $pointer_default, $ms_union); 683 $struct->{ALIGN} = 5; 684 $struct->{NAME} = "$pname\_chunk"; 685 686 # 'count' is element [0] and 'array' [1] 687 my $e = $struct->{ELEMENTS}[1]; 688 # level [0] is of type "ARRAY" 689 my $l = $e->{LEVELS}[1]; 690 691 # here we check that pipe elements have a fixed size type 692 while (defined($l)) { 693 my $cl = $l; 694 $l = GetNextLevel($e, $cl); 695 if ($cl->{TYPE} ne "DATA") { 696 fatal($pipe, el_name($pipe) . ": pipe contains non DATA level"); 697 } 698 699 # for now we only support scalars 700 next if is_fixed_size_scalar($cl->{DATA_TYPE}); 701 702 fatal($pipe, el_name($pipe) . ": pipe contains non fixed size type[$cl->{DATA_TYPE}]"); 703 } 704 705 return { 706 TYPE => "PIPE", 707 NAME => $pipe->{NAME}, 708 DATA => $struct, 709 PROPERTIES => $pipe->{PROPERTIES}, 710 ORIGINAL => $pipe, 711 }; 712 } 713 714 sub ParseType($$$) 715 { 716 my ($d, $pointer_default, $ms_union) = @_; 587 717 588 718 my $data = { … … 592 722 BITMAP => \&ParseBitmap, 593 723 TYPEDEF => \&ParseTypedef, 594 }->{$d->{TYPE}}->($d, $pointer_default); 724 PIPE => \&ParsePipe, 725 }->{$d->{TYPE}}->($d, $pointer_default, $ms_union); 595 726 596 727 return $data; … … 599 730 sub ParseTypedef($$) 600 731 { 601 my ($d, $pointer_default) = @_; 602 603 if (defined($d->{DATA}->{PROPERTIES}) && !defined($d->{PROPERTIES})) { 604 $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES}; 605 } 606 607 my $data = ParseType($d->{DATA}, $pointer_default); 608 $data->{ALIGN} = align_type($d->{NAME}); 732 my ($d, $pointer_default, $ms_union) = @_; 733 734 my $data; 735 736 if (ref($d->{DATA}) eq "HASH") { 737 if (defined($d->{DATA}->{PROPERTIES}) 738 and not defined($d->{PROPERTIES})) { 739 $d->{PROPERTIES} = $d->{DATA}->{PROPERTIES}; 740 } 741 742 $data = ParseType($d->{DATA}, $pointer_default, $ms_union); 743 $data->{ALIGN} = align_type($d->{NAME}); 744 } else { 745 $data = getType($d->{DATA}); 746 } 609 747 610 748 return { … … 612 750 TYPE => $d->{TYPE}, 613 751 PROPERTIES => $d->{PROPERTIES}, 614 LEVELS => GetTypedefLevelTable($d, $data, $pointer_default ),752 LEVELS => GetTypedefLevelTable($d, $data, $pointer_default, $ms_union), 615 753 DATA => $data, 616 754 ORIGINAL => $d … … 625 763 } 626 764 627 sub ParseFunction($$$ )628 { 629 my ($ndr,$d,$opnum ) = @_;765 sub ParseFunction($$$$) 766 { 767 my ($ndr,$d,$opnum,$ms_union) = @_; 630 768 my @elements = (); 631 769 my $rettype = undef; … … 640 778 641 779 foreach my $x (@{$d->{ELEMENTS}}) { 642 my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default} );780 my $e = ParseElement($x, $ndr->{PROPERTIES}->{pointer_default}, $ms_union); 643 781 push (@{$e->{DIRECTION}}, "in") if (has_property($x, "in")); 644 782 push (@{$e->{DIRECTION}}, "out") if (has_property($x, "out")); … … 650 788 $rettype = expandAlias($d->{RETURN_TYPE}); 651 789 } 652 653 my $async = 0;654 if (has_property($d, "async")) { $async = 1; }655 790 656 791 return { … … 658 793 TYPE => "FUNCTION", 659 794 OPNUM => $thisopnum, 660 ASYNC => $async,661 795 RETURN_TYPE => $rettype, 662 796 PROPERTIES => $d->{PROPERTIES}, … … 705 839 my $opnum = 0; 706 840 my $version; 841 my $ms_union = 0; 842 $ms_union = 1 if has_property($idl, "ms_union"); 707 843 708 844 if (not has_property($idl, "pointer_default")) { … … 714 850 foreach my $d (@{$idl->{DATA}}) { 715 851 if ($d->{TYPE} eq "FUNCTION") { 716 push (@functions, ParseFunction($idl, $d, \$opnum ));852 push (@functions, ParseFunction($idl, $d, \$opnum, $ms_union)); 717 853 } elsif ($d->{TYPE} eq "CONST") { 718 854 push (@consts, ParseConst($idl, $d)); 719 855 } else { 720 push (@types, ParseType($d, $idl->{PROPERTIES}->{pointer_default} ));856 push (@types, ParseType($d, $idl->{PROPERTIES}->{pointer_default}, $ms_union)); 721 857 FindNestedTypes(\@types, $d); 722 858 } … … 830 966 } 831 967 968 sub ContainsPipe($$) 969 { 970 my ($e,$l) = @_; 971 972 return 1 if ($l->{TYPE} eq "PIPE"); 973 974 while ($l = GetNextLevel($e,$l)) 975 { 976 return 1 if ($l->{TYPE} eq "PIPE"); 977 } 978 979 return 0; 980 } 981 832 982 sub el_name($) 833 983 { … … 878 1028 "pyhelper" => ["INTERFACE"], 879 1029 "authservice" => ["INTERFACE"], 880 "restricted" => ["INTERFACE"], 1030 "restricted" => ["INTERFACE"], 1031 "no_srv_register" => ["INTERFACE"], 881 1032 882 1033 # dcom … … 891 1042 "in" => ["ELEMENT"], 892 1043 "out" => ["ELEMENT"], 893 "async" => ["FUNCTION"],894 1044 895 1045 # pointer 896 "ref" => ["ELEMENT" ],897 "ptr" => ["ELEMENT" ],898 "unique" => ["ELEMENT" ],1046 "ref" => ["ELEMENT", "TYPEDEF"], 1047 "ptr" => ["ELEMENT", "TYPEDEF"], 1048 "unique" => ["ELEMENT", "TYPEDEF"], 899 1049 "ignore" => ["ELEMENT"], 900 "relative" => ["ELEMENT"], 901 "null_is_ffffffff" => ["ELEMENT"], 1050 "relative" => ["ELEMENT", "TYPEDEF"], 1051 "relative_short" => ["ELEMENT", "TYPEDEF"], 1052 "null_is_ffffffff" => ["ELEMENT"], 902 1053 "relative_base" => ["TYPEDEF", "STRUCT", "UNION"], 903 1054 904 1055 "gensize" => ["TYPEDEF", "STRUCT", "UNION"], 905 1056 "value" => ["ELEMENT"], 906 "flag" => ["ELEMENT", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP" ],1057 "flag" => ["ELEMENT", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "PIPE"], 907 1058 908 1059 # generic 909 "public" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP" ],910 "nopush" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP" ],911 "nopull" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP" ],1060 "public" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "PIPE"], 1061 "nopush" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "PIPE"], 1062 "nopull" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "PIPE"], 912 1063 "nosize" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"], 913 "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT"], 1064 "noprint" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP", "ELEMENT", "PIPE"], 1065 "nopython" => ["FUNCTION", "TYPEDEF", "STRUCT", "UNION", "ENUM", "BITMAP"], 914 1066 "todo" => ["FUNCTION"], 915 1067 … … 918 1070 "switch_type" => ["ELEMENT", "UNION"], 919 1071 "nodiscriminant" => ["UNION"], 1072 "ms_union" => ["INTERFACE", "UNION"], 920 1073 "case" => ["ELEMENT"], 921 1074 "default" => ["ELEMENT"], … … 1007 1160 $discriminator_type = "uint32" unless defined ($discriminator_type); 1008 1161 1009 my $t1 = map ToScalar($discriminator_type);1162 my $t1 = mapScalarType(mapToScalar($discriminator_type)); 1010 1163 1011 1164 if (not defined($t1)) { … … 1013 1166 } 1014 1167 1015 my $t2 = map ToScalar($e2->{TYPE});1168 my $t2 = mapScalarType(mapToScalar($e2->{TYPE})); 1016 1169 if (not defined($t2)) { 1017 1170 fatal($e, el_name($e) . ": unable to map variable used for switch_is() to scalar"); … … 1056 1209 has_property($e, "unique") or 1057 1210 has_property($e, "relative") or 1211 has_property($e, "relative_short") or 1058 1212 has_property($e, "ref"))) { 1059 1213 fatal($e, el_name($e) . " : pointer properties on non-pointer element\n"); … … 1137 1291 { 1138 1292 my ($pipe) = @_; 1139 my $ data= $pipe->{DATA};1293 my $struct = $pipe->{DATA}; 1140 1294 1141 1295 ValidProperties($pipe, "PIPE"); 1142 1296 1143 fatal($pipe, $pipe->{NAME} . ": 'pipe' is not yet supported by pidl"); 1297 $struct->{PARENT} = $pipe; 1298 1299 $struct->{FILE} = $pipe->{FILE} unless defined($struct->{FILE}); 1300 $struct->{LINE} = $pipe->{LINE} unless defined($struct->{LINE}); 1301 1302 ValidType($struct); 1144 1303 } 1145 1304 … … 1153 1312 ValidProperties($typedef, "TYPEDEF"); 1154 1313 1314 return unless (ref($data) eq "HASH"); 1315 1155 1316 $data->{PARENT} = $typedef; 1156 1317 … … 1158 1319 $data->{LINE} = $typedef->{LINE} unless defined($data->{LINE}); 1159 1320 1160 ValidType($data) if (ref($data) eq "HASH");1321 ValidType($data); 1161 1322 } 1162 1323
Note:
See TracChangeset
for help on using the changeset viewer.