27 if (IsConst && (Decl->getStorageClass() != SC_Static)) {
33 char FC = Decl->getName()[0];
34 if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
41 char SC = Decl->getName()[1];
42 if ((FC ==
'k' || FC ==
'g') && !llvm::isAlpha(SC)) {
49 auto NewName = (IsConst ?
"k" :
"g") +
50 llvm::StringRef(std::string(1, FC)).upper() +
51 Decl->getName().substr(1).str();
53 return FixItHint::CreateReplacement(
54 CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
55 llvm::StringRef(NewName));
67 varDecl(hasGlobalStorage(), unless(hasType(isConstQualified())),
68 unless(isLocalVariable()), unless(matchesName(
"::g[A-Z]")))
71 Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
72 unless(isLocalVariable()),
73 unless(matchesName(
"::(k[A-Z])|([A-Z][A-Z0-9])")))
74 .bind(
"global_const"),
79 const MatchFinder::MatchResult &Result) {
80 if (
const auto *Decl = Result.Nodes.getNodeAs<VarDecl>(
"global_var")) {
81 if (Decl->isStaticDataMember())
83 diag(Decl->getLocation(),
84 "non-const global variable '%0' must have a name which starts with "
88 if (
const auto *Decl = Result.Nodes.getNodeAs<VarDecl>(
"global_const")) {
89 if (Decl->isStaticDataMember())
91 diag(Decl->getLocation(),
92 "const global variable '%0' must have a name which starts with "
93 "an appropriate prefix")