1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/*
* 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<Int>;
cs.Lib.fixed({
var pSrc:cs.Pointer<Int> = 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<T> from Int64 from PointerAccess<T> to PointerAccess<T> {
@:op(A + B) public static function addIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A + B) public static function addp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A * B) public static function mulIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A * B) public static function mulp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A % B) public static function modIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A % B) public static function modp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A - B) public static function subIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A - B) public static function subp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A / B) public static function divIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A / B) public static function divp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A | B) public static function orIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A | B) public static function orp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A ^ B) public static function xorIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A ^ B) public static function xorp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A & B) public static function andIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A & B) public static function andp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A << B) public static function shlIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A << B) public static function shlp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A >> B) public static function shrIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
@:op(A >> B) public static function shrp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;
@:op(A > B) public static function gtp<T>(lhs:Pointer<T>, rhs:Pointer<T>):Bool;
@:op(A >= B) public static function gtep<T>(lhs:Pointer<T>, rhs:Pointer<T>):Bool;
@:op(A < B) public static function ltp<T>(lhs:Pointer<T>, rhs:Pointer<T>):Bool;
@:op(A <= B) public static function ltep<T>(lhs:Pointer<T>, rhs:Pointer<T>):Bool;
@:op(~A) public static function bnegp<T>(t:Pointer<T>):Pointer<T>;
@:op(A++) public static function prepp<T>(t:Pointer<T>):Pointer<T>;
@:op(A--) public static function prenn<T>(t:Pointer<T>):Pointer<T>;
@:op(++A) public static function postpp<T>(t:Pointer<T>):Pointer<T>;
@:op(--A) public static function postnn<T>(t:Pointer<T>):Pointer<T>;
/**
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<T>;
// @:analyzer(no_simplification)
extern inline private function get_acc():PointerAccess<T>
return (cast this : PointerAccess<T>);
// backwards compatibility
inline public function add(i:Int):Pointer<T> {
return this + i;
}
@:arrayAccess public static function getIp<T>(p:Pointer<T>, at:Int):T;
@:arrayAccess public static function setIp<T>(p:Pointer<T>, at:Int, val:T):T;
@:arrayAccess public static function getp<T>(p:Pointer<T>, at:Int64):T;
@:arrayAccess public static function setp<T>(p:Pointer<T>, at:Int64, val:T):T;
}
@:forward abstract PointerAccess<T>(T) {}
#end
|