1 /*
2  * Copyright 2010-2012, 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 
17 #ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_VAR_H_  // NOLINT
18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_VAR_H_
19 
20 #include <string>
21 
22 #include "clang/AST/Decl.h"
23 #include "clang/AST/Expr.h"
24 
25 #include "llvm/ADT/StringRef.h"
26 
27 #include "slang_assert.h"
28 #include "slang_rs_exportable.h"
29 
30 namespace slang {
31   class RSContext;
32   class RSExportType;
33 
34 class RSExportVar : public RSExportable {
35   friend class RSContext;
36  private:
37   std::string mName;
38   const RSExportType *mET;
39   bool mIsConst;
40   bool mIsUnsigned;
41 
42   clang::Expr::EvalResult mInit;
43 
44   size_t mArraySize; // number of elements
45   size_t mNumInits;
46   llvm::SmallVector<clang::Expr::EvalResult, 0> mInitArray;
47 
48   RSExportVar(RSContext *Context,
49               const clang::VarDecl *VD,
50               const RSExportType *ET);
51 
52  public:
getName()53   inline const std::string &getName() const { return mName; }
getType()54   inline const RSExportType *getType() const { return mET; }
isConst()55   inline bool isConst() const { return mIsConst; }
isUnsigned()56   inline bool isUnsigned() const { return mIsUnsigned; }
57 
getInit()58   inline const clang::APValue &getInit() const { return mInit.Val; }
59 
getArraySize()60   inline size_t getArraySize() const { return mArraySize; }
getNumInits()61   inline size_t getNumInits() const { return mNumInits; }
getInitArray(unsigned int i)62   inline const clang::APValue &getInitArray(unsigned int i) const {
63     slangAssert(i < mNumInits);
64     return mInitArray[i].Val;
65   }
66 };  // RSExportVar
67 
68 }   // namespace slang
69 
70 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_VAR_H_  NOLINT
71