From 6953586716b58717bfec27a28bc7ec3611986022 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Thu, 3 Nov 2016 14:25:16 -0700 Subject: [PATCH] Add .clang-format and run clang-format on runtime/platform. R=johnmccutchan@google.com Review URL: https://codereview.chromium.org/2470663006 . --- .clang-format | 16 ++++ runtime/platform/address_sanitizer.h | 12 ++- runtime/platform/assert.cc | 4 +- runtime/platform/assert.h | 126 +++++++++++-------------- runtime/platform/c99_support_win.h | 5 +- runtime/platform/floating_point.h | 8 +- runtime/platform/floating_point_win.cc | 5 +- runtime/platform/globals.h | 75 +++++++-------- runtime/platform/hashmap.h | 8 +- runtime/platform/memory_sanitizer.h | 12 ++- runtime/platform/signal_blocker.h | 58 +++++++----- runtime/platform/text_buffer.cc | 3 +- runtime/platform/text_buffer.h | 3 +- runtime/platform/utils.cc | 25 ++++- runtime/platform/utils.h | 41 ++++---- runtime/platform/utils_linux.h | 4 +- 16 files changed, 212 insertions(+), 193 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000000..96325aea288 --- /dev/null +++ b/.clang-format @@ -0,0 +1,16 @@ +# Defines the Chromium style for automatic reformatting. +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: Chromium + +# Keep up to 2 blank lines. More blank lines are removed. +MaxEmptyLinesToKeep: 2 + +# clang-format doesn't seem to do a good job of this for longer comments. +ReflowComments: 'false' + +# We have lots of these. Though we need to put them all in curly braces, +# clang-format can't do that. +AllowShortIfStatementsOnASingleLine: 'true' + +# Put escaped newlines into the rightmost column. +AlignEscapedNewlinesLeft: false diff --git a/runtime/platform/address_sanitizer.h b/runtime/platform/address_sanitizer.h index 584f3a52395..ec8baf70d1b 100644 --- a/runtime/platform/address_sanitizer.h +++ b/runtime/platform/address_sanitizer.h @@ -11,13 +11,17 @@ // told about areas where the VM does the equivalent of a long-jump. #if defined(__has_feature) #if __has_feature(address_sanitizer) -extern "C" void __asan_unpoison_memory_region(void *, size_t); +extern "C" void __asan_unpoison_memory_region(void*, size_t); #define ASAN_UNPOISON(ptr, len) __asan_unpoison_memory_region(ptr, len) #else // __has_feature(address_sanitizer) -#define ASAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0) +#define ASAN_UNPOISON(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) #endif // __has_feature(address_sanitizer) -#else // defined(__has_feature) -#define ASAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0) +#else // defined(__has_feature) +#define ASAN_UNPOISON(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) #endif // defined(__has_feature) #endif // RUNTIME_PLATFORM_ADDRESS_SANITIZER_H_ diff --git a/runtime/platform/assert.cc b/runtime/platform/assert.cc index 524c7a2470f..49c6bec4c00 100644 --- a/runtime/platform/assert.cc +++ b/runtime/platform/assert.cc @@ -28,9 +28,7 @@ void DynamicAssertionHelper::Fail(const char* format, ...) { va_list arguments; va_start(arguments, format); vsnprintf(buffer + file_and_line_length, - sizeof(buffer) - file_and_line_length, - format, - arguments); + sizeof(buffer) - file_and_line_length, format, arguments); va_end(arguments); // Print the buffer on stderr and/or syslog. diff --git a/runtime/platform/assert.h b/runtime/platform/assert.h index 1d353277d53..02e0e8f3bc3 100644 --- a/runtime/platform/assert.h +++ b/runtime/platform/assert.h @@ -26,51 +26,48 @@ namespace dart { class DynamicAssertionHelper { public: - enum Kind { - ASSERT, - EXPECT - }; + enum Kind { ASSERT, EXPECT }; DynamicAssertionHelper(const char* file, int line, Kind kind) - : file_(file), line_(line), kind_(kind) { } + : file_(file), line_(line), kind_(kind) {} void Fail(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); static bool failed() { return failed_; } #if defined(TESTING) - template + template void Equals(const E& expected, const A& actual); - template + template void NotEquals(const E& not_expected, const A& actual); - template + template void FloatEquals(const E& expected, const A& actual, const T& tol); - template + template void StringEquals(const E& expected, const A& actual); - template + template void IsSubstring(const E& needle, const A& haystack); - template + template void IsNotSubstring(const E& needle, const A& haystack); - template + template void LessThan(const E& left, const A& right); - template + template void LessEqual(const E& left, const A& right); - template + template void GreaterThan(const E& left, const A& right); - template + template void GreaterEqual(const E& left, const A& right); #endif - template + template T NotNull(const T p); private: @@ -84,24 +81,24 @@ class DynamicAssertionHelper { }; -class Assert: public DynamicAssertionHelper { +class Assert : public DynamicAssertionHelper { public: Assert(const char* file, int line) - : DynamicAssertionHelper(file, line, ASSERT) { } + : DynamicAssertionHelper(file, line, ASSERT) {} }; -class Expect: public DynamicAssertionHelper { +class Expect : public DynamicAssertionHelper { public: Expect(const char* file, int line) - : DynamicAssertionHelper(file, line, EXPECT) { } + : DynamicAssertionHelper(file, line, EXPECT) {} }; #if defined(TESTING) // Only allow the expensive (with respect to code size) assertions // in testing code. -template +template void DynamicAssertionHelper::Equals(const E& expected, const A& actual) { if (actual == expected) return; std::ostringstream ess, ass; @@ -112,9 +109,8 @@ void DynamicAssertionHelper::Equals(const E& expected, const A& actual) { } -template -void DynamicAssertionHelper::NotEquals(const E& not_expected, - const A& actual) { +template +void DynamicAssertionHelper::NotEquals(const E& not_expected, const A& actual) { if (actual != not_expected) return; std::ostringstream ness; ness << not_expected; @@ -123,7 +119,7 @@ void DynamicAssertionHelper::NotEquals(const E& not_expected, } -template +template void DynamicAssertionHelper::FloatEquals(const E& expected, const A& actual, const T& tol) { @@ -135,16 +131,14 @@ void DynamicAssertionHelper::FloatEquals(const E& expected, ass << actual; tolss << tol; std::string es = ess.str(), as = ass.str(), tols = tolss.str(); - Fail("expected: <%s> but was: <%s> (tolerance: <%s>)", - es.c_str(), - as.c_str(), + Fail("expected: <%s> but was: <%s> (tolerance: <%s>)", es.c_str(), as.c_str(), tols.c_str()); } -template -NO_SANITIZE_MEMORY -void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) { +template +NO_SANITIZE_MEMORY void DynamicAssertionHelper::StringEquals(const E& expected, + const A& actual) { std::ostringstream ess, ass; ess << expected; ass << actual; @@ -154,34 +148,34 @@ void DynamicAssertionHelper::StringEquals(const E& expected, const A& actual) { } -template -NO_SANITIZE_MEMORY -void DynamicAssertionHelper::IsSubstring(const E& needle, const A& haystack) { +template +NO_SANITIZE_MEMORY void DynamicAssertionHelper::IsSubstring(const E& needle, + const A& haystack) { std::ostringstream ess, ass; ess << needle; ass << haystack; std::string es = ess.str(), as = ass.str(); if (as.find(es) != std::string::npos) return; - Fail("expected <\"%s\"> to be a substring of <\"%s\">", - es.c_str(), as.c_str()); + Fail("expected <\"%s\"> to be a substring of <\"%s\">", es.c_str(), + as.c_str()); } -template -NO_SANITIZE_MEMORY -void DynamicAssertionHelper::IsNotSubstring(const E& needle, - const A& haystack) { +template +NO_SANITIZE_MEMORY void DynamicAssertionHelper::IsNotSubstring( + const E& needle, + const A& haystack) { std::ostringstream ess, ass; ess << needle; ass << haystack; std::string es = ess.str(), as = ass.str(); if (as.find(es) == std::string::npos) return; - Fail("expected <\"%s\"> to not be a substring of <\"%s\">", - es.c_str(), as.c_str()); + Fail("expected <\"%s\"> to not be a substring of <\"%s\">", es.c_str(), + as.c_str()); } -template +template void DynamicAssertionHelper::LessThan(const E& left, const A& right) { if (left < right) return; std::ostringstream ess, ass; @@ -192,7 +186,7 @@ void DynamicAssertionHelper::LessThan(const E& left, const A& right) { } -template +template void DynamicAssertionHelper::LessEqual(const E& left, const A& right) { if (left <= right) return; std::ostringstream ess, ass; @@ -203,7 +197,7 @@ void DynamicAssertionHelper::LessEqual(const E& left, const A& right) { } -template +template void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) { if (left > right) return; std::ostringstream ess, ass; @@ -214,7 +208,7 @@ void DynamicAssertionHelper::GreaterThan(const E& left, const A& right) { } -template +template void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) { if (left >= right) return; std::ostringstream ess, ass; @@ -226,7 +220,7 @@ void DynamicAssertionHelper::GreaterEqual(const E& left, const A& right) { #endif -template +template T DynamicAssertionHelper::NotNull(const T p) { if (p != NULL) return p; Fail("expected: not NULL, found NULL"); @@ -236,11 +230,9 @@ T DynamicAssertionHelper::NotNull(const T p) { } // namespace dart -#define FATAL(error) \ - dart::Assert(__FILE__, __LINE__).Fail("%s", error) +#define FATAL(error) dart::Assert(__FILE__, __LINE__).Fail("%s", error) -#define FATAL1(format, p1) \ - dart::Assert(__FILE__, __LINE__).Fail(format, (p1)) +#define FATAL1(format, p1) dart::Assert(__FILE__, __LINE__).Fail(format, (p1)) #define FATAL2(format, p1, p2) \ dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2)) @@ -248,14 +240,11 @@ T DynamicAssertionHelper::NotNull(const T p) { #define FATAL3(format, p1, p2, p3) \ dart::Assert(__FILE__, __LINE__).Fail(format, (p1), (p2), (p3)) -#define UNIMPLEMENTED() \ - FATAL("unimplemented code") +#define UNIMPLEMENTED() FATAL("unimplemented code") -#define UNREACHABLE() \ - FATAL("unreachable code") +#define UNREACHABLE() FATAL("unreachable code") -#define OUT_OF_MEMORY() \ - FATAL("Out of memory.") +#define OUT_OF_MEMORY() FATAL("Out of memory.") #if defined(DEBUG) @@ -275,15 +264,16 @@ T DynamicAssertionHelper::NotNull(const T p) { // Returns 'ptr'; useful for initializer lists: // class Foo { Foo(int* ptr) : ptr_(ASSERT_NOTNULL(ptr)) ... -#define ASSERT_NOTNULL(ptr) \ - dart::Assert(__FILE__, __LINE__).NotNull((ptr)) +#define ASSERT_NOTNULL(ptr) dart::Assert(__FILE__, __LINE__).NotNull((ptr)) #else // if defined(DEBUG) // In order to avoid variable unused warnings for code that only uses // a variable in an ASSERT or EXPECT, we make sure to use the macro // argument. -#define ASSERT(condition) do {} while (false && (condition)) +#define ASSERT(condition) \ + do { \ + } while (false && (condition)) #define DEBUG_ASSERT(cond) @@ -310,8 +300,7 @@ T DynamicAssertionHelper::NotNull(const T p) { // template -struct CompileAssert { -}; +struct CompileAssert {}; // Macro to concatenate two tokens. The helper is need to proper expansion // in case an argument is a macro itself. #if !defined(COMPILE_ASSERT) @@ -319,8 +308,8 @@ struct CompileAssert { #define COMPILE_ASSERT_JOIN_HELPER(a, b) a##b #define COMPILE_ASSERT(expr) \ DART_UNUSED typedef CompileAssert<(static_cast(expr))> \ - COMPILE_ASSERT_JOIN(CompileAssertTypeDef, __LINE__)[static_cast(expr) \ - ? 1 : -1] + COMPILE_ASSERT_JOIN(CompileAssertTypeDef, \ + __LINE__)[static_cast(expr) ? 1 : -1] #endif // !defined(COMPILE_ASSERT) #if defined(TESTING) @@ -365,14 +354,11 @@ struct CompileAssert { #define EXPECT_GE(left, right) \ dart::Expect(__FILE__, __LINE__).GreaterEqual((left), (right)) -#define EXPECT_NOTNULL(ptr) \ - dart::Expect(__FILE__, __LINE__).NotNull((ptr)) +#define EXPECT_NOTNULL(ptr) dart::Expect(__FILE__, __LINE__).NotNull((ptr)) -#define FAIL(error) \ - dart::Expect(__FILE__, __LINE__).Fail("%s", error) +#define FAIL(error) dart::Expect(__FILE__, __LINE__).Fail("%s", error) -#define FAIL1(format, p1) \ - dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) +#define FAIL1(format, p1) dart::Expect(__FILE__, __LINE__).Fail(format, (p1)) #define FAIL2(format, p1, p2) \ dart::Expect(__FILE__, __LINE__).Fail(format, (p1), (p2)) diff --git a/runtime/platform/c99_support_win.h b/runtime/platform/c99_support_win.h index d90f34dfe36..b7b625b0e87 100644 --- a/runtime/platform/c99_support_win.h +++ b/runtime/platform/c99_support_win.h @@ -21,11 +21,10 @@ static const unsigned __int64 kQuietNaNMask = #ifndef va_copy #define va_copy(dst, src) (memmove(&(dst), &(src), sizeof(dst))) -#endif /* va_copy */ +#endif /* va_copy */ -#define NAN \ - *reinterpret_cast(&kQuietNaNMask) +#define NAN *reinterpret_cast(&kQuietNaNMask) namespace std { diff --git a/runtime/platform/floating_point.h b/runtime/platform/floating_point.h index 24d2f9c17bf..0d29a707d01 100644 --- a/runtime/platform/floating_point.h +++ b/runtime/platform/floating_point.h @@ -5,7 +5,11 @@ #ifndef RUNTIME_PLATFORM_FLOATING_POINT_H_ #define RUNTIME_PLATFORM_FLOATING_POINT_H_ -inline double fmod_ieee(double x, double y) { return fmod(x, y); } -inline double atan2_ieee(double y, double x) { return atan2(y, x); } +inline double fmod_ieee(double x, double y) { + return fmod(x, y); +} +inline double atan2_ieee(double y, double x) { + return atan2(y, x); +} #endif // RUNTIME_PLATFORM_FLOATING_POINT_H_ diff --git a/runtime/platform/floating_point_win.cc b/runtime/platform/floating_point_win.cc index 76ce626507a..8863ec5f8f0 100644 --- a/runtime/platform/floating_point_win.cc +++ b/runtime/platform/floating_point_win.cc @@ -38,9 +38,8 @@ double atan2_ieee(double x, double y) { // Same is with index_y. int index_x = (cls_x & _FPCLASS_PINF) != 0 ? 0 : 1; int index_y = (cls_y & _FPCLASS_PINF) != 0 ? 0 : 1; - static double atans_at_infinities[2][2] = - { { atan2(1., 1.), atan2(1., -1.) }, - { atan2(-1., 1.), atan2(-1., -1.) } }; + static double atans_at_infinities[2][2] = { + {atan2(1., 1.), atan2(1., -1.)}, {atan2(-1., 1.), atan2(-1., -1.)}}; return atans_at_infinities[index_x][index_y]; } else { return atan2(x, y); diff --git a/runtime/platform/globals.h b/runtime/platform/globals.h index 85032215236..cd7490169fa 100644 --- a/runtime/platform/globals.h +++ b/runtime/platform/globals.h @@ -195,9 +195,7 @@ struct simd128_value_t { v[0] = double_storage[0]; v[1] = double_storage[1]; } - void writeTo(simd128_value_t* v) { - *v = *this; - } + void writeTo(simd128_value_t* v) { *v = *this; } }; // Processor architecture detection. For more info on what's defined, see: @@ -228,18 +226,17 @@ typedef simd128_value_t fpu_register_t; typedef struct { union { uint32_t u; - float f; + float f; } data_[4]; } simd_value_t; typedef simd_value_t fpu_register_t; -#define simd_value_safe_load(addr) \ - (*reinterpret_cast(addr)) +#define simd_value_safe_load(addr) (*reinterpret_cast(addr)) #define simd_value_safe_store(addr, value) \ do { \ - reinterpret_cast(addr)->data_[0] = value.data_[0]; \ - reinterpret_cast(addr)->data_[1] = value.data_[1]; \ - reinterpret_cast(addr)->data_[2] = value.data_[2]; \ - reinterpret_cast(addr)->data_[3] = value.data_[3]; \ + reinterpret_cast(addr)->data_[0] = value.data_[0]; \ + reinterpret_cast(addr)->data_[1] = value.data_[1]; \ + reinterpret_cast(addr)->data_[2] = value.data_[2]; \ + reinterpret_cast(addr)->data_[3] = value.data_[3]; \ } while (0) #elif defined(__MIPSEL__) @@ -335,14 +332,12 @@ typedef simd128_value_t fpu_register_t; // Verify that host and target architectures match, we cannot // have a 64 bit Dart VM generating 32 bit code or vice-versa. -#if defined(TARGET_ARCH_X64) || \ - defined(TARGET_ARCH_ARM64) +#if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM64) #if !defined(ARCH_IS_64_BIT) #error Mismatched Host/Target architectures. #endif -#elif defined(TARGET_ARCH_IA32) || \ - defined(TARGET_ARCH_ARM) || \ - defined(TARGET_ARCH_MIPS) +#elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) || \ + defined(TARGET_ARCH_MIPS) #if !defined(ARCH_IS_32_BIT) #error Mismatched Host/Target architectures. #endif @@ -350,9 +345,9 @@ typedef simd128_value_t fpu_register_t; // Determine whether we will be using the simulator. #if defined(TARGET_ARCH_IA32) - // No simulator used. +// No simulator used. #elif defined(TARGET_ARCH_X64) - // No simulator used. +// No simulator used. #elif defined(TARGET_ARCH_ARM) #if !defined(HOST_ARCH_ARM) #define USING_SIMULATOR 1 @@ -429,7 +424,7 @@ typedef simd128_value_t fpu_register_t; // Usage: instead of writing 0x1234567890123456ULL // write DART_2PART_UINT64_C(0x12345678,90123456); #define DART_2PART_UINT64_C(a, b) \ - (((static_cast(a) << 32) + 0x##b##u)) + (((static_cast(a) << 32) + 0x##b##u)) // Integer constants. const int32_t kMinInt32 = 0x80000000; @@ -457,11 +452,11 @@ typedef uint32_t classid_t; // Byte sizes. const int kWordSize = sizeof(word); const int kDoubleSize = sizeof(double); // NOLINT -const int kFloatSize = sizeof(float); // NOLINT +const int kFloatSize = sizeof(float); // NOLINT const int kQuadSize = 4 * kFloatSize; const int kSimd128Size = sizeof(simd128_value_t); // NOLINT -const int kInt32Size = sizeof(int32_t); // NOLINT -const int kInt16Size = sizeof(int16_t); // NOLINT +const int kInt32Size = sizeof(int32_t); // NOLINT +const int kInt16Size = sizeof(int16_t); // NOLINT #ifdef ARCH_IS_32_BIT const int kWordSizeLog2 = 2; const uword kUwordMax = kMaxUint32; @@ -510,13 +505,13 @@ const intptr_t kIntptrMax = ~kIntptrMin; // Time constants. const int kMillisecondsPerSecond = 1000; const int kMicrosecondsPerMillisecond = 1000; -const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * - kMillisecondsPerSecond); +const int kMicrosecondsPerSecond = + (kMicrosecondsPerMillisecond * kMillisecondsPerSecond); const int kNanosecondsPerMicrosecond = 1000; -const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * - kMicrosecondsPerMillisecond); -const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * - kMicrosecondsPerSecond); +const int kNanosecondsPerMillisecond = + (kNanosecondsPerMicrosecond * kMicrosecondsPerMillisecond); +const int kNanosecondsPerSecond = + (kNanosecondsPerMicrosecond * kMicrosecondsPerSecond); // Helpers to scale micro second times to human understandable values. inline double MicrosecondsToSeconds(int64_t micros) { @@ -530,7 +525,7 @@ inline double MicrosecondsToMilliseconds(int64_t micros) { // This should be used in the private: declarations for a class. #if !defined(DISALLOW_COPY_AND_ASSIGN) #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ -private: \ + private: \ TypeName(const TypeName&); \ void operator=(const TypeName&) #endif // !defined(DISALLOW_COPY_AND_ASSIGN) @@ -542,7 +537,7 @@ private: \ // containing only static methods. #if !defined(DISALLOW_IMPLICIT_CONSTRUCTORS) #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ -private: \ + private: \ TypeName(); \ DISALLOW_COPY_AND_ASSIGN(TypeName) #endif // !defined(DISALLOW_IMPLICIT_CONSTRUCTORS) @@ -553,19 +548,20 @@ private: \ // platform/assert.h. #if !defined(DISALLOW_ALLOCATION) #define DISALLOW_ALLOCATION() \ -public: \ + public: \ void operator delete(void* pointer) { \ fprintf(stderr, "unreachable code\n"); \ abort(); \ } \ -private: \ + \ + private: \ void* operator new(size_t size); #endif // !defined(DISALLOW_ALLOCATION) // The USE(x) template is used to silence C++ compiler warnings issued // for unused variables. template -static inline void USE(T) { } +static inline void USE(T) {} // Use implicit_cast as a safe version of static_cast or const_cast @@ -585,15 +581,15 @@ static inline void USE(T) { } // implicit_cast would have been part of the C++ standard library, // but the proposal was submitted too late. It will probably make // its way into the language in the future. -template -inline To implicit_cast(From const &f) { +template +inline To implicit_cast(From const& f) { return f; } // Use like this: down_cast(foo); -template // use like this: down_cast(foo); -inline To down_cast(From* f) { // so we only accept pointers +template // use like this: down_cast(foo); +inline To down_cast(From* f) { // so we only accept pointers // Ensures that To is a sub-type of From *. This test is here only // for compile-time type checking, and has no overhead in an // optimized build at run-time, as it will be optimized away completely. @@ -647,12 +643,11 @@ inline D bit_cast(const S& source) { // optimizations of GCC 4.4. Basically, GCC mindlessly relies on // obscure details in the C++ standard that make reinterpret_cast // virtually useless. -template +template inline D bit_copy(const S& source) { D destination; // This use of memcpy is safe: source and destination cannot overlap. - memcpy(&destination, - reinterpret_cast(&source), + memcpy(&destination, reinterpret_cast(&source), sizeof(destination)); return destination; } @@ -691,7 +686,7 @@ static inline T ReadUnaligned(const T* ptr) { // N.B.: As the GCC manual states, "[s]ince non-static C++ methods // have an implicit 'this' argument, the arguments of such methods // should be counted from two, not one." -#define PRINTF_ATTRIBUTE(string_index, first_to_check) \ +#define PRINTF_ATTRIBUTE(string_index, first_to_check) \ __attribute__((__format__(__printf__, string_index, first_to_check))) #else #define PRINTF_ATTRIBUTE(string_index, first_to_check) diff --git a/runtime/platform/hashmap.h b/runtime/platform/hashmap.h index 1cd8a4a2331..1fd1235153d 100644 --- a/runtime/platform/hashmap.h +++ b/runtime/platform/hashmap.h @@ -11,9 +11,9 @@ namespace dart { class HashMap { public: - typedef bool (*MatchFun) (void* key1, void* key2); + typedef bool (*MatchFun)(void* key1, void* key2); - typedef void (*ClearFun) (void* value); + typedef void (*ClearFun)(void* value); // initial_capacity is the size of the initial hash map; // it must be a power of 2 (and thus must not be 0). @@ -21,9 +21,7 @@ class HashMap { ~HashMap(); - static bool SamePointerValue(void* key1, void* key2) { - return key1 == key2; - } + static bool SamePointerValue(void* key1, void* key2) { return key1 == key2; } static uint32_t StringHash(char* key) { uint32_t hash_ = 0; diff --git a/runtime/platform/memory_sanitizer.h b/runtime/platform/memory_sanitizer.h index dddfe311352..27cb25d4b40 100644 --- a/runtime/platform/memory_sanitizer.h +++ b/runtime/platform/memory_sanitizer.h @@ -11,15 +11,19 @@ // told about areas that are initialized by generated code. #if defined(__has_feature) #if __has_feature(memory_sanitizer) -extern "C" void __msan_unpoison(void *, size_t); +extern "C" void __msan_unpoison(void*, size_t); #define MSAN_UNPOISON(ptr, len) __msan_unpoison(ptr, len) #define NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory)) #else // __has_feature(memory_sanitizer) -#define MSAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0) +#define MSAN_UNPOISON(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) #define NO_SANITIZE_MEMORY #endif // __has_feature(memory_sanitizer) -#else // defined(__has_feature) -#define MSAN_UNPOISON(ptr, len) do {} while (false && (ptr) == 0 && (len) == 0) +#else // defined(__has_feature) +#define MSAN_UNPOISON(ptr, len) \ + do { \ + } while (false && (ptr) == 0 && (len) == 0) #define NO_SANITIZE_MEMORY #endif // defined(__has_feature) diff --git a/runtime/platform/signal_blocker.h b/runtime/platform/signal_blocker.h index 28c22ac4b56..2afe49feda5 100644 --- a/runtime/platform/signal_blocker.h +++ b/runtime/platform/signal_blocker.h @@ -57,51 +57,59 @@ class ThreadSignalBlocker { // errors (type long int changed to intptr_t and do/while split on // separate lines with body in {}s) and to also block signals. #define TEMP_FAILURE_RETRY(expression) \ - ({ ThreadSignalBlocker tsb(SIGPROF); \ - intptr_t __result; \ - do { \ - __result = (expression); \ - } while ((__result == -1L) && (errno == EINTR)); \ - __result; }) + ({ \ + ThreadSignalBlocker tsb(SIGPROF); \ + intptr_t __result; \ + do { \ + __result = (expression); \ + } while ((__result == -1L) && (errno == EINTR)); \ + __result; \ + }) // This is a version of TEMP_FAILURE_RETRY which does not use the value // returned from the expression. #define VOID_TEMP_FAILURE_RETRY(expression) \ - (static_cast(TEMP_FAILURE_RETRY(expression))) + (static_cast(TEMP_FAILURE_RETRY(expression))) // This macro can be used to insert checks that a call is made, that // was expected to not return EINTR, but did it anyway. #define NO_RETRY_EXPECTED(expression) \ - ({ intptr_t __result = (expression); \ - if (__result == -1L && errno == EINTR) { \ - FATAL("Unexpected EINTR errno"); \ - } \ - __result; }) + ({ \ + intptr_t __result = (expression); \ + if (__result == -1L && errno == EINTR) { \ + FATAL("Unexpected EINTR errno"); \ + } \ + __result; \ + }) #define VOID_NO_RETRY_EXPECTED(expression) \ - (static_cast(NO_RETRY_EXPECTED(expression))) + (static_cast(NO_RETRY_EXPECTED(expression))) // Define to check in debug mode, if a signal is currently being blocked. #define CHECK_IS_BLOCKING(signal) \ - ({ sigset_t signal_mask; \ - int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask); \ - USE(__r); \ - ASSERT(__r == 0); \ - sigismember(&signal_mask, signal); }) \ + ({ \ + sigset_t signal_mask; \ + int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask); \ + USE(__r); \ + ASSERT(__r == 0); \ + sigismember(&signal_mask, signal); \ + }) // Versions of the above, that does not enter a signal blocking scope. Use only // when a signal blocking scope is entered manually. #define TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \ - ({ intptr_t __result; \ - ASSERT(CHECK_IS_BLOCKING(SIGPROF)); \ - do { \ - __result = (expression); \ - } while ((__result == -1L) && (errno == EINTR)); \ - __result; }) + ({ \ + intptr_t __result; \ + ASSERT(CHECK_IS_BLOCKING(SIGPROF)); \ + do { \ + __result = (expression); \ + } while ((__result == -1L) && (errno == EINTR)); \ + __result; \ + }) #define VOID_TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression) \ - (static_cast(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression))) + (static_cast(TEMP_FAILURE_RETRY_NO_SIGNAL_BLOCKER(expression))) } // namespace dart diff --git a/runtime/platform/text_buffer.cc b/runtime/platform/text_buffer.cc index b06c49fd80b..b44ed6941f0 100644 --- a/runtime/platform/text_buffer.cc +++ b/runtime/platform/text_buffer.cc @@ -52,8 +52,7 @@ void TextBuffer::AddChar(char ch) { } -void TextBuffer::AddRaw(const uint8_t* buffer, - intptr_t buffer_length) { +void TextBuffer::AddRaw(const uint8_t* buffer, intptr_t buffer_length) { EnsureCapacity(buffer_length); memmove(&buf_[msg_len_], buffer, buffer_length); msg_len_ += buffer_length; diff --git a/runtime/platform/text_buffer.h b/runtime/platform/text_buffer.h index 5689f0f0639..a9b5326d688 100644 --- a/runtime/platform/text_buffer.h +++ b/runtime/platform/text_buffer.h @@ -24,8 +24,7 @@ class TextBuffer : ValueObject { void EscapeAndAddCodeUnit(uint32_t cu); void AddString(const char* s); void AddEscapedString(const char* s); - void AddRaw(const uint8_t* buffer, - intptr_t buffer_length); + void AddRaw(const uint8_t* buffer, intptr_t buffer_length); void Clear(); diff --git a/runtime/platform/utils.cc b/runtime/platform/utils.cc index 77783909495..0dde3c70271 100644 --- a/runtime/platform/utils.cc +++ b/runtime/platform/utils.cc @@ -39,11 +39,26 @@ int Utils::HighestBit(int64_t v) { uint64_t x = static_cast((v > 0) ? v : -v); uint64_t t; int r = 0; - if ((t = x >> 32) != 0) { x = t; r += 32; } - if ((t = x >> 16) != 0) { x = t; r += 16; } - if ((t = x >> 8) != 0) { x = t; r += 8; } - if ((t = x >> 4) != 0) { x = t; r += 4; } - if ((t = x >> 2) != 0) { x = t; r += 2; } + if ((t = x >> 32) != 0) { + x = t; + r += 32; + } + if ((t = x >> 16) != 0) { + x = t; + r += 16; + } + if ((t = x >> 8) != 0) { + x = t; + r += 8; + } + if ((t = x >> 4) != 0) { + x = t; + r += 4; + } + if ((t = x >> 2) != 0) { + x = t; + r += 2; + } if (x > 1) r += 1; return r; } diff --git a/runtime/platform/utils.h b/runtime/platform/utils.h index b67c96e6d59..911cf508efc 100644 --- a/runtime/platform/utils.h +++ b/runtime/platform/utils.h @@ -12,28 +12,28 @@ namespace dart { class Utils { public: - template + template static inline T Minimum(T x, T y) { return x < y ? x : y; } - template + template static inline T Maximum(T x, T y) { return x > y ? x : y; } - template + template static inline T Abs(T x) { if (x < 0) return -x; return x; } - template + template static inline bool IsPowerOfTwo(T x) { return ((x & (x - 1)) == 0) && (x != 0); } - template + template static inline int ShiftForPowerOfTwo(T x) { ASSERT(IsPowerOfTwo(x)); int num_shifts = 0; @@ -44,34 +44,34 @@ class Utils { return num_shifts; } - template + template static inline bool IsAligned(T x, intptr_t n) { ASSERT(IsPowerOfTwo(n)); return (x & (n - 1)) == 0; } - template + template static inline bool IsAligned(T* x, intptr_t n) { return IsAligned(reinterpret_cast(x), n); } - template + template static inline T RoundDown(T x, intptr_t n) { ASSERT(IsPowerOfTwo(n)); return (x & -n); } - template + template static inline T* RoundDown(T* x, intptr_t n) { return reinterpret_cast(RoundDown(reinterpret_cast(x), n)); } - template + template static inline T RoundUp(T x, intptr_t n) { return RoundDown(x + n - 1, n); } - template + template static inline T* RoundUp(T* x, intptr_t n) { return reinterpret_cast(RoundUp(reinterpret_cast(x), n)); } @@ -97,7 +97,7 @@ class Utils { static uint32_t WordHash(intptr_t key); // Check whether an N-bit two's-complement representation can hold value. - template + template static inline bool IsInt(int N, T value) { ASSERT((0 < N) && (static_cast(N) < (kBitsPerByte * sizeof(value)))); @@ -105,7 +105,7 @@ class Utils { return (-limit <= value) && (value < limit); } - template + template static inline bool IsUint(int N, T value) { ASSERT((0 < N) && (static_cast(N) < (kBitsPerByte * sizeof(value)))); @@ -115,7 +115,7 @@ class Utils { // Check whether the magnitude of value fits in N bits, i.e., whether an // (N+1)-bit sign-magnitude representation can hold value. - template + template static inline bool IsAbsoluteUint(int N, T value) { ASSERT((0 < N) && (static_cast(N) < (kBitsPerByte * sizeof(value)))); @@ -143,14 +143,11 @@ class Utils { return (static_cast(high) << 32) | (low & 0x0ffffffffLL); } - static bool IsDecimalDigit(char c) { - return ('0' <= c) && (c <= '9'); - } + static bool IsDecimalDigit(char c) { return ('0' <= c) && (c <= '9'); } static bool IsHexDigit(char c) { - return IsDecimalDigit(c) - || (('A' <= c) && (c <= 'F')) - || (('a' <= c) && (c <= 'f')); + return IsDecimalDigit(c) || (('A' <= c) && (c <= 'F')) || + (('a' <= c) && (c <= 'f')); } static int HexDigitToInt(char c) { @@ -172,9 +169,7 @@ class Utils { static inline bool RangeCheck(intptr_t offset, intptr_t count, intptr_t length) { - return offset >= 0 && - count >= 0 && - length >= 0 && + return offset >= 0 && count >= 0 && length >= 0 && count <= (length - offset); } diff --git a/runtime/platform/utils_linux.h b/runtime/platform/utils_linux.h index 5be126d8cfc..b5214fdce3c 100644 --- a/runtime/platform/utils_linux.h +++ b/runtime/platform/utils_linux.h @@ -62,8 +62,8 @@ inline uint64_t Utils::HostToLittleEndian64(uint64_t value) { inline char* Utils::StrError(int err, char* buffer, size_t bufsize) { -#if !defined(__GLIBC__) || \ -((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) +#if !defined(__GLIBC__) || \ + ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) // Use the XSI version. if (strerror_r(err, buffer, bufsize) != 0) { snprintf(buffer, bufsize, "%s", "strerror_r failed");