| #include "slang_rs_export_var.h" |
| |
| #include "llvm/ADT/APSInt.h" |
| |
| #include "clang/AST/Type.h" |
| |
| #include "slang_rs_context.h" |
| #include "slang_rs_export_type.h" |
| |
| using namespace slang; |
| |
| RSExportVar::RSExportVar(RSContext *Context, |
| const clang::VarDecl *VD, |
| const RSExportType *ET) |
| : mContext(Context), |
| mName(VD->getName().data(), VD->getName().size()), |
| mET(ET), |
| mIsConst(false) { |
| // mInit - Evaluate initializer expression |
| const clang::Expr *Initializer = VD->getAnyInitializer(); |
| if (Initializer != NULL) { |
| switch (ET->getClass()) { |
| case RSExportType::ExportClassPrimitive: |
| case RSExportType::ExportClassVector: { |
| Initializer->Evaluate(mInit, *Context->getASTContext()); |
| break; |
| } |
| case RSExportType::ExportClassPointer: { |
| if (Initializer->isNullPointerConstant |
| (*Context->getASTContext(), |
| clang::Expr::NPC_ValueDependentIsNotNull) |
| ) |
| mInit.Val = clang::APValue(llvm::APSInt(1)); |
| else |
| Initializer->Evaluate(mInit, *Context->getASTContext()); |
| break; |
| } |
| case RSExportType::ExportClassRecord: { |
| // No action |
| fprintf(stderr, "RSExportVar::RSExportVar : Reflection of initializer " |
| "to variable '%s' (of type '%s') is unsupported " |
| "currently.\n", |
| mName.c_str(), |
| ET->getName().c_str()); |
| break; |
| } |
| default: { |
| assert(false && "Unknown class of type"); |
| } |
| } |
| } |
| |
| // mIsConst - Is it a constant? |
| clang::QualType QT = VD->getTypeSourceInfo()->getType(); |
| if (!QT.isNull()) { |
| mIsConst = QT.isConstQualified(); |
| } |
| |
| return; |
| } |