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

Side by Side Diff: src/globals.h

Issue 249183003: Extract common macros and start a base library (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_GLOBALS_H_ 28 #ifndef V8_GLOBALS_H_
29 #define V8_GLOBALS_H_ 29 #define V8_GLOBALS_H_
30 30
31 #include "../include/v8stdint.h" 31 #include "../include/v8stdint.h"
32 32
33 #include "base/macros.h"
34
33 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic' 35 // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
34 // warning flag and certain versions of GCC due to a bug: 36 // warning flag and certain versions of GCC due to a bug:
35 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 37 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
36 // For now, we use the more involved template-based version from <limits>, but 38 // For now, we use the more involved template-based version from <limits>, but
37 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) 39 // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
38 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0) 40 #if V8_CC_GNU && V8_GNUC_PREREQ(2, 96, 0) && !V8_GNUC_PREREQ(4, 1, 0)
39 # include <limits> // NOLINT 41 # include <limits> // NOLINT
40 # define V8_INFINITY std::numeric_limits<double>::infinity() 42 # define V8_INFINITY std::numeric_limits<double>::infinity()
41 #elif V8_LIBC_MSVCRT 43 #elif V8_LIBC_MSVCRT
42 # define V8_INFINITY HUGE_VAL 44 # define V8_INFINITY HUGE_VAL
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 typedef uint16_t uc16; 315 typedef uint16_t uc16;
314 typedef int32_t uc32; 316 typedef int32_t uc32;
315 const int kOneByteSize = kCharSize; 317 const int kOneByteSize = kCharSize;
316 const int kUC16Size = sizeof(uc16); // NOLINT 318 const int kUC16Size = sizeof(uc16); // NOLINT
317 319
318 320
319 // Round up n to be a multiple of sz, where sz is a power of 2. 321 // Round up n to be a multiple of sz, where sz is a power of 2.
320 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) 322 #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
321 323
322 324
323 // The expression OFFSET_OF(type, field) computes the byte-offset
324 // of the specified field relative to the containing type. This
325 // corresponds to 'offsetof' (in stddef.h), except that it doesn't
326 // use 0 or NULL, which causes a problem with the compiler warnings
327 // we have enabled (which is also why 'offsetof' doesn't seem to work).
328 // Here we simply use the non-zero value 4, which seems to work.
329 #define OFFSET_OF(type, field) \
330 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
331
332
333 // The expression ARRAY_SIZE(a) is a compile-time constant of type
334 // size_t which represents the number of elements of the given
335 // array. You should only use ARRAY_SIZE on statically allocated
336 // arrays.
337 #define ARRAY_SIZE(a) \
338 ((sizeof(a) / sizeof(*(a))) / \
339 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
340
341
342 // The USE(x) template is used to silence C++ compiler warnings 325 // The USE(x) template is used to silence C++ compiler warnings
343 // issued for (yet) unused variables (typically parameters). 326 // issued for (yet) unused variables (typically parameters).
344 template <typename T> 327 template <typename T>
345 inline void USE(T) { } 328 inline void USE(T) { }
346 329
347 330
348 // FUNCTION_ADDR(f) gets the address of a C function f. 331 // FUNCTION_ADDR(f) gets the address of a C function f.
349 #define FUNCTION_ADDR(f) \ 332 #define FUNCTION_ADDR(f) \
350 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f))) 333 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
351 334
352 335
353 // FUNCTION_CAST<F>(addr) casts an address into a function 336 // FUNCTION_CAST<F>(addr) casts an address into a function
354 // of type F. Used to invoke generated code from within C. 337 // of type F. Used to invoke generated code from within C.
355 template <typename F> 338 template <typename F>
356 F FUNCTION_CAST(Address addr) { 339 F FUNCTION_CAST(Address addr) {
357 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr)); 340 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
358 } 341 }
359 342
360 343
361 // A macro to disallow the evil copy constructor and operator= functions
362 // This should be used in the private: declarations for a class
363 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
364 TypeName(const TypeName&) V8_DELETE; \
365 void operator=(const TypeName&) V8_DELETE
366
367
368 // A macro to disallow all the implicit constructors, namely the
369 // default constructor, copy constructor and operator= functions.
370 //
371 // This should be used in the private: declarations for a class
372 // that wants to prevent anyone from instantiating it. This is
373 // especially useful for classes containing only static methods.
374 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
375 TypeName() V8_DELETE; \
376 DISALLOW_COPY_AND_ASSIGN(TypeName)
377
378
379 // Newly written code should use V8_INLINE and V8_NOINLINE directly.
380 #define INLINE(declarator) V8_INLINE declarator
381 #define NO_INLINE(declarator) V8_NOINLINE declarator
382
383
384 // Newly written code should use V8_WARN_UNUSED_RESULT.
385 #define MUST_USE_RESULT V8_WARN_UNUSED_RESULT
386
387
388 // Define DISABLE_ASAN macros.
389 #if defined(__has_feature)
390 #if __has_feature(address_sanitizer)
391 #define DISABLE_ASAN __attribute__((no_sanitize_address))
392 #endif
393 #endif
394
395
396 #ifndef DISABLE_ASAN
397 #define DISABLE_ASAN
398 #endif
399
400 #if V8_CC_GNU
401 #define V8_IMMEDIATE_CRASH() __builtin_trap()
402 #else
403 #define V8_IMMEDIATE_CRASH() ((void(*)())0)()
404 #endif
405
406
407 // ----------------------------------------------------------------------------- 344 // -----------------------------------------------------------------------------
408 // Forward declarations for frequently used classes 345 // Forward declarations for frequently used classes
409 // (sorted alphabetically) 346 // (sorted alphabetically)
410 347
411 class FreeStoreAllocationPolicy; 348 class FreeStoreAllocationPolicy;
412 template <typename T, class P = FreeStoreAllocationPolicy> class List; 349 template <typename T, class P = FreeStoreAllocationPolicy> class List;
413 350
414 // ----------------------------------------------------------------------------- 351 // -----------------------------------------------------------------------------
415 // Declarations for use in both the preparser and the rest of V8. 352 // Declarations for use in both the preparser and the rest of V8.
416 353
417 // The Strict Mode (ECMA-262 5th edition, 4.2.2). 354 // The Strict Mode (ECMA-262 5th edition, 4.2.2).
418 355
419 enum StrictMode { SLOPPY, STRICT }; 356 enum StrictMode { SLOPPY, STRICT };
420 357
421 358
422 } } // namespace v8::internal 359 } } // namespace v8::internal
423 360
424 #endif // V8_GLOBALS_H_ 361 #endif // V8_GLOBALS_H_
OLDNEW
« src/base/macros.h ('K') | « src/base/macros.h ('k') | src/libplatform/default-platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698