blob: cb97f3af389ecbfb17387e206adee0da16f47708 [file] [log] [blame]
Avi Drissmandfd880852022-09-15 20:11:091// Copyright 2015 The Chromium Authors
yutak414be582015-09-17 09:34:132// 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
14class RecordCache;
15class 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.
20class CheckTraceVisitor : public clang::RecursiveASTVisitor<CheckTraceVisitor> {
21 public:
22 CheckTraceVisitor(clang::CXXMethodDecl* trace,
23 RecordInfo* info,
24 RecordCache* cache);
25
yutak414be582015-09-17 09:34:1326 bool VisitMemberExpr(clang::MemberExpr* member);
27 bool VisitCallExpr(clang::CallExpr* call);
Omer Katza7499cad2024-02-02 08:02:4828 bool VisitStmt(clang::Stmt* stmt);
yutak414be582015-09-17 09:34:1329
30 private:
31 bool IsTraceCallName(const std::string& name);
32
Hans Wennborg96a1e29a2024-05-27 20:43:0633 clang::CXXRecordDecl* GetDependentTemplatedDecl(
34 clang::DependentScopeDeclRefExpr* expr);
35
36 void CheckDependentScopeDeclRefExpr(clang::CallExpr* call,
37 clang::DependentScopeDeclRefExpr* expr);
yutak414be582015-09-17 09:34:1338 bool CheckTraceBaseCall(clang::CallExpr* call);
39 bool CheckTraceFieldMemberCall(clang::CXXMemberCallExpr* call);
40 bool CheckTraceFieldCall(const std::string& name,
41 clang::CXXRecordDecl* callee,
Omer Katz6a789762025-03-19 18:51:2742 clang::Expr* arg1,
43 clang::Expr* arg2);
yutak414be582015-09-17 09:34:1344 bool CheckRegisterWeakMembers(clang::CXXMemberCallExpr* call);
Keishi Hattoribe83e302020-02-03 05:35:2245 bool CheckImplicitCastExpr(clang::CallExpr* call,
46 clang::ImplicitCastExpr* expr);
yutak414be582015-09-17 09:34:1347
48 bool IsWeakCallback() const;
49
50 void MarkTraced(RecordInfo::Fields::iterator it);
Omer Katza52d7b72025-01-23 08:59:5851 void MarkTracedIfNeeded(RecordInfo::Fields::iterator it);
52 void FoundField(clang::FieldDecl* field, bool is_trace_if_needed);
yutak414be582015-09-17 09:34:1353 void MarkAllWeakMembersTraced();
54
55 clang::CXXMethodDecl* trace_;
56 RecordInfo* info_;
57 RecordCache* cache_;
yutak414be582015-09-17 09:34:1358};
59
60#endif // TOOLS_BLINK_GC_PLUGIN_CHECK_TRACE_VISITOR_H_