forked from facebook/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWarning.cpp
54 lines (46 loc) · 1.27 KB
/
Warning.cpp
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
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "Warning.h"
#include <cstdarg>
#include <cstdio>
OptWarningLevel g_warning_level = WARN_COUNT;
const char* s_warning_text[] = {
#define OPT_WARN(warn, str) str,
OPT_WARNINGS
#undef OPT_WARN
};
size_t s_warning_counts[] = {
#define OPT_WARN(...) 0,
OPT_WARNINGS
#undef OPT_WARN
};
constexpr size_t kNumWarnings =
sizeof(s_warning_counts) / sizeof(s_warning_counts[0]);
void opt_warn(OptWarning warn, const char* fmt, ...) {
++s_warning_counts[warn];
if (g_warning_level == WARN_FULL) {
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "%s: ", s_warning_text[warn]);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
}
void print_warning_summary() {
if (g_warning_level != WARN_COUNT) return;
for (size_t i = 0; i < kNumWarnings; i++) {
size_t count = s_warning_counts[i];
if (count > 0) {
fprintf(stderr,
"Optimization warning: %s: %lu occurrences\n",
s_warning_text[i],
count);
}
}
}