Browse Source

Add Pointer.addressOf. Pointer postInc returns value, not pointer

hughsando 11 years ago
parent
commit
892420ea2b
3 changed files with 24 additions and 4 deletions
  1. 18 2
      gencpp.ml
  2. 2 1
      std/cpp/ConstPointer.hx
  3. 4 1
      std/cpp/Pointer.hx

+ 18 - 2
gencpp.ml

@@ -450,8 +450,6 @@ let is_interface_type t =
    | _ -> false
    | _ -> false
 ;;
 ;;
 
 
-
-
 let is_cpp_function_instance haxe_type =
 let is_cpp_function_instance haxe_type =
    match follow haxe_type with
    match follow haxe_type with
    | TInst (klass,params) ->
    | TInst (klass,params) ->
@@ -477,6 +475,21 @@ let is_fromStaticFunction_call func =
    | _ -> false
    | _ -> false
 ;;
 ;;
 
 
+let is_addressOf_call func =
+   match (remove_parens func).eexpr with
+   | TField (_,FStatic ({cl_path=["cpp"],"Pointer"},{cf_name="addressOf"} ) ) -> true
+   | _ -> false
+;;
+
+let is_lvalue var =
+   match (remove_parens var).eexpr with
+   | TLocal _ -> true
+   | TField (_,FStatic(_,field) ) | TField (_,FInstance(_,field) ) -> is_var_field field
+   | _ -> false
+;;
+
+
+
 let is_pointer haxe_type =
 let is_pointer haxe_type =
    match follow haxe_type with
    match follow haxe_type with
    | TInst (klass,params) ->
    | TInst (klass,params) ->
@@ -1873,6 +1886,9 @@ and gen_expression ctx retval expression =
          | _ -> error "fromStaticFunction must take a static function" expression.epos;
          | _ -> error "fromStaticFunction must take a static function" expression.epos;
       )
       )
 
 
+   | TCall (func, [arg]) when is_addressOf_call func && not (is_lvalue arg) ->
+      error "addressOf must take a local or member variable" expression.epos;
+
    | TCall (func, arg_list) ->
    | TCall (func, arg_list) ->
       let rec is_variable e = match e.eexpr with
       let rec is_variable e = match e.eexpr with
       | TField _ | TEnumParameter _ -> false
       | TField _ | TEnumParameter _ -> false

+ 2 - 1
std/cpp/ConstPointer.hx

@@ -3,11 +3,12 @@ package cpp;
 @:coreType @:include("cpp/Pointer.h")
 @:coreType @:include("cpp/Pointer.h")
 extern class ConstPointer<T> extends BasePointer<T>
 extern class ConstPointer<T> extends BasePointer<T>
 {
 {
+
 	public function at(inIndex:Int):T;
 	public function at(inIndex:Int):T;
 
 
 	public function inc():ConstPointer<T>;
 	public function inc():ConstPointer<T>;
 	public function dec():ConstPointer<T>;
 	public function dec():ConstPointer<T>;
-	public function postIncBy(inT:Int):ConstPointer<T>;
+	public function postIncVal():T;
 	public function incBy(inT:Int):ConstPointer<T>;
 	public function incBy(inT:Int):ConstPointer<T>;
 	public function add(inT:Int):ConstPointer<T>;
 	public function add(inT:Int):ConstPointer<T>;
 
 

+ 4 - 1
std/cpp/Pointer.hx

@@ -5,14 +5,17 @@ extern class Pointer<T> extends ConstPointer<T> implements ArrayAccess<T>
 {
 {
 	public var ref(get,set):T;
 	public var ref(get,set):T;
 
 
+   public static function addressOf<T>(inVariable:T) : Pointer<T>;
+
 	public static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>;
 	public static function arrayElem<T>(array:Array<T>, inElem:Int):Pointer<T>;
 
 
 	override public function inc():Pointer<T>;
 	override public function inc():Pointer<T>;
 	override public function dec():Pointer<T>;
 	override public function dec():Pointer<T>;
-	override public function postIncBy(inT:Int):Pointer<T>;
 	override public function incBy(inT:Int):Pointer<T>;
 	override public function incBy(inT:Int):Pointer<T>;
 	override public function add(inT:Int):Pointer<T>;
 	override public function add(inT:Int):Pointer<T>;
 
 
+	public function postIncRef():T;
+
 	public function destroy():Void;
 	public function destroy():Void;
 	public function destroyArray():Void;
 	public function destroyArray():Void;
 }
 }