slang_rs_context.h revision 34e6205f1d5ceb90a73192cee8b215fa0b7ab306
1c383a500aa59423264811be3874461bf8adbfea0Zonr Chang/*
20a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines * Copyright 2010-2012, 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
17e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_  // NOLINT
18e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_
19462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
20e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <cstdio>
21462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#include <list>
22e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include <map>
23462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao#include <string>
24fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni#include <vector>
25e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines
26e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/Lex/Preprocessor.h"
27be27482cdeaf08576bc39b72a15d35d13014a636Logan#include "clang/AST/Mangle.h"
28462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include "llvm/ADT/StringSet.h"
309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include "llvm/ADT/StringMap.h"
31462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3234e6205f1d5ceb90a73192cee8b215fa0b7ab306David Gross#include "slang_pragma_list.h"
333fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines
34462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm {
356315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class LLVMContext;
3623c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines  class DataLayout;
379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace llvm
38462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
39462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace clang {
406315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class VarDecl;
416315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class ASTContext;
426315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class TargetInfo;
436315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class FunctionDecl;
44fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  class QualType;
456315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class SourceManager;
46fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  class TypeDecl;
479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace clang
48462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
49462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang {
50a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportable;
51a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportVar;
52a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportFunc;
53593a894650e81be54173106ec266f0311cebebd3Stephen Hines  class RSExportForEach;
54c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  class RSExportReduce;
55a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportType;
56462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
57462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSContext {
589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringSet<> NeedExportVarSet;
599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringSet<> NeedExportFuncSet;
609ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringSet<> NeedExportTypeSet;
619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
63a41ce1d98094da84643995d40d71c529905123fcZonr Chang  typedef std::list<RSExportable*> ExportableList;
649ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<RSExportVar*> ExportVarList;
659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<RSExportFunc*> ExportFuncList;
66fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  typedef std::vector<RSExportForEach*> ExportForEachVector;
67c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  typedef std::list<RSExportReduce*> ExportReduceList;
689ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringMap<RSExportType*> ExportTypeMap;
699ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
709ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
719e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  clang::Preprocessor &mPP;
729e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  clang::ASTContext &mCtx;
733fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines  PragmaList *mPragmas;
74109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  // Precision specified via pragma, either rs_fp_full or rs_fp_relaxed. If
75109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  // empty, rs_fp_full is assumed.
76109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  std::string mPrecision;
77c9454afec1649846512993d0ef65a9f868976bb4Chris Wailes  unsigned int mTargetAPI;
78fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines  bool mVerbose;
799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
8023c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines  llvm::DataLayout *mDataLayout;
819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  llvm::LLVMContext &mLLVMContext;
829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
83a41ce1d98094da84643995d40d71c529905123fcZonr Chang  ExportableList mExportables;
84a41ce1d98094da84643995d40d71c529905123fcZonr Chang
859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  NeedExportTypeSet mNeedExportTypes;
869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string *mLicenseNote;
889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mReflectJavaPackageName;
899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mReflectJavaPathName;
909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
910a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines  std::string mRSPackageName;
920a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines
9396ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  int version;
9482754d87921c94e70562aa977cc92e28fc38b1d0Stephen Hines
952eb9a3f7c48fe54eb4e813d80e3363bc79553a1eStephen Hines  std::unique_ptr<clang::MangleContext> mMangleCtx;
9696ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines
979ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines  bool mIs64Bit;
989ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines
999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool processExportVar(const clang::VarDecl *VD);
1009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool processExportFunc(const clang::FunctionDecl *FD);
1019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool processExportType(const llvm::StringRef &Name);
1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
103fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  int getForEachSlotNumber(const clang::StringRef& funcName);
104fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  unsigned mNextSlot;
105c17e198ffcd37bfc57e3add1f6eee952ae2a2eabStephen Hines
1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ExportVarList mExportVars;
1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ExportFuncList mExportFuncs;
108fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  std::map<llvm::StringRef, unsigned> mExportForEachMap;
109fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  ExportForEachVector mExportForEach;
110c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  ExportReduceList mExportReduce;
1119ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ExportTypeMap mExportTypes;
1129ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
113fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  clang::QualType mAllocationType;
114fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni
1159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1169e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  RSContext(clang::Preprocessor &PP,
1179e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines            clang::ASTContext &Ctx,
1183fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines            const clang::TargetInfo &Target,
1194cc67fce91f43215d61b2695746eab102a3db516Stephen Hines            PragmaList *Pragmas,
120fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines            unsigned int TargetAPI,
121fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines            bool Verbose);
1229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1239e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  inline clang::Preprocessor &getPreprocessor() const { return mPP; }
1249e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  inline clang::ASTContext &getASTContext() const { return mCtx; }
125be27482cdeaf08576bc39b72a15d35d13014a636Logan  inline clang::MangleContext &getMangleContext() const {
126be27482cdeaf08576bc39b72a15d35d13014a636Logan    return *mMangleCtx;
127f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines  }
12823c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines  inline const llvm::DataLayout *getDataLayout() const { return mDataLayout; }
1299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline llvm::LLVMContext &getLLVMContext() const { return mLLVMContext; }
1309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const clang::SourceManager *getSourceManager() const {
1319e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines    return &mPP.getSourceManager();
1329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1339207a2e495c8363606861e4f034504ec5c153dabLogan Chien  inline clang::DiagnosticsEngine *getDiagnostics() const {
1342ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines    return &mPP.getDiagnostics();
1352ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines  }
136c9454afec1649846512993d0ef65a9f868976bb4Chris Wailes  inline unsigned int getTargetAPI() const {
1374a4bf92a8add68629a7e6e59ef81c3c3fe603a75Stephen Hines    return mTargetAPI;
1384a4bf92a8add68629a7e6e59ef81c3c3fe603a75Stephen Hines  }
1399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
140fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines  inline bool getVerbose() const {
141fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines    return mVerbose;
142fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines  }
1439ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines  inline bool is64Bit() const {
1449ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines    return mIs64Bit;
1459ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines  }
146fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines
1479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline void setLicenseNote(const std::string &S) {
1489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    mLicenseNote = new std::string(S);
1499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const std::string *getLicenseNote() const { return mLicenseNote; }
1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1529ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline void addExportType(const std::string &S) {
1539ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    mNeedExportTypes.insert(S);
1549ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline void setReflectJavaPackageName(const std::string &S) {
1579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    mReflectJavaPackageName = S;
1589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
159dde98533fad4c6534af537ae583aa4db35a1c699Tim Murray  inline const std::string &getReflectJavaPackageName() const {
1604cc67fce91f43215d61b2695746eab102a3db516Stephen Hines    return mReflectJavaPackageName;
1614cc67fce91f43215d61b2695746eab102a3db516Stephen Hines  }
1629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1630a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines  inline void setRSPackageName(const std::string &S) {
1640a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines    mRSPackageName = S;
1650a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines  }
16612fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet
16712fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet  inline const std::string &getRSPackageName() const { return mRSPackageName; }
1680a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines
169fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  bool addForEach(const clang::FunctionDecl* FD);
170fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  bool processExports();
171a41ce1d98094da84643995d40d71c529905123fcZonr Chang  inline void newExportable(RSExportable *E) {
1725abbe0e9ca2508260b627ffef2bf01e2554e8357Chris Wailes    if (E != nullptr)
173a41ce1d98094da84643995d40d71c529905123fcZonr Chang      mExportables.push_back(E);
174a41ce1d98094da84643995d40d71c529905123fcZonr Chang  }
175641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  typedef ExportableList::iterator exportable_iterator;
176641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  exportable_iterator exportable_begin() {
177641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang    return mExportables.begin();
178641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  }
179641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  exportable_iterator exportable_end() {
180641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang    return mExportables.end();
181641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  }
1829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportVarList::const_iterator const_export_var_iterator;
1849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_var_iterator export_vars_begin() const {
1859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportVars.begin();
1869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_var_iterator export_vars_end() const {
1889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportVars.end();
1899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool hasExportVar() const {
1919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return !mExportVars.empty();
1929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportFuncList::const_iterator const_export_func_iterator;
1959ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_func_iterator export_funcs_begin() const {
1969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportFuncs.begin();
1979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_func_iterator export_funcs_end() const {
1999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportFuncs.end();
2009ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2019ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool hasExportFunc() const { return !mExportFuncs.empty(); }
2029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
203fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  typedef ExportForEachVector::const_iterator const_export_foreach_iterator;
204593a894650e81be54173106ec266f0311cebebd3Stephen Hines  const_export_foreach_iterator export_foreach_begin() const {
205593a894650e81be54173106ec266f0311cebebd3Stephen Hines    return mExportForEach.begin();
206593a894650e81be54173106ec266f0311cebebd3Stephen Hines  }
207593a894650e81be54173106ec266f0311cebebd3Stephen Hines  const_export_foreach_iterator export_foreach_end() const {
208593a894650e81be54173106ec266f0311cebebd3Stephen Hines    return mExportForEach.end();
209593a894650e81be54173106ec266f0311cebebd3Stephen Hines  }
210593a894650e81be54173106ec266f0311cebebd3Stephen Hines  inline bool hasExportForEach() const { return !mExportForEach.empty(); }
211fb40ee2a90f37967bf4a40a18dec7f60e5c580d8Yang Ni  int getForEachSlotNumber(const clang::FunctionDecl* FD);
212593a894650e81be54173106ec266f0311cebebd3Stephen Hines
213c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  typedef ExportReduceList::const_iterator const_export_reduce_iterator;
214c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  const_export_reduce_iterator export_reduce_begin() const {
215c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala    return mExportReduce.begin();
216c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  }
217c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  const_export_reduce_iterator export_reduce_end() const {
218c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala    return mExportReduce.end();
219c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  }
220c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  inline bool hasExportReduce() const { return !mExportReduce.empty(); }
221c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala
2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportTypeMap::iterator export_type_iterator;
2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportTypeMap::const_iterator const_export_type_iterator;
2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  export_type_iterator export_types_begin() { return mExportTypes.begin(); }
2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  export_type_iterator export_types_end() { return mExportTypes.end(); }
2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_type_iterator export_types_begin() const {
2279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.begin();
2289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_type_iterator export_types_end() const {
2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.end();
2319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool hasExportType() const { return !mExportTypes.empty(); }
2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  export_type_iterator findExportType(const llvm::StringRef &TypeName) {
2349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.find(TypeName);
2359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_type_iterator findExportType(const llvm::StringRef &TypeName)
2379ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      const {
2389ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.find(TypeName);
2399ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Insert the specified Typename/Type pair into the map. If the key already
2429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // exists in the map, return false and ignore the request, otherwise insert it
2439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // and return true.
2449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool insertExportType(const llvm::StringRef &TypeName, RSExportType *Type);
2459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
24696ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  int getVersion() const { return version; }
24796ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  void setVersion(int v) {
24896ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines    version = v;
24996ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  }
25096ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines
25112fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet  bool isCompatLib() const {
25212fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet    // If we are not targeting the actual Android Renderscript classes,
25312fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet    // we should reflect code that works with the compatibility library.
25412fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet    return (mRSPackageName.compare("android.renderscript") != 0);
25512fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet  }
25682754d87921c94e70562aa977cc92e28fc38b1d0Stephen Hines
2573fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines  void addPragma(const std::string &T, const std::string &V) {
2583fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines    mPragmas->push_back(make_pair(T, V));
2593fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines  }
260109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  void setPrecision(const std::string &P) { mPrecision = P; }
261109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  std::string getPrecision() { return mPrecision; }
2623fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines
263d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  // Report an error or a warning to the user.
264ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
265d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level,
266ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                             const char (&Message)[N]) {
267ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticsEngine *DiagEngine = getDiagnostics();
268ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  return DiagEngine->Report(DiagEngine->getCustomDiagID(Level, Message));
269ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray}
270ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
271ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
272d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level,
273ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                             const clang::SourceLocation Loc,
274ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                             const char (&Message)[N]) {
275ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticsEngine *DiagEngine = getDiagnostics();
276ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  const clang::SourceManager *SM = getSourceManager();
277ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  return DiagEngine->Report(clang::FullSourceLoc(Loc, *SM),
278ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                            DiagEngine->getCustomDiagID(Level, Message));
279ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray}
280d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet
281d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  // Utility functions to report errors and warnings to make the calling code
282d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  // easier to read.
283ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
284ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticBuilder ReportError(const char (&Message)[N]) {
285ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Error, Message);
286d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
287ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
288ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
289d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder ReportError(const clang::SourceLocation Loc,
290ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                       const char (&Message)[N]) {
291ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Error, Loc, Message);
292d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
293ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
294ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
295ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticBuilder ReportWarning(const char (&Message)[N]) {
296ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Warning, Message);
297d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
298ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
299ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
300d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder ReportWarning(const clang::SourceLocation Loc,
301ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                         const char (&Message)[N]) {
302ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Warning, Loc, Message);
303d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
304d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet
3059ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ~RSContext();
306462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao};
307462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
3089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace slang
309462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
310e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_  NOLINT
311