Skip to content

Commit acafa24

Browse files
anerokhisawenzel
authored andcommitted
Check only ::o2 subnamespaces
1 parent 9478379 commit acafa24

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

aliceO2/NamespaceNamingCheck.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "NamespaceNamingCheck.h"
1111
#include "clang/AST/ASTContext.h"
12+
#include "clang/ASTMatchers/ASTMatchersMacros.h"
1213
#include "clang/ASTMatchers/ASTMatchFinder.h"
1314
#include <regex>
1415
#include <string>
@@ -17,6 +18,13 @@
1718
using namespace clang::ast_matchers;
1819

1920
namespace clang {
21+
namespace ast_matchers {
22+
AST_MATCHER_P(UsingDirectiveDecl, nominatedNamespace,
23+
internal::Matcher<NamespaceDecl>, InnerMatcher)
24+
{
25+
return InnerMatcher.matches(*Node.getNominatedNamespace(), Finder, Builder);
26+
}
27+
} // namespace ast_matchers
2028
namespace tidy {
2129
namespace aliceO2 {
2230

@@ -42,18 +50,26 @@ bool isOutsideOfTargetScope(std::string filename)
4250

4351
void NamespaceNamingCheck::registerMatchers(MatchFinder *Finder) {
4452
const auto validNameMatch = matchesName( std::string("::") + VALID_NAME_REGEX + "$" );
53+
const auto inO2NSMatch = matchesName("^::o2::");
4554

4655
// matches namespace declarations that have invalid name
4756
Finder->addMatcher(namespaceDecl(allOf(
57+
inO2NSMatch,
4858
unless(validNameMatch),
4959
unless(isAnonymous())
5060
)).bind("namespace-decl"), this);
5161
// matches usage of namespace
52-
Finder->addMatcher(nestedNameSpecifierLoc(loc(nestedNameSpecifier(specifiesNamespace(unless(validNameMatch)
53-
)))).bind("namespace-usage"), this );
62+
Finder->addMatcher(nestedNameSpecifierLoc(loc(nestedNameSpecifier(specifiesNamespace(allOf(
63+
inO2NSMatch,
64+
unless(validNameMatch)
65+
))))).bind("namespace-usage"), this);
5466
// matches "using namespace" declarations
55-
Finder->addMatcher(usingDirectiveDecl(unless(isImplicit()
56-
)).bind("using-namespace"), this);
67+
Finder->addMatcher(usingDirectiveDecl(allOf(
68+
unless(isImplicit()),
69+
nominatedNamespace(allOf(
70+
inO2NSMatch,
71+
unless(validNameMatch)
72+
)))).bind("using-namespace"), this);
5773
}
5874

5975
void NamespaceNamingCheck::check(const MatchFinder::MatchResult &Result) {
@@ -112,11 +128,6 @@ void NamespaceNamingCheck::check(const MatchFinder::MatchResult &Result) {
112128
std::string newName(MatchedUsingNamespace->getNominatedNamespace()->getDeclName().getAsString());
113129
std::string oldName=newName;
114130

115-
if( std::regex_match(newName, std::regex(VALID_NAME_REGEX)) )
116-
{
117-
return;
118-
}
119-
120131
if(fixNamespaceName(newName))
121132
{
122133
diag(MatchedUsingNamespace->getLocation(), "namespace %q0 does not follow the underscore convention")

0 commit comments

Comments
 (0)