slang_rs_export_var.cpp revision 81c1b4865e9c8fd655ea4528814f6c53e225ba6d
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    mIsConst(false)
16{
17  /* mInit - Evaluate initializer expression */
18  const Expr* Initializer = VD->getAnyInitializer();
19  if(Initializer != NULL) {
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    }
42  }
43
44  /* mIsConst - Is it a constant? */
45  QualType QT = VD->getTypeSourceInfo()->getType();
46  if (!QT.isNull()) {
47    mIsConst = QT.isConstQualified();
48  }
49
50  return;
51}
52
53}   /* namespace slang */
54