Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: Source/heap/Visitor.h

Issue 22887044: [oilpan] Make the oilpan branch build on Mac. (Closed) Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Add FIXME. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/heap/Heap.cpp ('k') | Source/heap/atomicops/atomicops.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 static intptr_t getTypeMarker() 77 static intptr_t getTypeMarker()
78 { 78 {
79 #ifndef NDEBUG 79 #ifndef NDEBUG
80 return reinterpret_cast<intptr_t>(&T::s_gcTypeMarker); 80 return reinterpret_cast<intptr_t>(&T::s_gcTypeMarker);
81 #else 81 #else
82 return 0; 82 return 0;
83 #endif 83 #endif
84 } 84 }
85 85
86 #ifndef NDEBUG 86 #ifndef NDEBUG
87 static void check(Visitor*, const T*); 87 static void checkTypeMarker(Visitor*, const T*);
88 #endif 88 #endif
89 }; 89 };
90 90
91 template<typename U> class AcceptTrait<const U> : public AcceptTrait<U> { }; 91 template<typename U> class AcceptTrait<const U> : public AcceptTrait<U> { };
92 92
93 class Visitor { 93 class Visitor {
94 public: 94 public:
95 // One-argument templated visit method. This uses the static type of 95 // One-argument templated visit method. This uses the static type of
96 // the argument to get the AcceptTrait. By default, the visit method 96 // the argument to get the AcceptTrait. By default, the visit method
97 // of the AcceptTrait just calls the virtual two-argument visit method on th is 97 // of the AcceptTrait just calls the virtual two-argument visit method on th is
98 // visitor, where the second argument is the static accept method. 98 // visitor, where the second argument is the static accept method.
99 template<typename T> 99 template<typename T>
100 void visit(T* t) 100 void visit(T* t)
101 { 101 {
102 if (!t) 102 if (!t)
103 return; 103 return;
104 #ifndef NDEBUG 104 #ifndef NDEBUG
105 AcceptTrait<T>::check(this, t); 105 AcceptTrait<T>::checkTypeMarker(this, t);
106 #endif 106 #endif
107 AcceptTrait<T>::visit(this, t); 107 AcceptTrait<T>::visit(this, t);
108 } 108 }
109 109
110 // Member version of the one-argument templated visit method. 110 // Member version of the one-argument templated visit method.
111 template<typename T> 111 template<typename T>
112 void visit(const Member<T>& t) 112 void visit(const Member<T>& t)
113 { 113 {
114 if (!t) 114 if (!t)
115 return; 115 return;
116 #ifndef NDEBUG 116 #ifndef NDEBUG
117 AcceptTrait<T>::check(this, t.raw()); 117 AcceptTrait<T>::checkTypeMarker(this, t.raw());
118 #endif 118 #endif
119 AcceptTrait<T>::visit(this, t.raw()); 119 AcceptTrait<T>::visit(this, t.raw());
120 } 120 }
121 121
122 // Result version of the one-argument templated visit method. This is used 122 // Result version of the one-argument templated visit method. This is used
123 // for visiting collections: The iterator returns Result<T> and we visit 123 // for visiting collections: The iterator returns Result<T> and we visit
124 // them. This visitor method is befriended by Result<T> which allows it to 124 // them. This visitor method is befriended by Result<T> which allows it to
125 // use releaseRaw. 125 // use releaseRaw.
126 template<typename T> 126 template<typename T>
127 void visit(const Result<T>& t) { visit(t.releaseRaw()); } 127 void visit(const Result<T>& t) { visit(t.releaseRaw()); }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // to objects where isAlive returned false. 162 // to objects where isAlive returned false.
163 virtual void registerWeakPointers(const void*, WeakPointerCallback) { } 163 virtual void registerWeakPointers(const void*, WeakPointerCallback) { }
164 virtual bool isAlive(const void*) { return false; } 164 virtual bool isAlive(const void*) { return false; }
165 165
166 #ifndef NDEBUG 166 #ifndef NDEBUG
167 void checkTypeMarker(const void*, intptr_t marker); 167 void checkTypeMarker(const void*, intptr_t marker);
168 #endif 168 #endif
169 }; 169 };
170 170
171 #ifndef NDEBUG 171 #ifndef NDEBUG
172 template<typename T> void AcceptTrait<T>::check(Visitor* visitor, const T* t) 172 template<typename T> void AcceptTrait<T>::checkTypeMarker(Visitor* visitor, cons t T* t)
173 { 173 {
174 visitor->checkTypeMarker(const_cast<T*>(t), getTypeMarker()); 174 visitor->checkTypeMarker(const_cast<T*>(t), getTypeMarker());
175 } 175 }
176 #endif 176 #endif
177 177
178 template<typename T> void AcceptTrait<T>::visit(Visitor* visitor, const T* t) 178 template<typename T> void AcceptTrait<T>::visit(Visitor* visitor, const T* t)
179 { 179 {
180 // Default visit method of the trait just calls the two-argument visit 180 // Default visit method of the trait just calls the two-argument visit
181 // method on the visitor. The second argument is the static accept method 181 // method on the visitor. The second argument is the static accept method
182 // of the trait, which by default calls the instance method 182 // of the trait, which by default calls the instance method
183 // accept(Visitor*) on the object. 183 // accept(Visitor*) on the object.
184 visitor->visit(const_cast<T*>(t), &accept); 184 visitor->visit(const_cast<T*>(t), &accept);
185 } 185 }
186 186
187 inline void doNothingAccept(Visitor*, void*) 187 inline void doNothingAccept(Visitor*, void*)
188 { 188 {
189 } 189 }
190 190
191 // Non-class types like float don't have an accept method, so we provide a more 191 // Non-class types like float don't have an accept method, so we provide a more
192 // specialized template instantiation here that will be selected in preference 192 // specialized template instantiation here that will be selected in preference
193 // to the default. Most of them do nothing, since the type in question cannot 193 // to the default. Most of them do nothing, since the type in question cannot
194 // point to other heap allocated objects. 194 // point to other heap allocated objects.
195 #define DO_NOTHING_TRAIT(type) \ 195 #define DO_NOTHING_TRAIT(type) \
196 template<> \ 196 template<> \
197 class AcceptTrait<type> { \ 197 class AcceptTrait<type> { \
198 public: \ 198 public: \
199 static void accept(Visitor*, void*) { } \ 199 static void accept(Visitor*, void*) { } \
200 static void check(Visitor*, const void*) { } \ 200 static void checkTypeMarker(Visitor*, const void*) { } \
201 static void visit(Visitor* v, type* p) { \ 201 static void visit(Visitor* v, type* p) { \
202 v->visit(p, &accept); \ 202 v->visit(p, &accept); \
203 } \ 203 } \
204 static intptr_t getTypeMarker() \ 204 static intptr_t getTypeMarker() \
205 { \ 205 { \
206 return 0; \ 206 return 0; \
207 } \ 207 } \
208 } 208 }
209 DO_NOTHING_TRAIT(const float); 209 DO_NOTHING_TRAIT(const float);
210 DO_NOTHING_TRAIT(uint8_t); 210 DO_NOTHING_TRAIT(uint8_t);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 public: 290 public:
291 virtual void accept(Visitor*) = 0; 291 virtual void accept(Visitor*) = 0;
292 virtual ~HeapVisitable() 292 virtual ~HeapVisitable()
293 { 293 {
294 } 294 }
295 }; 295 };
296 296
297 } 297 }
298 298
299 #endif 299 #endif
OLDNEW
« no previous file with comments | « Source/heap/Heap.cpp ('k') | Source/heap/atomicops/atomicops.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698