First part with introduction of auto_string_vec class.

Martin
>From c05ad6d3715fcc99e94dbe2fd3fa1ef94552bea4 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Mon, 14 May 2018 14:00:07 +0200
Subject: [PATCH 1/3] Introduce auto_string_vec class.

gcc/ChangeLog:

2018-05-14  Martin Liska  <mli...@suse.cz>

	* vec.h (class auto_string_vec): New (moved from auto_argvec).
	(auto_string_vec::~auto_string_vec): Likewise.

gcc/jit/ChangeLog:

2018-05-14  Martin Liska  <mli...@suse.cz>

	* jit-playback.c (class auto_argvec): Moved to vec.h.
	(auto_argvec::~auto_argvec): Likewise.
	(compile): Use the renamed name.
	(invoke_driver): Likewise.
---
 gcc/jit/jit-playback.c | 24 ++----------------------
 gcc/vec.h              | 39 +++++++++++++++++++++++++++------------
 2 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index 258ebe8ef86..01c4567de05 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -1749,26 +1749,6 @@ block (function *func,
   m_label_expr = NULL;
 }
 
-/* A subclass of auto_vec <char *> that frees all of its elements on
-   deletion.  */
-
-class auto_argvec : public auto_vec <char *>
-{
- public:
-  ~auto_argvec ();
-};
-
-/* auto_argvec's dtor, freeing all contained strings, automatically
-   chaining up to ~auto_vec <char *>, which frees the internal buffer.  */
-
-auto_argvec::~auto_argvec ()
-{
-  int i;
-  char *str;
-  FOR_EACH_VEC_ELT (*this, i, str)
-    free (str);
-}
-
 /* Compile a playback::context:
 
    - Use the context's options to cconstruct command-line options, and
@@ -1822,7 +1802,7 @@ compile ()
   /* Acquire the JIT mutex and set "this" as the active playback ctxt.  */
   acquire_mutex ();
 
-  auto_argvec fake_args;
+  auto_string_vec fake_args;
   make_fake_args (&fake_args, ctxt_progname, &requested_dumps);
   if (errors_occurred ())
     {
@@ -2440,7 +2420,7 @@ invoke_driver (const char *ctxt_progname,
   /* Currently this lumps together both assembling and linking into
      TV_ASSEMBLE.  */
   auto_timevar assemble_timevar (get_timer (), tv_id);
-  auto_argvec argvec;
+  auto_string_vec argvec;
 #define ADD_ARG(arg) argvec.safe_push (xstrdup (arg))
 
   ADD_ARG (gcc_driver_name);
diff --git a/gcc/vec.h b/gcc/vec.h
index 2d1f468ca1c..905985c41b0 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1447,19 +1447,11 @@ public:
   ~auto_vec () { this->release (); }
 };
 
-
-/* Allocate heap memory for pointer V and create the internal vector
-   with space for NELEMS elements.  If NELEMS is 0, the internal
-   vector is initialized to empty.  */
-
-template<typename T>
-inline void
-vec_alloc (vec<T> *&v, unsigned nelems CXX_MEM_STAT_INFO)
+class auto_string_vec : public auto_vec <char *>
 {
-  v = new vec<T>;
-  v->create (nelems PASS_MEM_STAT);
-}
-
+ public:
+  ~auto_string_vec ();
+};
 
 /* Conditionally allocate heap memory for VEC and its internal vector.  */
 
@@ -1553,6 +1545,29 @@ vec<T, va_heap, vl_ptr>::iterate (unsigned ix, T **ptr) const
        vec_safe_iterate ((V), (I), &(P));	\
        (I)--)
 
+/* auto_string_vec's dtor, freeing all contained strings, automatically
+   chaining up to ~auto_vec <char *>, which frees the internal buffer.  */
+
+inline
+auto_string_vec::~auto_string_vec ()
+{
+  int i;
+  char *str;
+  FOR_EACH_VEC_ELT (*this, i, str)
+    free (str);
+}
+
+/* Allocate heap memory for pointer V and create the internal vector
+   with space for NELEMS elements.  If NELEMS is 0, the internal
+   vector is initialized to empty.  */
+
+template<typename T>
+inline void
+vec_alloc (vec<T> *&v, unsigned nelems CXX_MEM_STAT_INFO)
+{
+  v = new vec<T>;
+  v->create (nelems PASS_MEM_STAT);
+}
 
 /* Return a copy of this vector.  */
 
-- 
2.16.3

Reply via email to