CheckFinalizerVisitor.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_FINALIZER_VISITOR_H_
  5. #define TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_
  6. #include <set>
  7. #include <vector>
  8. #include "Edge.h"
  9. #include "RecordInfo.h"
  10. #include "clang/AST/RecursiveASTVisitor.h"
  11. // This visitor checks that a finalizer method does not have invalid access to
  12. // fields that are potentially finalized. A potentially finalized field is
  13. // either a Member, a heap-allocated collection or an off-heap collection that
  14. // contains Members. Invalid uses are currently identified as passing the field
  15. // as the argument of a procedure call or using the -> or [] operators on it.
  16. class CheckFinalizerVisitor
  17. : public clang::RecursiveASTVisitor<CheckFinalizerVisitor> {
  18. public:
  19. struct Error {
  20. Error(clang::MemberExpr* member,
  21. FieldPoint* field)
  22. : member(member),
  23. field(field) {}
  24. clang::MemberExpr* member;
  25. FieldPoint* field;
  26. };
  27. typedef std::vector<Error> Errors;
  28. explicit CheckFinalizerVisitor(RecordCache* cache);
  29. Errors& finalized_fields();
  30. bool WalkUpFromCXXOperatorCallExpr(clang::CXXOperatorCallExpr* expr);
  31. bool WalkUpFromCallExpr(clang::CallExpr* expr);
  32. bool VisitMemberExpr(clang::MemberExpr* member);
  33. private:
  34. bool MightBeCollected(FieldPoint* point);
  35. bool blacklist_context_;
  36. Errors finalized_fields_;
  37. std::set<clang::MemberExpr*> seen_members_;
  38. RecordCache* cache_;
  39. };
  40. #endif // TOOLS_BLINK_GC_PLUGIN_CHECK_FINALIZER_VISITOR_H_