Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 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" |
Stephen Hines | 48d893d | 2013-12-06 18:00:27 -0800 | [diff] [blame] | 21 | #include "slang_rs_context.h" |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 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: |
Stephen Hines | 48d893d | 2013-12-06 18:00:27 -0800 | [diff] [blame] | 32 | slang::RSContext *Context; |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 33 | clang::ASTContext &C; |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 34 | clang::SourceManager &mSM; |
| 35 | bool mValid; |
| 36 | unsigned int mTargetAPI; |
| 37 | bool mIsFilterscript; |
Stephen Hines | 089cde3 | 2012-12-07 19:19:10 -0800 | [diff] [blame] | 38 | bool mInKernel; |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 39 | |
Tobias Grosser | 6168543 | 2013-07-31 14:52:24 -0700 | [diff] [blame] | 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 | |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 48 | public: |
Stephen Hines | 48d893d | 2013-12-06 18:00:27 -0800 | [diff] [blame] | 49 | explicit RSCheckAST(RSContext *Con, unsigned int TargetAPI, |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 50 | bool IsFilterscript) |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 51 | : Context(Con), |
| 52 | C(Con->getASTContext()), |
Stephen Hines | 48d893d | 2013-12-06 18:00:27 -0800 | [diff] [blame] | 53 | mSM(C.getSourceManager()), |
Jean-Luc Brouillet | d3f7527 | 2014-01-16 18:20:28 -0800 | [diff] [blame] | 54 | mValid(true), |
| 55 | mTargetAPI(TargetAPI), |
| 56 | mIsFilterscript(IsFilterscript), |
Stephen Hines | 089cde3 | 2012-12-07 19:19:10 -0800 | [diff] [blame] | 57 | mInKernel(false) { |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void VisitStmt(clang::Stmt *S); |
| 61 | |
Tobias Grosser | 6168543 | 2013-07-31 14:52:24 -0700 | [diff] [blame] | 62 | void VisitCallExpr(clang::CallExpr *CE); |
| 63 | |
Stephen Hines | dbb6dc3 | 2013-05-08 13:43:13 -0700 | [diff] [blame] | 64 | void VisitCastExpr(clang::CastExpr *CE); |
| 65 | |
Stephen Hines | 11274a7 | 2012-09-26 19:14:20 -0700 | [diff] [blame] | 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 |