slang_rs_export_foreach.h revision b5a89fbfcba6d8817c1c3700ed78bd6482cf1a5d
1/* 2 * Copyright 2011, 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_FOREACH_H_ // NOLINT 18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ 19 20#include "llvm/ADT/StringRef.h" 21#include "llvm/Support/raw_ostream.h" 22 23#include "clang/AST/Decl.h" 24 25#include "slang_assert.h" 26#include "slang_rs_context.h" 27#include "slang_rs_exportable.h" 28#include "slang_rs_export_type.h" 29 30namespace clang { 31 class FunctionDecl; 32} // namespace clang 33 34namespace slang { 35 36// Base class for reflecting control-side forEach (currently for root() 37// functions that fit appropriate criteria) 38class RSExportForEach : public RSExportable { 39 private: 40 std::string mName; 41 RSExportRecordType *mParamPacketType; 42 RSExportType *mInType; 43 RSExportType *mOutType; 44 size_t numParams; 45 46 const clang::ParmVarDecl *mIn; 47 const clang::ParmVarDecl *mOut; 48 const clang::ParmVarDecl *mUsrData; 49 const clang::ParmVarDecl *mX; 50 const clang::ParmVarDecl *mY; 51 const clang::ParmVarDecl *mZ; 52 const clang::ParmVarDecl *mAr; 53 54 // TODO(all): Add support for LOD/face when we have them 55 RSExportForEach(RSContext *Context, const llvm::StringRef &Name, 56 const clang::FunctionDecl *FD) 57 : RSExportable(Context, RSExportable::EX_FOREACH), 58 mName(Name.data(), Name.size()), mParamPacketType(NULL), mInType(NULL), 59 mOutType(NULL), numParams(0), mIn(NULL), mOut(NULL), mUsrData(NULL), 60 mX(NULL), mY(NULL), mZ(NULL), mAr(NULL) { 61 return; 62 } 63 64 bool validateAndConstructParams(RSContext *Context, 65 const clang::FunctionDecl *FD); 66 67 public: 68 static RSExportForEach *Create(RSContext *Context, 69 const clang::FunctionDecl *FD); 70 71 inline const std::string &getName() const { 72 return mName; 73 } 74 75 inline size_t getNumParameters() const { 76 return numParams; 77 } 78 79 inline bool hasIn() const { 80 return (mIn != NULL); 81 } 82 83 inline bool hasOut() const { 84 return (mOut != NULL); 85 } 86 87 inline bool hasUsrData() const { 88 return (mUsrData != NULL); 89 } 90 91 inline const RSExportType *getInType() const { 92 return mInType; 93 } 94 95 inline const RSExportType *getOutType() const { 96 return mOutType; 97 } 98 99 inline const RSExportRecordType *getParamPacketType() const { 100 return mParamPacketType; 101 } 102 103 typedef RSExportRecordType::const_field_iterator const_param_iterator; 104 105 inline const_param_iterator params_begin() const { 106 slangAssert((mParamPacketType != NULL) && 107 "Get parameter from export foreach having no parameter!"); 108 return mParamPacketType->fields_begin(); 109 } 110 111 inline const_param_iterator params_end() const { 112 slangAssert((mParamPacketType != NULL) && 113 "Get parameter from export foreach having no parameter!"); 114 return mParamPacketType->fields_end(); 115 } 116 117 inline static bool isInitRSFunc(const clang::FunctionDecl *FD) { 118 if (!FD) { 119 return false; 120 } 121 const llvm::StringRef Name = FD->getName(); 122 static llvm::StringRef FuncInit("init"); 123 return Name.equals(FuncInit); 124 } 125 126 inline static bool isRootRSFunc(const clang::FunctionDecl *FD) { 127 if (!FD) { 128 return false; 129 } 130 const llvm::StringRef Name = FD->getName(); 131 static llvm::StringRef FuncRoot("root"); 132 return Name.equals(FuncRoot); 133 } 134 135 static bool isRSForEachFunc(const clang::FunctionDecl *FD); 136 137 inline static bool isSpecialRSFunc(const clang::FunctionDecl *FD) { 138 return isRootRSFunc(FD) || isInitRSFunc(FD); 139 } 140 141 static bool validateSpecialFuncDecl(clang::Diagnostic *Diags, 142 const clang::FunctionDecl *FD); 143}; // RSExportForEach 144 145} // namespace slang 146 147#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORT_FOREACH_H_ NOLINT 148