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

Side by Side Diff: Source/wtf/TypeTraits.h

Issue 827723002: Reland: Templatize visitor arguments for TraceTrait mark and trace methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 5 years, 11 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
« no previous file with comments | « Source/wtf/HashTable.h ('k') | Source/wtf/Vector.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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 #define EnsurePtrConvertibleArgDecl(From, To) \ 296 #define EnsurePtrConvertibleArgDecl(From, To) \
297 typename WTF::EnableIf<WTF::IsPointerConvertible<From, To>::Value, bool>::Ty pe = true 297 typename WTF::EnableIf<WTF::IsPointerConvertible<From, To>::Value, bool>::Ty pe = true
298 #define EnsurePtrConvertibleArgDefn(From, To) \ 298 #define EnsurePtrConvertibleArgDefn(From, To) \
299 typename WTF::EnableIf<WTF::IsPointerConvertible<From, To>::Value, bool>::Ty pe 299 typename WTF::EnableIf<WTF::IsPointerConvertible<From, To>::Value, bool>::Ty pe
300 300
301 } // namespace WTF 301 } // namespace WTF
302 302
303 namespace blink { 303 namespace blink {
304 304
305 class JSONValue; 305 class JSONValue;
306 class Visitor;
306 307
307 } // namespace blink 308 } // namespace blink
308 309
309 namespace WTF { 310 namespace WTF {
310 311
311 // FIXME: Disable pointer conversion checking against JSONValue. 312 // FIXME: Disable pointer conversion checking against JSONValue.
312 // The current CodeGeneratorInspector.py generates code which upcasts to JSO NValue from undefined types. 313 // The current CodeGeneratorInspector.py generates code which upcasts to JSO NValue from undefined types.
313 template<typename From> class IsPointerConvertible<From, blink::JSONValue> { 314 template<typename From> class IsPointerConvertible<From, blink::JSONValue> {
314 public: 315 public:
315 enum { 316 enum {
316 Value = true 317 Value = true
317 }; 318 };
318 }; 319 };
319 320
321 #if COMPILER(MSVC)
322 template<typename T, bool = __is_class(T)> struct NeedsTracingMSVC;
323
324 template<typename T>
325 struct NeedsTracingMSVC<T, true> {
326 __if_exists(T::trace)
327 {
328 static const bool value = true;
329 }
330 __if_not_exists(T::trace)
331 {
332 static const bool value = false;
333 }
334 };
335
336 template<typename T>
337 struct NeedsTracingMSVC<T, false> {
338 static const bool value = false;
339 };
340 #endif
341
320 template<typename T> 342 template<typename T>
321 class NeedsTracing { 343 class NeedsTracing {
344 #if COMPILER(MSVC)
345 public:
346 static const bool value = NeedsTracingMSVC<T>::value;
347 #else
322 typedef char YesType; 348 typedef char YesType;
323 typedef struct NoType { 349 typedef struct NoType {
324 char padding[8]; 350 char padding[8];
325 } NoType; 351 } NoType;
326 #if COMPILER(MSVC)
327 template<typename V> static YesType checkHasTraceMethod(char[&V::trace != 0] );
328 #else
329 template<size_t> struct HasMethod; 352 template<size_t> struct HasMethod;
330 template<typename V> static YesType checkHasTraceMethod(HasMethod<sizeof(&V: :trace)>*); 353 template<typename V> static YesType checkHasTraceMethod(HasMethod<sizeof(sta tic_cast<void (V::*)(blink::Visitor*)>(&V::trace))>*);
331 #endif // COMPILER(MSVC)
332 template<typename V> static NoType checkHasTraceMethod(...); 354 template<typename V> static NoType checkHasTraceMethod(...);
333 public: 355 public:
334 // We add sizeof(T) to both sides here, because we want it to fail for 356 // We add sizeof(T) to both sides here, because we want it to fail for
335 // incomplete types. Otherwise it just assumes that incomplete types do not 357 // incomplete types. Otherwise it just assumes that incomplete types do not
336 // have a trace method, which may not be true. 358 // have a trace method, which may not be true.
337 static const bool value = sizeof(YesType) + sizeof(T) == sizeof(checkHasTrac eMethod<T>(0)) + sizeof(T); 359 static const bool value = sizeof(YesType) + sizeof(T) == sizeof(checkHasTrac eMethod<T>(nullptr)) + sizeof(T);
360 #endif // COMPILER(MSVC)
338 }; 361 };
339 362
340 // Convenience template wrapping the NeedsTracingLazily template in 363 // Convenience template wrapping the NeedsTracingLazily template in
341 // Collection Traits. It helps make the code more readable. 364 // Collection Traits. It helps make the code more readable.
342 template<typename Traits> 365 template<typename Traits>
343 class ShouldBeTraced { 366 class ShouldBeTraced {
344 public: 367 public:
345 static const bool value = Traits::template NeedsTracingLazily<>::value; 368 static const bool value = Traits::template NeedsTracingLazily<>::value;
346 }; 369 };
347 370
348 template<typename T, typename U> 371 template<typename T, typename U>
349 struct NeedsTracing<std::pair<T, U> > { 372 struct NeedsTracing<std::pair<T, U> > {
350 static const bool value = NeedsTracing<T>::value || NeedsTracing<U>::value | | IsWeak<T>::value || IsWeak<U>::value; 373 static const bool value = NeedsTracing<T>::value || NeedsTracing<U>::value | | IsWeak<T>::value || IsWeak<U>::value;
351 }; 374 };
352 375
353 } // namespace WTF 376 } // namespace WTF
354 377
355 #endif // TypeTraits_h 378 #endif // TypeTraits_h
OLDNEW
« no previous file with comments | « Source/wtf/HashTable.h ('k') | Source/wtf/Vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698