added support for enumerated types in IDL files. This makes unions
authorAndrew Tridgell <tridge@samba.org>
Sat, 22 Nov 2003 22:53:08 +0000 (22:53 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 22 Nov 2003 22:53:08 +0000 (22:53 +0000)
easier to work with.

source/build/pidl/header.pm
source/build/pidl/idl.gram
source/librpc/idl/samr.idl

index 751383a2b302e4c8040f07a8528de3dcc189d89b..d6584a05ad86372860538682b0ed2ced66840a2e 100644 (file)
@@ -86,6 +86,31 @@ sub HeaderStruct($$)
     $res .= "}";
 }
 
+#####################################################################
+# parse a struct
+sub HeaderEnum($$)
+{
+    my($enum) = shift;
+    my($name) = shift;
+    $res .= "\nenum $name {\n";
+    $tab_depth++;
+    my $els = \@{$enum->{ELEMENTS}};
+    foreach my $i (0 .. $#{$els}-1) {
+           my $e = ${$els}[$i];
+           tabs();
+           chomp $e;
+           $res .= "$e,\n";
+    }
+
+    my $e = ${$els}[$#{$els}];
+    tabs();
+    chomp $e;
+    $e =~ /^(.*?)\s*$/;
+    $res .= "$1\n";
+    $tab_depth--;
+    $res .= "}";
+}
+
 
 #####################################################################
 # parse a union element
@@ -105,7 +130,7 @@ sub HeaderUnion($$)
     my($union) = shift;
     my($name) = shift;
     (defined $union->{PROPERTIES}) && HeaderProperties($union->{PROPERTIES});
-    $res .= "union $name {\n";
+    $res .= "\nunion $name {\n";
     foreach my $e (@{$union->{DATA}}) {
        HeaderUnionElement($e);
     }
@@ -120,6 +145,8 @@ sub HeaderType($$$)
        my($data) = shift;
        my($name) = shift;
        if (ref($data) eq "HASH") {
+               ($data->{TYPE} eq "ENUM") &&
+                   HeaderEnum($data, $name);
                ($data->{TYPE} eq "STRUCT") &&
                    HeaderStruct($data, $name);
                ($data->{TYPE} eq "UNION") &&
index 70d1c36b5e64ddbf2bb4fbb153740b0fdd47ee17..1e19ae6cf1fca056e71be0bd46de6568fd1e456c 100644 (file)
@@ -48,6 +48,15 @@ typedef : 'typedef' <commit> type identifier array_len(?) ';'
         }}
         | <error?>
 
+enum: 'enum' <commit> '{' enum_element(s? /,/) '}' 
+        {{
+                     "TYPE" => "ENUM", 
+                    "ELEMENTS" => $item[4]
+        }}
+      | <error?>
+
+enum_element: /[\w\s=]+/
+
 struct: property_list(s?) 'struct' <commit> '{' element_list1(?) '}' 
         {{
                      "TYPE" => "STRUCT", 
@@ -65,16 +74,16 @@ union: property_list(s?) 'union' <commit> '{' union_element(s?) '}'
         | <error?>
 
 union_element: 
-         '[' 'case' '(' constant ')' ']' base_element ';'
+         '[' 'case' '(' identifier ')' ']' base_element ';'
         {{
                "TYPE" => "UNION_ELEMENT",
-               "CASE" => $item{constant},
+               "CASE" => $item{identifier},
                "DATA" => $item{base_element}
         }}
-         | '[' 'case' '(' constant ')' ']' ';'
+         | '[' 'case' '(' identifier ')' ']' ';'
         {{
                "TYPE" => "EMPTY",
-               "CASE" => $item{constant},
+               "CASE" => $item{identifier},
         }}
          | '[' 'default' ']' base_element ';'
         {{
@@ -124,20 +133,16 @@ property: 'unique'
          | 'in'
          | 'out'
          | 'ref'
-         | 'context_handle'
-         | 'string'
          | 'public'
          | 'noprint'
          | 'relative'    
          | 'nodiscriminant'
           | 'subcontext' '(' constant ')' {{ "$item[1]" => "$item{constant}" }}
           | 'flag' '(' anytext ')' {{ "$item[1]" => "$item{anytext}" }}
-         | 'byte_count_pointer' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
           | 'size_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
           | 'length_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
           | 'switch_is' '(' expression ')' {{ "$item[1]" => "$item{expression}" }}
           | 'value' '(' anytext ')' {{ "$item[1]" => "$item{anytext}" }}
-          | 'switch_type' '(' type ')' {{ "$item[1]" => $item{type} }}
 
 identifier: /[\w?]+/
 
@@ -153,12 +158,9 @@ function : type identifier '(' <commit> element_list2 ');'
          | <error?>
 
 type : 
-       'unsigned' type { "$item[1] $item[2]" }
-     | 'long'    { $item[1] }
-     | 'string'  { $item[1] }
-     | 'wchar_t' { $item[1] }
-     | struct    { $item[1] }
+       struct    { $item[1] }
      | union     { $item[1] }
+     | enum      { $item[1] }
      | identifier { $item[1] }
      | <error>
 
@@ -172,9 +174,6 @@ anytext: text2 '(' <commit> anytext ')' anytext
         {{ "$item[1]+$item[3]" }}
         | text2
 
-call: expression '(' <commit> expression ')'
-        {{ "$item[1]($item[4])" }}
-
 constant: /-?[\dx]+/
          | '*'
 
index 8b349123fb49bcf220f47aeefe344ffca26bc8f8..eb1d1262270f1a82e44bdc9eeb7526395f4d59df 100644 (file)
                samr_Name description;
        } samr_GroupInfoDesciption;
 
+       typedef enum {
+               GroupInfoAll = 1,
+               GroupInfoName,
+               GroupInfoX,
+               GroupInfoDescription
+       } GroupInfo;
+
        typedef union {
-               [case(1)] samr_GroupInfoAll all;
-               [case(2)] samr_GroupInfoName name;
-               [case(3)] samr_GroupInfoX unknown;
-               [case(4)] samr_GroupInfoDesciption description;
+               [case(GroupInfoAll)]         samr_GroupInfoAll        all;
+               [case(GroupInfoName)]        samr_GroupInfoName       name;
+               [case(GroupInfoX)]           samr_GroupInfoX          unknown;
+               [case(GroupInfoDescription)] samr_GroupInfoDesciption description;
        } samr_GroupInfo;
 
        NTSTATUS samr_QueryGroupInfo(