[PATCH] D13081: [clang-tidy] Implement FixitHints for identifier references in IdentifierNamingCheck
Beren Minor via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 29 07:00:12 PDT 2015
berenm added inline comments.
================
Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:545
@@ +544,3 @@
+ if (const auto *Loc = Result.Nodes.getNodeAs<TypeLoc>("typeLoc")) {
+ if (const auto &Ref = Loc->getAs<TagTypeLoc>()) {
+ addUsage(NamingCheckFailures, Ref.getDecl(), Loc->getSourceRange(),
----------------
alexfh wrote:
> The four cases are too similar. It should be possible to write the code much shorter. This might work:
>
> if (isa<TagTypeLoc>(Loc) || isa<InjectedClassNameTypeLoc>(Loc) || ...)
> addUsage(NamingCheckFailures, Loc->getType()->getDecl(),
> Loc->getSourceRange(), Result.SourceManager);
>
It doesn't look to work well with `TypeLoc`. This looks to be a convoluted class hierarchy (http://clang.llvm.org/doxygen/classclang_1_1TypeLoc.html) and getDecl() is only available on some derived `TypeLoc` classes.
I can change to something smaller, is that any better?
```
NamedDecl *Decl = nullptr;
if (const auto &Ref = Loc->getAs<TagTypeLoc>()) {
Decl = Ref.getDecl();
} else if (const auto &Ref = Loc->getAs<InjectedClassNameTypeLoc>()) {
Decl = Ref.getDecl();
} else if (const auto &Ref = Loc->getAs<UnresolvedUsingTypeLoc>()) {
Decl = Ref.getDecl();
} else if (const auto &Ref = Loc->getAs<TemplateTypeParmTypeLoc>()) {
Decl = Ref.getDecl();
}
if (Decl) {
addUsage(NamingCheckFailures, Decl, Loc->getSourceRange(),
Result.SourceManager);
return;
}
```
http://reviews.llvm.org/D13081
More information about the cfe-commits
mailing list