diff options
author | Jean-Luc Brouillet <jeanluc@google.com> | 2014-06-04 01:02:31 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-06-04 01:02:31 +0000 |
commit | 95e4462cb5ffbff4aefa13f760ff2b1c57b8d008 (patch) | |
tree | 83e3403b120f0fc9aa0826a602617d17a8753d9f /slang_rs_reflection.cpp | |
parent | ff76edf45d41b6129be1559da457ff321a7bcf12 (diff) | |
parent | efcff1017f5f1e120a8ffb67125e412343479f94 (diff) | |
download | android_frameworks_compile_slang-95e4462cb5ffbff4aefa13f760ff2b1c57b8d008.tar.gz android_frameworks_compile_slang-95e4462cb5ffbff4aefa13f760ff2b1c57b8d008.tar.bz2 android_frameworks_compile_slang-95e4462cb5ffbff4aefa13f760ff2b1c57b8d008.zip |
Merge "Remove ReflectionBase."
Diffstat (limited to 'slang_rs_reflection.cpp')
-rw-r--r-- | slang_rs_reflection.cpp | 52 |
1 files changed, 47 insertions, 5 deletions
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; |