Experimental automated 'follower' code.
[virt-mem.git] / extract / codegen / struct_classify.ml
index d959a1f..376c301 100644 (file)
@@ -42,13 +42,13 @@ let classify_field names = function
 type shape_field_struct = {
   sf_i : int;
   sf_name : string;
-  sf_fields : PP.field list;
+  sf_fields : (string * PP.f_type) list;
 }
 
 and content_field_struct = {
   cf_i : int;
   cf_name : string;
-  cf_fields : PP.field list;
+  cf_fields : (string * PP.f_type) list;
 }
 
 and parser_ = {
@@ -88,7 +88,7 @@ let unique =
 
 (* Minimization of shape fields & content fields. *)
 
-let cmp { PP.field_name = n1 } { PP.field_name = n2 } = compare n1 n2
+let cmp (n1,_) (n2,_) = compare n1 n2
 
 let hash_values h = Hashtbl.fold (fun _ v vs -> v :: vs) h []
 
@@ -97,9 +97,10 @@ let minimize_shape_field_structs struct_name names kernels =
   let rh = Hashtbl.create 13 in
 
   let only_shape_fields =
-    List.filter (
-      fun { PP.field_type = typ } ->
-       classify_field names typ = ShapeField
+    List.filter_map (
+      fun { PP.field_name = name; field_type = typ } ->
+       if classify_field names typ = ShapeField then Some (name, typ)
+       else None
     )
   in
 
@@ -110,7 +111,7 @@ let minimize_shape_field_structs struct_name names kernels =
         { PP.struct_fields = fields; struct_name = name_check }) ->
       assert (struct_name = name_check);
       let fields = List.sort ~cmp (only_shape_fields fields) in
-      let key = List.map (fun { PP.field_name = name } -> name) fields in
+      let key = List.map fst fields in
       let sf =
        try Hashtbl.find h key
        with Not_found ->
@@ -129,9 +130,10 @@ let minimize_content_field_structs struct_name names kernels =
   let rh = Hashtbl.create 13 in
 
   let only_content_fields =
-    List.filter (
-      fun { PP.field_type = typ } ->
-       classify_field names typ = ContentField
+    List.filter_map (
+      fun { PP.field_name = name; field_type = typ } ->
+       if classify_field names typ = ContentField then Some (name, typ)
+       else None
     )
   in
 
@@ -142,7 +144,7 @@ let minimize_content_field_structs struct_name names kernels =
         { PP.struct_fields = fields; struct_name = name_check }) ->
       assert (struct_name = name_check);
       let fields = List.sort ~cmp (only_content_fields fields) in
-      let key = List.map (fun { PP.field_name = name } -> name) fields in
+      let key = List.map fst fields in
       let cf =
        try Hashtbl.find h key
        with Not_found ->