blob: 19a8a63115f7af6fea1b61ef1a6ec0d0146a66b4 [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
2 * Copyright 2010, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
zonr6315f762010-10-05 15:35:14 +080017#include "slang_rs_export_var.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070018
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070019#include "llvm/ADT/APSInt.h"
Shih-wei Liao324c0472010-06-21 13:15:11 -070020
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070021#include "clang/AST/Type.h"
Shih-wei Liao462aefd2010-06-04 15:32:04 -070022
zonr6315f762010-10-05 15:35:14 +080023#include "slang_rs_context.h"
24#include "slang_rs_export_type.h"
25
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070026using namespace slang;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070027
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070028RSExportVar::RSExportVar(RSContext *Context,
29 const clang::VarDecl *VD,
zonr6315f762010-10-05 15:35:14 +080030 const RSExportType *ET)
Zonr Changa41ce1d2010-10-06 02:23:12 +080031 : RSExportable(Context, RSExportable::EX_VAR),
zonr6315f762010-10-05 15:35:14 +080032 mName(VD->getName().data(), VD->getName().size()),
33 mET(ET),
34 mIsConst(false) {
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070035 // mInit - Evaluate initializer expression
36 const clang::Expr *Initializer = VD->getAnyInitializer();
37 if (Initializer != NULL) {
38 switch (ET->getClass()) {
Shih-wei Liao324c0472010-06-21 13:15:11 -070039 case RSExportType::ExportClassPrimitive:
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070040 case RSExportType::ExportClassVector: {
Stephen Hines9e5b5032010-11-03 13:19:14 -070041 Initializer->Evaluate(mInit, Context->getASTContext());
Shih-wei Liao324c0472010-06-21 13:15:11 -070042 break;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070043 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070044 case RSExportType::ExportClassPointer: {
45 if (Initializer->isNullPointerConstant
Stephen Hines9e5b5032010-11-03 13:19:14 -070046 (Context->getASTContext(),
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070047 clang::Expr::NPC_ValueDependentIsNotNull)
48 )
49 mInit.Val = clang::APValue(llvm::APSInt(1));
Shih-wei Liao324c0472010-06-21 13:15:11 -070050 else
Stephen Hines9e5b5032010-11-03 13:19:14 -070051 Initializer->Evaluate(mInit, Context->getASTContext());
Shih-wei Liao324c0472010-06-21 13:15:11 -070052 break;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070053 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070054 case RSExportType::ExportClassRecord: {
55 // No action
56 fprintf(stderr, "RSExportVar::RSExportVar : Reflection of initializer "
57 "to variable '%s' (of type '%s') is unsupported "
58 "currently.\n",
59 mName.c_str(),
60 ET->getName().c_str());
Shih-wei Liao324c0472010-06-21 13:15:11 -070061 break;
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070062 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070063 default: {
Shih-wei Liao324c0472010-06-21 13:15:11 -070064 assert(false && "Unknown class of type");
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070065 }
Shih-wei Liao324c0472010-06-21 13:15:11 -070066 }
Shih-wei Liao81c1b482010-07-19 15:17:14 -070067 }
Shih-wei Liao324c0472010-06-21 13:15:11 -070068
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070069 // mIsConst - Is it a constant?
70 clang::QualType QT = VD->getTypeSourceInfo()->getType();
Shih-wei Liao81c1b482010-07-19 15:17:14 -070071 if (!QT.isNull()) {
72 mIsConst = QT.isConstQualified();
73 }
Shih-wei Liao9ef2f782010-10-01 12:31:37 -070074
Shih-wei Liao324c0472010-06-21 13:15:11 -070075 return;
Shih-wei Liao462aefd2010-06-04 15:32:04 -070076}