Skip to content

Commit

Permalink
BlinkGCPlugin: Move CheckDispatchVisitor out of BlinkGCPlugin.cpp.
Browse files Browse the repository at this point in the history
Part 6 of dividing a 2000-line cpp file.

Nothing to note here; this patch is a simple code move.

BUG=531879
R=haraken@chromium.org, oilpan-reviews@chromium.org, sigbjornf@opera.com

Review URL: https://codereview.chromium.org/1377773002

Cr-Commit-Position: refs/heads/master@{#351293}
  • Loading branch information
yutak authored and Commit bot committed Sep 29, 2015
1 parent 8b8d7f5 commit f81cb5b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 36 deletions.
37 changes: 1 addition & 36 deletions tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <algorithm>

#include "BlinkGCPluginOptions.h"
#include "CheckDispatchVisitor.h"
#include "CheckFieldsVisitor.h"
#include "CheckFinalizerVisitor.h"
#include "CheckGCRootsVisitor.h"
Expand Down Expand Up @@ -183,42 +184,6 @@ std::set<FunctionDecl*> GetLateParsedFunctionDecls(TranslationUnitDecl* decl) {
return v.late_parsed_decls;
}

// This visitor checks that a method contains within its body, a call to a
// method on the provided receiver class. This is used to check manual
// dispatching for trace and finalize methods.
class CheckDispatchVisitor : public RecursiveASTVisitor<CheckDispatchVisitor> {
public:
CheckDispatchVisitor(RecordInfo* receiver)
: receiver_(receiver), dispatched_to_receiver_(false) {}

bool dispatched_to_receiver() { return dispatched_to_receiver_; }

bool VisitMemberExpr(MemberExpr* member) {
if (CXXMethodDecl* fn = dyn_cast<CXXMethodDecl>(member->getMemberDecl())) {
if (fn->getParent() == receiver_->record())
dispatched_to_receiver_ = true;
}
return true;
}

bool VisitUnresolvedMemberExpr(UnresolvedMemberExpr* member) {
for (Decl* decl : member->decls()) {
if (CXXMethodDecl* method = dyn_cast<CXXMethodDecl>(decl)) {
if (method->getParent() == receiver_->record() &&
Config::GetTraceMethodType(method) ==
Config::TRACE_AFTER_DISPATCH_METHOD) {
dispatched_to_receiver_ = true;
return true;
}
}
}
return true;
}

private:
RecordInfo* receiver_;
bool dispatched_to_receiver_;
};

class EmptyStmtVisitor
: public RecursiveASTVisitor<EmptyStmtVisitor> {
Expand Down
1 change: 1 addition & 0 deletions tools/clang/blink_gc_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(LIBRARYNAME BlinkGCPlugin)

set(plugin_sources
BlinkGCPlugin.cpp
CheckDispatchVisitor.cpp
CheckFieldsVisitor.cpp
CheckFinalizerVisitor.cpp
CheckGCRootsVisitor.cpp
Expand Down
42 changes: 42 additions & 0 deletions tools/clang/blink_gc_plugin/CheckDispatchVisitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "CheckDispatchVisitor.h"

#include "Config.h"
#include "RecordInfo.h"

using namespace clang;

CheckDispatchVisitor::CheckDispatchVisitor(RecordInfo* receiver)
: receiver_(receiver),
dispatched_to_receiver_(false) {
}

bool CheckDispatchVisitor::dispatched_to_receiver() {
return dispatched_to_receiver_;
}

bool CheckDispatchVisitor::VisitMemberExpr(MemberExpr* member) {
if (CXXMethodDecl* fn = dyn_cast<CXXMethodDecl>(member->getMemberDecl())) {
if (fn->getParent() == receiver_->record())
dispatched_to_receiver_ = true;
}
return true;
}

bool CheckDispatchVisitor::VisitUnresolvedMemberExpr(
UnresolvedMemberExpr* member) {
for (Decl* decl : member->decls()) {
if (CXXMethodDecl* method = dyn_cast<CXXMethodDecl>(decl)) {
if (method->getParent() == receiver_->record() &&
Config::GetTraceMethodType(method) ==
Config::TRACE_AFTER_DISPATCH_METHOD) {
dispatched_to_receiver_ = true;
return true;
}
}
}
return true;
}
30 changes: 30 additions & 0 deletions tools/clang/blink_gc_plugin/CheckDispatchVisitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TOOLS_BLINK_GC_PLUGIN_CHECK_DISPATCH_VISITOR_H_
#define TOOLS_BLINK_GC_PLUGIN_CHECK_DISPATCH_VISITOR_H_

#include "clang/AST/RecursiveASTVisitor.h"

class RecordInfo;

// This visitor checks that a method contains within its body, a call to a
// method on the provided receiver class. This is used to check manual
// dispatching for trace and finalize methods.
class CheckDispatchVisitor
: public clang::RecursiveASTVisitor<CheckDispatchVisitor> {
public:
explicit CheckDispatchVisitor(RecordInfo* receiver);

bool dispatched_to_receiver();

bool VisitMemberExpr(clang::MemberExpr* member);
bool VisitUnresolvedMemberExpr(clang::UnresolvedMemberExpr* member);

private:
RecordInfo* receiver_;
bool dispatched_to_receiver_;
};

#endif // TOOLS_BLINK_GC_PLUGIN_CHECK_DISPATCH_VISITOR_H_

0 comments on commit f81cb5b

Please sign in to comment.