Kaydet (Commit) b4e5b8bc authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Add compat::isInMainFile

Change-Id: I0e155c6c68a43020110a8e1c0cb29cabdcade454
üst 9db717d0
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "clang/AST/Type.h" #include "clang/AST/Type.h"
#include "clang/Basic/Diagnostic.h" #include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticIDs.h" #include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
...@@ -101,6 +102,16 @@ inline unsigned getBuiltinCallee(clang::CallExpr const & expr) { ...@@ -101,6 +102,16 @@ inline unsigned getBuiltinCallee(clang::CallExpr const & expr) {
#endif #endif
} }
inline bool isInMainFile(
clang::SourceManager const & manager, clang::SourceLocation Loc)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
return manager.isInMainFile(Loc);
#else
return manager.isFromMainFile(Loc);
#endif
}
inline unsigned getCustomDiagID( inline unsigned getCustomDiagID(
clang::DiagnosticsEngine & engine, clang::DiagnosticsEngine::Level L, clang::DiagnosticsEngine & engine, clang::DiagnosticsEngine::Level L,
llvm::StringRef FormatString) llvm::StringRef FormatString)
......
...@@ -151,17 +151,11 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -151,17 +151,11 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
bool LiteralToBoolConversion::isFromCIncludeFile( bool LiteralToBoolConversion::isFromCIncludeFile(
SourceLocation spellingLocation) const SourceLocation spellingLocation) const
{ {
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3 return !compat::isInMainFile(compiler.getSourceManager(), spellingLocation)
if (compiler.getSourceManager().isInMainFile(spellingLocation)) { && (StringRef(
return false; compiler.getSourceManager().getPresumedLoc(spellingLocation)
} .getFilename())
#else .endswith(".h"));
if (compiler.getSourceManager().isFromMainFile(spellingLocation)) {
return false;
}
#endif
return StringRef(compiler.getSourceManager().getPresumedLoc(spellingLocation)
.getFilename()).endswith(".h");
} }
bool LiteralToBoolConversion::isMacroBodyExpansion(SourceLocation location) bool LiteralToBoolConversion::isMacroBodyExpansion(SourceLocation location)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment