瀏覽代碼

add `@:astSource` metadata

This is related to #3285, but it's also useful in its own right for macro users.
Simon Krajewski 9 年之前
父節點
當前提交
a44caafc8b
共有 3 個文件被更改,包括 6 次插入0 次删除
  1. 1 0
      ast.ml
  2. 1 0
      common.ml
  3. 4 0
      typeload.ml

+ 1 - 0
ast.ml

@@ -36,6 +36,7 @@ module Meta = struct
 		| Annotation
 		| ArrayAccess
 		| Ast
+		| AstSource
 		| AutoBuild
 		| Bind
 		| Bitmap

+ 1 - 0
common.ml

@@ -368,6 +368,7 @@ module MetaInfo = struct
 		| Annotation -> ":annotation",("Annotation (@interface) definitions on -java-lib imports will be annotated with this metadata. Has no effect on types compiled by Haxe",[Platform Java; UsedOn TClass])
 		| ArrayAccess -> ":arrayAccess",("Allows [] access on an abstract",[UsedOnEither [TAbstract;TAbstractField]])
 		| Ast -> ":ast",("Internally used to pass the AST source into the typed AST",[Internal])
+		| AstSource -> ":astSource",("Filled by the compiler with the parsed expression of the field",[UsedOn TClassField])
 		| AutoBuild -> ":autoBuild",("Extends @:build metadata to all extending and implementing classes",[HasParam "Build macro call";UsedOn TClass])
 		| Bind -> ":bind",("Override Swf class declaration",[Platform Flash;UsedOn TClass])
 		| Bitmap -> ":bitmap",("Embeds given bitmap data into the class (must extend flash.display.BitmapData)",[HasParam "Bitmap file path";UsedOn TClass;Platform Flash])

+ 4 - 0
typeload.ml

@@ -2441,6 +2441,10 @@ module ClassInitializer = struct
 			cf_params = params;
 			cf_overloads = [];
 		} in
+		cf.cf_meta <- List.map (fun (m,el,p) -> match m,el with
+			| Meta.AstSource,[] -> (m,(match fd.f_expr with None -> [] | Some e -> [e]),p)
+			| _ -> m,el,p
+		) cf.cf_meta;
 		generate_value_meta ctx.com (Some c) cf fd.f_args;
 		check_abstract (ctx,cctx,fctx) c cf fd t ret p;
 		init_meta_overloads ctx (Some c) cf;