Daily bump.
[official-gcc.git] / gcc / analyzer / pending-diagnostic.cc
blobadff25130fd4709f1afbf1ba439a0ad31f270046
1 /* Classes for analyzer diagnostics.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "intl.h"
26 #include "diagnostic.h"
27 #include "function.h"
28 #include "json.h"
29 #include "analyzer/analyzer.h"
30 #include "diagnostic-event-id.h"
31 #include "analyzer/analyzer-logging.h"
32 #include "analyzer/sm.h"
33 #include "diagnostic-event-id.h"
34 #include "analyzer/sm.h"
35 #include "analyzer/pending-diagnostic.h"
37 #if ENABLE_ANALYZER
39 namespace ana {
41 /* Generate a label_text by printing FMT.
43 Use a clone of the global_dc for formatting callbacks.
45 Use this evdesc::event_desc's m_colorize flag to control colorization
46 (so that e.g. we can disable it for JSON output). */
48 label_text
49 evdesc::event_desc::formatted_print (const char *fmt, ...) const
51 pretty_printer *pp = global_dc->printer->clone ();
53 pp_show_color (pp) = m_colorize;
55 text_info ti;
56 rich_location rich_loc (line_table, UNKNOWN_LOCATION);
57 va_list ap;
58 va_start (ap, fmt);
59 ti.format_spec = _(fmt);
60 ti.args_ptr = &ap;
61 ti.err_no = 0;
62 ti.x_data = NULL;
63 ti.m_richloc = &rich_loc;
64 pp_format (pp, &ti);
65 pp_output_formatted_text (pp);
66 va_end (ap);
68 label_text result = label_text::take (xstrdup (pp_formatted_text (pp)));
69 delete pp;
70 return result;
73 /* Return true if T1 and T2 are "the same" for the purposes of
74 diagnostic deduplication. */
76 bool
77 pending_diagnostic::same_tree_p (tree t1, tree t2)
79 return simple_cst_equal (t1, t2) == 1;
82 } // namespace ana
84 #endif /* #if ENABLE_ANALYZER */