Browse Source

[cpp] Fix array access for cpp.Pointer. Closes #5239. Add array access for cpp.RawPointer

Hugh 9 years ago
parent
commit
2c21039ff5
2 changed files with 21 additions and 1 deletions
  1. 20 0
      src/generators/gencpp.ml
  2. 1 1
      std/cpp/RawConstPointer.hx

+ 20 - 0
src/generators/gencpp.ml

@@ -1380,6 +1380,8 @@ and tcppfuncloc =
 
 
 and tcpparrayloc =
 and tcpparrayloc =
    | ArrayTyped of tcppexpr * tcppexpr
    | ArrayTyped of tcppexpr * tcppexpr
+   | ArrayPointer of tcppexpr * tcppexpr
+   | ArrayRawPointer of tcppexpr * tcppexpr
    | ArrayObject of tcppexpr * tcppexpr * tcpp
    | ArrayObject of tcppexpr * tcppexpr * tcpp
    | ArrayVirtual of tcppexpr * tcppexpr
    | ArrayVirtual of tcppexpr * tcppexpr
    | ArrayImplements of tclass * tcppexpr * tcppexpr
    | ArrayImplements of tclass * tcppexpr * tcppexpr
@@ -2500,6 +2502,10 @@ let retype_expression ctx request_type function_args expression_tree forInjectio
             (match retypedObj.cpptype with
             (match retypedObj.cpptype with
               | TCppScalarArray scalar ->
               | TCppScalarArray scalar ->
                  CppArray( ArrayTyped(retypedObj,retypedIdx) ), scalar
                  CppArray( ArrayTyped(retypedObj,retypedIdx) ), scalar
+              | TCppPointer (_,elem) ->
+                 CppArray( ArrayPointer(retypedObj, retypedIdx) ), elem
+              | TCppRawPointer (_,elem) ->
+                 CppArray( ArrayRawPointer(retypedObj, retypedIdx) ), elem
               | TCppObjectArray TCppDynamic ->
               | TCppObjectArray TCppDynamic ->
                  CppArray( ArrayObject(retypedObj,retypedIdx,TCppDynamic) ), TCppDynamic
                  CppArray( ArrayObject(retypedObj,retypedIdx,TCppDynamic) ), TCppDynamic
               | TCppObjectArray elem ->
               | TCppObjectArray elem ->
@@ -3076,6 +3082,12 @@ let gen_cpp_ast_expression_tree ctx class_name func_name function_args injection
          | ArrayTyped(arrayObj,index) ->
          | ArrayTyped(arrayObj,index) ->
             gen arrayObj; out "->__get("; gen index; out ")"
             gen arrayObj; out "->__get("; gen index; out ")"
 
 
+         | ArrayPointer(arrayObj,index) ->
+            gen arrayObj; out ".ptr["; gen index; out "]"
+
+         | ArrayRawPointer(arrayObj,index) ->
+            gen arrayObj; out "["; gen index; out "]"
+
          | ArrayObject(arrayObj,index,elem) ->
          | ArrayObject(arrayObj,index,elem) ->
             let close = if cpp_is_dynamic_type elem then
             let close = if cpp_is_dynamic_type elem then
                   ""
                   ""
@@ -3107,6 +3119,10 @@ let gen_cpp_ast_expression_tree ctx class_name func_name function_args injection
             | ArrayObject(arrayObj, index, _)
             | ArrayObject(arrayObj, index, _)
             | ArrayTyped(arrayObj, index) ->
             | ArrayTyped(arrayObj, index) ->
                gen arrayObj; out "["; gen index; out "] = "; gen rvalue
                gen arrayObj; out "["; gen index; out "] = "; gen rvalue
+            | ArrayPointer(arrayObj, index) ->
+               gen arrayObj; out ".ptr["; gen index; out "] = "; gen rvalue
+            | ArrayRawPointer(arrayObj, index) ->
+               gen arrayObj; out "["; gen index; out "] = "; gen rvalue
             | ArrayVirtual(arrayObj, index) ->
             | ArrayVirtual(arrayObj, index) ->
                gen arrayObj; out "->set("; gen index; out ","; gen rvalue; out ")"
                gen arrayObj; out "->set("; gen index; out ","; gen rvalue; out ")"
 
 
@@ -3432,6 +3448,10 @@ let gen_cpp_ast_expression_tree ctx class_name func_name function_args injection
          | ArrayObject(arrayObj, index, _)
          | ArrayObject(arrayObj, index, _)
          | ArrayTyped(arrayObj, index) ->
          | ArrayTyped(arrayObj, index) ->
             gen arrayObj; out "["; gen index; out "]";
             gen arrayObj; out "["; gen index; out "]";
+         | ArrayPointer(arrayObj, index) ->
+            gen arrayObj; out ".ptr["; gen index; out "]";
+         | ArrayRawPointer(arrayObj, index) ->
+            gen arrayObj; out "["; gen index; out "]";
          | ArrayVirtual(arrayObj, index)
          | ArrayVirtual(arrayObj, index)
          | ArrayDynamic(arrayObj, index) ->
          | ArrayDynamic(arrayObj, index) ->
             out "hx::IndexRef("; gen arrayObj; out ".mPtr,"; gen index; out ")";
             out "hx::IndexRef("; gen arrayObj; out ".mPtr,"; gen index; out ")";

+ 1 - 1
std/cpp/RawConstPointer.hx

@@ -22,6 +22,6 @@
  package cpp;
  package cpp;
 
 
 @:unreflective
 @:unreflective
-extern class RawConstPointer<T>
+extern class RawConstPointer<T> implements ArrayAccess<T>
 {
 {
 }
 }