slang_rs_object_ref_count.h revision 4b32ffdfc1ac766f8932e7effbcdf7484e804a8e
1/* 2 * Copyright 2010, 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#include <stack> 18 19#include "clang/AST/StmtVisitor.h" 20 21#include "slang_rs_export_type.h" 22 23using namespace slang; 24 25namespace clang { 26 class Expr; 27} 28 29class RSObjectRefCount : public clang::StmtVisitor<RSObjectRefCount> { 30 private: 31 class Scope { 32 private: 33 clang::CompoundStmt *mCS; // Associated compound statement ({ ... }) 34 std::list<clang::Decl*> mRSO; // Declared RS objects in this scope 35 36 public: 37 Scope(clang::CompoundStmt *CS) : mCS(CS) { 38 return; 39 } 40 41 inline void addRSObject(clang::Decl* D) { 42 mRSO.push_back(D); 43 return; 44 } 45 }; 46 47 std::stack<Scope*> mScopeStack; 48 49 inline Scope *getCurrentScope() { 50 return mScopeStack.top(); 51 } 52 53 // Return false if the type of variable declared in VD is not an RS object 54 // type. 55 static bool InitializeRSObject(clang::VarDecl *VD); 56 57 // Return a zero-initializer expr of the type DT. This processes both 58 // RS matrix type and RS object type. 59 static clang::Expr *CreateZeroInitializerForRSSpecificType( 60 RSExportPrimitiveType::DataType DT, 61 clang::ASTContext &C, 62 const clang::SourceLocation &Loc); 63 64 public: 65 void VisitStmt(clang::Stmt *S); 66 void VisitDeclStmt(clang::DeclStmt *DS); 67 void VisitCompoundStmt(clang::CompoundStmt *CS); 68 void VisitBinAssign(clang::BinaryOperator *AS); 69 70 // We believe that RS objects are never involved in CompoundAssignOperator. 71 // I.e., rs_allocation foo; foo += bar; 72}; 73 74