Skip to content
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

Closed

Conversation

carlos4242
Copy link
Contributor

Here's the sort of approach I"m looking at @owenca

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

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
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

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.

Copy link

github-actions bot commented Jan 21, 2024

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

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

@owenca
Copy link
Contributor

owenca commented Jan 22, 2024

Here's the sort of approach I"m looking at @owenca

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
@carlos4242 carlos4242 force-pushed the improved-isSimpleTypeSpecifier branch from d46a0f8 to 2622ca4 Compare January 22, 2024 18:03
@carlos4242
Copy link
Contributor Author

closed in favour of #79037

@carlos4242 carlos4242 closed this Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants