slang_rs_special_func.h revision eae0b7ad0195360b0afc37d51553f2917f1aa365
1/*
2 * Copyright 2015, 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_SPECIAL_FUNC_H_
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_SPECIAL_FUNC_H_
19
20#include "llvm/ADT/StringRef.h"
21
22#include "clang/AST/Decl.h"
23
24#include "slang_rs_context.h"
25
26namespace slang {
27
28namespace RSSpecialFunc {
29
30inline bool isInitRSFunc(const clang::FunctionDecl *FD) {
31  if (!FD) {
32    return false;
33  }
34  const llvm::StringRef Name = FD->getName();
35  static llvm::StringRef FuncInit("init");
36  return Name.equals(FuncInit);
37}
38
39inline bool isDtorRSFunc(const clang::FunctionDecl *FD) {
40  if (!FD) {
41    return false;
42  }
43  const llvm::StringRef Name = FD->getName();
44  static llvm::StringRef FuncDtor(".rs.dtor");
45  return Name.equals(FuncDtor);
46}
47
48bool isGraphicsRootRSFunc(unsigned int targetAPI,
49                          const clang::FunctionDecl *FD);
50
51inline bool isSpecialRSFunc(unsigned int targetAPI,
52                                   const clang::FunctionDecl *FD) {
53  return isGraphicsRootRSFunc(targetAPI, FD) || isInitRSFunc(FD) ||
54         isDtorRSFunc(FD);
55}
56
57bool validateSpecialFuncDecl(unsigned int targetAPI,
58                             slang::RSContext *Context,
59                             const clang::FunctionDecl *FD);
60
61} // namespace RSSpecialFunc
62
63} // namespace slang
64
65#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_SPECIAL_FUNC_H
66