aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic-context-rich-location.h
blob: 676b9d23b05c76747f073c9f293f1684802fd884 (plain)
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
70
71
72
73
/* A rich_location subclass that lazily populates a diagnostic_path
   with diagnostic context events, but only if the path is actually to be
   used.
   Copyright (C) 2025 Free Software Foundation, Inc.
   Contributed by Qing Zhao<qing.zhao@oracle.com>

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

#ifndef GCC_DIAGNOSTIC_CONTEXT_RICH_LOCATION_H
#define GCC_DIAGNOSTIC_CONTEXT_RICH_LOCATION_H

#include "gcc-rich-location.h"
#include "diagnostics/lazy-paths.h"
#include "tree-logical-location.h"

class lazy_diagnostic_context_path : public diagnostics::paths::lazy_path
{
public:
  lazy_diagnostic_context_path (const tree_logical_location_manager
				&logical_loc_mgr,
				location_t location, gimple *stmt)
  : diagnostics::paths::lazy_path (logical_loc_mgr),
    m_logical_loc_mgr (logical_loc_mgr),
    m_location (location), m_stmt (stmt)
  {
  }

  std::unique_ptr<diagnostics::paths::path>
  make_inner_path () const final override;
  /* This method will be called on demand if a diagnostic is actually
     emitted for this rich_location.  */

  const tree_logical_location_manager &m_logical_loc_mgr;
  location_t m_location;
  gimple *m_stmt;
};

class rich_location_with_details : public gcc_rich_location
{
public:
  rich_location_with_details (location_t location, gimple *stmt)
  : gcc_rich_location (location),
    m_lazy_diagnostic_context_path (m_logical_loc_mgr, location, stmt)
  {
    set_path (&m_lazy_diagnostic_context_path);
  }

  rich_location_with_details (location_t location, tree exp ATTRIBUTE_UNUSED)
  : gcc_rich_location (location),
    m_lazy_diagnostic_context_path (m_logical_loc_mgr, location, nullptr)
  {
  }

private:
  const tree_logical_location_manager m_logical_loc_mgr;
  lazy_diagnostic_context_path m_lazy_diagnostic_context_path;
};

#endif // GCC_DIAGNOSTIC_CONTEXT_RICH_LOCATION_H