[PATCH] D101572: Make `hasTypeLoc` matcher support nodes of type `CXXFunctionalCastExpr` and `CXXTemporaryObjectExpr`.
Weston Carvalho via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 30 11:46:59 PDT 2021
SilensAngelusNex added a comment.
Yes, the motivation for adding these is so I can use clang-transformer to refactor a bunch of constructor calls to call a static factory method instead.
// Before
ns::Foo x(1);
auto y = ns::Foo(1, 2);
// After
auto x = ns::Foo::Make(1);
auto y = ns::Foo::Make(1, 2);
That refactor only needs `hasTypeInfo` to work on these three node types, but for consistency's sake I'd be happy to add overloads for others as well. I looked at the types in the results of the `grep` you posted; I think it would make sense for `hasTypeInfo` to be able to handle the classes in the first and third groups; do you think that would be reasonable?
Pretty sure these should work with `hasTypeInfo`.
- TypedefNameDecl (`getTypeSourceInfo`)
- CXXBaseSpecifier (`getTypeSourceInfo`)
- CXXCtorInitializer (`getTypeSourceInfo`)
- ObjCPropertyDecl (`getTypeSourceInfo`)
- ClassTemplateSpecializationDecl (`getTypeAsWritten`)
- CompoundLiteralExpr (`getTypeSourceInfo`)
- ExplicitCastExpr (`getTypeInfoAsWritten`)
- CXXTemporaryObjectExpr (`getTypeSourceInfo`)
- CXXUnresolvedConstructExpr (`getTypeSourceInfo`)
- TemplateArgumentLoc (`getTypeSourceInfo`)
These could make sense, but no other matchers exist for nodes of these types:
- VarTemplateSpecializationDecl (`getTypeAsWritten`)
- OffsetOfExpr (`getTypeSourceInfo`)
- ConvertVectorExpr (`getTypeSourceInfo`)
- VAArgExpr (`getWrittenTypeInfo`)
- CXXScalarValueInitExpr (`getTypeSourceInfo`)
These nodes have a method with a different name, but probably still make sense to use with `hasTypeLoc`.
- BlockDecl (`getSignatureAsWritten`)
- CXXNewExpr (`getAllocatedTypeSourceInfo`)
These all have a method that returns a `TypeSourceInfo*`, but seem like they're expressing something different and shouldn't work with `hasTypeInfo`.
- EnumDecl (`getIntegerTypeSourceInfo`)
- CXXRecordDecl (`getLambdaTypeInfo`) fails if not a lambda
- FriendDecl (`getFriendType`)
- ObjCMethodDecl (`getReturnTypeSourceInfo`)
- ObjCInterfaceDecl (`getSuperClassTInfo`)
- UnaryExprOrTypeTraitExpr (`getArgumentTypeInfo`) fails when arg is expr instead of type
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101572/new/
https://reviews.llvm.org/D101572
More information about the cfe-commits
mailing list