• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gen/thing.h"
6 
7 namespace v8 {
8 
9 class InterfaceOutsideOfBlink {
10  public:
11   virtual void nonBlinkVirtual() = 0;
12 };
13 
14 }  // namespace v8
15 
16 namespace blink {
17 
18 class InsideOfBlink : public v8::InterfaceOutsideOfBlink {
19  public:
20   // This function overrides something outside of blink so don't rename it.
nonBlinkVirtual()21   void nonBlinkVirtual() override {}
22   // This function is in blink so rename it.
BlinkVirtual()23   virtual void BlinkVirtual() {}
24 };
25 
26 class MyIterator {};
27 using my_iterator = char*;
28 
29 class Task {
30  public:
31   // Already style-compliant methods shouldn't change.
OutputDebugString()32   void OutputDebugString() {}
33 
34   // Tests that the declarations for methods are updated.
35   void DoTheWork();
36   // Overload to test using declarations that introduce multiple shadow
37   // declarations.
38   void DoTheWork(int);
39   virtual void ReallyDoTheWork() = 0;
40 
41   // Note: this is purposely copyable and assignable, to make sure the Clang
42   // tool doesn't try to emit replacements for things that aren't explicitly
43   // written.
44 
45   // Overloaded operators should not be rewritten.
operator ++()46   Task& operator++() { return *this; }
47 
48   // Conversion functions should not be rewritten.
operator int() const49   explicit operator int() const { return 42; }
50 
51   // These are special functions that we don't rename so that range-based
52   // for loops and STL things work.
begin()53   MyIterator begin() {}
end()54   my_iterator end() {}
rbegin()55   my_iterator rbegin() {}
rend()56   MyIterator rend() {}
57   // The trace() method is used by Oilpan, we shouldn't rename it.
trace()58   void trace() {}
59   // These are used by std::unique_lock and std::lock_guard.
lock()60   void lock() {}
unlock()61   void unlock() {}
try_lock()62   void try_lock() {}
63 };
64 
65 class Other {
66   // Static begin/end/trace don't count, and should be renamed.
Begin()67   static MyIterator Begin() {}
End()68   static my_iterator End() {}
Trace()69   static void Trace() {}
Lock()70   static void Lock() {}
71 };
72 
73 class NonIterators {
74   // begin()/end() and friends are renamed if they don't return an iterator.
Begin()75   void Begin() {}
End()76   int End() { return 0; }
Rbegin()77   void Rbegin() {}
Rend()78   int Rend() { return 0; }
79 };
80 
81 // Test that the actual method definition is also updated.
DoTheWork()82 void Task::DoTheWork() {
83   ReallyDoTheWork();
84 }
85 
86 template <typename T>
87 class Testable {
88  public:
89   typedef T Testable::*UnspecifiedBoolType;
90   // This method has a reference to a member in a "member context" and a
91   // "non-member context" to verify both are rewritten.
operator UnspecifiedBoolType()92   operator UnspecifiedBoolType() { return ptr_ ? &Testable::ptr_ : 0; }
93 
94  private:
95   int ptr_;
96 };
97 
98 namespace subname {
99 
100 class SubnameParent {
SubnameMethod()101   virtual void SubnameMethod() {}
102 };
103 
104 }  // namespace subname
105 
106 class SubnameChild : public subname::SubnameParent {
107   // This subclasses from blink::subname::SubnameParent and should be renamed.
SubnameMethod()108   void SubnameMethod() override {}
109 };
110 
111 class GenChild : public blink::GenClass {
112   // This subclasses from the blink namespace but in the gen directory so it
113   // should not be renamed.
genMethod()114   void genMethod() override {}
115 };
116 
117 }  // namespace blink
118 
119 // Test that overrides from outside the Blink namespace are also updated.
120 class BovineTask : public blink::Task {
121  public:
122   using Task::DoTheWork;
123   void ReallyDoTheWork() override;
124 };
125 
126 class SuperBovineTask : public BovineTask {
127  public:
128   using BovineTask::ReallyDoTheWork;
129 };
130 
ReallyDoTheWork()131 void BovineTask::ReallyDoTheWork() {
132   DoTheWork();
133   // Calls via an overridden method should also be updated.
134   ReallyDoTheWork();
135 }
136 
137 // Finally, test that method pointers are also updated.
F()138 void F() {
139   void (blink::Task::*p1)() = &blink::Task::DoTheWork;
140   void (blink::Task::*p2)() = &BovineTask::DoTheWork;
141   void (blink::Task::*p3)() = &blink::Task::ReallyDoTheWork;
142   void (BovineTask::*p4)() = &BovineTask::ReallyDoTheWork;
143 }
144 
G()145 bool G() {
146   // Use the Testable class to rewrite the method.
147   blink::Testable<int> tt;
148   return tt;
149 }
150 
151 class SubclassOfInsideOfBlink : public blink::InsideOfBlink {
152  public:
153   // This function overrides something outside of blink so don't rename it.
nonBlinkVirtual()154   void nonBlinkVirtual() override {}
155   // This function overrides something in blink so rename it.
BlinkVirtual()156   void BlinkVirtual() override {}
157 };
158 
159 class TestSubclassInsideOfBlink : public SubclassOfInsideOfBlink {
160  public:
161  public:
162   // This function overrides something outside of blink so don't rename it.
nonBlinkVirtual()163   void nonBlinkVirtual() override {}
164   // This function overrides something in blink so rename it.
BlinkVirtual()165   void BlinkVirtual() override {}
166 };
167 
168 namespace blink {
169 
170 struct StructInBlink {
171   // Structs in blink should rename their methods to capitals.
Functionblink::StructInBlink172   bool Function() { return true; }
173 };
174 
175 class BitVector {
176  public:
177   class OutOfLineBits {};
178   enum Foo { kBlah };
179   struct Bar {};
180   class Baz {};
181   class FooBar {};
182 
183   template <typename T>
184   class MyRefPtr {};
185 
186   // Naive renaming will break the build, by leaving return type the same
187   // as the method name - to avoid this "Get" prefix needs to be prepended
188   // as suggested in https://crbug.com/582312#c17.
GetOutOfLineBits() const189   const OutOfLineBits* GetOutOfLineBits() const { return nullptr; }
GetFoo()190   Foo GetFoo() { return kBlah; }
GetBar() const191   const Bar& GetBar() const { return bar_; }
GetBaz()192   MyRefPtr<Baz> GetBaz() { return MyRefPtr<Baz>(); }
GetFooBar()193   const MyRefPtr<FooBar>& GetFooBar() { return foobar_; }
194 
195  private:
196   Bar bar_;
197   MyRefPtr<FooBar> foobar_;
198 };
199 
200 }  // namespace blink
201 
202 namespace WTF {
203 
204 struct StructInWTF {
205   // Structs in WTF should rename their methods to capitals.
FunctionWTF::StructInWTF206   bool Function() { return true; }
207 };
208 
209 }  // namespace WTF
210 
F2()211 void F2() {
212   blink::StructInBlink b;
213   b.Function();
214   WTF::StructInWTF w;
215   w.Function();
216 }
217 
218 namespace blink {
219 
220 class ClassDeclaredInsideBlink {
221  public:
222   static void MethodDefinedOutsideBlink();
223 };
224 
225 namespace internal {
226 
227 class InternalClass {
228  public:
229   static void Method();
230 };
231 
232 }  // namespace internal
233 
234 }  // namespace blink
235 
236 // https://crbug.com/640688 - need to rewrite method name below.
MethodDefinedOutsideBlink()237 void blink::ClassDeclaredInsideBlink::MethodDefinedOutsideBlink() {}
Method()238 void blink::internal::InternalClass::Method() {}
239