-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved is simple type specifier #78903
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
You can test this locally with the following command:git-clang-format --diff f73bf45d68bd2c17602a909751da4a23138d711a 2622ca430d7edb1c49cda9bbbf6145b60e2e37c4 -- clang/include/clang/Basic/IdentifierTable.h clang/include/clang/Sema/Sema.h clang/lib/Basic/IdentifierTable.cpp clang/lib/Format/FormatToken.cpp clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Parse/ParseObjc.cpp clang/lib/Sema/SemaDecl.cpp View the diff from clang-format here.diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c365dacd49..88cea044c2 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2406,7 +2406,8 @@ private:
// Heuristically try to determine whether the parentheses contain a type.
auto IsQualifiedPointerOrReference = [](FormatToken *T) {
// This is used to handle cases such as x = (foo *const)&y;
- assert(!T->isSimpleTypeSpecifier(Style) && "Should have already been checked");
+ assert(!T->isSimpleTypeSpecifier(Style) &&
+ "Should have already been checked");
// Strip trailing qualifiers such as const or volatile when checking
// whether the parens could be a cast to a pointer/reference type.
while (T) {
@@ -4155,7 +4156,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
if (Right.isPointerOrReference()) {
const FormatToken *Previous = &Left;
while (Previous && Previous->isNot(tok::kw_operator)) {
- if (Previous->is(tok::identifier) || Previous->isSimpleTypeSpecifier(Style)) {
+ if (Previous->is(tok::identifier) ||
+ Previous->isSimpleTypeSpecifier(Style)) {
Previous = Previous->getPreviousNonComment();
continue;
}
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 7e6f59c2f6..8f9f918bf5 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1597,7 +1597,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
if (TryAnnotateTypeOrScopeToken())
return ExprError();
- if (!Tok.getIdentifierInfo() || !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()))
+ if (!Tok.getIdentifierInfo() ||
+ !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()))
// We are trying to parse a simple-type-specifier but might not get such
// a token after error recovery.
return ExprError();
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 58e5bc4a42..5565770610 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2971,7 +2971,8 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
tok::annot_cxxscope))
TryAnnotateTypeOrScopeToken();
- if (!Tok.getIdentifierInfo() || !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo())) {
+ if (!Tok.getIdentifierInfo() ||
+ !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo())) {
// objc-receiver:
// expression
// Make sure any typos in the receiver are corrected or diagnosed, so that
|
Can you restore the clang-format files for this pull request? I'll open another PR that depends on this one. |
Currently returns false for _Bool, regardless of C dialect. Fixes llvm#72203. - move simple type decision code into shared location (IdentifierInfo) - replace the logic with a check for simple types and a proper check for a valid keyword in the appropriate dialect - change the duplicate functions from Sema and Format to stub functions that both invoke this - attempt to reverse engineer language options in Format from the Style - change all call sites to match the above new API
d46a0f8
to
2622ca4
Compare
closed in favour of #79037 |
Here's the sort of approach I"m looking at @owenca