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);
|
|
|
|
StringRef FileExtension =
|
|
|
|
llvm::sys::path::extension(SM.getFilename(ExpansionLoc));
|
|
|
|
return HeaderFileExtensions.count(FileExtension.substr(1)) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPresumedLocInHeaderFile(
|
|
|
|
SourceLocation Loc, SourceManager &SM,
|
|
|
|
const HeaderFileExtensionsSet &HeaderFileExtensions) {
|
|
|
|
PresumedLoc PresumedLocation = SM.getPresumedLoc(Loc);
|
|
|
|
StringRef FileExtension =
|
|
|
|
llvm::sys::path::extension(PresumedLocation.getFilename());
|
|
|
|
return HeaderFileExtensions.count(FileExtension.substr(1)) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSpellingLocInHeaderFile(
|
|
|
|
SourceLocation Loc, SourceManager &SM,
|
|
|
|
const HeaderFileExtensionsSet &HeaderFileExtensions) {
|
|
|
|
SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
|
|
|
|
StringRef FileExtension =
|
|
|
|
llvm::sys::path::extension(SM.getFilename(SpellingLoc));
|
|
|
|
|
|
|
|
return HeaderFileExtensions.count(FileExtension.substr(1)) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace utils
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|