/* * Copyright (C)2005-2019 Haxe Foundation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ package cs; import cs.StdTypes.Int64; /** This type represents pointer types for C# function parameters. It should only be used inside an unsafe context (not checked by the Haxe compiler) C# code: int[] src; fixed (int* pSrc = src) { ... } Haxe code: var src:NativeArray; cs.Lib.fixed({ var pSrc:cs.Pointer = cs.Lib.pointerOfArray(src); ... }); **/ #if !unsafe #error "You need to define 'unsafe' to be able to use unsafe code in hxcs" #else @:runtimeValue @:coreType abstract Pointer from Int64 from PointerAccess to PointerAccess { @:op(A + B) public static function addIp(lhs:Pointer, rhs:Int):Pointer; @:op(A + B) public static function addp(lhs:Pointer, rhs:Int64):Pointer; @:op(A * B) public static function mulIp(lhs:Pointer, rhs:Int):Pointer; @:op(A * B) public static function mulp(lhs:Pointer, rhs:Int64):Pointer; @:op(A % B) public static function modIp(lhs:Pointer, rhs:Int):Pointer; @:op(A % B) public static function modp(lhs:Pointer, rhs:Int64):Pointer; @:op(A - B) public static function subIp(lhs:Pointer, rhs:Int):Pointer; @:op(A - B) public static function subp(lhs:Pointer, rhs:Int64):Pointer; @:op(A / B) public static function divIp(lhs:Pointer, rhs:Int):Pointer; @:op(A / B) public static function divp(lhs:Pointer, rhs:Int64):Pointer; @:op(A | B) public static function orIp(lhs:Pointer, rhs:Int):Pointer; @:op(A | B) public static function orp(lhs:Pointer, rhs:Int64):Pointer; @:op(A ^ B) public static function xorIp(lhs:Pointer, rhs:Int):Pointer; @:op(A ^ B) public static function xorp(lhs:Pointer, rhs:Int64):Pointer; @:op(A & B) public static function andIp(lhs:Pointer, rhs:Int):Pointer; @:op(A & B) public static function andp(lhs:Pointer, rhs:Int64):Pointer; @:op(A << B) public static function shlIp(lhs:Pointer, rhs:Int):Pointer; @:op(A << B) public static function shlp(lhs:Pointer, rhs:Int64):Pointer; @:op(A >> B) public static function shrIp(lhs:Pointer, rhs:Int):Pointer; @:op(A >> B) public static function shrp(lhs:Pointer, rhs:Int64):Pointer; @:op(A > B) public static function gtp(lhs:Pointer, rhs:Pointer):Bool; @:op(A >= B) public static function gtep(lhs:Pointer, rhs:Pointer):Bool; @:op(A < B) public static function ltp(lhs:Pointer, rhs:Pointer):Bool; @:op(A <= B) public static function ltep(lhs:Pointer, rhs:Pointer):Bool; @:op(~A) public static function bnegp(t:Pointer):Pointer; @:op(A++) public static function prepp(t:Pointer):Pointer; @:op(A--) public static function prenn(t:Pointer):Pointer; @:op(++A) public static function postpp(t:Pointer):Pointer; @:op(--A) public static function postnn(t:Pointer):Pointer; /** Returns a `cs.PointerAccess` type, which in turn allows the underlying Pointer's fields to be accessed. **/ // @:analyzer(no_simplification) public var acc(get, never):PointerAccess; // @:analyzer(no_simplification) extern inline private function get_acc():PointerAccess return (cast this : PointerAccess); // backwards compatibility inline public function add(i:Int):Pointer { return this + i; } @:arrayAccess public static function getIp(p:Pointer, at:Int):T; @:arrayAccess public static function setIp(p:Pointer, at:Int, val:T):T; @:arrayAccess public static function getp(p:Pointer, at:Int64):T; @:arrayAccess public static function setp(p:Pointer, at:Int64, val:T):T; } @:forward abstract PointerAccess(T) {} #end