HaxeFoundation/haxe — pull request #2875 by waneck (2014-04-12 23:28:44+00:00)
Title: Inline support for __cpp__ magic

This request introduces the possibility of having `__cpp__ ` magic on inline functions. The following test case was used:
```haxe
class Main
{
static function main()
{
var bytes = haxe.io.Bytes.alloc(8).getData();
setInt(bytes,4,0xFF0FF0F0);
trace(getInt(bytes,4));
trace(0xFF0FF0F0);
}

inline private static function setInt(bytes:haxe.io.BytesData, addr:Int, x:Int)
{
untyped __cpp__("*((int *) ({0}->GetBase() + {1})) = {2}",bytes,addr,x);
}

inline private static function getInt(bytes:haxe.io.BytesData, addr:Int):Int
{
return untyped __cpp__("*((int *) ({0}->GetBase() + {1}))",bytes,addr);
}
}
```
And it works as expected. As seen on the example above, this will add a special `{\d}` construct for the `__cpp__` magic keyword, which will be replaced by the actual expression representation. This is backwards-compatible as the behaviour will only be triggered when there is more than one argument in the `__cpp__` magic. Also invalid input is detected and there is an effort to more precisely indicate the position where the error occurs.