slang_rs_export_var.cpp revision 324c0479ec3edda573de60b2e6476507a99d06f7
1#include "slang_rs_context.hpp" 2#include "slang_rs_export_var.hpp" 3#include "slang_rs_export_type.hpp" /* for macro GET_CANONICAL_TYPE() */ 4 5#include "clang/AST/Type.h" /* for class clang::Type and clang::QualType */ 6 7#include "llvm/ADT/APSInt.h" /* for class llvm::APSInt */ 8 9namespace slang { 10 11RSExportVar::RSExportVar(RSContext* Context, const VarDecl* VD, const RSExportType* ET) : 12 mContext(Context), 13 mName(VD->getName().data(), VD->getName().size()), 14 mET(ET) 15{ 16 const Expr* Initializer = VD->getAnyInitializer(); 17 if(Initializer != NULL) 18 switch(ET->getClass()) { 19 case RSExportType::ExportClassPrimitive: 20 case RSExportType::ExportClassVector: 21 Initializer->EvaluateAsAny(mInit, *Context->getASTContext()); 22 break; 23 24 case RSExportType::ExportClassPointer: 25 if(Initializer->isNullPointerConstant(*Context->getASTContext(), Expr::NPC_ValueDependentIsNotNull)) 26 mInit.Val = APValue(llvm::APSInt(1)); 27 else 28 Initializer->EvaluateAsAny(mInit, *Context->getASTContext()); 29 break; 30 31 case RSExportType::ExportClassRecord: 32 /* No action */ 33 printf("RSExportVar::RSExportVar : Reflection of initializer to variable '%s' (of type '%s') is unsupported currently.\n", mName.c_str(), ET->getName().c_str()); 34 break; 35 36 default: 37 assert(false && "Unknown class of type"); 38 break; 39 } 40 41 return; 42} 43 44} /* namespace slang */ 45