Ver código fonte

move Codegen.concat to Type.concat

Simon Krajewski 11 anos atrás
pai
commit
f8aea1c92d
9 arquivos alterados com 29 adições e 29 exclusões
  1. 1 1
      ast.ml
  2. 1 10
      codegen.ml
  3. 4 4
      filters.ml
  4. 9 9
      gencommon.ml
  5. 1 1
      gencs.ml
  6. 2 2
      genjava.ml
  7. 1 1
      genjs.ml
  8. 1 1
      genphp.ml
  9. 9 0
      type.ml

+ 1 - 1
ast.ml

@@ -53,7 +53,7 @@ module Meta = struct
 		| Debug
 		| Decl
 		| DefParam
-    | Delegate
+		| Delegate
 		| Depend
 		| Deprecated
 		| DynamicObject

+ 1 - 10
codegen.ml

@@ -47,15 +47,6 @@ let binop op a b t p =
 let index com e index t p =
 	mk (TArray (e,mk (TConst (TInt (Int32.of_int index))) com.basic.tint p)) t p
 
-let concat e1 e2 =
-	let e = (match e1.eexpr, e2.eexpr with
-		| TBlock el1, TBlock el2 -> TBlock (el1@el2)
-		| TBlock el, _ -> TBlock (el @ [e2])
-		| _, TBlock el -> TBlock (e1 :: el)
-		| _ , _ -> TBlock [e1;e2]
-	) in
-	mk e e2.etype (punion e1.epos e2.epos)
-
 let type_constant com c p =
 	let t = com.basic in
 	match c with
@@ -1615,4 +1606,4 @@ module UnificationCallback = struct
 				etf
 			| _ ->
 				check (Type.map_expr (run f) e)
-end;;
+end;;

+ 4 - 4
filters.ml

@@ -120,7 +120,7 @@ let handle_side_effects com gen_temp e =
 			let e_break = mk TBreak t_dynamic p in
 			let e_not = mk (TUnop(Not,Prefix,Codegen.mk_parent e1)) e1.etype e1.epos in
 			let e_if = mk (TIf(e_not,e_break,None)) com.basic.tvoid p in
-			let e_block = if flag = NormalWhile then Codegen.concat e_if e2 else Codegen.concat e2 e_if in
+			let e_block = if flag = NormalWhile then Type.concat e_if e2 else Type.concat e2 e_if in
 			let e_true = mk (TConst (TBool true)) com.basic.tbool p in
 			let e = mk (TWhile(Codegen.mk_parent e_true,e_block,NormalWhile)) e.etype p in
 			loop e
@@ -493,13 +493,13 @@ let captured_vars com e =
 			let vtmp = mk_var v used in
 			let it = wrap used it in
 			let expr = wrap used expr in
-			mk (TFor (vtmp,it,Codegen.concat (mk_init v vtmp e.epos) expr)) e.etype e.epos
+			mk (TFor (vtmp,it,Type.concat (mk_init v vtmp e.epos) expr)) e.etype e.epos
 		| TTry (expr,catchs) ->
 			let catchs = List.map (fun (v,e) ->
 				let e = wrap used e in
 				try
 					let vtmp = mk_var v used in
-					vtmp, Codegen.concat (mk_init v vtmp e.epos) e
+					vtmp, Type.concat (mk_init v vtmp e.epos) e
 				with Not_found ->
 					v, e
 			) catchs in
@@ -547,7 +547,7 @@ let captured_vars com e =
 			let fargs = List.map (fun (v,o) ->
 				if PMap.mem v.v_id used then
 					let vtmp = mk_var v used in
-					fexpr := Codegen.concat (mk_init v vtmp e.epos) !fexpr;
+					fexpr := Type.concat (mk_init v vtmp e.epos) !fexpr;
 					vtmp, o
 				else
 					v, o

+ 9 - 9
gencommon.ml

@@ -2056,7 +2056,7 @@ struct
                           { e with eexpr = TBlock( (add_fn hd) :: tl ) }
                         | _ ->
                           { e with eexpr = TBlock( funs @ (hd :: tl) ) })
-                      | _ -> Codegen.concat { e with eexpr = TBlock(funs) } e
+                      | _ -> Type.concat { e with eexpr = TBlock(funs) } e
                     in
                     let tf_expr = add_fn (mk_block tf.tf_expr) in
                     { e with eexpr = TFunction({ tf with tf_expr = tf_expr }) }
@@ -2645,7 +2645,7 @@ struct
                   | [] ->
                     match catchall with
                       | Some (v,s) ->
-                        Codegen.concat { eexpr = TVar(v, Some(catchall_local)); etype = gen.gcon.basic.tvoid; epos = pos } s
+                        Type.concat { eexpr = TVar(v, Some(catchall_local)); etype = gen.gcon.basic.tvoid; epos = pos } s
                       | None ->
                         mk_block (rethrow_expr temp_local)
                 in
@@ -3430,7 +3430,7 @@ struct
         *)
         let real_get_args = gen.gexpr_filters#run_f { eexpr = TBlock(get_args); etype = basic.tvoid; epos = pos } in
 
-        let func_expr = Codegen.concat real_get_args tf_expr in
+        let func_expr = Type.concat real_get_args tf_expr in
 
         (* set invoke function *)
         (* todo properly abstract how naming for invoke is made *)
@@ -5133,7 +5133,7 @@ struct
     let block = if flag = Ast.NormalWhile then
       { e1 with eexpr = TIf(cond, e1, Some({ e1 with eexpr = TBreak; etype = basic.tvoid })) }
     else
-      Codegen.concat e1 { e1 with
+      Type.concat e1 { e1 with
         eexpr = TIf({
           eexpr = TUnop(Ast.Not, Ast.Prefix, mk_paren cond);
           etype = basic.tbool;
@@ -9043,7 +9043,7 @@ struct
               {
                 eexpr = TWhile(
                   { eexpr = TCall(mk_access gen temp "hasNext" in_expr.epos, []); etype = basic.tbool; epos = in_expr.epos },
-                  Codegen.concat ({
+                  Type.concat ({
                     eexpr = TVar(var, Some({ eexpr = TCall(mk_access gen temp "next" in_expr.epos, []); etype = var.v_type; epos = in_expr.epos }));
                     etype = basic.tvoid;
                     epos = in_expr.epos
@@ -9720,7 +9720,7 @@ struct
       (fun (expr,kind) ->
         match kind with
           | Normal when has_fallback expr -> expr
-          | Normal -> Codegen.concat expr (mk_sbreak expr.epos)
+          | Normal -> Type.concat expr (mk_sbreak expr.epos)
           | BreaksLoop | BreaksFunction -> expr
       )
     else
@@ -9759,7 +9759,7 @@ struct
         | TFunction tf ->
           let changed, kind = process_expr tf.tf_expr in
           let changed = if handle_not_final_returns && not (is_void tf.tf_type) && kind <> BreaksFunction then
-            Codegen.concat changed { eexpr = TReturn( Some (null tf.tf_type expr.epos) ); etype = basic.tvoid; epos = expr.epos }
+            Type.concat changed { eexpr = TReturn( Some (null tf.tf_type expr.epos) ); etype = basic.tvoid; epos = expr.epos }
           else
             changed
           in
@@ -9977,7 +9977,7 @@ struct
                   { tf.tf_expr with eexpr = TBlock((if !found then { super with eexpr = TCall(e1,args) } else super) :: !block @ tl) }
                 | _ -> assert false)
               with | Not_found ->
-                Codegen.concat { tf.tf_expr with eexpr = TBlock(!block); etype = basic.tvoid } tf.tf_expr
+                Type.concat { tf.tf_expr with eexpr = TBlock(!block); etype = basic.tvoid } tf.tf_expr
             in
 
             args := fun_args tf_args;
@@ -10541,7 +10541,7 @@ struct
                 f.cf_expr <- Some({ e with
                   eexpr = TFunction({ tf with
                     tf_args = List.rev new_args;
-                    tf_expr = Codegen.concat { eexpr = TBlock(List.map (fun (v,ve) -> { eexpr = TVar(v,ve); etype = gen.gcon.basic.tvoid; epos = e.epos }) vardecl); etype = gen.gcon.basic.tvoid; epos = e.epos } tf.tf_expr
+                    tf_expr = Type.concat { eexpr = TBlock(List.map (fun (v,ve) -> { eexpr = TVar(v,ve); etype = gen.gcon.basic.tvoid; epos = e.epos }) vardecl); etype = gen.gcon.basic.tvoid; epos = e.epos } tf.tf_expr
                   });
                 });
                 f

+ 1 - 1
gencs.ml

@@ -2589,7 +2589,7 @@ let configure gen =
         let exc_field = mk_static_field_access_infer exc_cl "exception" e.epos [] in
         let esetstack = mk (TBinop(Ast.OpAssign, exc_field, mk_local v e.epos)) v.v_type e.epos in
 
-        Codegen.concat esetstack e;
+        Type.concat esetstack e;
       )
   );
 

+ 2 - 2
genjava.ml

@@ -486,8 +486,8 @@ struct
             Some conds, hashed_exprs
           | _ -> assert false
       ) (None,[]) el in
-      let e = if has_default then Codegen.concat execute_def_set e else e in
-      let e = if !has_conflict then Codegen.concat e { e with eexpr = TBreak; etype = basic.tvoid } else e in
+      let e = if has_default then Type.concat execute_def_set e else e in
+      let e = if !has_conflict then Type.concat e { e with eexpr = TBreak; etype = basic.tvoid } else e in
       let e = {
         eexpr = TIf(get conds, e, None);
         etype = basic.tvoid;

+ 1 - 1
genjs.ml

@@ -287,7 +287,7 @@ let fun_block ctx f p =
 	let e = List.fold_left (fun e (a,c) ->
 		match c with
 		| None | Some TNull -> e
-		| Some c -> Codegen.concat (Codegen.set_default ctx.com a c p) e
+		| Some c -> Type.concat (Codegen.set_default ctx.com a c p) e
 	) f.tf_expr f.tf_args in
 	e
 

+ 1 - 1
genphp.ml

@@ -509,7 +509,7 @@ let fun_block ctx f p =
 	let e = List.fold_left (fun e (v,c) ->
 		match c with
 		| None | Some TNull -> e
-		| Some c -> Codegen.concat (Codegen.set_default ctx.com v c p) e
+		| Some c -> Type.concat (Codegen.set_default ctx.com v c p) e
 	) e f.tf_args in
 	if ctx.com.debug then begin
 		Codegen.stack_block ctx.stack ctx.curclass ctx.curmethod e

+ 9 - 0
type.ml

@@ -600,6 +600,15 @@ let rec has_mono t = match t with
 	| TLazy r ->
 		has_mono (!r())
 
+let concat e1 e2 =
+	let e = (match e1.eexpr, e2.eexpr with
+		| TBlock el1, TBlock el2 -> TBlock (el1@el2)
+		| TBlock el, _ -> TBlock (el @ [e2])
+		| _, TBlock el -> TBlock (e1 :: el)
+		| _ , _ -> TBlock [e1;e2]
+	) in
+	mk e e2.etype (punion e1.epos e2.epos)
+
 (* ======= Field utility ======= *)
 
 let field_name f =