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