Branch data Line data Source code
1 : : /* A rich_location subclass that lazily populates a diagnostic_path
2 : : with diagnostic context events, but only if the path is actually to be
3 : : used.
4 : : Copyright (C) 2025 Free Software Foundation, Inc.
5 : : Contributed by Qing Zhao<qing.zhao@oracle.com>
6 : :
7 : : This file is part of GCC.
8 : :
9 : : GCC is free software; you can redistribute it and/or modify it under
10 : : the terms of the GNU General Public License as published by the Free
11 : : Software Foundation; either version 3, or (at your option) any later
12 : : version.
13 : :
14 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 : : for more details.
18 : :
19 : : You should have received a copy of the GNU General Public License
20 : : along with GCC; see the file COPYING3. If not see
21 : : <http://www.gnu.org/licenses/>. */
22 : :
23 : : #ifndef GCC_DIAGNOSTIC_CONTEXT_RICH_LOCATION_H
24 : : #define GCC_DIAGNOSTIC_CONTEXT_RICH_LOCATION_H
25 : :
26 : : #include "gcc-rich-location.h"
27 : : #include "diagnostics/lazy-paths.h"
28 : : #include "tree-logical-location.h"
29 : :
30 : : class lazy_diagnostic_context_path : public diagnostics::paths::lazy_path
31 : : {
32 : : public:
33 : 847110 : lazy_diagnostic_context_path (const tree_logical_location_manager
34 : : &logical_loc_mgr,
35 : : location_t location, gimple *stmt)
36 : 847110 : : diagnostics::paths::lazy_path (logical_loc_mgr),
37 : 842930 : m_logical_loc_mgr (logical_loc_mgr),
38 : 847110 : m_location (location), m_stmt (stmt)
39 : : {
40 : : }
41 : :
42 : : std::unique_ptr<diagnostics::paths::path>
43 : : make_inner_path () const final override;
44 : : /* This method will be called on demand if a diagnostic is actually
45 : : emitted for this rich_location. */
46 : :
47 : : const tree_logical_location_manager &m_logical_loc_mgr;
48 : : location_t m_location;
49 : : gimple *m_stmt;
50 : : };
51 : :
52 : : class rich_location_with_details : public gcc_rich_location
53 : : {
54 : : public:
55 : 846357 : rich_location_with_details (location_t location, gimple *stmt)
56 : 846357 : : gcc_rich_location (location),
57 : 846357 : m_lazy_diagnostic_context_path (m_logical_loc_mgr, location, stmt)
58 : : {
59 : 846357 : set_path (&m_lazy_diagnostic_context_path);
60 : : }
61 : :
62 : 753 : rich_location_with_details (location_t location, tree exp ATTRIBUTE_UNUSED)
63 : 753 : : gcc_rich_location (location),
64 : 753 : m_lazy_diagnostic_context_path (m_logical_loc_mgr, location, nullptr)
65 : : {
66 : : }
67 : :
68 : : private:
69 : : const tree_logical_location_manager m_logical_loc_mgr;
70 : : lazy_diagnostic_context_path m_lazy_diagnostic_context_path;
71 : : };
72 : :
73 : : #endif // GCC_DIAGNOSTIC_CONTEXT_RICH_LOCATION_H
|