]> sourceware.org Git - systemtap.git/commitdiff
semantic_error: let it own its chain
authorJonathan Lebon <jlebon@redhat.com>
Thu, 16 Jan 2014 22:07:03 +0000 (17:07 -0500)
committerJonathan Lebon <jlebon@redhat.com>
Wed, 22 Jan 2014 18:57:07 +0000 (13:57 -0500)
This patch simplifies the way semantic_error chains are used by allowing
the parent object to own its chain. Upon setting the chain, the parent
creates a copy and keeps it secret, to be de-allocated upon destruction.

The patch also modifies the semantic_error constructor to allow the
chain to be also set at the same time.

elaborate.cxx
session.cxx
staptree.cxx
staptree.h
tapsets.cxx

index 2e415b6674e2511cb255fc7af6501e095dd5e46a..537bb7d6d98119623f416b8a4f0fe6eb82feca3e 100644 (file)
@@ -1061,8 +1061,7 @@ derive_probes (systemtap_session& s,
             {
               // XXX: prefer not to print_error at every nest/unroll level
               semantic_error* er = new SEMANTIC_ERROR (_("while resolving probe point"),
-                                                       loc->components[0]->tok);
-              er->chain = & e;
+                                                       loc->components[0]->tok, NULL, &e);
               s.print_error (* er);
               delete er;
             }
@@ -5446,10 +5445,10 @@ typeresolution_info::mismatch (const token *tok, exp_type type,
         chain_msg << _F(" of index %d", index);
       chain_msg << _F(" was first inferred here (%s)",
                       lex_cast(decl->type).c_str());
-      err.chain = new SEMANTIC_ERROR(chain_msg.str(), original->tok);
+      semantic_error chain(ERR_SRC, chain_msg.str(), original->tok);
 
+      err.set_chain(chain);
       session.print_error (err);
-      if (err.chain) delete err.chain;
     }
   else if (!assert_resolvability)
     mismatch_complexity = max(3, mismatch_complexity);
index 074253b03a8543e4fab45a2b07a41a872082cc68..fa40c71afe2cd3834543d0484fa60b0d920c4e45 100644 (file)
@@ -1815,11 +1815,9 @@ systemtap_session::register_library_aliases()
             }
           catch (const semantic_error& e)
             {
-              semantic_error* er = new SEMANTIC_ERROR (_("while registering probe alias"),
-                                                       alias->tok);
-              er->chain = & e;
-              print_error (* er);
-              delete er;
+              semantic_error er(ERR_SRC, _("while registering probe alias"),
+                                alias->tok, NULL, &e);
+              print_error (er);
             }
        }
     }
@@ -1872,7 +1870,7 @@ systemtap_session::print_error (const semantic_error& se)
   if (verbose > 0 || seen_errors[se.errsrc_chain()] < 1)
     {
       seen_errors[se.errsrc_chain()]++;
-      for (const semantic_error *e = &se; e != NULL; e = e->chain)
+      for (const semantic_error *e = &se; e != NULL; e = e->get_chain())
         cerr << build_error_msg(*e);
     }
   else suppressed_errors++;
index c8aede4a729032b2d777733c0dab867ed69d372b..77bb7f03dbc3500aaf813e89eae95eb96c77dfa9 100644 (file)
@@ -169,10 +169,13 @@ vardecl::set_arity (int a, const token* t)
   if (arity != a && arity >= 0)
     {
       semantic_error err (ERR_SRC, _F("inconsistent arity (%s vs %d)",
-                             lex_cast(arity).c_str(), a), t?:tok);
+                                      lex_cast(arity).c_str(), a), t?:tok);
       if (arity_tok)
-       err.chain = new SEMANTIC_ERROR (_F("arity %s first inferred here",
+        {
+          semantic_error chain(ERR_SRC, _F("arity %s first inferred here",
                                            lex_cast(arity).c_str()), arity_tok);
+          err.set_chain(chain);
+        }
       throw err;
     }
 
@@ -276,8 +279,12 @@ void target_symbol::chain (const semantic_error &er)
   semantic_error* e = new semantic_error(er);
   if (!e->tok1)
     e->tok1 = this->tok;
-  assert (e->chain == 0);
-  e->chain = this->saved_conversion_error;
+  assert (e->get_chain() == 0);
+  if (this->saved_conversion_error)
+    {
+      e->set_chain(*this->saved_conversion_error);
+      delete this->saved_conversion_error;
+    }
   this->saved_conversion_error = e;
 }
 
index 3d263d567c4d4b64fad501f5547e2d9a14a0e7aa..032bb75495c8cd7a896c729b5e2aa9ddb8ec9b57 100644 (file)
@@ -32,22 +32,53 @@ struct semantic_error: public std::runtime_error
 {
   const token* tok1;
   const token* tok2;
-  const semantic_error *chain;
-  const std::string errsrc;
+  std::string errsrc;
 
-  ~semantic_error () throw () {}
+  ~semantic_error () throw ()
+    {
+      if (chain)
+        delete chain;
+    }
 
   semantic_error (const std::string& src, const std::string& msg, const token* t1=0):
-    runtime_error (msg), tok1 (t1), tok2 (0), chain (0), errsrc(src) {}
+    runtime_error (msg), tok1 (t1), tok2 (0), errsrc (src), chain (0) {}
 
   semantic_error (const std::string& src, const std::string& msg, const token* t1,
-                  const token* t2):
-    runtime_error (msg), tok1 (t1), tok2 (t2), chain (0), errsrc(src) {}
+                  const token* t2, const semantic_error* chn=0):
+      runtime_error (msg), tok1 (t1), tok2 (t2), errsrc (src), chain (0)
+    {
+      if (chn)
+        set_chain(*chn);
+    }
+
+  /* override copy-ctor to deep-copy chain */
+  semantic_error (const semantic_error& other):
+      runtime_error(other), tok1(other.tok1), tok2(other.tok2),
+      errsrc(other.errsrc), chain (0)
+    {
+      if (other.chain)
+        set_chain(*other.chain);
+    }
 
   std::string errsrc_chain(void) const
     {
       return errsrc + (chain ? "|" + chain->errsrc_chain() : "");
     }
+
+  void set_chain(const semantic_error& new_chain)
+    {
+      if (chain)
+        delete chain;
+      chain = new semantic_error(new_chain);
+    }
+
+  const semantic_error* get_chain(void) const
+    {
+      return chain;
+    }
+
+private:
+  const semantic_error* chain;
 };
 
 // ------------------------------------------------------------------------
index 85065933f141871ac31968ba1de6a4c62c276274..a34dd486b682576c0249d7f1251deb9a0733486e 100644 (file)
@@ -3698,7 +3698,7 @@ dwarf_var_expanding_visitor::visit_target_symbol_context (target_symbol* e)
                       {
                         for (const semantic_error *c = tsym->saved_conversion_error;
                              c != 0;
-                             c = c->chain) {
+                             c = c->get_chain()) {
                             clog << _("variable location problem [man error::dwarf]: ") << c->what() << endl;
                         }
                       }
@@ -9604,7 +9604,7 @@ tracepoint_var_expanding_visitor::visit_target_symbol_context (target_symbol* e)
             {
               if (dw.sess.verbose>2)
                 for (const semantic_error *c = tsym->saved_conversion_error;
-                     c != 0; c = c->chain)
+                     c != 0; c = c->get_chain())
                   clog << _("variable location problem [man error::dwarf]: ") << c->what() << endl;
               pf->raw_components += "=?";
               continue;
This page took 0.061327 seconds and 5 git commands to generate.