blob: e4b0dff3e973f6e5c4d32963571ccca69ce782b2 [file] [log] [blame]
Stephen Hines11274a72012-09-26 19:14:20 -07001/*
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"
Stephen Hines48d893d2013-12-06 18:00:27 -080021#include "slang_rs_context.h"
Stephen Hines11274a72012-09-26 19:14:20 -070022#include "clang/AST/ASTContext.h"
23#include "clang/AST/StmtVisitor.h"
24
25namespace 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).
30class RSCheckAST : public clang::StmtVisitor<RSCheckAST> {
31 private:
Stephen Hines48d893d2013-12-06 18:00:27 -080032 slang::RSContext *Context;
Stephen Hines11274a72012-09-26 19:14:20 -070033 clang::ASTContext &C;
Stephen Hines11274a72012-09-26 19:14:20 -070034 clang::SourceManager &mSM;
35 bool mValid;
36 unsigned int mTargetAPI;
37 bool mIsFilterscript;
Stephen Hines089cde32012-12-07 19:19:10 -080038 bool mInKernel;
Stephen Hines11274a72012-09-26 19:14:20 -070039
Tobias Grosser61685432013-07-31 14:52:24 -070040 /// @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
Stephen Hines11274a72012-09-26 19:14:20 -070048 public:
Stephen Hines48d893d2013-12-06 18:00:27 -080049 explicit RSCheckAST(RSContext *Con, unsigned int TargetAPI,
Stephen Hines11274a72012-09-26 19:14:20 -070050 bool IsFilterscript)
Jean-Luc Brouilletd3f75272014-01-16 18:20:28 -080051 : Context(Con),
52 C(Con->getASTContext()),
Stephen Hines48d893d2013-12-06 18:00:27 -080053 mSM(C.getSourceManager()),
Jean-Luc Brouilletd3f75272014-01-16 18:20:28 -080054 mValid(true),
55 mTargetAPI(TargetAPI),
56 mIsFilterscript(IsFilterscript),
Stephen Hines089cde32012-12-07 19:19:10 -080057 mInKernel(false) {
Stephen Hines11274a72012-09-26 19:14:20 -070058 }
59
60 void VisitStmt(clang::Stmt *S);
61
Tobias Grosser61685432013-07-31 14:52:24 -070062 void VisitCallExpr(clang::CallExpr *CE);
63
Stephen Hinesdbb6dc32013-05-08 13:43:13 -070064 void VisitCastExpr(clang::CastExpr *CE);
65
Stephen Hines11274a72012-09-26 19:14:20 -070066 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