Home | History | Annotate | Download | only in blink_gc_plugin
      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 delegates_to_traceimpl() const;
     27 
     28   bool VisitMemberExpr(clang::MemberExpr* member);
     29   bool VisitCallExpr(clang::CallExpr* call);
     30 
     31  private:
     32   bool IsTraceCallName(const std::string& name);
     33 
     34   clang::CXXRecordDecl* GetDependentTemplatedDecl(
     35       clang::CXXDependentScopeMemberExpr* expr);
     36 
     37   void CheckCXXDependentScopeMemberExpr(
     38       clang::CallExpr* call,
     39       clang::CXXDependentScopeMemberExpr* expr);
     40   bool CheckTraceBaseCall(clang::CallExpr* call);
     41   bool CheckTraceFieldMemberCall(clang::CXXMemberCallExpr* call);
     42   bool CheckTraceFieldCall(const std::string& name,
     43                            clang::CXXRecordDecl* callee,
     44                            clang::Expr* arg);
     45   bool CheckRegisterWeakMembers(clang::CXXMemberCallExpr* call);
     46 
     47   bool IsWeakCallback() const;
     48 
     49   void MarkTraced(RecordInfo::Fields::iterator it);
     50   void FoundField(clang::FieldDecl* field);
     51   void MarkAllWeakMembersTraced();
     52 
     53   clang::CXXMethodDecl* trace_;
     54   RecordInfo* info_;
     55   RecordCache* cache_;
     56   bool delegates_to_traceimpl_;
     57 };
     58 
     59 #endif  // TOOLS_BLINK_GC_PLUGIN_CHECK_TRACE_VISITOR_H_
     60