CheckTraceVisitor.h 1.9 KB

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