Mentions légales du service

Skip to content
Snippets Groups Projects
Verified Commit 2dc63b2d authored by Thierry Martinez's avatar Thierry Martinez
Browse files

Expand `*e` into `tmp = e; *tmp`

parent 361be733
No related branches found
No related tags found
No related merge requests found
Pipeline #891707 failed
...@@ -178,6 +178,12 @@ module Applicative = ...@@ -178,6 +178,12 @@ module Applicative =
let ( + ) = plus_with_warning let ( + ) = plus_with_warning
end))) end)))
let rec deref_decl (expr : Clang.Ast.expr) =
match expr.desc with
| DeclRef _ -> true
| UnaryOperator { kind = Deref; operand } -> deref_decl operand
| _ -> false
module rec Visitor : Refl.Visit.VisitorS module rec Visitor : Refl.Visit.VisitorS
with type 'a Applicative.t = 'a Applicative.t = struct with type 'a Applicative.t = 'a Applicative.t = struct
module Applicative = Applicative module Applicative = Applicative
...@@ -328,9 +334,17 @@ with type 'a Applicative.t = 'a Applicative.t = struct ...@@ -328,9 +334,17 @@ with type 'a Applicative.t = 'a Applicative.t = struct
match kind with match kind with
| LNot -> { env with in_condition = true } | LNot -> { env with in_condition = true }
| _ -> { env with in_condition = false } in | _ -> { env with in_condition = false } in
let operand, operand_value = let operand, delayed_stmts =
Visit.visit [%refl: Clang.Ast.expr] [] operand operand_env in Visit.visit [%refl: Clang.Ast.expr] [] operand operand_env in
UnaryOperator { kind; operand }, operand_value let operand, delayed_stmts =
match kind with
| Deref when not (deref_decl operand) ->
let operand, stmts = assign_to_tmp operand in
let delayed_stmts =
Free_monoid.plus delayed_stmts (Free_monoid.of_list stmts) in
operand, delayed_stmts
| _ -> operand, delayed_stmts in
UnaryOperator { kind; operand }, delayed_stmts
let rec visit_if(cond : Clang.Ast.expr) (then_branch : Clang.Ast.stmt) let rec visit_if(cond : Clang.Ast.expr) (then_branch : Clang.Ast.stmt)
(else_branch : Clang.Ast.stmt option) env (else_branch : Clang.Ast.stmt option) env
...@@ -420,7 +434,7 @@ with type 'a Applicative.t = 'a Applicative.t = struct ...@@ -420,7 +434,7 @@ with type 'a Applicative.t = 'a Applicative.t = struct
| _ -> | _ ->
let (expr : Clang.Ast.expr), delayed_stmts = let (expr : Clang.Ast.expr), delayed_stmts =
super expr { env with statement_root = false; assign_rhs = false } in super expr { env with statement_root = false; assign_rhs = false } in
let make_assign expr lhs = let make_assign (expr : Clang.Ast.expr) (lhs : Clang.Ast.expr) =
if env.statement_root then if env.statement_root then
expr, delayed_stmts expr, delayed_stmts
else else
...@@ -642,13 +656,12 @@ with type 'a Applicative.t = 'a Applicative.t = struct ...@@ -642,13 +656,12 @@ with type 'a Applicative.t = 'a Applicative.t = struct
visit_unary_expr_size_of argument env visit_unary_expr_size_of argument env
| ArraySubscript { base; index } | ArraySubscript { base; index }
when not (is_array base) -> when not (is_array base) ->
let x' : Clang.Ast.expr_desc = UnaryOperator { let operand : Clang.Ast.expr =
kind = Deref; { base with desc = BinaryOperator {
operand = { base with desc = BinaryOperator { lhs = base;
lhs = base; kind = Add;
kind = Add; rhs = index; }} in
rhs = index; }}} in visit_unary_operator env Deref operand
super x' env
| _ -> super x env | _ -> super x env
end end
| Clang.Ast.Refl_decl_desc -> | Clang.Ast.Refl_decl_desc ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment