• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EXPORTABLE_H_  // NOLINT
18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_
19 
20 #include "clang/Basic/SourceLocation.h"
21 #include "slang_rs_context.h"
22 
23 namespace slang {
24 
25 class RSExportable {
26  public:
27   enum Kind {
28     EX_FUNC,
29     EX_TYPE,
30     EX_VAR,
31     EX_FOREACH,
32     EX_REDUCE
33   };
34 
35  private:
36   RSContext *mContext;
37 
38   Kind mK;
39 
40   clang::SourceLocation mLoc;
41 
42  protected:
RSExportable(RSContext * Context,RSExportable::Kind K,clang::SourceLocation Loc)43   RSExportable(RSContext *Context, RSExportable::Kind K, clang::SourceLocation Loc)
44       : mContext(Context),
45         mK(K),
46         mLoc(Loc) {
47     Context->newExportable(this);
48   }
49 
50  public:
getKind()51   Kind getKind() const { return mK; }
52 
getLocation()53   clang::SourceLocation getLocation() const { return mLoc; }
54 
55   // When keep() is invoked, mKeep will set to true and the associated RSContext
56   // won't free this RSExportable object in its destructor. The deallocation
57   // responsibility is then transferred to the object who invoked this function.
58   // Return false if the exportable is kept or failed to keep.
59   virtual bool keep();
isKeep()60   bool isKeep() const { return (mContext == nullptr); }
61 
getRSContext()62   RSContext *getRSContext() const { return mContext; }
63 
~RSExportable()64   virtual ~RSExportable() { }
65 };
66 }  // namespace slang
67 
68 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_EXPORTABLE_H_  NOLINT
69