@@ -2340,13 +2340,6 @@ let integerArrayLength (leno: exp option) : int =
23402340 d_exp len)
23412341 end
23422342
2343- (* sm: I'm sure something like this already exists, but ... *)
2344- let isNone (o : 'a option ) : bool =
2345- match o with
2346- | None -> true
2347- | Some _ -> false
2348-
2349-
23502343let annonCompFieldNameId = ref 0
23512344let annonCompFieldName = " __annonCompField"
23522345
@@ -5364,7 +5357,7 @@ and doInit
53645357 (* ISO 6.7.8 para 14: final NUL added only if no size specified, or
53655358 if there is room for it; btw, we can't rely on zero-init of
53665359 globals, since this array might be a local variable *)
5367- if ((isNone leno) || ((String. length s) < (integerArrayLength leno)))
5360+ if ((Option. is_none leno) || ((String. length s) < (integerArrayLength leno)))
53685361 then ref [init Int64. zero]
53695362 else ref []
53705363 in
@@ -5426,7 +5419,7 @@ and doInit
54265419 (* ISO 6.7.8 para 14: final NUL added only if no size specified, or
54275420 if there is room for it; btw, we can't rely on zero-init of
54285421 globals, since this array might be a local variable *)
5429- if ((isNone leno) || ((List. length s) < (integerArrayLength leno)))
5422+ if ((Option. is_none leno) || ((List. length s) < (integerArrayLength leno)))
54305423 then [init Int64. zero]
54315424 else [] )
54325425(*
@@ -5590,6 +5583,28 @@ and doInit
55905583
55915584 (* We have a designator *)
55925585 | _ , (what , ie ) :: restil when what != A. NEXT_INIT ->
5586+ let rec unrollDesignatorForNestedAnonymous (comp : compinfo ) (designator : string ) (whatnext : initwhat ) =
5587+ let own_field = List. filter (fun fld -> fld.fname = designator) comp.cfields in
5588+ match own_field with
5589+ | fld :: _ -> (true , Some (A. INFIELD_INIT (designator, whatnext)))
5590+ | [] ->
5591+ let anonymous_compounds = List. filter_map (fun f ->
5592+ (* f.ftype need not be unrolled here, inner anonymous struct cannot be typdef'ed *)
5593+ match f.ftype with
5594+ | TComp (compinfo , _ ) when prefix annonCompFieldName f.fname -> Some (f, compinfo)
5595+ | _ -> None
5596+ ) comp.cfields
5597+ in
5598+ let anonymous_compound_inits = List. filter_map (fun (comp_field , comp ) ->
5599+ match unrollDesignatorForNestedAnonymous comp designator whatnext with
5600+ | _ , Some (what ) -> Some (comp_field, what)
5601+ | _ , None -> None
5602+ ) anonymous_compounds
5603+ in
5604+ match anonymous_compound_inits with
5605+ | [] -> (false , None )
5606+ | (comp_fld , compwhat ) :: _ -> (false , Some (A. INFIELD_INIT (comp_fld.fname, compwhat)))
5607+ in
55935608 (* Process a designator and position to the designated subobject *)
55945609 let addressSubobj
55955610 (so : subobj )
@@ -5604,10 +5619,17 @@ and doInit
56045619 | A. INFIELD_INIT (fn , whatnext ) -> begin
56055620 match unrollType so.soTyp with
56065621 TComp (comp , _ ) ->
5607- let toinit = fieldsToInit comp (Some fn) in
5608- so.stack < - InComp (so.soOff, comp, toinit) :: so.stack;
5609- normalSubobj so;
5610- address whatnext acc
5622+ let unrolledWhat = unrollDesignatorForNestedAnonymous comp fn whatnext in
5623+ begin
5624+ match unrolledWhat with
5625+ false , Some (unrolled ) ->
5626+ address unrolled acc
5627+ | _ ->
5628+ let toinit = fieldsToInit comp (Some fn) in
5629+ so.stack < - InComp (so.soOff, comp, toinit) :: so.stack;
5630+ normalSubobj so;
5631+ address whatnext acc
5632+ end ;
56115633
56125634 | _ -> E. s (error " Field designator %s not in a struct " fn)
56135635 end
0 commit comments