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