slang_rs_context.h revision c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9
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>
24e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines
25e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#include "clang/Lex/Preprocessor.h"
26be27482cdeaf08576bc39b72a15d35d13014a636Logan#include "clang/AST/Mangle.h"
27462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include "llvm/ADT/StringSet.h"
299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao#include "llvm/ADT/StringMap.h"
30462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
313fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines#include "slang_pragma_recorder.h"
323fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines
33462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace llvm {
346315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class LLVMContext;
3523c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines  class DataLayout;
369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace llvm
37462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
38462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace clang {
396315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class VarDecl;
406315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class ASTContext;
416315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class TargetInfo;
426315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class FunctionDecl;
436315f76e3cc6ff2d012d1183a0b030d4ff0dc808zonr  class SourceManager;
449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace clang
45462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
46462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaonamespace slang {
47a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportable;
48a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportVar;
49a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportFunc;
50593a894650e81be54173106ec266f0311cebebd3Stephen Hines  class RSExportForEach;
51c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  class RSExportReduce;
52a41ce1d98094da84643995d40d71c529905123fcZonr Chang  class RSExportType;
53462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
54462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liaoclass RSContext {
559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringSet<> NeedExportVarSet;
569ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringSet<> NeedExportFuncSet;
579ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringSet<> NeedExportTypeSet;
589ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
599ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
60a41ce1d98094da84643995d40d71c529905123fcZonr Chang  typedef std::list<RSExportable*> ExportableList;
619ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<RSExportVar*> ExportVarList;
629ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef std::list<RSExportFunc*> ExportFuncList;
63593a894650e81be54173106ec266f0311cebebd3Stephen Hines  typedef std::list<RSExportForEach*> ExportForEachList;
64c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  typedef std::list<RSExportReduce*> ExportReduceList;
659ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef llvm::StringMap<RSExportType*> ExportTypeMap;
669ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
679ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao private:
689e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  clang::Preprocessor &mPP;
699e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  clang::ASTContext &mCtx;
703fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines  PragmaList *mPragmas;
71109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  // Precision specified via pragma, either rs_fp_full or rs_fp_relaxed. If
72109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  // empty, rs_fp_full is assumed.
73109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  std::string mPrecision;
74c9454afec1649846512993d0ef65a9f868976bb4Chris Wailes  unsigned int mTargetAPI;
75fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines  bool mVerbose;
769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
7723c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines  llvm::DataLayout *mDataLayout;
789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  llvm::LLVMContext &mLLVMContext;
799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
80a41ce1d98094da84643995d40d71c529905123fcZonr Chang  ExportableList mExportables;
81a41ce1d98094da84643995d40d71c529905123fcZonr Chang
829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  NeedExportTypeSet mNeedExportTypes;
839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string *mLicenseNote;
859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mReflectJavaPackageName;
869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  std::string mReflectJavaPathName;
879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
880a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines  std::string mRSPackageName;
890a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines
9096ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  int version;
9182754d87921c94e70562aa977cc92e28fc38b1d0Stephen Hines
922eb9a3f7c48fe54eb4e813d80e3363bc79553a1eStephen Hines  std::unique_ptr<clang::MangleContext> mMangleCtx;
9396ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines
949ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines  bool mIs64Bit;
959ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines
969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool processExportVar(const clang::VarDecl *VD);
979ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool processExportFunc(const clang::FunctionDecl *FD);
989ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool processExportType(const llvm::StringRef &Name);
999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
100c17e198ffcd37bfc57e3add1f6eee952ae2a2eabStephen Hines  void cleanupForEach();
101c17e198ffcd37bfc57e3add1f6eee952ae2a2eabStephen Hines
1029ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ExportVarList mExportVars;
1039ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ExportFuncList mExportFuncs;
104593a894650e81be54173106ec266f0311cebebd3Stephen Hines  ExportForEachList mExportForEach;
105c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  ExportReduceList mExportReduce;
1069ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ExportTypeMap mExportTypes;
1079ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1089ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao public:
1099e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  RSContext(clang::Preprocessor &PP,
1109e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines            clang::ASTContext &Ctx,
1113fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines            const clang::TargetInfo &Target,
1124cc67fce91f43215d61b2695746eab102a3db516Stephen Hines            PragmaList *Pragmas,
113fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines            unsigned int TargetAPI,
114fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines            bool Verbose);
1159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1169e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  inline clang::Preprocessor &getPreprocessor() const { return mPP; }
1179e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines  inline clang::ASTContext &getASTContext() const { return mCtx; }
118be27482cdeaf08576bc39b72a15d35d13014a636Logan  inline clang::MangleContext &getMangleContext() const {
119be27482cdeaf08576bc39b72a15d35d13014a636Logan    return *mMangleCtx;
120f2174cfd6a556b51aadf2b8765e50df080e8f18eStephen Hines  }
12123c4358f12bd9d0ba7166eceebd683db95a41b3fStephen Hines  inline const llvm::DataLayout *getDataLayout() const { return mDataLayout; }
1229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline llvm::LLVMContext &getLLVMContext() const { return mLLVMContext; }
1239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const clang::SourceManager *getSourceManager() const {
1249e5b503349719144f63ccb7c62ee9c291a7d83b8Stephen Hines    return &mPP.getSourceManager();
1259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1269207a2e495c8363606861e4f034504ec5c153dabLogan Chien  inline clang::DiagnosticsEngine *getDiagnostics() const {
1272ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines    return &mPP.getDiagnostics();
1282ef9bc0cfbca2152d972c0975005f8c897c2a42cStephen Hines  }
129c9454afec1649846512993d0ef65a9f868976bb4Chris Wailes  inline unsigned int getTargetAPI() const {
1304a4bf92a8add68629a7e6e59ef81c3c3fe603a75Stephen Hines    return mTargetAPI;
1314a4bf92a8add68629a7e6e59ef81c3c3fe603a75Stephen Hines  }
1329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
133fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines  inline bool getVerbose() const {
134fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines    return mVerbose;
135fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines  }
1369ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines  inline bool is64Bit() const {
1379ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines    return mIs64Bit;
1389ae18b2bbee0b08afd400542e863dd665ff76059Stephen Hines  }
139fc4f78b9c7941132fb048a83f0e4ba528c3b4fd0Stephen Hines
1409ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline void setLicenseNote(const std::string &S) {
1419ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    mLicenseNote = new std::string(S);
1429ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1439ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline const std::string *getLicenseNote() const { return mLicenseNote; }
1449ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1459ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline void addExportType(const std::string &S) {
1469ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    mNeedExportTypes.insert(S);
1479ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1489ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1499ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline void setReflectJavaPackageName(const std::string &S) {
1509ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    mReflectJavaPackageName = S;
1519ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
152dde98533fad4c6534af537ae583aa4db35a1c699Tim Murray  inline const std::string &getReflectJavaPackageName() const {
1534cc67fce91f43215d61b2695746eab102a3db516Stephen Hines    return mReflectJavaPackageName;
1544cc67fce91f43215d61b2695746eab102a3db516Stephen Hines  }
1559ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1560a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines  inline void setRSPackageName(const std::string &S) {
1570a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines    mRSPackageName = S;
1580a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines  }
15912fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet
16012fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet  inline const std::string &getRSPackageName() const { return mRSPackageName; }
1610a813a3ef2a82f19d7eab9e23ae8493197143803Stephen Hines
162c808a99831115928b4648f4c8b86dc682594217aStephen Hines  bool processExport();
163a41ce1d98094da84643995d40d71c529905123fcZonr Chang  inline void newExportable(RSExportable *E) {
1645abbe0e9ca2508260b627ffef2bf01e2554e8357Chris Wailes    if (E != nullptr)
165a41ce1d98094da84643995d40d71c529905123fcZonr Chang      mExportables.push_back(E);
166a41ce1d98094da84643995d40d71c529905123fcZonr Chang  }
167641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  typedef ExportableList::iterator exportable_iterator;
168641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  exportable_iterator exportable_begin() {
169641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang    return mExportables.begin();
170641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  }
171641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  exportable_iterator exportable_end() {
172641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang    return mExportables.end();
173641558f02fe6ce0ee3ae5076eb366c25e2ad5903Zonr Chang  }
1749ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1759ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportVarList::const_iterator const_export_var_iterator;
1769ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_var_iterator export_vars_begin() const {
1779ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportVars.begin();
1789ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1799ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_var_iterator export_vars_end() const {
1809ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportVars.end();
1819ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1829ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool hasExportVar() const {
1839ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return !mExportVars.empty();
1849ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1859ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
1869ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportFuncList::const_iterator const_export_func_iterator;
1879ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_func_iterator export_funcs_begin() const {
1889ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportFuncs.begin();
1899ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1909ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_func_iterator export_funcs_end() const {
1919ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportFuncs.end();
1929ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
1939ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool hasExportFunc() const { return !mExportFuncs.empty(); }
1949ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
195593a894650e81be54173106ec266f0311cebebd3Stephen Hines  typedef ExportForEachList::const_iterator const_export_foreach_iterator;
196593a894650e81be54173106ec266f0311cebebd3Stephen Hines  const_export_foreach_iterator export_foreach_begin() const {
197593a894650e81be54173106ec266f0311cebebd3Stephen Hines    return mExportForEach.begin();
198593a894650e81be54173106ec266f0311cebebd3Stephen Hines  }
199593a894650e81be54173106ec266f0311cebebd3Stephen Hines  const_export_foreach_iterator export_foreach_end() const {
200593a894650e81be54173106ec266f0311cebebd3Stephen Hines    return mExportForEach.end();
201593a894650e81be54173106ec266f0311cebebd3Stephen Hines  }
202593a894650e81be54173106ec266f0311cebebd3Stephen Hines  inline bool hasExportForEach() const { return !mExportForEach.empty(); }
203593a894650e81be54173106ec266f0311cebebd3Stephen Hines
204c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  typedef ExportReduceList::const_iterator const_export_reduce_iterator;
205c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  const_export_reduce_iterator export_reduce_begin() const {
206c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala    return mExportReduce.begin();
207c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  }
208c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  const_export_reduce_iterator export_reduce_end() const {
209c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala    return mExportReduce.end();
210c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  }
211c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala  inline bool hasExportReduce() const { return !mExportReduce.empty(); }
212c0c5dd85f2d2df2bcf0cb284001f544d6c42eff9Matt Wala
2139ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportTypeMap::iterator export_type_iterator;
2149ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  typedef ExportTypeMap::const_iterator const_export_type_iterator;
2159ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  export_type_iterator export_types_begin() { return mExportTypes.begin(); }
2169ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  export_type_iterator export_types_end() { return mExportTypes.end(); }
2179ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_type_iterator export_types_begin() const {
2189ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.begin();
2199ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2209ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_type_iterator export_types_end() const {
2219ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.end();
2229ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2239ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  inline bool hasExportType() const { return !mExportTypes.empty(); }
2249ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  export_type_iterator findExportType(const llvm::StringRef &TypeName) {
2259ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.find(TypeName);
2269ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2279ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  const_export_type_iterator findExportType(const llvm::StringRef &TypeName)
2289ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao      const {
2299ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao    return mExportTypes.find(TypeName);
2309ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  }
2319ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
2329ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // Insert the specified Typename/Type pair into the map. If the key already
2339ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // exists in the map, return false and ignore the request, otherwise insert it
2349ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  // and return true.
2359ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  bool insertExportType(const llvm::StringRef &TypeName, RSExportType *Type);
2369ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao
23796ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  int getVersion() const { return version; }
23896ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  void setVersion(int v) {
23996ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines    version = v;
24096ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines  }
24196ab06cbe40b2d73c0eb614f814cd761d8962b6bStephen Hines
24212fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet  bool isCompatLib() const {
24312fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet    // If we are not targeting the actual Android Renderscript classes,
24412fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet    // we should reflect code that works with the compatibility library.
24512fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet    return (mRSPackageName.compare("android.renderscript") != 0);
24612fc283f4108fd6f7f0164c121ff2f6fb5044225Jean-Luc Brouillet  }
24782754d87921c94e70562aa977cc92e28fc38b1d0Stephen Hines
2483fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines  void addPragma(const std::string &T, const std::string &V) {
2493fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines    mPragmas->push_back(make_pair(T, V));
2503fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines  }
251109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  void setPrecision(const std::string &P) { mPrecision = P; }
252109e90a854ac8d8f4df24ef27db636a641ba9913Jean-Luc Brouillet  std::string getPrecision() { return mPrecision; }
2533fd0a94a5cf1656569b1aea07043cc63939dcb46Stephen Hines
254d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  // Report an error or a warning to the user.
255ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
256d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level,
257ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                             const char (&Message)[N]) {
258ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticsEngine *DiagEngine = getDiagnostics();
259ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  return DiagEngine->Report(DiagEngine->getCustomDiagID(Level, Message));
260ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray}
261ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
262ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
263d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder Report(clang::DiagnosticsEngine::Level Level,
264ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                             const clang::SourceLocation Loc,
265ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                             const char (&Message)[N]) {
266ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticsEngine *DiagEngine = getDiagnostics();
267ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  const clang::SourceManager *SM = getSourceManager();
268ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  return DiagEngine->Report(clang::FullSourceLoc(Loc, *SM),
269ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                            DiagEngine->getCustomDiagID(Level, Message));
270ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray}
271d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet
272d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  // Utility functions to report errors and warnings to make the calling code
273d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  // easier to read.
274ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
275ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticBuilder ReportError(const char (&Message)[N]) {
276ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Error, Message);
277d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
278ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
279ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
280d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder ReportError(const clang::SourceLocation Loc,
281ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                       const char (&Message)[N]) {
282ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Error, Loc, Message);
283d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
284ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
285ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
286ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  clang::DiagnosticBuilder ReportWarning(const char (&Message)[N]) {
287ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Warning, Message);
288d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
289ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray
290ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray  template <unsigned N>
291d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  clang::DiagnosticBuilder ReportWarning(const clang::SourceLocation Loc,
292ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray                                         const char (&Message)[N]) {
293ee4016d1247d3fbe50822de279d3da273d8aef4cTim Murray    return Report<N>(clang::DiagnosticsEngine::Warning, Loc, Message);
294d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet  }
295d3f7527b105d21f1c69d3473eb88a762f2c3ab5aJean-Luc Brouillet
2969ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao  ~RSContext();
297462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao};
298462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
2999ef2f785e0cc490af678dfd685995dec787321ffShih-wei Liao}   // namespace slang
300462aefd62cc646d2ff753c1d003ef3cd7bbea26Shih-wei Liao
301e639eb5caa2c386b4a60659a4929e8a6141a2cbeStephen Hines#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CONTEXT_H_  NOLINT
302