23 if (IsConst && (Decl->getStorageClass() != SC_Static)) {
29 const char FC = Decl->getName()[0];
30 if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
37 const char SC = Decl->getName()[1];
38 if ((FC ==
'k' || FC ==
'g') && !llvm::isAlpha(SC)) {
45 const auto NewName = (IsConst ?
"k" :
"g") +
46 StringRef(std::string(1, FC)).upper() +
47 Decl->getName().substr(1).str();
49 return FixItHint::CreateReplacement(
50 CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
63 varDecl(hasGlobalStorage(), unless(hasType(isConstQualified())),
64 unless(isLocalVarDecl()), unless(matchesName(
"::g[A-Z]")))
67 Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
68 unless(isLocalVarDecl()),
69 unless(matchesName(
"::(k[A-Z])|([A-Z][A-Z0-9])")))
70 .bind(
"global_const"),
75 const MatchFinder::MatchResult &Result) {
76 if (
const auto *Decl = Result.Nodes.getNodeAs<VarDecl>(
"global_var")) {
77 if (Decl->isStaticDataMember())
79 diag(Decl->getLocation(),
80 "non-const global variable '%0' must have a name which starts with "
84 if (
const auto *Decl = Result.Nodes.getNodeAs<VarDecl>(
"global_const")) {
85 if (Decl->isStaticDataMember())
87 diag(Decl->getLocation(),
88 "const global variable '%0' must have a name which starts with "
89 "an appropriate prefix")