Merge "Don't go through RSContext for the Java reflection (take 2)"
diff --git a/slang_rs.cpp b/slang_rs.cpp
index eb2bdbb..e2910ce 100644
--- a/slang_rs.cpp
+++ b/slang_rs.cpp
@@ -36,6 +36,7 @@
#include "slang_rs_context.h"
#include "slang_rs_export_type.h"
+#include "slang_rs_reflection.h"
#include "slang_rs_reflection_cpp.h"
namespace slang {
@@ -74,19 +75,9 @@
}
}
-bool SlangRS::reflectToJava(const std::string &OutputPathBase,
- const std::string &RSPackageName,
- bool EmbedBitcodeInJava) {
- return mRSContext->reflectToJava(OutputPathBase,
- RSPackageName,
- getInputFileName(),
- getOutputFileName(),
- EmbedBitcodeInJava);
-}
-
bool SlangRS::generateJavaBitcodeAccessor(const std::string &OutputPathBase,
- const std::string &PackageName,
- const std::string *LicenseNote) {
+ const std::string &PackageName,
+ const std::string *LicenseNote) {
RSSlangReflectUtils::BitCodeAccessorContext BCAccessorContext;
BCAccessorContext.rsFileName = getInputFileName().c_str();
@@ -229,8 +220,7 @@
getASTContext(),
getTargetInfo(),
&mPragmas,
- mTargetAPI,
- &mGeneratedFileNames);
+ mTargetAPI);
}
clang::ASTConsumer
@@ -353,13 +343,26 @@
if (BitcodeStorage == BCST_CPP_CODE) {
RSReflectionCpp R(mRSContext);
- bool ret = R.reflect(JavaReflectionPathBase, getInputFileName(), getOutputFileName());
+ bool ret = R.reflect(JavaReflectionPathBase, getInputFileName(),
+ getOutputFileName());
if (!ret) {
return false;
}
} else {
+ if (!RSPackageName.empty()) {
+ mRSContext->setRSPackageName(RSPackageName);
+ }
- if (!reflectToJava(JavaReflectionPathBase, RSPackageName, (BitcodeStorage == BCST_JAVA_CODE))) {
+ RSReflectionJava R(mRSContext, &mGeneratedFileNames);
+ if (!R.reflect(JavaReflectionPathBase,
+ mRSContext->getReflectJavaPackageName(),
+ mRSContext->getRSPackageName(), getInputFileName(),
+ getOutputFileName(), BitcodeStorage == BCST_JAVA_CODE)) {
+ // TODO Is this needed or will the error message have been printed
+ // already? and why not for the C++ case?
+ fprintf(stderr, "RSContext::reflectToJava : failed to do reflection "
+ "(%s)\n",
+ R.getLastError());
return false;
}
diff --git a/slang_rs.h b/slang_rs.h
index 65653b6..bce77fa 100644
--- a/slang_rs.h
+++ b/slang_rs.h
@@ -62,10 +62,6 @@
typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy;
ReflectedDefinitionListTy ReflectedDefinitions;
- bool reflectToJava(const std::string &OutputPathBase,
- const std::string &RSPackageName,
- bool EmbedBitcodeInJava);
-
bool generateJavaBitcodeAccessor(const std::string &OutputPathBase,
const std::string &PackageName,
const std::string *LicenseNote);
diff --git a/slang_rs_context.cpp b/slang_rs_context.cpp
index 59929e2..38dfff1 100644
--- a/slang_rs_context.cpp
+++ b/slang_rs_context.cpp
@@ -46,21 +46,17 @@
clang::ASTContext &Ctx,
const clang::TargetInfo &Target,
PragmaList *Pragmas,
- unsigned int TargetAPI,
- std::vector<std::string> *GeneratedFileNames)
+ unsigned int TargetAPI)
: mPP(PP),
mCtx(Ctx),
mPragmas(Pragmas),
mTargetAPI(TargetAPI),
- mGeneratedFileNames(GeneratedFileNames),
mDataLayout(NULL),
mLLVMContext(llvm::getGlobalContext()),
mLicenseNote(NULL),
mRSPackageName("android.renderscript"),
version(0),
- mIsCompatLib(false),
mMangleCtx(Ctx.createMangleContext()) {
- slangAssert(mGeneratedFileNames && "Must supply GeneratedFileNames");
// For #pragma rs export_type
PP.AddPragmaHandler(
@@ -278,31 +274,6 @@
}
}
-bool RSContext::reflectToJava(const std::string &OutputPathBase,
- const std::string &RSPackageName,
- const std::string &InputFileName,
- const std::string &OutputBCFileName,
- bool EmbedBitcodeInJava) {
- if (!RSPackageName.empty()) {
- mRSPackageName = RSPackageName;
- }
-
- // If we are not targeting the actual Android Renderscript classes,
- // we should reflect code that works with the compatibility library.
- if (mRSPackageName.compare("android.renderscript") != 0) {
- mIsCompatLib = true;
- }
-
- RSReflectionJava *R = new RSReflectionJava(this, mGeneratedFileNames);
- bool ret = R->reflect(OutputPathBase, mReflectJavaPackageName, mRSPackageName,
- InputFileName, OutputBCFileName, EmbedBitcodeInJava);
- if (!ret)
- fprintf(stderr, "RSContext::reflectToJava : failed to do reflection "
- "(%s)\n", R->getLastError());
- delete R;
- return ret;
-}
-
RSContext::~RSContext() {
delete mLicenseNote;
delete mDataLayout;
diff --git a/slang_rs_context.h b/slang_rs_context.h
index 0b70bdf..cdb35c6 100644
--- a/slang_rs_context.h
+++ b/slang_rs_context.h
@@ -68,7 +68,6 @@
clang::ASTContext &mCtx;
PragmaList *mPragmas;
unsigned int mTargetAPI;
- std::vector<std::string> *mGeneratedFileNames;
llvm::DataLayout *mDataLayout;
llvm::LLVMContext &mLLVMContext;
@@ -85,8 +84,6 @@
int version;
- bool mIsCompatLib;
-
llvm::OwningPtr<clang::MangleContext> mMangleCtx;
bool processExportVar(const clang::VarDecl *VD);
@@ -105,8 +102,7 @@
clang::ASTContext &Ctx,
const clang::TargetInfo &Target,
PragmaList *Pragmas,
- unsigned int TargetAPI,
- std::vector<std::string> *GeneratedFileNames);
+ unsigned int TargetAPI);
inline clang::Preprocessor &getPreprocessor() const { return mPP; }
inline clang::ASTContext &getASTContext() const { return mCtx; }
@@ -144,9 +140,8 @@
inline void setRSPackageName(const std::string &S) {
mRSPackageName = S;
}
- inline const std::string &getRSPackageName() const {
- return mRSPackageName;
- }
+
+ inline const std::string &getRSPackageName() const { return mRSPackageName; }
bool processExport();
inline void newExportable(RSExportable *E) {
@@ -214,18 +209,16 @@
// and return true.
bool insertExportType(const llvm::StringRef &TypeName, RSExportType *Type);
- bool reflectToJava(const std::string &OutputPathBase,
- const std::string &RSPackageName,
- const std::string &InputFileName,
- const std::string &OutputBCFileName,
- bool EmbedBitcodeInJava);
-
int getVersion() const { return version; }
void setVersion(int v) {
version = v;
}
- bool isCompatLib() const { return mIsCompatLib; }
+ bool isCompatLib() const {
+ // If we are not targeting the actual Android Renderscript classes,
+ // we should reflect code that works with the compatibility library.
+ return (mRSPackageName.compare("android.renderscript") != 0);
+ }
void addPragma(const std::string &T, const std::string &V) {
mPragmas->push_back(make_pair(T, V));