summaryrefslogtreecommitdiff
path: root/cparser/StructByValue.ml
diff options
context:
space:
mode:
Diffstat (limited to 'cparser/StructByValue.ml')
-rw-r--r--cparser/StructByValue.ml18
1 files changed, 13 insertions, 5 deletions
diff --git a/cparser/StructByValue.ml b/cparser/StructByValue.ml
index 60c1154..07a6acf 100644
--- a/cparser/StructByValue.ml
+++ b/cparser/StructByValue.ml
@@ -55,6 +55,14 @@ and transf_funarg env (id, t) =
then (id, TPtr(add_attributes_type [AConst] t, []))
else (id, t)
+(* Smart constructor that "bubble up" sequence expressions *)
+
+let rec addrof e =
+ match e.edesc with
+ | EBinop(Ocomma, e1, e2, _) -> ecomma e1 (addrof e2)
+ | EUnop(Oderef, e1) -> e1
+ | _ -> eaddrof e
+
(* Expressions: transform calls + rewrite the types *)
type context = Val | Effects
@@ -101,7 +109,7 @@ let rec transf_expr env ctx e =
and transf_arg env e =
let e' = transf_expr env Val e in
- if is_composite_type env e'.etyp then eaddrof e' else e'
+ if is_composite_type env e'.etyp then addrof e' else e'
(* Function calls returning a composite: add first argument.
ctx = Effects: lv = f(...) -> f(&lv, ...)
@@ -117,17 +125,17 @@ and transf_composite_call env ctx opt_lhs fn args ty =
match ctx, opt_lhs with
| Effects, None ->
let tmp = new_temp ~name:"_res" ty in
- {edesc = ECall(fn, eaddrof tmp :: args); etyp = TVoid []}
+ {edesc = ECall(fn, addrof tmp :: args); etyp = TVoid []}
| Effects, Some lhs ->
let lhs = transf_expr env Val lhs in
- {edesc = ECall(fn, eaddrof lhs :: args); etyp = TVoid []}
+ {edesc = ECall(fn, addrof lhs :: args); etyp = TVoid []}
| Val, None ->
let tmp = new_temp ~name:"_res" ty in
- ecomma {edesc = ECall(fn, eaddrof tmp :: args); etyp = TVoid []} tmp
+ ecomma {edesc = ECall(fn, addrof tmp :: args); etyp = TVoid []} tmp
| Val, Some lhs ->
let lhs = transf_expr env Val lhs in
let tmp = new_temp ~name:"_res" ty in
- ecomma (ecomma {edesc = ECall(fn, eaddrof tmp :: args); etyp = TVoid []}
+ ecomma (ecomma {edesc = ECall(fn, addrof tmp :: args); etyp = TVoid []}
(eassign lhs tmp))
tmp