HaxeFoundation/haxe — pull request #2946 by nadako (2014-05-01 01:18:37+00:00)
Title: [python] register type reflection data with class decorators

This changes the generation of reflection-related `_hx_*` metadata for python classes to a more compact class decorator usage.

Also, it changes enum generation so constructors with parameters are generated as `@staticmethod`'s.

cc @frabbit, @Simn

Source:
```haxe
class A {}

class B extends A implements IA
{
var a:String;
var b(get, null):Int;
function get_b() return 0;
static var c:Bool;
}

enum MyEnum
{
A;
B(?a:MyEnum);
C(b:Int);
}
```

Before:
```python
class MyEnum(Enum):
def __init__(self, t, i, p):
super(MyEnum,self).__init__(t, i, p)
MyEnum.A = MyEnum("A", 0, list())

def _MyEnum_statics_B (a = None):
return MyEnum("B", 1, [a])
MyEnum.B = _MyEnum_statics_B

def _MyEnum_statics_C (b):
return MyEnum("C", 2, [b])
MyEnum.C = _MyEnum_statics_C

MyEnum._hx_constructs = ["A","B","C"]
MyEnum._hx_class = MyEnum
MyEnum._hx_class_name = "MyEnum"
_hx_classes["MyEnum"] = MyEnum

class A:
pass

@staticmethod
def _hx_empty_init(_hx_o):
pass

A._hx_class = A
A._hx_class_name = "A"
_hx_classes["A"] = A
A._hx_fields = []
A._hx_props = []
A._hx_methods = []
A._hx_statics = []
A._hx_interfaces = []

class B(A):
def get_b(self):
return 0
c = None

@staticmethod
def _hx_empty_init(_hx_o):
_hx_o.a = None

B._hx_class = B
B._hx_class_name = "B"
_hx_classes["B"] = B
B._hx_fields = ["a"]
B._hx_props = ["b"]
B._hx_methods = ["get_b"]
B._hx_statics = ["c"]
B._hx_interfaces = [IA]
B._hx_super = A
```

After:
```python
@_hx_classes.register_enum("MyEnum", ["A","B","C"])
class MyEnum(Enum):
def __init__(self, t, i, p):
super(MyEnum,self).__init__(t, i, p)

@staticmethod
def B(a = None):
return MyEnum("B", 1, [a])

@staticmethod
def C(b):
return MyEnum("C", 2, [b])

MyEnum.A = MyEnum("A", 0, list())

@_hx_classes.register_class("A")
class A:
@staticmethod
def _hx_empty_init(_hx_o):
pass

@_hx_classes.register_class("B", fields=["a"], props=["b"], methods=["get_b"], statics=["c"], interfaces=[IA], super=A)
class B(A):
def get_b(self):
return 0
c = None

@staticmethod
def _hx_empty_init(_hx_o):
_hx_o.a = None
```