| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 // Identifiers in macros should never be rewritten, as the risk of things |
| 6 // breaking is extremely high. |
| 7 |
| 8 namespace blink { |
| 9 |
| 10 #define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, predicate) \ |
| 11 inline thisType* to##thisType(argumentType* argumentName) { \ |
| 12 if (!predicate) \ |
| 13 asm("int 3"); \ |
| 14 return static_cast<thisType*>(argumentName); \ |
| 15 } |
| 16 |
| 17 #define LIKELY(x) x |
| 18 |
| 19 struct Base {}; |
| 20 struct Derived : public Base {}; |
| 21 |
| 22 DEFINE_TYPE_CASTS(Derived, Base, object, true); |
| 23 |
| 24 void F() { |
| 25 Base* basePtr = new Derived; |
| 26 // 'toDerived' should not be renamed, since the definition lives inside |
| 27 // a macro invocation. |
| 28 Derived* derivedPtr = toDerived(basePtr); |
| 29 // 'derivedPtr' should be renamed: it's a reference to a declaration defined |
| 30 // outside a macro invocation. |
| 31 if (LIKELY(derivedPtr)) { |
| 32 delete derivedPtr; |
| 33 } |
| 34 } |
| 35 |
| 36 } // namespace blink |
| OLD | NEW |