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_
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
> {
24 Error(clang::MemberExpr
* member
,
25 bool as_eagerly_finalized
,
28 as_eagerly_finalized(as_eagerly_finalized
),
31 clang::MemberExpr
* member
;
32 bool as_eagerly_finalized
;
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
);
48 bool MightBeCollected(FieldPoint
* point
, bool* as_eagerly_finalized
);
50 bool blacklist_context_
;
51 Errors finalized_fields_
;
52 std::set
<clang::MemberExpr
*> seen_members_
;
54 bool is_eagerly_finalized_
;
57 #endif // TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_