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 #include "CheckDispatchVisitor.h" 6 7 #include "Config.h" 8 #include "RecordInfo.h" 9 10 using namespace clang; 11 12 CheckDispatchVisitor::CheckDispatchVisitor(RecordInfo* receiver) 13 : receiver_(receiver), 14 dispatched_to_receiver_(false) { 15 } 16 17 bool CheckDispatchVisitor::dispatched_to_receiver() { 18 return dispatched_to_receiver_; 19 } 20 21 bool CheckDispatchVisitor::VisitMemberExpr(MemberExpr* member) { 22 if (CXXMethodDecl* fn = dyn_cast<CXXMethodDecl>(member->getMemberDecl())) { 23 if (fn->getParent() == receiver_->record()) 24 dispatched_to_receiver_ = true; 25 } 26 return true; 27 } 28 29 bool CheckDispatchVisitor::VisitUnresolvedMemberExpr( 30 UnresolvedMemberExpr* member) { 31 for (Decl* decl : member->decls()) { 32 if (CXXMethodDecl* method = dyn_cast<CXXMethodDecl>(decl)) { 33 if (method->getParent() == receiver_->record() && 34 Config::GetTraceMethodType(method) == 35 Config::TRACE_AFTER_DISPATCH_METHOD) { 36 dispatched_to_receiver_ = true; 37 return true; 38 } 39 } 40 } 41 return true; 42 } 43