Browse Source

- all : added --macro keepClass('classname')
- minor fix to class elimination

Franco Ponticelli 14 years ago
parent
commit
cfc1fc307c
4 changed files with 15 additions and 2 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 1 1
      optimizer.ml
  3. 13 0
      std/haxe/macro/Compiler.hx
  4. 0 1
      typeload.ml

+ 1 - 0
doc/CHANGES.txt

@@ -44,6 +44,7 @@
 	flash9 : fixed use of default values when null is passed for nullable basic types
 	all : fixed issues with inlining and class/function type parameters
 	all : big speedup for compiler internal completion
+	all : added --macro keepClass('classname')
 
 2010-08-14: 2.06
 	neko : change serializer to be able to handle instances of basic classes from other modules

+ 1 - 1
optimizer.ml

@@ -507,7 +507,7 @@ let filter_dead_classes com =
 	com.types <- List.filter (fun t ->
 		match t with
 		| TClassDecl c ->
-			if c.cl_extern then 
+			if (c.cl_extern or has_meta ":keep" c.cl_meta) then 
 				true 
 			else (match (c.cl_ordered_statics, c.cl_ordered_fields, c.cl_constructor) with
 			| ([], [], None) ->

+ 13 - 0
std/haxe/macro/Compiler.hx

@@ -169,6 +169,19 @@ class Compiler {
 		} catch( e : haxe.io.Eof ) {
 		}
 	}
+	
+	/**
+		Mark a class (or array of classes) with the metadata @:keep
+	**/
+	public static function keepClass(?cl : String, ?acl : Array<String>)
+	{
+		if (null == acl)
+			acl = [];
+		if (null != cl)
+			acl.push(cl);
+		for(cl in acl)
+			addMetadata("@:keep", cl);
+	}
 
 	static function load( f, nargs ) : Dynamic {
 		#if macro

+ 0 - 1
typeload.ml

@@ -803,7 +803,6 @@ let init_class ctx c p herits fields =
 					) in
 					cf.cf_type <- TLazy r;
 					(fun () ->
-						if ctx.com.verbose then print_endline ("field " ^ (s_type_path c.cl_path) ^ "." ^ cf.cf_name);
 						if not (keep f stat) then
 							delay ctx (remove_var_if_unreferenced cf stat)
 						else