This is an archive of the discontinued LLVM Phabricator instance.

[clang] Adapt ASTMatcher to explicit(bool) specifier
ClosedPublic

Authored by Tyker on May 4 2019, 5:57 AM.

Details

Summary

Changes:

  • add an ast matcher for deductiong guide.
  • allow isExplicit matcher for deductiong guide.
  • add hasExplicitSpecifier matcher which give access to the expression of the explicit specifier if present.

Diff Detail

Repository
rL LLVM

Event Timeline

Tyker created this revision.May 4 2019, 5:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2019, 5:57 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Tyker added a reviewer: rsmith.May 4 2019, 5:59 AM
rsmith added a comment.May 4 2019, 6:57 PM

This seems reasonable to me, but I'll leave it to @klimek or someone else to judge whether the isExplicit / hasExplicitSpecifier approach is the right way to expose this functionality to matcher users.

aaron.ballman requested changes to this revision.May 5 2019, 5:59 AM
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a subscriber: aaron.ballman.

You should also regenerate the documentation by running clang/docs/tools/dump_ast_matchers.py.

clang/include/clang/ASTMatchers/ASTMatchers.h
1141 ↗(On Diff #198137)

Including implicit deduction guides? Might be worth clarifying that.

6168 ↗(On Diff #198137)

conversion function and deduction -> conversion function, and deduction

6197 ↗(On Diff #198137)

Oxford comma here as well, please.

6219 ↗(On Diff #198137)

I think this is a somewhat useful AST matcher, but I think we are going to need a way to match on the expression contained within the explicit specifier too, won't we? Perhaps a different approach is to make a matcher named explicitSpecifier() that allows traversing to the inner expression?

clang/lib/ASTMatchers/Dynamic/Registry.cpp
163 ↗(On Diff #198137)

This is missing the new hasExplicitSpecifier() matcher.

Tyker updated this revision to Diff 203115.EditedJun 5 2019, 3:52 AM
Tyker marked an inline comment as done.
Tyker edited the summary of this revision. (Show Details)

i didn't manage to get "clang/docs/tools/dump_ast_matchers.py" to work. it keep failing to parse and generating empty files as a result.

hasExplicitSpecifier now gives access to the expression if present.

i didn't manage to get "clang/docs/tools/dump_ast_matchers.py" to work. it keep failing to parse and generating empty files as a result.

Are you getting errors from running it, or just incorrect output?

clang/include/clang/ASTMatchers/ASTMatchers.h
6190 ↗(On Diff #203115)

Why won't it match #2?

6220 ↗(On Diff #203115)

Not keen on the name hasExplicitExpr -- I think hasExplicitSpecifier() would be a more intuitive name.

clang/lib/ASTMatchers/Dynamic/Registry.cpp
171 ↗(On Diff #203115)

Please sort alphabetically.

263 ↗(On Diff #203115)

Please sort alphabetically.

Tyker updated this revision to Diff 205559.EditedJun 19 2019, 5:58 AM
Tyker marked 3 inline comments as done.

fixed requested changes.

Are you getting errors from running it, or just incorrect output?

the issue happens to me even on master so i suppose the input is correct.
here is the error report:

[tyker@tyker tools]$ ./dump_ast_matchers.py 
*** Unparsable: " #ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H #define LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H " ***
*** Unparsable: " #include "clang/AST/ASTContext.h" #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclFriend.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/OpenMPClause.h" #include "clang/AST/OperationKinds.h" #include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" #include "clang/AST/StmtOpenMP.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" #include "clang/ASTMatchers/ASTMatchersInternal.h" #include "clang/ASTMatchers/ASTMatchersMacros.h" #include "clang/Basic/AttrKinds.h" #include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/TypeTraits.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Regex.h" #include <cassert> #include <cstddef> #include <iterator> #include <limits> #include <string> #include <utility> #include <vector> " ***
*** Unparsable: " namespace clang {" ***
*** Unparsable: " using DeclarationMatcher = internal::Matcher<Decl>;" ***
*** Unparsable: " using StatementMatcher = internal::Matcher<Stmt>;" ***
*** Unparsable: " using TypeMatcher = internal::Matcher<QualType>;" ***
*** Unparsable: " using TypeLocMatcher = internal::Matcher<TypeLoc>;" ***
*** Unparsable: " using NestedNameSpecifierMatcher = internal::Matcher<NestedNameSpecifier>;" ***
*** Unparsable: " using NestedNameSpecifierLocMatcher = internal::Matcher<NestedNameSpecifierLoc>;" ***
*** Unparsable: " using CXXCtorInitializerMatcher = internal::Matcher<CXXCtorInitializer>;" ***
Probing https://clang.llvm.org/doxygen/classclang_1_1Decl.html...

after this the script keep probing with no issues.
i tested using python 2.7 and python 3.7 the same error occurs

fixed requested changes.

Are you getting errors from running it, or just incorrect output?

the issue happens to me even on master so i suppose the input is correct.
here is the error report:

[tyker@tyker tools]$ ./dump_ast_matchers.py 
*** Unparsable: " #ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H #define LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H " ***
*** Unparsable: " #include "clang/AST/ASTContext.h" #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclFriend.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/OpenMPClause.h" #include "clang/AST/OperationKinds.h" #include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" #include "clang/AST/StmtOpenMP.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" #include "clang/ASTMatchers/ASTMatchersInternal.h" #include "clang/ASTMatchers/ASTMatchersMacros.h" #include "clang/Basic/AttrKinds.h" #include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/TypeTraits.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Regex.h" #include <cassert> #include <cstddef> #include <iterator> #include <limits> #include <string> #include <utility> #include <vector> " ***
*** Unparsable: " namespace clang {" ***
*** Unparsable: " using DeclarationMatcher = internal::Matcher<Decl>;" ***
*** Unparsable: " using StatementMatcher = internal::Matcher<Stmt>;" ***
*** Unparsable: " using TypeMatcher = internal::Matcher<QualType>;" ***
*** Unparsable: " using TypeLocMatcher = internal::Matcher<TypeLoc>;" ***
*** Unparsable: " using NestedNameSpecifierMatcher = internal::Matcher<NestedNameSpecifier>;" ***
*** Unparsable: " using NestedNameSpecifierLocMatcher = internal::Matcher<NestedNameSpecifierLoc>;" ***
*** Unparsable: " using CXXCtorInitializerMatcher = internal::Matcher<CXXCtorInitializer>;" ***
Probing https://clang.llvm.org/doxygen/classclang_1_1Decl.html...

after this the script keep probing with no issues.
i tested using python 2.7 and python 3.7 the same error occurs

That output matches what I get, and my docs generate for me. Are you sure the .html file is not being generated properly for you?

Tyker updated this revision to Diff 205602.EditedJun 19 2019, 8:23 AM

i was confuse because the log seemed like an error and it was happening in python2.7 and python3.7
but the actual error that was preventing generating the documentation only occurs in 3.7.

it works in python2.7.
sorry for my confusion.

clang/include/clang/ASTMatchers/ASTMatchers.h
6190 ↗(On Diff #203115)

#2 matches.

Tyker marked 4 inline comments as done.Jun 19 2019, 8:24 AM
aaron.ballman accepted this revision.Jun 19 2019, 8:49 AM

LGTM aside from a documentation nit.

clang/include/clang/ASTMatchers/ASTMatchers.h
6190 ↗(On Diff #203115)

I figured it would -- the comment should be updated to correct that (and then generate the docs again).

This revision is now accepted and ready to land.Jun 19 2019, 8:49 AM
Tyker marked an inline comment as done.Jun 19 2019, 9:01 AM
Tyker added inline comments.
clang/include/clang/ASTMatchers/ASTMatchers.h
6190 ↗(On Diff #203115)

but the comment says it matches

cxxConstructorDecl(isExplicit()) will match #2, but not #1.

aaron.ballman added inline comments.Jun 19 2019, 9:10 AM
clang/include/clang/ASTMatchers/ASTMatchers.h
6190 ↗(On Diff #203115)

Because this comment says it doesn't:

/// cxxConstructorDecl(isExplicit()) will match #8, but not #7 or #9.

I see now that there are two different comments that say different and incorrect things. I'd say they should be combined into one correct comment.

Tyker updated this revision to Diff 205645.Jun 19 2019, 11:17 AM
Tyker marked an inline comment as done.
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2019, 11:25 AM