slang_rs_export_var.cpp revision a41ce1d98094da84643995d40d71c529905123fc
1#include "slang_rs_export_var.h" 2 3#include "llvm/ADT/APSInt.h" 4 5#include "clang/AST/Type.h" 6 7#include "slang_rs_context.h" 8#include "slang_rs_export_type.h" 9 10using namespace slang; 11 12RSExportVar::RSExportVar(RSContext *Context, 13 const clang::VarDecl *VD, 14 const RSExportType *ET) 15 : RSExportable(Context, RSExportable::EX_VAR), 16 mContext(Context), 17 mName(VD->getName().data(), VD->getName().size()), 18 mET(ET), 19 mIsConst(false) { 20 // mInit - Evaluate initializer expression 21 const clang::Expr *Initializer = VD->getAnyInitializer(); 22 if (Initializer != NULL) { 23 switch (ET->getClass()) { 24 case RSExportType::ExportClassPrimitive: 25 case RSExportType::ExportClassVector: { 26 Initializer->Evaluate(mInit, *Context->getASTContext()); 27 break; 28 } 29 case RSExportType::ExportClassPointer: { 30 if (Initializer->isNullPointerConstant 31 (*Context->getASTContext(), 32 clang::Expr::NPC_ValueDependentIsNotNull) 33 ) 34 mInit.Val = clang::APValue(llvm::APSInt(1)); 35 else 36 Initializer->Evaluate(mInit, *Context->getASTContext()); 37 break; 38 } 39 case RSExportType::ExportClassRecord: { 40 // No action 41 fprintf(stderr, "RSExportVar::RSExportVar : Reflection of initializer " 42 "to variable '%s' (of type '%s') is unsupported " 43 "currently.\n", 44 mName.c_str(), 45 ET->getName().c_str()); 46 break; 47 } 48 default: { 49 assert(false && "Unknown class of type"); 50 } 51 } 52 } 53 54 // mIsConst - Is it a constant? 55 clang::QualType QT = VD->getTypeSourceInfo()->getType(); 56 if (!QT.isNull()) { 57 mIsConst = QT.isConstQualified(); 58 } 59 60 return; 61} 62