@@ -277,6 +277,7 @@ and typ =
277277
278278 | TBuiltin_va_list of attributes
279279 (* * This is the same as the gcc's type with the same name *)
280+ | TDefault
280281
281282(* * Various kinds of integers *)
282283and ikind =
@@ -537,6 +538,7 @@ and exp =
537538 * It is not printed. Given an lval of type
538539 * [TArray(T)] produces an expression of type
539540 * [TPtr(T)]. *)
541+ | Generic of exp * ((typ * exp) list )
540542
541543
542544(* * Literal constants *)
@@ -1526,6 +1528,7 @@ let rec typeAttrs = function
15261528 | TEnum (enum , a ) -> addAttributes enum.eattr a
15271529 | TFun (_ , _ , _ , a ) -> a
15281530 | TBuiltin_va_list a -> a
1531+ | TDefault -> []
15291532
15301533
15311534let setTypeAttrs t a =
@@ -1540,6 +1543,7 @@ let setTypeAttrs t a =
15401543 | TEnum (enum , _ ) -> TEnum (enum, a)
15411544 | TFun (r , args , v , _ ) -> TFun (r,args,v,a)
15421545 | TBuiltin_va_list _ -> TBuiltin_va_list a
1546+ | TDefault -> TDefault
15431547
15441548
15451549let typeAddAttributes a0 t =
@@ -1562,6 +1566,7 @@ begin
15621566 | TComp (comp , a ) -> TComp (comp, add a)
15631567 | TNamed (t , a ) -> TNamed (t, add a)
15641568 | TBuiltin_va_list a -> TBuiltin_va_list (add a)
1569+ | TDefault -> TDefault
15651570end
15661571
15671572let typeRemoveAttributes (anl : string list ) t =
@@ -1577,6 +1582,7 @@ let typeRemoveAttributes (anl: string list) t =
15771582 | TComp (comp , a ) -> TComp (comp, drop a)
15781583 | TNamed (t , a ) -> TNamed (t, drop a)
15791584 | TBuiltin_va_list a -> TBuiltin_va_list (drop a)
1585+ | TDefault -> TDefault
15801586
15811587let unrollType (t : typ ) : typ =
15821588 let rec withAttrs (al : attributes ) (t : typ ) : typ =
@@ -1857,6 +1863,7 @@ let getParenthLevel (e: exp) =
18571863
18581864 | Lval (Var _ , NoOffset) -> 0 (* Plain variables *)
18591865 | Const _ -> 0 (* Constants *)
1866+ | Generic _ -> 0 (* TODO*)
18601867
18611868
18621869let getParenthLevelAttrParam (a : attrparam ) =
@@ -1953,6 +1960,7 @@ let rec typeOf (e: exp) : typ =
19531960 TArray (t ,_ , a ) -> TPtr (t, a)
19541961 | _ -> E. s (E. bug " typeOf: StartOf on a non-array" )
19551962 end
1963+ | Generic (e , lst ) -> match lst with (t , e1 ) :: rest -> typeOf e1 | _ -> voidType (* TODO: implement properly *)
19561964
19571965and typeOfInit (i : init ) : typ =
19581966 match i with
@@ -2242,6 +2250,7 @@ let rec alignOf_int t =
22422250
22432251 | TFun _ as t -> raise (SizeOfError (" function" , t))
22442252 | TVoid _ as t -> raise (SizeOfError (" void" , t))
2253+ | TDefault -> raise (SizeOfError (" default" , t))
22452254 in
22462255 match filterAttributes " aligned" (typeAttrs t) with
22472256 [] ->
@@ -2554,6 +2563,7 @@ and bitsSizeOf t =
25542563 0
25552564
25562565 | TFun _ -> raise (SizeOfError (" function" , t))
2566+ | TDefault -> raise (SizeOfError (" default" , t))
25572567
25582568
25592569and addTrailing nrbits roundto =
@@ -2821,6 +2831,8 @@ let rec isConstant = function
28212831 | AddrOf (Mem e, off) | StartOf (Mem e, off)
28222832 -> isConstant e && isConstantOffset off
28232833 | AddrOfLabel _ -> true
2834+ | Generic _ -> false (* TODO*)
2835+
28242836and isConstantOffset = function
28252837 NoOffset -> true
28262838 | Field (fi , off ) -> isConstantOffset off
@@ -3524,6 +3536,14 @@ class defaultCilPrinterClass : cilPrinter = object (self)
35243536
35253537 | StartOf (lv ) -> self#pLval () lv
35263538
3539+ | Generic (e , lst ) ->
3540+ let rec print_generic_exp l doc =
3541+ match l with
3542+ | [] -> doc
3543+ | (t , e1 ) :: rest -> print_generic_exp rest (doc ++ text " , " ++ (self#pType None () t) ++ text " :" ++ self#pExp () e1)
3544+ in
3545+ text " _Generic(" ++ self#pExp () e ++ print_generic_exp lst nil ++ text " )"
3546+
35273547 (* Print an expression, given the precedence of the context in which it
35283548 * appears. *)
35293549 method private pExpPrec (contextprec : int ) () (e : exp ) =
@@ -4460,6 +4480,7 @@ class defaultCilPrinterClass : cilPrinter = object (self)
44604480 ++ self#pAttrs () a
44614481 ++ text " "
44624482 ++ name
4483+ | TDefault -> text " default"
44634484
44644485
44654486 (* *** PRINTING ATTRIBUTES *********)
@@ -4795,6 +4816,7 @@ class plainCilPrinterClass =
47954816 end
47964817 | TBuiltin_va_list a ->
47974818 dprintf " TBuiltin_va_list(%a)" self#pAttrs a
4819+ | TDefault -> dprintf " TDefault"
47984820
47994821
48004822 (* Some plain pretty-printers. Unlike the above these expose all the
@@ -4873,6 +4895,13 @@ class plainCilPrinterClass =
48734895 | StartOf lv -> dprintf " StartOf(%a)" self#pLval lv
48744896 | AddrOf (lv ) -> dprintf " AddrOf(%a)" self#pLval lv
48754897 | AddrOfLabel (sref ) -> dprintf " AddrOfLabel(%a)" self#pStmt ! sref
4898+ | Generic (e , lst ) ->
4899+ let rec print_generic_exp l doc =
4900+ match l with
4901+ | [] -> doc
4902+ | (t , e1 ) :: rest -> print_generic_exp rest (doc ++ text " ," ++ (self#pType None () t) ++ text " :" ++ self#pExp () e1)
4903+ in
4904+ text " _Generic(" ++ self#pExp () e ++ text " ," ++ print_generic_exp lst nil
48764905
48774906
48784907
@@ -5386,6 +5415,8 @@ and childrenExp (vis: cilVisitor) (e: exp) : exp =
53865415 | StartOf lv ->
53875416 let lv' = vLval lv in
53885417 if lv' != lv then StartOf lv' else e
5418+ | Generic (e , lst ) -> e (* TODO*)
5419+
53895420
53905421and visitCilInit (vis : cilVisitor ) (forglob : varinfo )
53915422 (atoff : offset ) (i : init ) : init =
@@ -6170,6 +6201,7 @@ let rec typeSigWithAttrs ?(ignoreSign=false) doattr t =
61706201 TSFun (typeSig rt, (Util. list_map_opt (fun (_ , atype , _ ) -> (typeSig atype)) args), isva, doattr a)
61716202 | TNamed (t , a ) -> typeSigAddAttrs (doattr a) (typeSig t.ttype)
61726203 | TBuiltin_va_list al -> TSBase (TBuiltin_va_list (doattr al))
6204+ | TDefault -> TSBase (TDefault )
61736205
61746206let typeSig t =
61756207 typeSigWithAttrs (fun al -> al) t
0 commit comments