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
24namespace 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).
29class 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
38 public:
39  explicit RSCheckAST(clang::ASTContext &Con, unsigned int TargetAPI,
40                      bool IsFilterscript)
41      : C(Con), mDiagEngine(Con.getDiagnostics()), mSM(C.getSourceManager()),
42        mValid(true), mTargetAPI(TargetAPI), mIsFilterscript(IsFilterscript) {
43    return;
44  }
45
46  void VisitStmt(clang::Stmt *S);
47
48  void VisitExpr(clang::Expr *E);
49
50  void VisitDeclStmt(clang::DeclStmt *DS);
51
52  void ValidateFunctionDecl(clang::FunctionDecl *FD);
53
54  void ValidateVarDecl(clang::VarDecl *VD);
55
56  bool Validate();
57};
58
59}  // namespace slang
60
61#endif  // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_CHECK_AST_H_  NOLINT
62