Procházet zdrojové kódy

some optional structures fields

Nicolas Cannasse před 13 roky
rodič
revize
1685c6e1ef
2 změnil soubory, kde provedl 12 přidání a 7 odebrání
  1. 7 2
      interp.ml
  2. 5 5
      std/haxe/macro/Expr.hx

+ 7 - 2
interp.ml

@@ -3187,6 +3187,11 @@ let opt f v =
 	| VNull -> None
 	| _ -> Some (f v)
 
+let opt_list f v =
+	match v with
+	| VNull -> []
+	| _ -> f v
+
 let decode_pos = function
 	| VAbstract (APos p) -> p
 	| _ -> raise Invalid_expr
@@ -3318,8 +3323,8 @@ and decode_field v =
 		cff_doc = opt dec_string (field v "doc");
 		cff_pos = decode_pos (field v "pos");
 		cff_kind = fkind;
-		cff_access = List.map decode_access (dec_array (field v "access"));
-		cff_meta = decode_meta_content (field v "meta");
+		cff_access = List.map decode_access (opt_list dec_array (field v "access"));
+		cff_meta = opt_list decode_meta_content (field v "meta");
 	}
 
 and decode_ctype t =

+ 5 - 5
std/haxe/macro/Expr.hx

@@ -131,7 +131,7 @@ typedef TypePath = {
 	var pack : Array<String>;
 	var name : String;
 	var params : Array<TypeParam>;
-	var sub : Null<String>;
+	@:optional var sub : Null<String>;
 }
 
 enum TypeParam {
@@ -150,18 +150,18 @@ typedef FunctionArg = {
 	var name : String;
 	var opt : Bool;
 	var type : Null<ComplexType>;
-	var value : Null<Expr>;
+	@:optional var value : Null<Expr>;
 }
 
 typedef Metadata = Array<{ name : String, params : Array<Expr>, pos : Position }>;
 
 typedef Field = {
 	var name : String;
-	var doc : Null<String>;
-	var access : Array<Access>;
+	@:optional var doc : Null<String>;
+	@:optional var access : Array<Access>;
 	var kind : FieldType;
 	var pos : Position;
-	var meta : Metadata;
+	@:optional var meta : Metadata;
 }
 
 enum Access {