Browse Source

support enums in Compiler.keep and don't include abstract implementation classes when keeping module

Dan Korostelev 11 years ago
parent
commit
6f78d48b44
1 changed files with 13 additions and 7 deletions
  1. 13 7
      std/haxe/macro/Compiler.hx

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

@@ -305,20 +305,24 @@ class Compiler {
 	{
 		var module = path.substring(0, path.lastIndexOf("."));
 		var typeName = path.substring(path.lastIndexOf(".") + 1);
-		var found = false;
+		var subType:Type.BaseType = null;
 		for (type in Context.getModule(module)) {
 			switch(type) {
 				case TInst(_.get() => cls, _) if (cls.name == typeName):
-					cls.meta.add(":keep", [], cls.pos);
-					found = true;
+					subType = cls;
+					break;
+				case TEnum(_.get() => en, _) if (en.name == typeName):
+					subType = en;
 					break;
 				default:
 					//
 			}
 		}
 
-		if (!found)
-			Context.warning("subtype not found, can't keep: "+path, Context.currentPos());
+		if (subType == null)
+			Context.warning('Cannot keep $path: type not found or is not a class or enum', Context.currentPos());
+		else
+			subType.meta.add(":keep", [], subType.pos);
 	}
 
 	private static function keepModule( path : String )
@@ -326,8 +330,10 @@ class Compiler {
 		var types = Context.getModule(path);
 		for (type in types) {
 			switch(type) {
-				case TInst(cls, _):
-					cls.get().meta.add(":keep", [], cls.get().pos);
+				case TInst(_.get() => cls, _) if (!cls.kind.match(KAbstractImpl(_))):
+					cls.meta.add(":keep", [], cls.pos);
+				case TEnum(_.get() => en, _):
+					en.meta.add(":keep", [], en.pos);
 				default:
 					//
 			}