slang_rs_export_var.cpp revision 6315f76e3cc6ff2d012d1183a0b030d4ff0dc808
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 : mContext(Context), 16 mName(VD->getName().data(), VD->getName().size()), 17 mET(ET), 18 mIsConst(false) { 19 // mInit - Evaluate initializer expression 20 const clang::Expr *Initializer = VD->getAnyInitializer(); 21 if (Initializer != NULL) { 22 switch (ET->getClass()) { 23 case RSExportType::ExportClassPrimitive: 24 case RSExportType::ExportClassVector: { 25 Initializer->Evaluate(mInit, *Context->getASTContext()); 26 break; 27 } 28 case RSExportType::ExportClassPointer: { 29 if (Initializer->isNullPointerConstant 30 (*Context->getASTContext(), 31 clang::Expr::NPC_ValueDependentIsNotNull) 32 ) 33 mInit.Val = clang::APValue(llvm::APSInt(1)); 34 else 35 Initializer->Evaluate(mInit, *Context->getASTContext()); 36 break; 37 } 38 case RSExportType::ExportClassRecord: { 39 // No action 40 fprintf(stderr, "RSExportVar::RSExportVar : Reflection of initializer " 41 "to variable '%s' (of type '%s') is unsupported " 42 "currently.\n", 43 mName.c_str(), 44 ET->getName().c_str()); 45 break; 46 } 47 default: { 48 assert(false && "Unknown class of type"); 49 } 50 } 51 } 52 53 // mIsConst - Is it a constant? 54 clang::QualType QT = VD->getTypeSourceInfo()->getType(); 55 if (!QT.isNull()) { 56 mIsConst = QT.isConstQualified(); 57 } 58 59 return; 60} 61