瀏覽代碼

remove empty blocks and objects in blocks

Simon Krajewski 13 年之前
父節點
當前提交
a48a665352
共有 2 個文件被更改,包括 9 次插入6 次删除
  1. 1 5
      genas3.ml
  2. 8 1
      optimizer.ml

+ 1 - 5
genas3.ml

@@ -598,11 +598,7 @@ and gen_expr ctx e =
             (fun() -> print ctx "}")
 		end) in
 		(match ctx.block_inits with None -> () | Some i -> i());
-		List.iter (fun e ->
-			match e.eexpr with
-			| TBlock [] | TObjectDecl [] -> ()
-			| _ -> newline ctx; gen_expr ctx e
-		) el;
+		List.iter (fun e -> newline ctx; gen_expr ctx e) el;
 		bend();
 		newline ctx;
 		cb();

+ 8 - 1
optimizer.ml

@@ -681,7 +681,14 @@ let reduce_expr ctx e =
 		| [] -> e
 		| ec :: l ->
 			(* remove all no-ops : not-final constants in blocks *)
-			match List.filter (fun e -> match e.eexpr with TConst _ -> false | _ -> true) l with
+			match List.filter (fun e -> match e.eexpr with
+				| TConst _
+				| TBlock []
+				| TObjectDecl [] ->
+					false
+				| _ ->
+					true
+			) l with
 			| [] -> { ec with epos = e.epos }
 			| l -> { e with eexpr = TBlock (List.rev (ec :: l)) })
 	| TParenthesis ec ->