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 TRACEIMPL_OVERLOADED_H_ 6 #define TRACEIMPL_OVERLOADED_H_ 7 8 #include "heap/stubs.h" 9 10 namespace blink { 11 12 class X : public GarbageCollected<X> { 13 public: 14 void trace(Visitor*) {} 15 void trace(InlinedGlobalMarkingVisitor) {} 16 }; 17 18 class InlinedBase : public GarbageCollected<InlinedBase> { 19 public: 20 virtual void trace(Visitor* visitor) { traceImpl(visitor); } 21 virtual void trace(InlinedGlobalMarkingVisitor visitor) { 22 traceImpl(visitor); 23 } 24 25 private: 26 template <typename VisitorDispatcher> 27 void traceImpl(VisitorDispatcher visitor) { visitor->trace(x_base_); } 28 29 Member<X> x_base_; 30 }; 31 32 class InlinedDerived : public InlinedBase { 33 public: 34 void trace(Visitor* visitor) override { traceImpl(visitor); } 35 void trace(InlinedGlobalMarkingVisitor visitor) override { 36 traceImpl(visitor); 37 } 38 39 private: 40 template <typename VisitorDispatcher> 41 void traceImpl(VisitorDispatcher visitor) { 42 visitor->trace(x_derived_); 43 InlinedBase::trace(visitor); 44 } 45 46 Member<X> x_derived_; 47 }; 48 49 class ExternBase : public GarbageCollected<ExternBase> { 50 public: 51 virtual void trace(Visitor*); 52 virtual void trace(InlinedGlobalMarkingVisitor); 53 54 private: 55 template <typename VisitorDispatcher> 56 void traceImpl(VisitorDispatcher); 57 58 Member<X> x_base_; 59 }; 60 61 class ExternDerived : public ExternBase { 62 public: 63 void trace(Visitor*) override; 64 void trace(InlinedGlobalMarkingVisitor) override; 65 66 private: 67 template <typename VisitorDispatcher> 68 void traceImpl(VisitorDispatcher); 69 70 Member<X> x_derived_; 71 }; 72 73 } 74 75 #endif // TRACEIMPL_OVERLOADED_H_ 76