aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Luc Brouillet <jeanluc@google.com>2014-06-03 16:13:51 -0700
committerJean-Luc Brouillet <jeanluc@google.com>2014-06-03 17:38:17 -0700
commitefcff1017f5f1e120a8ffb67125e412343479f94 (patch)
tree83e3403b120f0fc9aa0826a602617d17a8753d9f
parentff76edf45d41b6129be1559da457ff321a7bcf12 (diff)
downloadandroid_frameworks_compile_slang-efcff1017f5f1e120a8ffb67125e412343479f94.tar.gz
android_frameworks_compile_slang-efcff1017f5f1e120a8ffb67125e412343479f94.tar.bz2
android_frameworks_compile_slang-efcff1017f5f1e120a8ffb67125e412343479f94.zip
Remove ReflectionBase.
Some of the methods of this base class only applies to the C++ reflection. Other methods better belong in reflection_utils. Change-Id: Ib539eb3b31cdc2230a5a7dd925642b5a697a899a
-rw-r--r--Android.mk1
-rw-r--r--slang_rs_reflect_utils.cpp4
-rw-r--r--slang_rs_reflect_utils.h7
-rw-r--r--slang_rs_reflection.cpp52
-rw-r--r--slang_rs_reflection.h1
-rw-r--r--slang_rs_reflection_base.cpp231
-rw-r--r--slang_rs_reflection_base.h88
-rw-r--r--slang_rs_reflection_cpp.cpp101
-rw-r--r--slang_rs_reflection_cpp.h36
9 files changed, 171 insertions, 350 deletions
diff --git a/Android.mk b/Android.mk
index b2614a9..f049c17 100644
--- a/Android.mk
+++ b/Android.mk
@@ -145,7 +145,6 @@ LOCAL_SRC_FILES := \
slang_rs_export_foreach.cpp \
slang_rs_object_ref_count.cpp \
slang_rs_reflection.cpp \
- slang_rs_reflection_base.cpp \
slang_rs_reflection_cpp.cpp \
slang_rs_reflect_utils.cpp \
strip_unknown_attributes.cpp
diff --git a/slang_rs_reflect_utils.cpp b/slang_rs_reflect_utils.cpp
index 3a41a14..7b375cb 100644
--- a/slang_rs_reflect_utils.cpp
+++ b/slang_rs_reflect_utils.cpp
@@ -99,6 +99,10 @@ RSSlangReflectUtils::JavaClassNameFromRSFileName(const char *rsFileName) {
return InternalFileNameConvert(rsFileName, false);
}
+std::string RootNameFromRSFileName(const std::string &rsFileName) {
+ return InternalFileNameConvert(rsFileName.c_str(), false);
+}
+
std::string
RSSlangReflectUtils::BCFileNameFromRSFileName(const char *rsFileName) {
return InternalFileNameConvert(rsFileName, true);
diff --git a/slang_rs_reflect_utils.h b/slang_rs_reflect_utils.h
index 833bcaa..8df1d88 100644
--- a/slang_rs_reflect_utils.h
+++ b/slang_rs_reflect_utils.h
@@ -90,6 +90,13 @@ public:
// JoinPath("foo/", "/bar") returns "foo/bar".
std::string JoinPath(const std::string &path1, const std::string &path2);
+/* Compute a safe root name from a .rs file name. Any non-alphanumeric,
+ * non-underscore characters will be discarded.
+ * E.g. RootNameFromRSFileName("./foo/bar/my-Renderscript_file.rs") returns
+ * "myRenderscript_file".
+ */
+std::string RootNameFromRSFileName(const std::string &rsFileName);
+
/* This class is used to generate one source file. There will be one instance
* for each generated file.
*/
diff --git a/slang_rs_reflection.cpp b/slang_rs_reflection.cpp
index 0b9553c..52b439c 100644
--- a/slang_rs_reflection.cpp
+++ b/slang_rs_reflection.cpp
@@ -38,8 +38,6 @@
#include "slang_version.h"
#include "slang_utils.h"
-#include "slang_rs_reflection_base.h"
-
#define RS_SCRIPT_CLASS_NAME_PREFIX "ScriptC_"
#define RS_SCRIPT_CLASS_SUPER_CLASS_NAME "ScriptC"
@@ -420,7 +418,8 @@ RSReflectionJava::genInitPrimitiveExportVariable(const std::string &VarName,
slangAssert(!Val.isUninit() && "Not a valid initializer");
indent() << RS_EXPORT_VAR_PREFIX << VarName << " = ";
- out() << RSReflectionBase::genInitValue(Val) << ";\n";
+ genInitValue(Val, false);
+ out() << ";\n";
}
void RSReflectionJava::genInitExportVariable(const RSExportType *ET,
@@ -841,8 +840,8 @@ void RSReflectionJava::genPrimitiveTypeExportVariable(const RSExportVar *EV) {
indent() << "public final static " << TypeName
<< " " RS_EXPORT_VAR_CONST_PREFIX << VarName << " = ";
const clang::APValue &Val = EV->getInit();
- out() << RSReflectionBase::genInitValue(Val, EPT->getType() ==
- DataTypeBoolean) << ";\n";
+ genInitValue(Val, EPT->getType() == DataTypeBoolean);
+ out() << ";\n";
} else {
// set_*()
// This must remain synchronized, since multiple Dalvik threads may
@@ -886,6 +885,49 @@ void RSReflectionJava::genPrimitiveTypeExportVariable(const RSExportVar *EV) {
genGetFieldID(VarName);
}
+void RSReflectionJava::genInitValue(const clang::APValue &Val, bool asBool) {
+ switch (Val.getKind()) {
+ case clang::APValue::Int: {
+ llvm::APInt api = Val.getInt();
+ if (asBool) {
+ out() << ((api.getSExtValue() == 0) ? "false" : "true");
+ } else {
+ // TODO: Handle unsigned correctly
+ out() << api.getSExtValue();
+ if (api.getBitWidth() > 32) {
+ out() << "L";
+ }
+ }
+ break;
+ }
+
+ case clang::APValue::Float: {
+ llvm::APFloat apf = Val.getFloat();
+ llvm::SmallString<30> s;
+ apf.toString(s);
+ out() << s.c_str();
+ if (&apf.getSemantics() == &llvm::APFloat::IEEEsingle) {
+ if (s.count('.') == 0) {
+ out() << ".f";
+ } else {
+ out() << "f";
+ }
+ }
+ break;
+ }
+
+ case clang::APValue::ComplexInt:
+ case clang::APValue::ComplexFloat:
+ case clang::APValue::LValue:
+ case clang::APValue::Vector: {
+ slangAssert(false && "Primitive type cannot have such kind of initializer");
+ break;
+ }
+
+ default: { slangAssert(false && "Unknown kind of initializer"); }
+ }
+}
+
void RSReflectionJava::genPointerTypeExportVariable(const RSExportVar *EV) {
const RSExportType *ET = EV->getType();
const RSExportType *PointeeType;
diff --git a/slang_rs_reflection.h b/slang_rs_reflection.h
index a5823b2..e054b24 100644
--- a/slang_rs_reflection.h
+++ b/slang_rs_reflection.h
@@ -198,6 +198,7 @@ private:
const clang::APValue &Val);
void genInitExportVariable(const RSExportType *ET, const std::string &VarName,
const clang::APValue &Val);
+ void genInitValue(const clang::APValue &Val, bool asBool);
void genExportVariable(const RSExportVar *EV);
void genPrimitiveTypeExportVariable(const RSExportVar *EV);
void genPointerTypeExportVariable(const RSExportVar *EV);
diff --git a/slang_rs_reflection_base.cpp b/slang_rs_reflection_base.cpp
deleted file mode 100644
index c16b266..0000000
--- a/slang_rs_reflection_base.cpp
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/stat.h>
-
-#include <cstdarg>
-#include <cctype>
-
-#include <algorithm>
-#include <limits>
-#include <sstream>
-#include <string>
-#include <utility>
-
-#include "os_sep.h"
-#include "slang_rs_context.h"
-#include "slang_rs_export_var.h"
-#include "slang_rs_export_foreach.h"
-#include "slang_rs_export_func.h"
-#include "slang_rs_reflect_utils.h"
-#include "slang_version.h"
-#include "slang_utils.h"
-
-#include "slang_rs_reflection_base.h"
-
-
-
-using namespace std;
-
-namespace slang {
-
-static const char *const gApacheLicenseNote =
-"/*\n"
-" * Copyright (C) 2012 The Android Open Source Project\n"
-" *\n"
-" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
-" * you may not use this file except in compliance with the License.\n"
-" * You may obtain a copy of the License at\n"
-" *\n"
-" * http://www.apache.org/licenses/LICENSE-2.0\n"
-" *\n"
-" * Unless required by applicable law or agreed to in writing, software\n"
-" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
-" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
-" * See the License for the specific language governing permissions and\n"
-" * limitations under the License.\n"
-" */\n"
-"\n";
-
-
-RSReflectionBase::RSReflectionBase(const RSContext *con)
- : mVerbose(true) {
- mRSContext = con;
- mLicenseNote = gApacheLicenseNote;
-
-}
-
-RSReflectionBase::~RSReflectionBase() {
-
-}
-
-/*
-bool RSReflectionBase::openFile(const string &name, string &errorMsg) {
- if(!mUseStdout) {
- mOF.clear();
- if(!SlangUtils::CreateDirectoryWithParents(mOutputPath, &errorMsg)) {
- return false;
- }
-
- string cf(mOutputPath + OS_PATH_SEPARATOR_STR + name);
- mOF.open(cf.c_str());
- if(!mOF.good()) {
- errorMsg = "failed to open file '" + cf + "' for write";
- return false;
- }
- }
- return true;
-}
-*/
-
-void RSReflectionBase::startFile(const string &filename) {
- if(mVerbose) {
- printf("Generating %s\n", filename.c_str());
- }
-
- // License
- write(mLicenseNote);
-
- // Notice of generated file
- write("/*");
- write(" * This file is auto-generated. DO NOT MODIFY!");
- write(" * The source Renderscript file: " + mInputFileName);
- write(" */");
- write("");
-}
-
-// remove path plus .rs from filename to generate class name
-string RSReflectionBase::stripRS(const string &s) const {
- string tmp(s);
- size_t pos = tmp.rfind(".rs");
- if (pos == string::npos) {
- pos = tmp.rfind(".fs");
- }
- if(pos != string::npos) {
- tmp.erase(pos);
- }
- pos = tmp.rfind("/");
- if (pos != string::npos) {
- tmp.erase(0, pos+1);
- }
- return tmp;
-}
-
-void RSReflectionBase::write(const std::string &t) {
- //printf("%s%s\n", mIndent.c_str(), t.c_str());
- mText.push_back(mIndent + t);
-}
-
-void RSReflectionBase::write(const std::stringstream &t) {
- mText.push_back(mIndent + t.str());
-}
-
-
-void RSReflectionBase::incIndent() {
- mIndent.append(" ");
-}
-
-void RSReflectionBase::decIndent() {
- mIndent.erase(0, 4);
-}
-
-bool RSReflectionBase::writeFile(const string &filename, const vector< string > &txt) {
- FILE *pfin = fopen((mOutputPath + filename).c_str(), "wt");
- if (pfin == NULL) {
- fprintf(stderr, "Error: could not write file %s\n", filename.c_str());
- return false;
- }
-
- for(size_t ct=0; ct < txt.size(); ct++) {
- fprintf(pfin, "%s\n", txt[ct].c_str());
- }
- fclose(pfin);
- return true;
-}
-
-
-string RSReflectionBase::genInitValue(const clang::APValue &Val, bool asBool) {
- stringstream tmp;
- switch (Val.getKind()) {
- case clang::APValue::Int: {
- llvm::APInt api = Val.getInt();
- if(asBool) {
- tmp << ((api.getSExtValue() == 0) ? "false" : "true");
- } else {
- // TODO: Handle unsigned possibly for C++ API.
- tmp << api.getSExtValue();
- if (api.getBitWidth() > 32) {
- tmp << "L";
- }
- }
- break;
- }
-
- case clang::APValue::Float: {
- llvm::APFloat apf = Val.getFloat();
- llvm::SmallString<30> s;
- apf.toString(s);
- tmp << s.c_str();
- if (&apf.getSemantics() == &llvm::APFloat::IEEEsingle) {
- if (s.count('.') == 0) {
- tmp << ".f";
- } else {
- tmp << "f";
- }
- }
- break;
- }
-
- case clang::APValue::ComplexInt:
- case clang::APValue::ComplexFloat:
- case clang::APValue::LValue:
- case clang::APValue::Vector: {
- slangAssert(false && "Primitive type cannot have such kind of initializer");
- break;
- }
-
- default: {
- slangAssert(false && "Unknown kind of initializer");
- }
- }
- return tmp.str();
-}
-
-bool RSReflectionBase::addTypeNameForElement(
- const std::string &TypeName) {
- if (mTypesToCheck.find(TypeName) == mTypesToCheck.end()) {
- mTypesToCheck.insert(TypeName);
- return true;
- } else {
- return false;
- }
-}
-
-const char *RSReflectionBase::getVectorAccessor(unsigned Index) {
- static const char *VectorAccessorMap[] = {
- /* 0 */ "x",
- /* 1 */ "y",
- /* 2 */ "z",
- /* 3 */ "w",
- };
-
- slangAssert((Index < (sizeof(VectorAccessorMap) / sizeof(const char*))) &&
- "Out-of-bound index to access vector member");
-
- return VectorAccessorMap[Index];
-}
-
-}
diff --git a/slang_rs_reflection_base.h b/slang_rs_reflection_base.h
deleted file mode 100644
index 3383ad1..0000000
--- a/slang_rs_reflection_base.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2012, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_BASE_H_ // NOLINT
-#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_BASE_H_
-
-#include <fstream>
-#include <iostream>
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "llvm/ADT/StringExtras.h"
-
-#include "slang_assert.h"
-#include "slang_rs_export_type.h"
-
-namespace slang {
- class RSContext;
- class RSExportVar;
- class RSExportFunc;
- class RSExportForEach;
-
-class RSReflectionBase {
-protected:
- const RSContext *mRSContext;
-
- // Generated RS Elements for type-checking code.
- std::set<std::string> mTypesToCheck;
-
- RSReflectionBase(const RSContext *);
-
-
- bool mVerbose;
-
- std::string mLicenseNote;
- std::string mInputFileName;
-
- std::string mClassName;
- std::string mOutputPath;
- std::string mOutputBCFileName;
-
- std::vector< std::string > mText;
- std::string mIndent;
-
- bool openFile(const std::string &name, std::string &errorMsg);
- void startFile(const std::string &filename);
- void incIndent();
- void decIndent();
- void write(const std::string &t);
- void write(const std::stringstream &t);
-
- std::string stripRS(const std::string &s) const;
-
- bool writeFile(const std::string &filename, const std::vector< std::string > &txt);
-
- bool addTypeNameForElement(const std::string &TypeName);
-
- static const char *getVectorAccessor(unsigned index);
-
-private:
-
-public:
- typedef std::vector<std::pair<std::string, std::string> > ArgTy;
-
- virtual ~RSReflectionBase();
-
- static std::string genInitValue(const clang::APValue &Val, bool asBool=false);
-
-}; // class RSReflection
-
-} // namespace slang
-
-#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_BASE_H_ NOLINT
diff --git a/slang_rs_reflection_cpp.cpp b/slang_rs_reflection_cpp.cpp
index a6c84f5..bf2d896 100644
--- a/slang_rs_reflection_cpp.cpp
+++ b/slang_rs_reflection_cpp.cpp
@@ -110,7 +110,8 @@ static std::string GetTypeName(const RSExportType *ET, bool Brackets = true) {
return "";
}
-RSReflectionCpp::RSReflectionCpp(const RSContext *con) : RSReflectionBase(con) {
+RSReflectionCpp::RSReflectionCpp(const RSContext *Context)
+ : mRSContext(Context) {
clear();
}
@@ -119,10 +120,11 @@ RSReflectionCpp::~RSReflectionCpp() {}
bool RSReflectionCpp::reflect(const string &OutputPathBase,
const string &InputFileName,
const string &OutputBCFileName) {
- mInputFileName = InputFileName;
- mOutputPath = OutputPathBase + OS_PATH_SEPARATOR_STR;
- mOutputBCFileName = OutputBCFileName;
- mClassName = string("ScriptC_") + stripRS(InputFileName);
+ mRSSourceFilePath = InputFileName;
+ mOutputDirectory = OutputPathBase + OS_PATH_SEPARATOR_STR;
+ mBitCodeFilePath = OutputBCFileName;
+ mCleanedRSFileName = RootNameFromRSFileName(mRSSourceFilePath);
+ mClassName = "ScriptC_" + mCleanedRSFileName;
std::string Path =
RSSlangReflectUtils::ComputePackagedPath(OutputPathBase.c_str(), "");
@@ -144,7 +146,7 @@ bool RSReflectionCpp::reflect(const string &OutputPathBase,
bool RSReflectionCpp::makeHeader() {
// Create the file and write the license note.
- if (!mOut.startFile(mOutputPath, mClassName + ".h", mInputFileName,
+ if (!mOut.startFile(mOutputDirectory, mClassName + ".h", mRSSourceFilePath,
mRSContext->getLicenseNote())) {
return false;
}
@@ -223,7 +225,7 @@ bool RSReflectionCpp::makeHeader() {
continue;
}
- ArgTy Args;
+ ArgumentList Args;
std::string FunctionStart = "void forEach_" + ef->getName() + "(";
mOut.indent() << FunctionStart;
@@ -268,10 +270,10 @@ bool RSReflectionCpp::makeHeader() {
}
bool RSReflectionCpp::writeBC() {
- FILE *pfin = fopen(mOutputBCFileName.c_str(), "rb");
+ FILE *pfin = fopen(mBitCodeFilePath.c_str(), "rb");
if (pfin == NULL) {
fprintf(stderr, "Error: could not read file %s\n",
- mOutputBCFileName.c_str());
+ mBitCodeFilePath.c_str());
return false;
}
@@ -294,7 +296,7 @@ bool RSReflectionCpp::writeBC() {
}
bool RSReflectionCpp::makeImpl() {
- if (!mOut.startFile(mOutputPath, mClassName + ".cpp", mInputFileName,
+ if (!mOut.startFile(mOutputDirectory, mClassName + ".cpp", mRSSourceFilePath,
mRSContext->getLicenseNote())) {
return false;
}
@@ -313,9 +315,9 @@ bool RSReflectionCpp::makeImpl() {
mOut.indent() << mClassName << "::" << mClassName
<< "(android::RSC::sp<android::RSC::RS> rs):\n"
" ScriptC(rs, __txt, sizeof(__txt), \""
- << stripRS(mInputFileName) << "\", "
- << stripRS(mInputFileName).length() << ", \"/data/data/"
- << packageName << "/app\", sizeof(\"" << packageName << "\"))";
+ << mCleanedRSFileName << "\", " << mCleanedRSFileName.length()
+ << ", \"/data/data/" << packageName << "/app\", sizeof(\""
+ << packageName << "\"))";
mOut.startBlock();
for (std::set<std::string>::iterator I = mTypesToCheck.begin(),
E = mTypesToCheck.end();
@@ -352,7 +354,7 @@ bool RSReflectionCpp::makeImpl() {
continue;
}
- ArgTy Args;
+ ArgumentList Args;
std::string FunctionStart =
"void " + mClassName + "::forEach_" + ef->getName() + "(";
mOut.indent() << FunctionStart;
@@ -390,6 +392,9 @@ bool RSReflectionCpp::makeImpl() {
genTypeCheck(OET, "aout");
}
+ // TODO Add the appropriate dimension checking code, as seen in
+ // slang_rs_reflection.cpp.
+
std::string FieldPackerName = ef->getName() + "_fp";
if (ERT) {
if (genCreateFieldPacker(ERT, FieldPackerName.c_str())) {
@@ -632,10 +637,11 @@ void RSReflectionCpp::makeFunctionSignature(bool isDefinition,
}
}
-void RSReflectionCpp::makeArgs(const ArgTy &Args, int Offset) {
+void RSReflectionCpp::makeArgs(const ArgumentList &Args, int Offset) {
bool FirstArg = true;
- for (ArgTy::const_iterator I = Args.begin(), E = Args.end(); I != E; I++) {
+ for (ArgumentList::const_iterator I = Args.begin(), E = Args.end(); I != E;
+ I++) {
if (!FirstArg) {
mOut << ",\n";
mOut.indent() << string(Offset, ' ');
@@ -804,7 +810,7 @@ void RSReflectionCpp::genTypeInstance(const RSExportType *ET) {
case RSExportType::ExportClassConstantArray:
case RSExportType::ExportClassRecord: {
std::string TypeName = ET->getElementName();
- addTypeNameForElement(TypeName);
+ mTypesToCheck.insert(TypeName);
break;
}
@@ -881,6 +887,19 @@ void RSReflectionCpp::genInitExportVariable(const RSExportType *ET,
}
}
+const char *RSReflectionCpp::getVectorAccessor(unsigned Index) {
+ static const char *VectorAccessorMap[] = {/* 0 */ "x",
+ /* 1 */ "y",
+ /* 2 */ "z",
+ /* 3 */ "w",
+ };
+
+ slangAssert((Index < (sizeof(VectorAccessorMap) / sizeof(const char *))) &&
+ "Out-of-bound index to access vector member");
+
+ return VectorAccessorMap[Index];
+}
+
void RSReflectionCpp::genZeroInitExportVariable(const std::string &VarName) {
mOut.indent() << "memset(&" << RS_EXPORT_VAR_PREFIX << VarName
<< ", 0, sizeof(" << RS_EXPORT_VAR_PREFIX << VarName << "));\n";
@@ -891,8 +910,52 @@ RSReflectionCpp::genInitPrimitiveExportVariable(const std::string &VarName,
const clang::APValue &Val) {
slangAssert(!Val.isUninit() && "Not a valid initializer");
- mOut.indent() << RS_EXPORT_VAR_PREFIX << VarName << " = "
- << RSReflectionBase::genInitValue(Val) << ";\n";
+ mOut.indent() << RS_EXPORT_VAR_PREFIX << VarName << " = ";
+ genInitValue(Val);
+ mOut << ";\n";
+}
+
+void RSReflectionCpp::genInitValue(const clang::APValue &Val, bool asBool) {
+ switch (Val.getKind()) {
+ case clang::APValue::Int: {
+ llvm::APInt api = Val.getInt();
+ if (asBool) {
+ mOut << ((api.getSExtValue() == 0) ? "false" : "true");
+ } else {
+ // TODO: Handle unsigned correctly for C++
+ mOut << api.getSExtValue();
+ if (api.getBitWidth() > 32) {
+ mOut << "L";
+ }
+ }
+ break;
+ }
+
+ case clang::APValue::Float: {
+ llvm::APFloat apf = Val.getFloat();
+ llvm::SmallString<30> s;
+ apf.toString(s);
+ mOut << s.c_str();
+ if (&apf.getSemantics() == &llvm::APFloat::IEEEsingle) {
+ if (s.count('.') == 0) {
+ mOut << ".f";
+ } else {
+ mOut << "f";
+ }
+ }
+ break;
+ }
+
+ case clang::APValue::ComplexInt:
+ case clang::APValue::ComplexFloat:
+ case clang::APValue::LValue:
+ case clang::APValue::Vector: {
+ slangAssert(false && "Primitive type cannot have such kind of initializer");
+ break;
+ }
+
+ default: { slangAssert(false && "Unknown kind of initializer"); }
+ }
}
void RSReflectionCpp::genInitBoolExportVariable(const std::string &VarName,
diff --git a/slang_rs_reflection_cpp.h b/slang_rs_reflection_cpp.h
index 81043da..56c0f29 100644
--- a/slang_rs_reflection_cpp.h
+++ b/slang_rs_reflection_cpp.h
@@ -14,10 +14,9 @@
* limitations under the License.
*/
-#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ // NOLINT
+#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_ // NOLINT
#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_REFLECTION_CPP_H_
-#include "slang_rs_reflection_base.h"
#include "slang_rs_reflect_utils.h"
#include <set>
@@ -27,8 +26,8 @@
namespace slang {
-class RSReflectionCpp : public RSReflectionBase {
-public:
+class RSReflectionCpp {
+ public:
explicit RSReflectionCpp(const RSContext *);
virtual ~RSReflectionCpp();
@@ -36,11 +35,33 @@ public:
const std::string &InputFileName,
const std::string &OutputBCFileName);
-private:
+ private:
+ // List of of (type, name) pairs.
+ typedef std::vector<std::pair<std::string, std::string> > ArgumentList;
+
+ // Information coming from the compiler about the code we're reflecting.
+ const RSContext *mRSContext;
+
+ // Path to the *.rs file for which we're generating C++ code.
+ std::string mRSSourceFilePath;
+ // Path to the file that contains the byte code generated from the *.rs file.
+ std::string mBitCodeFilePath;
+ // The directory where we'll generate the C++ files.
+ std::string mOutputDirectory;
+ // A cleaned up version of the *.rs file name that can be used in generating
+ // C++ identifiers.
+ std::string mCleanedRSFileName;
+ // The name of the generated C++ class.
+ std::string mClassName;
+
+ // TODO document
unsigned int mNextExportVarSlot;
unsigned int mNextExportFuncSlot;
unsigned int mNextExportForEachSlot;
+ // Generated RS Elements for type-checking code.
+ std::set<std::string> mTypesToCheck;
+
inline void clear() {
mNextExportVarSlot = 0;
mNextExportFuncSlot = 0;
@@ -52,6 +73,9 @@ private:
// implementation file.
GeneratedFile mOut;
+ void genInitValue(const clang::APValue &Val, bool asBool = false);
+ static const char *getVectorAccessor(unsigned index);
+
inline unsigned int getNextExportVarSlot() { return mNextExportVarSlot++; }
inline unsigned int getNextExportFuncSlot() { return mNextExportFuncSlot++; }
@@ -77,7 +101,7 @@ private:
const clang::APValue &Val);
// Produce an argument string of the form "T1 t, T2 u, T3 v".
- void makeArgs(const ArgTy &Args, int Offset);
+ void makeArgs(const ArgumentList &Args, int Offset);
// Write out code for an export variable.
void genExportVariable(const RSExportVar *EV);