forked from include-what-you-use/include-what-you-use
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iwyu_port.h
69 lines (58 loc) · 2.25 KB
/
iwyu_port.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//===--- iwyu_port.h - OS/cpu specific stuff for include-what-you-use -----===//
//
// 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.
#ifndef INCLUDE_WHAT_YOU_USE_PORT_H_
#define INCLUDE_WHAT_YOU_USE_PORT_H_
#include <cstdlib> // for abort
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
// Count of statically allocated array.
#define IWYU_ARRAYSIZE(arr) sizeof(arr) / sizeof(*arr)
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;
}
[[noreturn]] ~FatalMessageEmitter() {
stream() << "\n";
::abort();
#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
}
llvm::raw_ostream& stream() {
return llvm::errs();
}
};
// 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 ?:
void operator&(llvm::raw_ostream&) {}
};
} // namespace include_what_you_use
// Usage: CHECK_(condition) << extra << information;
// The file, line, condition and extra information will be printed to stderr,
// 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()
// 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()
bool GlobMatchesPath(const char *glob, const char *path);
#endif // INCLUDE_WHAT_YOU_USE_PORT_H_