diff options
Diffstat (limited to 'clang/lib/Format/FormatToken.cpp')
-rw-r--r-- | clang/lib/Format/FormatToken.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 56a7b2d..4fb70ff 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -71,8 +71,22 @@ bool FormatToken::isSimpleTypeSpecifier() const { } } -bool FormatToken::isTypeOrIdentifier() const { - return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier); +// Sorted common C++ non-keyword types. +static SmallVector<StringRef> CppNonKeywordTypes = { + "clock_t", "int16_t", "int32_t", "int64_t", "int8_t", + "intptr_t", "ptrdiff_t", "size_t", "time_t", "uint16_t", + "uint32_t", "uint64_t", "uint8_t", "uintptr_t", +}; + +bool FormatToken::isTypeName(bool IsCpp) const { + return is(TT_TypeName) || isSimpleTypeSpecifier() || + (IsCpp && is(tok::identifier) && + std::binary_search(CppNonKeywordTypes.begin(), + CppNonKeywordTypes.end(), TokenText)); +} + +bool FormatToken::isTypeOrIdentifier(bool IsCpp) const { + return isTypeName(IsCpp) || isOneOf(tok::kw_auto, tok::identifier); } bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const { |