Merge "Launch options & multi inputs for single-source RS"
diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp
index efe989c..0683db0 100644
--- a/slang_rs_export_type.cpp
+++ b/slang_rs_export_type.cpp
@@ -75,9 +75,9 @@
 {PrimitiveDataType, "UNSIGNED_5_5_5_1",         _, 16,          _,         _,        _,        _,        _, false},
 {PrimitiveDataType, "UNSIGNED_4_4_4_4",         _, 16,          _,         _,        _,        _,        _, false},
 
-{MatrixDataType, "MATRIX_2X2", _,  4*32, "rsMatrix_2x2", "Matrix2f", _, _, _, false},
-{MatrixDataType, "MATRIX_3X3", _,  9*32, "rsMatrix_3x3", "Matrix3f", _, _, _, false},
-{MatrixDataType, "MATRIX_4X4", _, 16*32, "rsMatrix_4x4", "Matrix4f", _, _, _, false},
+{MatrixDataType, "MATRIX_2X2", _,  4*32, "rs_matrix2x2", "Matrix2f", _, _, _, false},
+{MatrixDataType, "MATRIX_3X3", _,  9*32, "rs_matrix3x3", "Matrix3f", _, _, _, false},
+{MatrixDataType, "MATRIX_4X4", _, 16*32, "rs_matrix4x4", "Matrix4f", _, _, _, false},
 
 // RS object types are 32 bits in 32-bit RS, but 256 bits in 64-bit RS.
 // This is handled specially by the GetSizeInBits(}, method.
diff --git a/slang_rs_reflection_cpp.cpp b/slang_rs_reflection_cpp.cpp
index 7d29627..15c48fa 100644
--- a/slang_rs_reflection_cpp.cpp
+++ b/slang_rs_reflection_cpp.cpp
@@ -60,7 +60,11 @@
   return nullptr;
 }
 
-static std::string GetTypeName(const RSExportType *ET, bool Brackets = true) {
+static std::string GetTypeName(const RSExportType *ET, bool PreIdentifier = true) {
+  if((!PreIdentifier) && (ET->getClass() != RSExportType::ExportClassConstantArray)) {
+    slangAssert(false && "Non-array type post identifier?");
+    return "";
+  }
   switch (ET->getClass()) {
   case RSExportType::ExportClassPrimitive: {
     const RSExportPrimitiveType *EPT =
@@ -92,14 +96,17 @@
     return GetMatrixTypeName(static_cast<const RSExportMatrixType *>(ET));
   }
   case RSExportType::ExportClassConstantArray: {
-    // TODO: Fix this for C arrays!
     const RSExportConstantArrayType *CAT =
         static_cast<const RSExportConstantArrayType *>(ET);
-    std::string ElementTypeName = GetTypeName(CAT->getElementType());
-    if (Brackets) {
-      ElementTypeName.append("[]");
+    if (PreIdentifier) {
+      std::string ElementTypeName = GetTypeName(CAT->getElementType());
+      return ElementTypeName;
     }
-    return ElementTypeName;
+    else {
+      std::stringstream ArraySpec;
+      ArraySpec << "[" << CAT->getSize() << "]";
+      return ArraySpec.str();
+    }
   }
   case RSExportType::ExportClassRecord: {
     // TODO: Fix for C structs!
@@ -679,7 +686,7 @@
                                          const RSExportVar *EV) {
   RSReflectionTypeData rtd;
   EPT->convertToRTD(&rtd);
-  std::string TypeName = GetTypeName(EPT, false);
+  std::string TypeName = GetTypeName(EPT);
 
   if (!EV->isConst()) {
     mOut.indent() << "void set_" << EV->getName() << "(" << TypeName << " v)";
@@ -776,12 +783,51 @@
 }
 
 void RSReflectionCpp::genMatrixTypeExportVariable(const RSExportVar *EV) {
-  slangAssert(false);
+  uint32_t slot = getNextExportVarSlot();
+  stringstream tmp;
+  tmp << slot;
+
+  const RSExportType *ET = EV->getType();
+  if (ET->getName() == "rs_matrix4x4") {
+    mOut.indent() << "void set_" << EV->getName() << "(float v[16])";
+    mOut.startBlock();
+    mOut.indent() << "setVar(" << tmp.str() << ", v, sizeof(float)*16);\n";
+    mOut.endBlock();
+  } else if (ET->getName() == "rs_matrix3x3") {
+    mOut.indent() << "void set_" << EV->getName() << "(float v[9])";
+    mOut.startBlock();
+    mOut.indent() << "setVar(" << tmp.str() << ", v, sizeof(float)*9);";
+    mOut.endBlock();
+  } else if (ET->getName() == "rs_matrix2x2") {
+    mOut.indent() << "void set_" << EV->getName() << "(float v[4])";
+    mOut.startBlock();
+    mOut.indent() << "setVar(" << tmp.str() << ", v, sizeof(float)*4);";
+    mOut.endBlock();
+  } else {
+    mOut.indent() << "#error: TODO: " << ET->getName();
+    slangAssert(false);
+  }
 }
 
 void RSReflectionCpp::genGetterAndSetter(const RSExportConstantArrayType *AT,
                                          const RSExportVar *EV) {
-  slangAssert(false);
+  std::stringstream ArraySpec;
+  const RSExportType *ET = EV->getType();
+
+  const RSExportConstantArrayType *CAT =
+      static_cast<const RSExportConstantArrayType *>(ET);
+
+  uint32_t slot = getNextExportVarSlot();
+  stringstream tmp;
+  tmp << slot;
+
+  ArraySpec << CAT->getSize();
+  mOut.indent() << "void set_" << EV->getName() << "(" << GetTypeName(EV->getType()) << " v "
+      << GetTypeName(EV->getType(), false) << ")";
+  mOut.startBlock();
+  mOut.indent() << "setVar(" << tmp.str() << ", v, sizeof(" << GetTypeName(EV->getType()) + ") *"
+      << ArraySpec.str() << ");";
+  mOut.endBlock();
 }
 
 void RSReflectionCpp::genGetterAndSetter(const RSExportRecordType *ERT,
@@ -807,7 +853,7 @@
       } else {
         FirstArg = false;
       }
-      mOut << GetTypeName((*i)->getType(), false) << " " << (*i)->getName();
+      mOut << GetTypeName((*i)->getType()) << " " << (*i)->getName();
     }
   }
 
diff --git a/tests/P_array_cpp/array.rs b/tests/P_array_cpp/array.rs
new file mode 100644
index 0000000..9a36c6d
--- /dev/null
+++ b/tests/P_array_cpp/array.rs
@@ -0,0 +1,5 @@
+// -reflect-c++
+#pragma version(1)
+#pragma rs java_package_name(foo)
+
+float array[16];
diff --git a/tests/P_array_cpp/stderr.txt.expect b/tests/P_array_cpp/stderr.txt.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/P_array_cpp/stderr.txt.expect
diff --git a/tests/P_array_cpp/stdout.txt.expect b/tests/P_array_cpp/stdout.txt.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/P_array_cpp/stdout.txt.expect
diff --git a/tests/P_matrix_cpp/matrix.rs b/tests/P_matrix_cpp/matrix.rs
new file mode 100644
index 0000000..4847b54
--- /dev/null
+++ b/tests/P_matrix_cpp/matrix.rs
@@ -0,0 +1,5 @@
+// -reflect-c++
+#pragma version(1)
+#pragma rs java_package_name(foo)
+
+rs_matrix4x4 mat;
diff --git a/tests/P_matrix_cpp/stderr.txt.expect b/tests/P_matrix_cpp/stderr.txt.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/P_matrix_cpp/stderr.txt.expect
diff --git a/tests/P_matrix_cpp/stdout.txt.expect b/tests/P_matrix_cpp/stdout.txt.expect
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/P_matrix_cpp/stdout.txt.expect