summaryrefslogtreecommitdiff
path: root/frontend/ast_printer.ml
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ansys.com>2014-07-03 17:52:37 +0200
committerAlex Auvolat <alex.auvolat@ansys.com>2014-07-03 17:52:37 +0200
commitf808eeaf3016f828d71b0f87afb89bb79a869035 (patch)
treea3baddb1e45087512318be680161c09f7949ced2 /frontend/ast_printer.ml
parent79bf56c809e727ed763e698386163706be2db0a7 (diff)
downloadscade-analyzer-f808eeaf3016f828d71b0f87afb89bb79a869035.tar.gz
scade-analyzer-f808eeaf3016f828d71b0f87afb89bb79a869035.zip
Changes to parser ; EDD optimisations ; test cases.
Diffstat (limited to 'frontend/ast_printer.ml')
-rw-r--r--frontend/ast_printer.ml25
1 files changed, 13 insertions, 12 deletions
diff --git a/frontend/ast_printer.ml b/frontend/ast_printer.ml
index 3ca2ff6..8908687 100644
--- a/frontend/ast_printer.ml
+++ b/frontend/ast_printer.ml
@@ -165,12 +165,15 @@ let rec print_expr fmt e =
let indent ind = ind^" "
-let rec print_vars ind fmt = function
- | [] -> ()
- | v ->
+let rec print_scope ind fmt = function
+ | [], [a, _] ->
+ print_eqn ind fmt a
+ | [], l -> print_body ind fmt l
+ | v, l ->
Format.fprintf fmt "%svar" ind;
List.iter (fun d -> Format.fprintf fmt " %a;" print_var_decl d) v;
Format.fprintf fmt "@\n";
+ print_body ind fmt l
and print_var_decl fmt (pr, i, ty) =
Format.fprintf fmt "%s%s: %s"
@@ -182,6 +185,9 @@ and print_body ind fmt body =
Format.fprintf fmt "%slet@\n%a%stel@\n"
ind (print_block ind) body ind
+and print_block ind fmt b =
+ List.iter (fun (bb,_) -> print_eqn (indent ind) fmt bb) b
+
and print_eqn ind fmt = function
| AST_assign (l,(e,_)) ->
Format.fprintf fmt "%s%a = %a;@\n"
@@ -207,8 +213,7 @@ and print_activate_if ind fmt = function
Format.fprintf fmt "%selse@\n" ind;
print_activate_if (indent ind) fmt e
| AST_activate_body(b) ->
- print_vars ind fmt b.act_locals;
- print_body ind fmt b.body
+ print_scope ind fmt (b.act_locals, b.body)
and print_automaton ind fmt (n, sts, r) =
Format.fprintf fmt "%sautomaton %s@\n" ind n;
@@ -218,8 +223,8 @@ and print_automaton ind fmt (n, sts, r) =
and print_state ind fmt (st, _) =
Format.fprintf fmt "%s%sstate %s@\n"
ind (if st.initial then "initial " else "") st.st_name;
- print_vars ind fmt st.st_locals;
- print_body ind fmt st.body;
+ let ind = indent ind in
+ print_scope ind fmt (st.st_locals, st.body);
if st.until <> [] then begin
Format.fprintf fmt "%suntil@\n" ind;
List.iter (fun ((e, _),(s, _), reset) ->
@@ -227,9 +232,6 @@ and print_state ind fmt (st, _) =
st.until
end
-and print_block ind fmt b =
- List.iter (fun (bb,_) -> print_eqn (indent ind) fmt bb) b
-
(* declarations *)
@@ -238,8 +240,7 @@ and print_node_decl fmt (d : node_decl) =
d.n_name
(print_list print_var_decl "; ") d.args
(print_list print_var_decl "; ") d.ret;
- print_vars "" fmt d.var;
- print_body "" fmt d.body
+ print_scope "" fmt (d.var, d.body)
let print_const_decl fmt (d : const_decl) =
Format.fprintf fmt