aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2013-11-20 22:03:35 -0800
committerStephen Hines <srhines@google.com>2013-11-26 16:55:04 -0800
commitd6f36b1347b487192103c9a17d5e9a1abcab534d (patch)
tree5b0deb9e7cb70dbc883303c80ff3ca84ba6d5ccf
parent80706836b18127b5733d790613a5d1b9f97cbb1d (diff)
downloadslang-d6f36b1347b487192103c9a17d5e9a1abcab534d.tar.gz
Support RS object types properly for C++ NDK reflection.
Change-Id: I7f475a212663ee8aa695d358a30c0474beb66a95
-rw-r--r--slang_rs_reflection_cpp.cpp30
-rw-r--r--tests/P_kernel_cpp/kernel_cpp.rs6
2 files changed, 28 insertions, 8 deletions
diff --git a/slang_rs_reflection_cpp.cpp b/slang_rs_reflection_cpp.cpp
index f583148..ff23206 100644
--- a/slang_rs_reflection_cpp.cpp
+++ b/slang_rs_reflection_cpp.cpp
@@ -64,8 +64,14 @@ static const char *GetMatrixTypeName(const RSExportMatrixType *EMT) {
static std::string GetTypeName(const RSExportType *ET, bool Brackets = true) {
switch (ET->getClass()) {
case RSExportType::ExportClassPrimitive: {
- return RSExportPrimitiveType::getRSReflectionType(
- static_cast<const RSExportPrimitiveType*>(ET))->c_name;
+ const RSExportPrimitiveType *EPT =
+ static_cast<const RSExportPrimitiveType*>(ET);
+ if (EPT->isRSObjectType()) {
+ return std::string("android::RSC::sp<const android::RSC::") +
+ RSExportPrimitiveType::getRSReflectionType(EPT)->c_name + ">";
+ } else {
+ return RSExportPrimitiveType::getRSReflectionType(EPT)->c_name;
+ }
}
case RSExportType::ExportClassPointer: {
const RSExportType *PointeeType =
@@ -506,21 +512,29 @@ void RSReflectionCpp::genExportVariable(const RSExportVar *EV) {
void RSReflectionCpp::genPrimitiveTypeExportVariable(const RSExportVar *EV) {
RSReflectionTypeData rtd;
- EV->getType()->convertToRTD(&rtd);
+ const RSExportPrimitiveType *EPT =
+ static_cast<const RSExportPrimitiveType *>(EV->getType());
+ EPT->convertToRTD(&rtd);
+ std::string TypeName = GetTypeName(EPT, false);
if (!EV->isConst()) {
- write(string("void set_") + EV->getName() + "(" + rtd.type->c_name +
+ write(string("void set_") + EV->getName() + "(" + TypeName.c_str() +
" v) {");
stringstream tmp;
- tmp << getNextExportVarSlot();
- write(string(" setVar(") + tmp.str() + ", &v, sizeof(v));");
+ tmp << getNextExportVarSlot() << ", ";
+ if (EPT->isRSObjectType()) {
+ tmp << "v);";
+ } else {
+ tmp << "&v, sizeof(v));";
+ }
+ write(string(" setVar(") + tmp.str());
write(string(" " RS_EXPORT_VAR_PREFIX) + EV->getName() + " = v;");
write("}");
}
- write(string(rtd.type->c_name) + " get_" + EV->getName() + "() const {");
+ write(TypeName + " get_" + EV->getName() + "() const {");
if (EV->isConst()) {
const clang::APValue &val = EV->getInit();
- bool isBool = !strcmp(rtd.type->c_name, "bool");
+ bool isBool = !strcmp(TypeName.c_str(), "bool");
write(string(" return ") + genInitValue(val, isBool) + ";");
} else {
write(string(" return " RS_EXPORT_VAR_PREFIX) + EV->getName() + ";");
diff --git a/tests/P_kernel_cpp/kernel_cpp.rs b/tests/P_kernel_cpp/kernel_cpp.rs
index 2a854c2..c5a41ce 100644
--- a/tests/P_kernel_cpp/kernel_cpp.rs
+++ b/tests/P_kernel_cpp/kernel_cpp.rs
@@ -10,6 +10,12 @@ bool bf = false;
int2 i2 = 2;
int3 i3 = {1, 2, 3};
+rs_allocation alloc;
+rs_element elem;
+rs_type type;
+rs_script script;
+rs_sampler sampler;
+
int __attribute__((kernel)) root(uint32_t ain) {
return 0;
}