GCC Middle and Back End API Reference
lazy-paths.h
Go to the documentation of this file.
1/* Helper class for deferring path creation until a diagnostic is emitted.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_DIAGNOSTICS_LAZY_PATHS_H
22#define GCC_DIAGNOSTICS_LAZY_PATHS_H
23
24#include "diagnostics/paths.h"
25
26namespace diagnostics {
27namespace paths {
28
29/* An implementation of diagnostics::paths::path which has a trivial ctor
30 and lazily creates another path the first time the path
31 is queried, deferring to this inner path for all queries.
32
33 Use this to avoid expensive path creation logic when creating
34 rich_location instances, so that expense can be deferred until the path
35 is actually used by a diagnostic, and thus avoided for warnings that
36 are disabled. */
37
38class lazy_path : public path
39{
40 public:
41 virtual ~lazy_path () {}
42
43 unsigned num_events () const final override;
44 const event & get_event (int idx) const final override;
45 unsigned num_threads () const final override;
46 const thread &
47 get_thread (thread_id_t) const final override;
48 bool
49 same_function_p (int event_idx_a,
50 int event_idx_b) const final override;
51
52 bool generated_p () const { return m_inner_path != nullptr; }
53
54protected:
55 lazy_path (const logical_locations::manager &logical_loc_mgr)
56 : path (logical_loc_mgr)
57 {
58 }
59
60 private:
61 void lazily_generate_path () const;
62 virtual std::unique_ptr<path> make_inner_path () const = 0;
63
64 mutable std::unique_ptr<path> m_inner_path;
65};
66
67} // namespace paths
68} // namespace diagnostics
69
70#endif /* ! GCC_DIAGNOSTICS_LAZY_PATHS_H */
Definition logical-locations.h:147
Definition paths.h:83
virtual ~lazy_path()
Definition lazy-paths.h:41
bool generated_p() const
Definition lazy-paths.h:52
unsigned num_events() const final override
Definition lazy-paths.cc:41
const thread & get_thread(thread_id_t) const final override
Definition lazy-paths.cc:62
void lazily_generate_path() const
Definition lazy-paths.cc:77
lazy_path(const logical_locations::manager &logical_loc_mgr)
Definition lazy-paths.h:55
virtual std::unique_ptr< path > make_inner_path() const =0
const event & get_event(int idx) const final override
Definition lazy-paths.cc:48
unsigned num_threads() const final override
Definition lazy-paths.cc:55
std::unique_ptr< path > m_inner_path
Definition lazy-paths.h:64
bool same_function_p(int event_idx_a, int event_idx_b) const final override
Definition lazy-paths.cc:69
path(const logical_locations::manager &logical_loc_mgr)
Definition paths.h:231
Definition paths.h:198
void final(rtx_insn *first, FILE *file, int optimize_p)
Definition final.cc:2009
Definition event-id.h:64
int thread_id_t
Definition event-id.h:71
Definition coretypes.h:167