Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / tools / clang / blink_gc_plugin / CheckFinalizerVisitor.h
blobf926a0d14b0c19e396e249fda40f207ab9fa8e88
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.
5 #ifndef TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_
6 #define TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_
8 #include <set>
9 #include <vector>
11 #include "Edge.h"
12 #include "RecordInfo.h"
13 #include "clang/AST/RecursiveASTVisitor.h"
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 {
24 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) {}
31 clang::MemberExpr* member;
32 bool as_eagerly_finalized;
33 FieldPoint* field;
36 typedef std::vector<Error> Errors;
38 CheckFinalizerVisitor(RecordCache* cache, bool is_eagerly_finalized);
40 Errors& finalized_fields();
42 bool WalkUpFromCXXOperatorCallExpr(clang::CXXOperatorCallExpr* expr);
43 bool WalkUpFromCallExpr(clang::CallExpr* expr);
45 bool VisitMemberExpr(clang::MemberExpr* member);
47 private:
48 bool MightBeCollected(FieldPoint* point, bool* as_eagerly_finalized);
50 bool blacklist_context_;
51 Errors finalized_fields_;
52 std::set<clang::MemberExpr*> seen_members_;
53 RecordCache* cache_;
54 bool is_eagerly_finalized_;
57 #endif // TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_