aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-07-13 11:58:05 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-07-15 09:40:47 +0100
commitf858fe7a8b250995bc5b0d18720a2ceb6815622d (patch)
tree25d0bc8282256c6407fa5474dfbe54a7cbdab7be /libcpp
parentae69e6f61b93dcb5b1e7ef609431f100c1b9b2e5 (diff)
downloadgcc-f858fe7a8b250995bc5b0d18720a2ceb6815622d.zip
gcc-f858fe7a8b250995bc5b0d18720a2ceb6815622d.tar.gz
gcc-f858fe7a8b250995bc5b0d18720a2ceb6815622d.tar.bz2
libcpp: Improve encapsulation of label_text
This adjusts the API of label_text so that the data members are private and cannot be modified by callers. Add accessors for them instead, and make the accessors const-correct. Also rename moved_from () to the more idiomatic release (). Also remove the unused take_or_copy () member function which has confusing ownership semantics. gcc/analyzer/ChangeLog: * call-info.cc (call_info::print): Adjust to new label_text API. * checker-path.cc (checker_event::dump): Likewise. (region_creation_event::get_desc): Likewise. (state_change_event::get_desc): Likewise. (superedge_event::should_filter_p): Likewise. (start_cfg_edge_event::get_desc): Likewise. (call_event::get_desc): Likewise. (return_event::get_desc): Likewise. (warning_event::get_desc): Likewise. (checker_path::dump): Likewise. (checker_path::debug): Likewise. * diagnostic-manager.cc (diagnostic_manager::prune_for_sm_diagnostic): Likewise. (diagnostic_manager::prune_interproc_events): Likewise. * engine.cc (feasibility_state::maybe_update_for_edge): Likewise. * program-state.cc (sm_state_map::to_json): Likewise. * region-model-impl-calls.cc (region_model::impl_call_analyzer_describe): Likewise. (region_model::impl_call_analyzer_dump_capacity): Likewise. * region.cc (region::to_json): Likewise. * sm-malloc.cc (inform_nonnull_attribute): Likewise. * store.cc (binding_map::to_json): Likewise. (store::to_json): Likewise. * supergraph.cc (superedge::dump): Likewise. * svalue.cc (svalue::to_json): Likewise. gcc/c-family/ChangeLog: * c-format.cc (class range_label_for_format_type_mismatch): Adjust to new label_text API. gcc/ChangeLog: * diagnostic-format-json.cc (json_from_location_range): Adjust to new label_text API. * diagnostic-format-sarif.cc (sarif_builder::make_location_object): Likewise. * diagnostic-show-locus.cc (struct pod_label_text): Likewise. (layout::print_any_labels): Likewise. * tree-diagnostic-path.cc (class path_label): Likewise. (struct event_range): Likewise. (default_tree_diagnostic_path_printer): Likewise. (default_tree_make_json_for_path): Likewise. libcpp/ChangeLog: * include/line-map.h (label_text::take_or_copy): Remove. (label_text::moved_from): Rename to release. (label_text::m_buffer, label_text::m_owned): Make private. (label_text::get, label_text::is_owned): New accessors.
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/include/line-map.h25
1 files changed, 13 insertions, 12 deletions
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index c434a24..9bdd5b9 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1851,7 +1851,7 @@ public:
label_text (label_text &&other)
: m_buffer (other.m_buffer), m_owned (other.m_owned)
{
- other.moved_from ();
+ other.release ();
}
/* Move assignment. */
@@ -1861,7 +1861,7 @@ public:
free (m_buffer);
m_buffer = other.m_buffer;
m_owned = other.m_owned;
- other.moved_from ();
+ other.release ();
return *this;
}
@@ -1882,25 +1882,26 @@ public:
return label_text (buffer, true);
}
- /* Take ownership of the buffer, copying if necessary. */
- char *take_or_copy ()
+ void release ()
{
- if (m_owned)
- return m_buffer;
- else
- return xstrdup (m_buffer);
+ m_buffer = NULL;
+ m_owned = false;
}
- void moved_from ()
+ const char *get () const
{
- m_buffer = NULL;
- m_owned = false;
+ return m_buffer;
}
+ bool is_owner () const
+ {
+ return m_owned;
+ }
+
+private:
char *m_buffer;
bool m_owned;
-private:
label_text (char *buffer, bool owned)
: m_buffer (buffer), m_owned (owned)
{}