aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/include/line-map.h31
2 files changed, 34 insertions, 4 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index f4376e6..2090bd7 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2019-12-09 David Malcolm <dmalcolm@redhat.com>
+
+ * include/line-map.h (label_text::label_text): Make private.
+ (label_text::borrow): New.
+ (label_text::take): New.
+ (label_text::take_or_copy): New.
+
2019-12-09 Lewis Hyatt <lhyatt@gmail.com>
PR preprocessor/49973
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 6f4cf5b..e78249f 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1764,18 +1764,41 @@ public:
: m_buffer (NULL), m_caller_owned (false)
{}
- label_text (char *buffer, bool caller_owned)
- : m_buffer (buffer), m_caller_owned (caller_owned)
- {}
-
void maybe_free ()
{
if (m_caller_owned)
free (m_buffer);
}
+ /* Create a label_text instance that borrows BUFFER from a
+ longer-lived owner. */
+ static label_text borrow (const char *buffer)
+ {
+ return label_text (const_cast <char *> (buffer), false);
+ }
+
+ /* Create a label_text instance that takes ownership of BUFFER. */
+ static label_text take (char *buffer)
+ {
+ return label_text (buffer, true);
+ }
+
+ /* Take ownership of the buffer, copying if necessary. */
+ char *take_or_copy ()
+ {
+ if (m_caller_owned)
+ return m_buffer;
+ else
+ return xstrdup (m_buffer);
+ }
+
char *m_buffer;
bool m_caller_owned;
+
+private:
+ label_text (char *buffer, bool owned)
+ : m_buffer (buffer), m_caller_owned (owned)
+ {}
};
/* Abstract base class for labelling a range within a rich_location