1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_ 6 #define TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_ 7 8 #include <set> 9 #include <vector> 10 11 #include "Edge.h" 12 #include "RecordInfo.h" 13 #include "clang/AST/RecursiveASTVisitor.h" 14 15 // This visitor checks that a finalizer method does not have invalid access to 16 // fields that are potentially finalized. A potentially finalized field is 17 // either a Member, a heap-allocated collection or an off-heap collection that 18 // contains Members. Invalid uses are currently identified as passing the field 19 // as the argument of a procedure call or using the -> or [] operators on it. 20 class CheckFinalizerVisitor 21 : public clang::RecursiveASTVisitor<CheckFinalizerVisitor> { 22 public: 23 struct Error { ErrorError24 Error(clang::MemberExpr* member, 25 bool as_eagerly_finalized, 26 FieldPoint* field) 27 : member(member), 28 as_eagerly_finalized(as_eagerly_finalized), 29 field(field) {} 30 31 clang::MemberExpr* member; 32 bool as_eagerly_finalized; 33 FieldPoint* field; 34 }; 35 36 typedef std::vector<Error> Errors; 37 38 CheckFinalizerVisitor(RecordCache* cache, bool is_eagerly_finalized); 39 40 Errors& finalized_fields(); 41 42 bool WalkUpFromCXXOperatorCallExpr(clang::CXXOperatorCallExpr* expr); 43 bool WalkUpFromCallExpr(clang::CallExpr* expr); 44 45 bool VisitMemberExpr(clang::MemberExpr* member); 46 47 private: 48 bool MightBeCollected(FieldPoint* point, bool* as_eagerly_finalized); 49 50 bool blacklist_context_; 51 Errors finalized_fields_; 52 std::set<clang::MemberExpr*> seen_members_; 53 RecordCache* cache_; 54 bool is_eagerly_finalized_; 55 }; 56 57 #endif // TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_ 58