slang_rs_export_func.h revision c383a500aa59423264811be3874461bf8adbfea0
1/* 2 * Copyright 2010, 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 _SLANG_COMPILER_RS_EXPORT_FUNC_H 18#define _SLANG_COMPILER_RS_EXPORT_FUNC_H 19 20#include <list> 21#include <string> 22 23#include "llvm/ADT/StringRef.h" 24 25#include "slang_rs_exportable.h" 26#include "slang_rs_export_type.h" 27 28namespace llvm { 29 class StructType; 30} 31 32namespace clang { 33 class FunctionDecl; 34} // namespace clang 35 36namespace slang { 37 38class RSContext; 39 40class RSExportFunc : public RSExportable { 41 friend class RSContext; 42 43 private: 44 RSContext *mContext; 45 std::string mName; 46 RSExportRecordType *mParamPacketType; 47 48 RSExportFunc(RSContext *Context, const llvm::StringRef &Name) 49 : RSExportable(Context, RSExportable::EX_FUNC), 50 mContext(Context), 51 mName(Name.data(), Name.size()), 52 mParamPacketType(NULL) { 53 return; 54 } 55 56 public: 57 static RSExportFunc *Create(RSContext *Context, 58 const clang::FunctionDecl *FD); 59 60 typedef RSExportRecordType::const_field_iterator const_param_iterator; 61 62 inline const_param_iterator params_begin() const { 63 assert((mParamPacketType != NULL) && 64 "Get parameter from export function having no parameter!"); 65 return mParamPacketType->fields_begin(); 66 } 67 inline const_param_iterator params_end() const { 68 assert((mParamPacketType != NULL) && 69 "Get parameter from export function having no parameter!"); 70 return mParamPacketType->fields_end(); 71 } 72 73 inline const std::string &getName() const { return mName; } 74 inline RSContext *getRSContext() const { return mContext; } 75 76 inline bool hasParam() const 77 { return (mParamPacketType && !mParamPacketType->getFields().empty()); } 78 inline size_t getNumParameters() const 79 { return ((mParamPacketType) ? mParamPacketType->getFields().size() : 0); } 80 81 inline const RSExportRecordType *getParamPacketType() const 82 { return mParamPacketType; } 83 84 // Check whether the given ParamsPacket type (in LLVM type) is "size 85 // equivalent" to the one obtained from getParamPacketType(). If the @Params 86 // is NULL, means there must be no any parameters. 87 bool checkParameterPacketType(const llvm::StructType *ParamTy) const; 88}; // RSExportFunc 89 90 91} // namespace slang 92 93#endif // _SLANG_COMPILER_RS_EXPORT_FUNC_H 94