2016-02-05 19:23:59 +08:00
|
|
|
//===--- HeaderFileExtensionsUtils.cpp - clang-tidy--------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "HeaderFileExtensionsUtils.h"
|
|
|
|
#include "clang/Basic/CharInfo.h"
|
2016-05-16 22:34:20 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2016-02-05 19:23:59 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace utils {
|
|
|
|
|
|
|
|
bool isExpansionLocInHeaderFile(
|
|
|
|
SourceLocation Loc, const SourceManager &SM,
|
|
|
|
const HeaderFileExtensionsSet &HeaderFileExtensions) {
|
|
|
|
SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
|
2016-08-26 19:15:38 +08:00
|
|
|
return isHeaderFileExtension(SM.getFilename(ExpansionLoc),
|
|
|
|
HeaderFileExtensions);
|
2016-02-05 19:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isPresumedLocInHeaderFile(
|
|
|
|
SourceLocation Loc, SourceManager &SM,
|
|
|
|
const HeaderFileExtensionsSet &HeaderFileExtensions) {
|
|
|
|
PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
|
2016-08-26 19:15:38 +08:00
|
|
|
return isHeaderFileExtension(PresumedLocation.getFilename(),
|
|
|
|
HeaderFileExtensions);
|
2016-02-05 19:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isSpellingLocInHeaderFile(
|
|
|
|
SourceLocation Loc, SourceManager &SM,
|
|
|
|
const HeaderFileExtensionsSet &HeaderFileExtensions) {
|
|
|
|
SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
|
2016-08-26 19:15:38 +08:00
|
|
|
return isHeaderFileExtension(SM.getFilename(SpellingLoc),
|
|
|
|
HeaderFileExtensions);
|
2016-02-05 19:23:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool parseHeaderFileExtensions(StringRef AllHeaderFileExtensions,
|
|
|
|
HeaderFileExtensionsSet &HeaderFileExtensions,
|
|
|
|
char delimiter) {
|
|
|
|
SmallVector<StringRef, 5> Suffixes;
|
|
|
|
AllHeaderFileExtensions.split(Suffixes, delimiter);
|
|
|
|
HeaderFileExtensions.clear();
|
|
|
|
for (StringRef Suffix : Suffixes) {
|
|
|
|
StringRef Extension = Suffix.trim();
|
|
|
|
for (StringRef::const_iterator it = Extension.begin();
|
|
|
|
it != Extension.end(); ++it) {
|
|
|
|
if (!isAlphanumeric(*it))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
HeaderFileExtensions.insert(Extension);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:15:38 +08:00
|
|
|
bool isHeaderFileExtension(
|
|
|
|
StringRef FileName, const HeaderFileExtensionsSet &HeaderFileExtensions) {
|
|
|
|
StringRef extension = llvm::sys::path::extension(FileName);
|
|
|
|
if (extension.empty())
|
|
|
|
return false;
|
|
|
|
// Skip "." prefix.
|
|
|
|
return HeaderFileExtensions.count(extension.substr(1)) > 0;
|
2016-08-26 13:59:53 +08:00
|
|
|
}
|
|
|
|
|
2016-02-05 19:23:59 +08:00
|
|
|
} // namespace utils
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|