Shih-wei Liao | 324c047 | 2010-06-21 13:15:11 -0700 | [diff] [blame] | 1 | #include "slang_rs_context.hpp" |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 2 | #include "slang_rs_export_var.hpp" |
| 3 | #include "slang_rs_export_type.hpp" /* for macro GET_CANONICAL_TYPE() */ |
| 4 | |
Shih-wei Liao | 324c047 | 2010-06-21 13:15:11 -0700 | [diff] [blame] | 5 | #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 Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 8 | |
| 9 | namespace slang { |
| 10 | |
| 11 | RSExportVar::RSExportVar(RSContext* Context, const VarDecl* VD, const RSExportType* ET) : |
| 12 | mContext(Context), |
| 13 | mName(VD->getName().data(), VD->getName().size()), |
Shih-wei Liao | 81c1b48 | 2010-07-19 15:17:14 -0700 | [diff] [blame^] | 14 | mET(ET), |
| 15 | mIsConst(false) |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 16 | { |
Shih-wei Liao | 81c1b48 | 2010-07-19 15:17:14 -0700 | [diff] [blame^] | 17 | /* mInit - Evaluate initializer expression */ |
Shih-wei Liao | 324c047 | 2010-06-21 13:15:11 -0700 | [diff] [blame] | 18 | const Expr* Initializer = VD->getAnyInitializer(); |
Shih-wei Liao | 81c1b48 | 2010-07-19 15:17:14 -0700 | [diff] [blame^] | 19 | if(Initializer != NULL) { |
Shih-wei Liao | 324c047 | 2010-06-21 13:15:11 -0700 | [diff] [blame] | 20 | 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 Liao | 81c1b48 | 2010-07-19 15:17:14 -0700 | [diff] [blame^] | 42 | } |
Shih-wei Liao | 324c047 | 2010-06-21 13:15:11 -0700 | [diff] [blame] | 43 | |
Shih-wei Liao | 81c1b48 | 2010-07-19 15:17:14 -0700 | [diff] [blame^] | 44 | /* mIsConst - Is it a constant? */ |
| 45 | QualType QT = VD->getTypeSourceInfo()->getType(); |
| 46 | if (!QT.isNull()) { |
| 47 | mIsConst = QT.isConstQualified(); |
| 48 | } |
| 49 | |
Shih-wei Liao | 324c047 | 2010-06-21 13:15:11 -0700 | [diff] [blame] | 50 | return; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | } /* namespace slang */ |