[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-13 Thread Owen Pan via cfe-commits

owenca wrote:

@dyung I've reverted all relevant commits in commit 
1fadb2b0c881ced247931f442fdee6c4ed96dccb.

https://github.com/llvm/llvm-project/pull/91712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-12 Thread via cfe-commits

dyung wrote:

Hi @owenca, this change is causing a test failure in the sanitizer bot 
(https://lab.llvm.org/buildbot/#/builders/5/builds/43303), that is still 
failing as of your most recent fix de641e2 
(https://lab.llvm.org/buildbot/#/builders/5/builds/43334). Can you please 
revert if you need time to investigate so that we can get the sanitizer bot 
back to green?

https://github.com/llvm/llvm-project/pull/91712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/91712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread Owen Pan via cfe-commits

owenca wrote:

> I think this will stop people introducing extra arguments to function
> 
> ...isCpp,isThis,isThat)

I meant to fix the FIXME after I had langded a8279a8bc541, but my previous 
attempts didn't quite work. Now it seems this solution will stick.

https://github.com/llvm/llvm-project/pull/91712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/91712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread via cfe-commits

https://github.com/mydeveloperday approved this pull request.

I think this will stop people introducing extra arguments to function

...isCpp,isThis,isThat)

LGTM

https://github.com/llvm/llvm-project/pull/91712
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Remove FormatToken::isSimpleTypeSpecifier() and call 
Token::isSimpleTypeSpecifier(LangOpts) instead.

---

Patch is 29.50 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/91712.diff


13 Files Affected:

- (modified) clang/lib/Format/Format.cpp (+1-2) 
- (modified) clang/lib/Format/FormatToken.cpp (+5-41) 
- (modified) clang/lib/Format/FormatToken.h (+2-6) 
- (modified) clang/lib/Format/FormatTokenLexer.cpp (-1) 
- (modified) clang/lib/Format/QualifierAlignmentFixer.cpp (+11-13) 
- (modified) clang/lib/Format/QualifierAlignmentFixer.h (+3-2) 
- (modified) clang/lib/Format/TokenAnalyzer.cpp (+2-2) 
- (modified) clang/lib/Format/TokenAnalyzer.h (+1) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+25-18) 
- (modified) clang/lib/Format/TokenAnnotator.h (+5-1) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+11-8) 
- (modified) clang/lib/Format/UnwrappedLineParser.h (+1) 
- (modified) clang/unittests/Format/QualifierFixerTest.cpp (+54-40) 


``diff
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c4eac1c99a663..c5c79dd0f883e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3858,8 +3858,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
   LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
 
   LangOpts.LineComment = 1;
-  bool AlternativeOperators = Style.isCpp();
-  LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
+  LangOpts.CXXOperatorNames = Style.isCpp();
   LangOpts.Bool = 1;
   LangOpts.ObjC = 1;
   LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 4fb70ffac706d..85bec71ffbbc8 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,43 +34,6 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
-}
-
 // Sorted common C++ non-keyword types.
 static SmallVector CppNonKeywordTypes = {
 "clock_t",  "int16_t",   "int32_t", "int64_t",   "int8_t",
@@ -78,15 +41,16 @@ static SmallVector CppNonKeywordTypes = {
 "uint32_t", "uint64_t",  "uint8_t", "uintptr_t",
 };
 
-bool FormatToken::isTypeName(bool IsCpp) const {
-  return is(TT_TypeName) || isSimpleTypeSpecifier() ||
+bool FormatToken::isTypeName(const LangOptions ) const {
+  const bool IsCpp = LangOpts.CXXOperatorNames;
+  return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) ||
  (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::isTypeOrIdentifier(const LangOptions ) const {
+  return isTypeName(LangOpts) || isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle ) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 95f16fde5005f..8792f4c750748 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -684,12 +684,8 @@ struct FormatToken {
isAttribute();
   }
 
-  /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
-
-  [[nodiscard]] bool isTypeName(bool IsCpp) const;
-
-  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
+  [[nodiscard]] bool isTypeName(const LangOptions ) const;
+  [[nodiscard]] bool isTypeOrIdentifier(const LangOptions ) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index f430d3764babe..e21b5a882b777 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -1442,7 +1442,6 @@ 

[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #91712)

2024-05-10 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/91712

Remove FormatToken::isSimpleTypeSpecifier() and call 
Token::isSimpleTypeSpecifier(LangOpts) instead.

>From 3e0b10020d15c102e050ad3785622bef01d1c075 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 10 May 2024 01:00:16 -0700
Subject: [PATCH] [clang-format] Fix FormatToken::isSimpleTypeSpecifier()

Remove FormatToken::isSimpleTypeSpecifier() and call
Token::isSimpleTypeSpecifier(LangOpts) instead.
---
 clang/lib/Format/Format.cpp   |  3 +-
 clang/lib/Format/FormatToken.cpp  | 46 +
 clang/lib/Format/FormatToken.h|  8 +-
 clang/lib/Format/FormatTokenLexer.cpp |  1 -
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 24 +++--
 clang/lib/Format/QualifierAlignmentFixer.h|  5 +-
 clang/lib/Format/TokenAnalyzer.cpp|  4 +-
 clang/lib/Format/TokenAnalyzer.h  |  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 43 +
 clang/lib/Format/TokenAnnotator.h |  6 +-
 clang/lib/Format/UnwrappedLineParser.cpp  | 19 ++--
 clang/lib/Format/UnwrappedLineParser.h|  1 +
 clang/unittests/Format/QualifierFixerTest.cpp | 94 +++
 13 files changed, 121 insertions(+), 134 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c4eac1c99a663..c5c79dd0f883e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3858,8 +3858,7 @@ LangOptions getFormattingLangOpts(const FormatStyle 
) {
   LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
 
   LangOpts.LineComment = 1;
-  bool AlternativeOperators = Style.isCpp();
-  LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
+  LangOpts.CXXOperatorNames = Style.isCpp();
   LangOpts.Bool = 1;
   LangOpts.ObjC = 1;
   LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 4fb70ffac706d..85bec71ffbbc8 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,43 +34,6 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
-}
-
 // Sorted common C++ non-keyword types.
 static SmallVector CppNonKeywordTypes = {
 "clock_t",  "int16_t",   "int32_t", "int64_t",   "int8_t",
@@ -78,15 +41,16 @@ static SmallVector CppNonKeywordTypes = {
 "uint32_t", "uint64_t",  "uint8_t", "uintptr_t",
 };
 
-bool FormatToken::isTypeName(bool IsCpp) const {
-  return is(TT_TypeName) || isSimpleTypeSpecifier() ||
+bool FormatToken::isTypeName(const LangOptions ) const {
+  const bool IsCpp = LangOpts.CXXOperatorNames;
+  return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) ||
  (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::isTypeOrIdentifier(const LangOptions ) const {
+  return isTypeName(LangOpts) || isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle ) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 95f16fde5005f..8792f4c750748 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -684,12 +684,8 @@ struct FormatToken {
isAttribute();
   }
 
-  /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
-
-  [[nodiscard]] bool isTypeName(bool IsCpp) const;
-
-  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
+  [[nodiscard]] bool isTypeName(const LangOptions ) const;
+  [[nodiscard]] bool isTypeOrIdentifier(const LangOptions ) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/FormatTokenLexer.cpp