• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, 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_CHECK_AST_H_  // NOLINT
18 #define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CHECK_AST_H_
19 
20 #include "slang_assert.h"
21 #include "slang_rs_context.h"
22 #include "clang/AST/ASTContext.h"
23 #include "clang/AST/StmtVisitor.h"
24 
25 namespace slang {
26 
27 // This class is designed to walk a Renderscript/Filterscript AST looking for
28 // violations. Examples of violations for FS are pointer declarations and
29 // casts (i.e. no pointers allowed in FS whatsoever).
30 class RSCheckAST : public clang::StmtVisitor<RSCheckAST> {
31  private:
32   slang::RSContext *Context;
33   clang::ASTContext &C;
34   clang::SourceManager &mSM;
35   bool mValid;
36   unsigned int mTargetAPI;
37   bool mIsFilterscript;
38   bool mInKernel;
39 
40   /// @brief Emit warnings for inapproriate uses of rsSetElementAt
41   ///
42   /// We warn in case generic rsSetElementAt() is used even though the user
43   /// could have used a typed rsSetElementAt_<type>() call. Typed calls
44   /// allow more aggressive optimization (e.g. due to better alias analysis
45   /// results). Hence, we want to steer the users to use them.
46   void WarnOnSetElementAt(clang::CallExpr*);
47 
48  public:
RSCheckAST(RSContext * Con,unsigned int TargetAPI,bool IsFilterscript)49   explicit RSCheckAST(RSContext *Con, unsigned int TargetAPI,
50                       bool IsFilterscript)
51       : Context(Con),
52         C(Con->getASTContext()),
53         mSM(C.getSourceManager()),
54         mValid(true),
55         mTargetAPI(TargetAPI),
56         mIsFilterscript(IsFilterscript),
57         mInKernel(false) {
58   }
59 
60   void VisitStmt(clang::Stmt *S);
61 
62   void VisitCallExpr(clang::CallExpr *CE);
63 
64   void VisitCastExpr(clang::CastExpr *CE);
65 
66   void VisitExpr(clang::Expr *E);
67 
68   void VisitDeclStmt(clang::DeclStmt *DS);
69 
70   void ValidateFunctionDecl(clang::FunctionDecl *FD);
71 
72   void ValidateVarDecl(clang::VarDecl *VD);
73 
74   bool Validate();
75 };
76 
77 }  // namespace slang
78 
79 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CHECK_AST_H_  NOLINT
80