• 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 "clang/AST/ASTContext.h"
22 #include "clang/AST/StmtVisitor.h"
23 
24 namespace slang {
25 
26 // This class is designed to walk a Renderscript/Filterscript AST looking for
27 // violations. Examples of violations for FS are pointer declarations and
28 // casts (i.e. no pointers allowed in FS whatsoever).
29 class RSCheckAST : public clang::StmtVisitor<RSCheckAST> {
30  private:
31   clang::ASTContext &C;
32   clang::DiagnosticsEngine &mDiagEngine;
33   clang::SourceManager &mSM;
34   bool mValid;
35   unsigned int mTargetAPI;
36   bool mIsFilterscript;
37   bool mInKernel;
38 
39  public:
RSCheckAST(clang::ASTContext & Con,unsigned int TargetAPI,bool IsFilterscript)40   explicit RSCheckAST(clang::ASTContext &Con, unsigned int TargetAPI,
41                       bool IsFilterscript)
42       : C(Con), mDiagEngine(Con.getDiagnostics()), mSM(C.getSourceManager()),
43         mValid(true), mTargetAPI(TargetAPI), mIsFilterscript(IsFilterscript),
44         mInKernel(false) {
45     return;
46   }
47 
48   void VisitStmt(clang::Stmt *S);
49 
50   void VisitExpr(clang::Expr *E);
51 
52   void VisitDeclStmt(clang::DeclStmt *DS);
53 
54   void ValidateFunctionDecl(clang::FunctionDecl *FD);
55 
56   void ValidateVarDecl(clang::VarDecl *VD);
57 
58   bool Validate();
59 };
60 
61 }  // namespace slang
62 
63 #endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CHECK_AST_H_  NOLINT
64