| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
| 6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <cmath> | 11 #include <cmath> |
| 12 | 12 |
| 13 #include "include/v8.h" | 13 #include "include/v8.h" |
| 14 #include "src/allocation.h" | 14 #include "src/allocation.h" |
| 15 #include "src/base/bits.h" | 15 #include "src/base/bits.h" |
| 16 #include "src/base/compiler-specific.h" | |
| 17 #include "src/base/logging.h" | 16 #include "src/base/logging.h" |
| 18 #include "src/base/macros.h" | 17 #include "src/base/macros.h" |
| 19 #include "src/base/platform/platform.h" | 18 #include "src/base/platform/platform.h" |
| 20 #include "src/globals.h" | 19 #include "src/globals.h" |
| 21 #include "src/list.h" | 20 #include "src/list.h" |
| 22 #include "src/vector.h" | 21 #include "src/vector.h" |
| 23 | 22 |
| 24 namespace v8 { | 23 namespace v8 { |
| 25 namespace internal { | 24 namespace internal { |
| 26 | 25 |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 static const int kFirstBreakContinueToken = 3; | 901 static const int kFirstBreakContinueToken = 3; |
| 903 static const int kInvalidToken = -1; | 902 static const int kInvalidToken = -1; |
| 904 | 903 |
| 905 private: | 904 private: |
| 906 int next_token_ = kFirstBreakContinueToken; | 905 int next_token_ = kFirstBreakContinueToken; |
| 907 }; | 906 }; |
| 908 | 907 |
| 909 // ---------------------------------------------------------------------------- | 908 // ---------------------------------------------------------------------------- |
| 910 // I/O support. | 909 // I/O support. |
| 911 | 910 |
| 911 #if __GNUC__ >= 4 |
| 912 // On gcc we can ask the compiler to check the types of %d-style format |
| 913 // specifiers and their associated arguments. TODO(erikcorry) fix this |
| 914 // so it works on MacOSX. |
| 915 #if defined(__MACH__) && defined(__APPLE__) |
| 916 #define PRINTF_CHECKING |
| 917 #define FPRINTF_CHECKING |
| 918 #define PRINTF_METHOD_CHECKING |
| 919 #define FPRINTF_METHOD_CHECKING |
| 920 #else // MacOsX. |
| 921 #define PRINTF_CHECKING __attribute__ ((format (printf, 1, 2))) |
| 922 #define FPRINTF_CHECKING __attribute__ ((format (printf, 2, 3))) |
| 923 #define PRINTF_METHOD_CHECKING __attribute__ ((format (printf, 2, 3))) |
| 924 #define FPRINTF_METHOD_CHECKING __attribute__ ((format (printf, 3, 4))) |
| 925 #endif |
| 926 #else |
| 927 #define PRINTF_CHECKING |
| 928 #define FPRINTF_CHECKING |
| 929 #define PRINTF_METHOD_CHECKING |
| 930 #define FPRINTF_METHOD_CHECKING |
| 931 #endif |
| 932 |
| 912 // Our version of printf(). | 933 // Our version of printf(). |
| 913 void PRINTF_FORMAT(1, 2) PrintF(const char* format, ...); | 934 void PRINTF_CHECKING PrintF(const char* format, ...); |
| 914 void PRINTF_FORMAT(2, 3) PrintF(FILE* out, const char* format, ...); | 935 void FPRINTF_CHECKING PrintF(FILE* out, const char* format, ...); |
| 915 | 936 |
| 916 // Prepends the current process ID to the output. | 937 // Prepends the current process ID to the output. |
| 917 void PRINTF_FORMAT(1, 2) PrintPID(const char* format, ...); | 938 void PRINTF_CHECKING PrintPID(const char* format, ...); |
| 918 | 939 |
| 919 // Prepends the current process ID and given isolate pointer to the output. | 940 // Prepends the current process ID and given isolate pointer to the output. |
| 920 void PRINTF_FORMAT(2, 3) PrintIsolate(void* isolate, const char* format, ...); | 941 void PrintIsolate(void* isolate, const char* format, ...); |
| 921 | 942 |
| 922 // Safe formatting print. Ensures that str is always null-terminated. | 943 // Safe formatting print. Ensures that str is always null-terminated. |
| 923 // Returns the number of chars written, or -1 if output was truncated. | 944 // Returns the number of chars written, or -1 if output was truncated. |
| 924 int PRINTF_FORMAT(2, 3) SNPrintF(Vector<char> str, const char* format, ...); | 945 int FPRINTF_CHECKING SNPrintF(Vector<char> str, const char* format, ...); |
| 925 int PRINTF_FORMAT(2, 0) | 946 int VSNPrintF(Vector<char> str, const char* format, va_list args); |
| 926 VSNPrintF(Vector<char> str, const char* format, va_list args); | |
| 927 | 947 |
| 928 void StrNCpy(Vector<char> dest, const char* src, size_t n); | 948 void StrNCpy(Vector<char> dest, const char* src, size_t n); |
| 929 | 949 |
| 930 // Our version of fflush. | 950 // Our version of fflush. |
| 931 void Flush(FILE* out); | 951 void Flush(FILE* out); |
| 932 | 952 |
| 933 inline void Flush() { | 953 inline void Flush() { |
| 934 Flush(stdout); | 954 Flush(stdout); |
| 935 } | 955 } |
| 936 | 956 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 #undef CASE | 1439 #undef CASE |
| 1420 #endif | 1440 #endif |
| 1421 | 1441 |
| 1422 | 1442 |
| 1423 class StringBuilder : public SimpleStringBuilder { | 1443 class StringBuilder : public SimpleStringBuilder { |
| 1424 public: | 1444 public: |
| 1425 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } | 1445 explicit StringBuilder(int size) : SimpleStringBuilder(size) { } |
| 1426 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } | 1446 StringBuilder(char* buffer, int size) : SimpleStringBuilder(buffer, size) { } |
| 1427 | 1447 |
| 1428 // Add formatted contents to the builder just like printf(). | 1448 // Add formatted contents to the builder just like printf(). |
| 1429 void PRINTF_FORMAT(2, 3) AddFormatted(const char* format, ...); | 1449 void AddFormatted(const char* format, ...); |
| 1430 | 1450 |
| 1431 // Add formatted contents like printf based on a va_list. | 1451 // Add formatted contents like printf based on a va_list. |
| 1432 void PRINTF_FORMAT(2, 0) AddFormattedList(const char* format, va_list list); | 1452 void AddFormattedList(const char* format, va_list list); |
| 1433 | |
| 1434 private: | 1453 private: |
| 1435 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); | 1454 DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); |
| 1436 }; | 1455 }; |
| 1437 | 1456 |
| 1438 | 1457 |
| 1439 bool DoubleToBoolean(double d); | 1458 bool DoubleToBoolean(double d); |
| 1440 | 1459 |
| 1441 template <typename Stream> | 1460 template <typename Stream> |
| 1442 bool StringToArrayIndex(Stream* stream, uint32_t* index) { | 1461 bool StringToArrayIndex(Stream* stream, uint32_t* index) { |
| 1443 uint16_t ch = stream->GetNext(); | 1462 uint16_t ch = stream->GetNext(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 } | 1535 } |
| 1517 | 1536 |
| 1518 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { | 1537 static inline void WriteUnalignedUInt32(void* p, uint32_t value) { |
| 1519 WriteUnalignedValue(p, value); | 1538 WriteUnalignedValue(p, value); |
| 1520 } | 1539 } |
| 1521 | 1540 |
| 1522 } // namespace internal | 1541 } // namespace internal |
| 1523 } // namespace v8 | 1542 } // namespace v8 |
| 1524 | 1543 |
| 1525 #endif // V8_UTILS_H_ | 1544 #endif // V8_UTILS_H_ |
| OLD | NEW |