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_TRACE_VISITOR_H_
6 #define TOOLS_BLINK_GC_PLUGIN_CHECK_TRACE_VISITOR_H_
7 
8 #include <string>
9 
10 #include "RecordInfo.h"
11 #include "clang/AST/AST.h"
12 #include "clang/AST/RecursiveASTVisitor.h"
13 
14 class RecordCache;
15 class RecordInfo;
16 
17 // This visitor checks a tracing method by traversing its body.
18 // - A member field is considered traced if it is referenced in the body.
19 // - A base is traced if a base-qualified call to a trace method is found.
20 class CheckTraceVisitor : public clang::RecursiveASTVisitor<CheckTraceVisitor> {
21  public:
22   CheckTraceVisitor(clang::CXXMethodDecl* trace,
23                     RecordInfo* info,
24                     RecordCache* cache);
25 
26   bool VisitMemberExpr(clang::MemberExpr* member);
27   bool VisitCallExpr(clang::CallExpr* call);
28 
29  private:
30   bool IsTraceCallName(const std::string& name);
31 
32   clang::CXXRecordDecl* GetDependentTemplatedDecl(
33       clang::CXXDependentScopeMemberExpr* expr);
34 
35   void CheckCXXDependentScopeMemberExpr(
36       clang::CallExpr* call,
37       clang::CXXDependentScopeMemberExpr* expr);
38   bool CheckTraceBaseCall(clang::CallExpr* call);
39   bool CheckTraceFieldMemberCall(clang::CXXMemberCallExpr* call);
40   bool CheckTraceFieldCall(const std::string& name,
41                            clang::CXXRecordDecl* callee,
42                            clang::Expr* arg);
43   bool CheckRegisterWeakMembers(clang::CXXMemberCallExpr* call);
44 
45   bool IsWeakCallback() const;
46 
47   void MarkTraced(RecordInfo::Fields::iterator it);
48   void FoundField(clang::FieldDecl* field);
49   void MarkAllWeakMembersTraced();
50 
51   clang::CXXMethodDecl* trace_;
52   RecordInfo* info_;
53   RecordCache* cache_;
54 };
55 
56 #endif  // TOOLS_BLINK_GC_PLUGIN_CHECK_TRACE_VISITOR_H_
57