1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/* 2c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Copyright 2010, The Android Open Source Project 3c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 4c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License"); 5c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * you may not use this file except in compliance with the License. 6c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * You may obtain a copy of the License at 7c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 8c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * http://www.apache.org/licenses/LICENSE-2.0 9c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * 10c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * Unless required by applicable law or agreed to in writing, software 11c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS, 12c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * See the License for the specific language governing permissions and 14c383a500aa59423264811be3874461bf8adbfea0Zonr Chang * limitations under the License. 15c383a500aa59423264811be3874461bf8adbfea0Zonr Chang */ 16c383a500aa59423264811be3874461bf8adbfea0Zonr Chang 176315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "slang_rs_export_var.h" 18462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include "clang/AST/Type.h" 20462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 21e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "llvm/ADT/APSInt.h" 22e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 236e6578a360497f78a181e63d7783422a9c9bfb15Stephen Hines#include "slang_assert.h" 246315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "slang_rs_context.h" 256315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr#include "slang_rs_export_type.h" 266315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr 27e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hinesnamespace slang { 28462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao 299ef2f785e0cc490af678dfd685995dec787321ffShih-wei LiaoRSExportVar::RSExportVar(RSContext *Context, 309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::VarDecl *VD, 316315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr const RSExportType *ET) 32a41ce1d98094da84643995d40d71c529905123fcZonr Chang : RSExportable(Context, RSExportable::EX_VAR), 336315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mName(VD->getName().data(), VD->getName().size()), 346315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mET(ET), 356315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr mIsConst(false) { 369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // mInit - Evaluate initializer expression 379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao const clang::Expr *Initializer = VD->getAnyInitializer(); 389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (Initializer != NULL) { 399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao switch (ET->getClass()) { 40324c0479ec3edda573de60b2e6476507a99d06f7Shih-wei Liao case RSExportType::ExportClassPrimitive: 419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao case RSExportType::ExportClassVector: { 429e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines Initializer->Evaluate(mInit, Context->getASTContext()); 43324c0479ec3edda573de60b2e6476507a99d06f7Shih-wei Liao break; 449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao case RSExportType::ExportClassPointer: { 469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao if (Initializer->isNullPointerConstant 479e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines (Context->getASTContext(), 489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao clang::Expr::NPC_ValueDependentIsNotNull) 499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ) 509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mInit.Val = clang::APValue(llvm::APSInt(1)); 51324c0479ec3edda573de60b2e6476507a99d06f7Shih-wei Liao else 529e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines Initializer->Evaluate(mInit, Context->getASTContext()); 53324c0479ec3edda573de60b2e6476507a99d06f7Shih-wei Liao break; 549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao case RSExportType::ExportClassRecord: { 569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // No action 579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao fprintf(stderr, "RSExportVar::RSExportVar : Reflection of initializer " 589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao "to variable '%s' (of type '%s') is unsupported " 599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao "currently.\n", 609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao mName.c_str(), 619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao ET->getName().c_str()); 62324c0479ec3edda573de60b2e6476507a99d06f7Shih-wei Liao break; 639ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao default: { 656e6578a360497f78a181e63d7783422a9c9bfb15Stephen Hines slangAssert(false && "Unknown class of type"); 669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao } 67324c0479ec3edda573de60b2e6476507a99d06f7Shih-wei Liao } 6881c1b4865e9c8fd655ea4528814f6c53e225ba6dShih-wei Liao } 6981c1b4865e9c8fd655ea4528814f6c53e225ba6dShih-wei Liao 709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao // mIsConst - Is it a constant? 719ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao clang::QualType QT = VD->getTypeSourceInfo()->getType(); 7281c1b4865e9c8fd655ea4528814f6c53e225ba6dShih-wei Liao if (!QT.isNull()) { 7381c1b4865e9c8fd655ea4528814f6c53e225ba6dShih-wei Liao mIsConst = QT.isConstQualified(); 7481c1b4865e9c8fd655ea4528814f6c53e225ba6dShih-wei Liao } 759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao 76324c0479ec3edda573de60b2e6476507a99d06f7Shih-wei Liao return; 77462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao} 78e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines 79e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines} // namespace slang 80