HaxeFoundation/haxe — pull request #3363 by Simn (2014-09-18 22:32:39+00:00)
Title: Auto generate property accessors on interfaces

This pull request changes interface properties so that they generate their accessors on the interface. This has three main advantages:

1. Field access can be typed properly instead of having to go through FDynamic.
2. Generators for static targets do not have to worry about creating the accessor fields on interfaces themselves.
3. DCE doesn't have to do crazy field name resolving to find these fields.

It works by detecting the "missing field" case like we already do, but instead of an error we simply create a field with the correct type. I have tagged it with the `@:compilerGenerated` metadata so we could retain visibility rules (else implemented accessor fields would have to be public).

Example code:

```
interface I {
public var x(never, set_x):String;
}

class C implements I {
public var x(never, set_x):String;
public function set_x(i) return "1";
public function new() { }
}

class Main {
static function main() {
var l:I = new C();
l.x = "bar";
}
}
```

Generated C++ before:

```
::I l = ::C_obj::__new();
l->__Field(HX_CSTRING("set_x"),true)(HX_CSTRING("bar"));
```

Generated C++ after:

```
::I l = ::C_obj::__new();
l->set_x(HX_CSTRING("bar"));
```