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 namespace blink { 6 7 // Note: do not add any copy or move constructors to this class: doing so will 8 // break test coverage that we don't clobber the class name by trying to emit 9 // replacements for synthesized functions. 10 class C { 11 public: 12 // Make sure initializers are updated to use the new names. C()13 C() : m_flagField(~0), m_fieldMentioningHTTPAndHTTPS(1), m_shouldRename(0) {} 14 method()15 int method() { 16 // Test that references to fields are updated correctly. 17 return instanceCount + m_flagField + m_fieldMentioningHTTPAndHTTPS; 18 } 19 20 // Test that a field without a m_ prefix is correctly renamed. 21 static int instanceCount; 22 23 protected: 24 // Test that a field with a m_ prefix is correctly renamed. 25 const int m_flagField; 26 // Statics should be named with s_, but make sure s_ and m_ are both correctly 27 // stripped. 28 static int s_staticCount; 29 static int m_staticCountWithBadName; 30 // Make sure that acronyms don't confuse the underscore inserter. 31 int m_fieldMentioningHTTPAndHTTPS; 32 // Already Google style, should not change. 33 int already_google_style_; 34 35 union { 36 // Anonymous union members should be renamed, as should contructor 37 // initializers of them. 38 char* m_shouldRename; 39 int* m_doesRename; 40 }; 41 }; 42 43 struct Derived : public C { 44 using C::m_flagField; 45 using C::m_fieldMentioningHTTPAndHTTPS; 46 }; 47 48 int C::instanceCount = 0; 49 50 // Structs are like classes. 51 struct S { 52 int m_integerField; 53 int wantsRename; 54 int google_style_already; 55 }; 56 57 // Unions also use struct-style naming. 58 union U { 59 char fourChars[4]; 60 short twoShorts[2]; 61 int one_hopefully_four_byte_int; 62 int m_hasPrefix; 63 }; 64 65 // https://crbug.com/640749#c1: Some type traits are inside blink namespace. 66 struct IsGarbageCollectedMixin { 67 static const bool value = true; 68 }; 69 70 } // namespace blink 71 72 namespace WTF { 73 74 // We don't want to capitalize fields in type traits 75 // (i.e. the |value| -> |kValue| rename is undesirable below). 76 struct TypeTrait1 { 77 static const bool value = true; 78 }; 79 80 // Some type traits are implemented as classes, not structs 81 // (e.g. WTF::IsGarbageCollectedType or WTF::IsAssignable). 82 // We should not perform a |value| -> |kValue| rename in the type trait below. 83 template <typename T> 84 class TypeTrait2 { 85 public: 86 static const bool value = false; 87 }; 88 template <> 89 class TypeTrait2<void> { 90 public: 91 static const bool value = false; 92 }; 93 94 // Some type traits have static methods. We should not perform 95 // a |value| -> |kValue| rename in the type trait below. 96 template <typename T, typename U> 97 struct IsSubclass { 98 private: 99 typedef char YesType; 100 struct NoType { 101 char padding[8]; 102 }; 103 104 static YesType subclassCheck(U*); 105 static NoType subclassCheck(...); 106 static T* t; 107 108 public: 109 static const bool value = sizeof(subclassCheck(t)) == sizeof(YesType); 110 }; 111 112 // Some type traits have deleted instance methods. We should not perform 113 // a |value| -> |kValue| rename in the type trait below. 114 template <typename U = void> 115 struct IsTraceableInCollection { 116 // Expanded from STATIC_ONLY(IsTraceableInCollection) macro: 117 private: 118 IsTraceableInCollection() = delete; 119 IsTraceableInCollection(const IsTraceableInCollection&) = delete; 120 IsTraceableInCollection& operator=(const IsTraceableInCollection&) = delete; 121 void* operator new(unsigned long) = delete; 122 void* operator new(unsigned long, void*) = delete; 123 124 public: 125 static const bool value = true; 126 }; 127 128 // Some type traits have a non-boolean value. 129 enum LifetimeManagementType { 130 RefCountedLifetime, 131 GarbageCollectedLifetime, 132 }; 133 template <typename T> 134 struct LifetimeOf { 135 private: 136 // Okay to rename |isGarbageCollected| to |kIsGarbageCollected|. 137 static const bool isGarbageCollected = true; 138 139 public: 140 // Expecting no rename of |value|. 141 static const LifetimeManagementType value = 142 !isGarbageCollected ? RefCountedLifetime : GarbageCollectedLifetime; 143 }; 144 145 }; // namespace WTF 146 F()147 void F() { 148 // Test that references to a static field are correctly rewritten. 149 blink::C::instanceCount++; 150 // Force instantiation of a copy constructor for blink::C to make sure field 151 // initializers for synthesized functions don't cause weird rewrites. 152 blink::C c; 153 blink::C c2 = c; 154 155 bool b1 = WTF::TypeTrait1::value; 156 bool b2 = WTF::TypeTrait2<void>::value; 157 } 158