blob: 20f4911b2702c47d807320a42413f5b9b652f2fb [file] [log] [blame]
Shih-wei Liao324c0472010-06-21 13:15:11 -07001#include "slang_rs_context.hpp"
Shih-wei Liao462aefd2010-06-04 15:32:04 -07002#include "slang_rs_export_var.hpp"
3#include "slang_rs_export_type.hpp" /* for macro GET_CANONICAL_TYPE() */
4
Shih-wei Liao324c0472010-06-21 13:15:11 -07005#include "clang/AST/Type.h" /* for class clang::Type and clang::QualType */
6
7#include "llvm/ADT/APSInt.h" /* for class llvm::APSInt */
Shih-wei Liao462aefd2010-06-04 15:32:04 -07008
9namespace slang {
10
11RSExportVar::RSExportVar(RSContext* Context, const VarDecl* VD, const RSExportType* ET) :
12 mContext(Context),
13 mName(VD->getName().data(), VD->getName().size()),
Shih-wei Liao81c1b482010-07-19 15:17:14 -070014 mET(ET),
15 mIsConst(false)
Shih-wei Liao462aefd2010-06-04 15:32:04 -070016{
Shih-wei Liao81c1b482010-07-19 15:17:14 -070017 /* mInit - Evaluate initializer expression */
Shih-wei Liao324c0472010-06-21 13:15:11 -070018 const Expr* Initializer = VD->getAnyInitializer();
Shih-wei Liao81c1b482010-07-19 15:17:14 -070019 if(Initializer != NULL) {
Shih-wei Liao324c0472010-06-21 13:15:11 -070020 switch(ET->getClass()) {
21 case RSExportType::ExportClassPrimitive:
22 case RSExportType::ExportClassVector:
23 Initializer->EvaluateAsAny(mInit, *Context->getASTContext());
24 break;
25
26 case RSExportType::ExportClassPointer:
27 if(Initializer->isNullPointerConstant(*Context->getASTContext(), Expr::NPC_ValueDependentIsNotNull))
28 mInit.Val = APValue(llvm::APSInt(1));
29 else
30 Initializer->EvaluateAsAny(mInit, *Context->getASTContext());
31 break;
32
33 case RSExportType::ExportClassRecord:
34 /* No action */
35 printf("RSExportVar::RSExportVar : Reflection of initializer to variable '%s' (of type '%s') is unsupported currently.\n", mName.c_str(), ET->getName().c_str());
36 break;
37
38 default:
39 assert(false && "Unknown class of type");
40 break;
41 }
Shih-wei Liao81c1b482010-07-19 15:17:14 -070042 }
Shih-wei Liao324c0472010-06-21 13:15:11 -070043
Shih-wei Liao81c1b482010-07-19 15:17:14 -070044 /* mIsConst - Is it a constant? */
45 QualType QT = VD->getTypeSourceInfo()->getType();
46 if (!QT.isNull()) {
47 mIsConst = QT.isConstQualified();
48 }
49
Shih-wei Liao324c0472010-06-21 13:15:11 -070050 return;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070051}
52
53} /* namespace slang */