diff options
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/include/rich-location.h | 31 | ||||
-rw-r--r-- | libcpp/line-map.cc | 28 |
2 files changed, 54 insertions, 5 deletions
diff --git a/libcpp/include/rich-location.h b/libcpp/include/rich-location.h index ae4886f..11c181e 100644 --- a/libcpp/include/rich-location.h +++ b/libcpp/include/rich-location.h @@ -91,6 +91,7 @@ class semi_embedded_vec public: semi_embedded_vec (); ~semi_embedded_vec (); + semi_embedded_vec (const semi_embedded_vec &other); unsigned int count () const { return m_num; } T& operator[] (int idx); @@ -115,6 +116,21 @@ semi_embedded_vec<T, NUM_EMBEDDED>::semi_embedded_vec () { } +/* Copy constructor for semi_embedded_vec. */ + +template <typename T, int NUM_EMBEDDED> +semi_embedded_vec<T, NUM_EMBEDDED>::semi_embedded_vec (const semi_embedded_vec &other) +: m_num (0), + m_alloc (other.m_alloc), + m_extra (nullptr) +{ + if (other.m_extra) + m_extra = XNEWVEC (T, m_alloc); + + for (int i = 0; i < other.m_num; i++) + push (other[i]); +} + /* semi_embedded_vec's dtor. Release any dynamically-allocated memory. */ template <typename T, int NUM_EMBEDDED> @@ -387,11 +403,10 @@ class rich_location /* Destructor. */ ~rich_location (); - /* The class manages the memory pointed to by the elements of - the M_FIXIT_HINTS vector and is not meant to be copied or - assigned. */ - rich_location (const rich_location &) = delete; - void operator= (const rich_location &) = delete; + rich_location (const rich_location &); + rich_location (rich_location &&) = delete; + rich_location &operator= (const rich_location &) = delete; + rich_location &operator= (rich_location &&) = delete; /* Accessors. */ location_t get_loc () const { return get_loc (0); } @@ -547,6 +562,8 @@ protected: mutable expanded_location m_expanded_location; + /* The class manages the memory pointed to by the elements of + the m_fixit_hints vector. */ static const int MAX_STATIC_FIXIT_HINTS = 2; semi_embedded_vec <fixit_hint *, MAX_STATIC_FIXIT_HINTS> m_fixit_hints; @@ -605,7 +622,11 @@ class fixit_hint fixit_hint (location_t start, location_t next_loc, const char *new_content); + fixit_hint (const fixit_hint &other); + fixit_hint (fixit_hint &&other) = delete; ~fixit_hint () { free (m_bytes); } + fixit_hint &operator= (const fixit_hint &) = delete; + fixit_hint &operator= (fixit_hint &&) = delete; bool affects_line_p (const line_maps *set, const char *file, diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc index 41aee98..05c4daf 100644 --- a/libcpp/line-map.cc +++ b/libcpp/line-map.cc @@ -2175,6 +2175,26 @@ rich_location::rich_location (line_maps *set, location_t loc, add_range (loc, SHOW_RANGE_WITH_CARET, label, label_highlight_color); } +/* Copy ctor for rich_location. + Take a deep copy of the fixit hints, which are owneed; + everything else is borrowed. */ + +rich_location::rich_location (const rich_location &other) +: m_line_table (other.m_line_table), + m_ranges (other.m_ranges), + m_column_override (other.m_column_override), + m_have_expanded_location (other.m_have_expanded_location), + m_seen_impossible_fixit (other.m_seen_impossible_fixit), + m_fixits_cannot_be_auto_applied (other.m_fixits_cannot_be_auto_applied), + m_escape_on_output (other.m_escape_on_output), + m_expanded_location (other.m_expanded_location), + m_fixit_hints (), + m_path (other.m_path) +{ + for (unsigned i = 0; i < other.m_fixit_hints.count (); i++) + m_fixit_hints.push (new fixit_hint (*other.m_fixit_hints[i])); +} + /* The destructor for class rich_location. */ rich_location::~rich_location () @@ -2595,6 +2615,14 @@ fixit_hint::fixit_hint (location_t start, { } +fixit_hint::fixit_hint (const fixit_hint &other) +: m_start (other.m_start), + m_next_loc (other.m_next_loc), + m_bytes (xstrdup (other.m_bytes)), + m_len (other.m_len) +{ +} + /* Does this fix-it hint affect the given line? */ bool |