diff --git a/.clang-format b/.clang-format index e5ca3fc0..30449a14 100644 --- a/.clang-format +++ b/.clang-format @@ -1,16 +1,14 @@ # clang-format configuration -# compatible with clang-format 18 +# compatible with clang-format 15 UseTab: Never -ColumnLimit: 120 +ColumnLimit: 100 # Indent IndentWidth: 4 -BracedInitializerIndentWidth: 4 AccessModifierOffset: -4 IndentAccessModifiers: false IndentCaseLabels: true -IndentExternBlock: Indent IndentGotoLabels: true IndentRequiresClause: true IndentWrappedFunctionNames: true @@ -20,25 +18,18 @@ BitFieldColonSpacing: Both # Insert InsertBraces: false -InsertNewlineAtEOF: true -KeepEmptyLinesAtEOF: true # Align AlignAfterOpenBracket: true -AlignTrailingComments: - Kind: Always AlignArrayOfStructures: Left PointerAlignment: Left -BreakAfterAttributes: Leave BreakBeforeBinaryOperators: None BreakBeforeConceptDeclarations: Always -BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: true BreakConstructorInitializers: AfterColon BreakInheritanceList: AfterColon -BreakAdjacentStringLiterals: false BreakStringLiterals: false CompactNamespaces: false Cpp11BracedListStyle: true @@ -47,10 +38,8 @@ EmptyLineBeforeAccessModifier: Always AllowAllArgumentsOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false -AllowBreakBeforeNoexceptSpecifier: Never AllowShortBlocksOnASingleLine: Always AllowShortCaseLabelsOnASingleLine: true -AllowShortCompoundRequirementOnASingleLine: true AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: WithoutElse @@ -83,20 +72,12 @@ SpaceInEmptyBlock: false SpacesBeforeTrailingComments: 2 SpacesInAngles: Never -SpacesInParens: Custom -SpacesInParensOptions: - InConditionalStatements: false - InCStyleCasts: false - InEmptyParentheses: false - Other: false - SpacesInSquareBrackets: false # Order QualifierAlignment: Custom QualifierOrder: ["constexpr", "const", "inline", "static", "type"] SortIncludes: Never -SortUsingDeclarations: LexicographicNumeric IncludeBlocks: Merge WhitespaceSensitiveMacros: ["PK_PROTECTED", "LUA_PROTECTED"] diff --git a/include/pocketpy/common/algorithm.h b/include/pocketpy/common/algorithm.h index 62a4a14a..6a093047 100644 --- a/include/pocketpy/common/algorithm.h +++ b/include/pocketpy/common/algorithm.h @@ -8,22 +8,22 @@ extern "C" { #define c11__less(a, b) ((a) < (b)) -#define c11__lower_bound(T, ptr, count, key, less, out) \ - do { \ - const T *__first = ptr; \ - int __len = count; \ - while (__len != 0) { \ - int __l2 = (int)((unsigned int)__len / 2); \ - const T *__m = __first + __l2; \ - if (less((*__m), (key))) { \ - __first = ++__m; \ - __len -= __l2 + 1; \ - } else { \ - __len = __l2; \ - } \ - } \ - *(out) = __first; \ - } while (0) +#define c11__lower_bound(T, ptr, count, key, less, out) \ + do { \ + T* __first = ptr; \ + int __len = count; \ + while(__len != 0) { \ + int __l2 = (int)((unsigned int)__len / 2); \ + T* __m = __first + __l2; \ + if(less((*__m), (key))) { \ + __first = ++__m; \ + __len -= __l2 + 1; \ + } else { \ + __len = __l2; \ + } \ + } \ + *(out) = __first; \ + } while(0) #ifdef __cplusplus } diff --git a/include/pocketpy/common/vector.h b/include/pocketpy/common/vector.h index fb7f72f1..d984a21d 100644 --- a/include/pocketpy/common/vector.h +++ b/include/pocketpy/common/vector.h @@ -56,19 +56,19 @@ void c11_vector__clear(c11_vector* self); }while(0) -#define c11_vector__insert(T, self, index, elem) \ +#define c11_vector__insert(T, self, p, elem) \ do{ \ if((self)->count == (self)->capacity) c11_vector__reserve((self), (self)->capacity*2); \ - T* p = (T*)(self)->data + (index); \ - memmove(p + 1, p, ((self)->count - (index)) * sizeof(T)); \ + int __n = (self)->count - (p - (T*)(self)->data); \ + memmove(p + 1, p, __n * sizeof(T)); \ *p = (elem); \ (self)->count++; \ }while(0) -#define c11_vector__erase(T, self, index) \ +#define c11_vector__erase(T, self, p) \ do{ \ - T* p = (T*)(self)->data + (index); \ - memmove(p, p + 1, ((self)->count - (index) - 1) * sizeof(T)); \ + int __n = (self)->count - (p - (T*)(self)->data) - 1; \ + memmove(p, p + 1, __n * sizeof(T)); \ (self)->count--; \ }while(0) diff --git a/src/common/str.c b/src/common/str.c index b9801b20..dd164919 100644 --- a/src/common/str.c +++ b/src/common/str.c @@ -387,7 +387,7 @@ static const int kLoRangeB[] = {170,186,443,451,660,1514,1522,1599,1610,1647,174 bool c11__is_unicode_Lo_char(int c){ if(c == 0x1f955) return true; const int* p; - c11__lower_bound(int, kLoRangeA, 476, c, c11__less, &p); + c11__lower_bound(const int, kLoRangeA, 476, c, c11__less, &p); int index = p - kLoRangeA; if(c == kLoRangeA[index]) return true; index -= 1; diff --git a/src/modules/random.cpp b/src/modules/random.cpp index 8d75b63f..4e43c3e0 100644 --- a/src/modules/random.cpp +++ b/src/modules/random.cpp @@ -199,7 +199,7 @@ struct Random { List result(k); for(int i = 0; i < k; i++) { f64 key = self.gen.uniform(0.0, cum_weights[size - 1]); - const f64* p; + f64* p; c11__lower_bound(f64, cum_weights.begin(), cum_weights.size(), key, c11__less, &p); result[i] = data[p - cum_weights.begin()]; }