GCC Middle and Back End API Reference
lazy-diagnostic-path.h
Go to the documentation of this file.
1/* Helper class for deferring path creation until a diagnostic is emitted.
2 Copyright (C) 2024 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_LAZY_DIAGNOSTIC_PATH_H
22#define GCC_LAZY_DIAGNOSTIC_PATH_H
23
24#include "diagnostic-path.h"
25
26/* An implementation of diagnostic_path which has a trivial ctor
27 and lazily creates another diagnostic_path the first time the path
28 is queried, deferring to this inner path for all queries.
29
30 Use this to avoid expensive path creation logic when creating
31 rich_location instances, so that expense can be deferred until the path
32 is actually used by a diagnostic, and thus avoided for warnings that
33 are disabled. */
34
36{
37 public:
39
40 unsigned num_events () const final override;
41 const diagnostic_event & get_event (int idx) const final override;
42 unsigned num_threads () const final override;
43 const diagnostic_thread &
45 bool
46 same_function_p (int event_idx_a,
47 int event_idx_b) const final override;
48
49 bool generated_p () const { return m_inner_path != nullptr; }
50
51 private:
52 void lazily_generate_path () const;
53 virtual std::unique_ptr<diagnostic_path> make_inner_path () const = 0;
54
55 mutable std::unique_ptr<diagnostic_path> m_inner_path;
56};
57
58#endif /* ! GCC_LAZY_DIAGNOSTIC_PATH_H */
Definition diagnostic-path.h:70
Definition diagnostic-path.h:188
Definition diagnostic-path.h:179
Definition lazy-diagnostic-path.h:36
virtual std::unique_ptr< diagnostic_path > make_inner_path() const =0
unsigned num_threads() const final override
Definition lazy-diagnostic-path.cc:58
std::unique_ptr< diagnostic_path > m_inner_path
Definition lazy-diagnostic-path.h:55
unsigned num_events() const final override
Definition lazy-diagnostic-path.cc:44
void lazily_generate_path() const
Definition lazy-diagnostic-path.cc:80
const diagnostic_thread & get_thread(diagnostic_thread_id_t) const final override
Definition lazy-diagnostic-path.cc:65
bool generated_p() const
Definition lazy-diagnostic-path.h:49
const diagnostic_event & get_event(int idx) const final override
Definition lazy-diagnostic-path.cc:51
virtual ~lazy_diagnostic_path()
Definition lazy-diagnostic-path.h:38
bool same_function_p(int event_idx_a, int event_idx_b) const final override
Definition lazy-diagnostic-path.cc:72
int diagnostic_thread_id_t
Definition diagnostic-event-id.h:70
void final(rtx_insn *first, FILE *file, int optimize_p)
Definition final.cc:2004