2019-12-27 20:52:37 +00:00
|
|
|
//===--- iwyu_port.h - OS/cpu specific stuff for include-what-you-use -----===//
|
2011-02-08 06:12:32 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Source file for architecture-specific logic.
|
|
|
|
|
2016-05-22 09:06:36 +01:00
|
|
|
#ifndef INCLUDE_WHAT_YOU_USE_PORT_H_
|
|
|
|
#define INCLUDE_WHAT_YOU_USE_PORT_H_
|
2011-02-08 06:12:32 +00:00
|
|
|
|
2016-06-02 00:43:00 +01:00
|
|
|
#include <cstdlib> // for abort
|
2013-12-31 15:38:47 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2019-12-26 12:10:39 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-09-20 23:12:17 +01:00
|
|
|
|
2013-02-15 06:04:44 +00:00
|
|
|
// Count of statically allocated array.
|
|
|
|
#define IWYU_ARRAYSIZE(arr) sizeof(arr) / sizeof(*arr)
|
|
|
|
|
2011-09-20 23:12:17 +01:00
|
|
|
namespace include_what_you_use {
|
|
|
|
|
|
|
|
// Helper class that allows programmers to log extra information in CHECK_s.
|
|
|
|
class FatalMessageEmitter {
|
|
|
|
public:
|
|
|
|
FatalMessageEmitter(const char* file, int line, const char* message) {
|
|
|
|
stream() << file << ":" << line << ": Assertion failed: " << message;
|
|
|
|
}
|
2021-08-06 11:37:44 +01:00
|
|
|
[[noreturn]] ~FatalMessageEmitter() {
|
2019-12-26 12:10:39 +00:00
|
|
|
stream() << "\n";
|
2011-09-20 23:12:17 +01:00
|
|
|
::abort();
|
2013-12-31 15:38:47 +00:00
|
|
|
#ifdef LLVM_BUILTIN_UNREACHABLE
|
|
|
|
// Windows systems and possibly others don't declare abort() to be noreturn,
|
|
|
|
// so use the unreachable builtin to avoid a Clang self-host warning.
|
|
|
|
LLVM_BUILTIN_UNREACHABLE;
|
|
|
|
#endif
|
2011-09-20 23:12:17 +01:00
|
|
|
}
|
2023-01-03 21:55:12 +00:00
|
|
|
llvm::raw_ostream& stream() {
|
|
|
|
return llvm::errs();
|
|
|
|
}
|
2011-09-20 23:12:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helper class that allows an ostream to 'appear' as a void expression.
|
|
|
|
class OstreamVoidifier {
|
|
|
|
public:
|
|
|
|
// This has to be an operator with a precedence lower than << but
|
|
|
|
// higher than ?:
|
2019-12-26 12:10:39 +00:00
|
|
|
void operator&(llvm::raw_ostream&) {}
|
2011-09-20 23:12:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace include_what_you_use
|
|
|
|
|
|
|
|
// Usage: CHECK_(condition) << extra << information;
|
2019-12-26 12:10:39 +00:00
|
|
|
// The file, line, condition and extra information will be printed to stderr,
|
2011-09-20 23:12:17 +01:00
|
|
|
// then the program will abort.
|
|
|
|
#define CHECK_(x) (x) ? (void)0 : \
|
|
|
|
::include_what_you_use::OstreamVoidifier() & \
|
|
|
|
::include_what_you_use::FatalMessageEmitter( \
|
|
|
|
__FILE__, __LINE__, #x).stream()
|
2013-12-31 15:38:47 +00:00
|
|
|
// Instead of CHECK_(false && "message") use CHECK_UNREACHABLE_("message").
|
|
|
|
#define CHECK_UNREACHABLE_(message) \
|
|
|
|
::include_what_you_use::OstreamVoidifier() & \
|
|
|
|
::include_what_you_use::FatalMessageEmitter( \
|
|
|
|
__FILE__, __LINE__, message).stream()
|
2011-03-04 00:29:56 +00:00
|
|
|
|
2012-07-15 09:54:54 +01:00
|
|
|
#if defined(_WIN32)
|
2011-02-08 06:12:32 +00:00
|
|
|
|
2018-01-30 06:13:44 +00:00
|
|
|
#define NOMINMAX 1 // Prevent Windows headers from redefining min/max.
|
2016-07-10 15:20:48 +01:00
|
|
|
#include "Shlwapi.h" // for PathMatchSpecA
|
2011-02-08 06:12:32 +00:00
|
|
|
|
2013-03-19 20:53:26 +00:00
|
|
|
// This undef is necessary to prevent conflicts between llvm
|
|
|
|
// and Windows headers.
|
|
|
|
// objbase.h has #define interface struct.
|
|
|
|
#undef interface
|
2011-05-04 19:30:53 +01:00
|
|
|
|
2011-05-25 00:12:28 +01:00
|
|
|
inline bool GlobMatchesPath(const char *glob, const char *path) {
|
2016-07-10 15:20:48 +01:00
|
|
|
return PathMatchSpecA(path, glob);
|
2011-05-13 00:10:38 +01:00
|
|
|
}
|
2011-02-08 06:12:32 +00:00
|
|
|
|
2012-07-15 09:54:54 +01:00
|
|
|
#else // #if defined(_WIN32)
|
2011-05-13 00:10:38 +01:00
|
|
|
|
2011-05-25 00:12:28 +01:00
|
|
|
#include <fnmatch.h>
|
|
|
|
|
|
|
|
inline bool GlobMatchesPath(const char *glob, const char *path) {
|
2019-11-17 19:16:43 +00:00
|
|
|
return fnmatch(glob, path, 0) == 0;
|
2011-05-25 00:12:28 +01:00
|
|
|
}
|
2011-05-13 00:10:38 +01:00
|
|
|
|
2012-07-15 09:54:54 +01:00
|
|
|
#endif // #if defined(_WIN32)
|
2011-02-08 06:12:32 +00:00
|
|
|
|
2016-05-22 09:06:36 +01:00
|
|
|
#endif // INCLUDE_WHAT_YOU_USE_PORT_H_
|