]> sourceware.org Git - systemtap.git/commitdiff
PR14927: move parser::print_error() to systemtap_session
authorJonathan Lebon <jlebon@redhat.com>
Mon, 24 Jun 2013 18:05:42 +0000 (14:05 -0400)
committerJonathan Lebon <jlebon@redhat.com>
Fri, 28 Jun 2013 14:26:59 +0000 (10:26 -0400)
The parser::print_error() method was moved from the parser class to the
systemtap_session class in anticipation for colorization. The session
class previously already took care of error printing, except for parser
errors. Making all the error-printing methods part of the same class
will simplify the implementation of colorization.

parse.cxx
parse.h
session.cxx
session.h

index c106b73b54f6ffc516707dbc774a3f801a78e4e7..eec5d255362d00b433dfd91c55bdbae4b9fcf52f 100644 (file)
--- a/parse.cxx
+++ b/parse.cxx
@@ -315,48 +315,8 @@ operator << (ostream& o, const token& t)
 void
 parser::print_error  (const parse_error &pe)
 {
-  string align_parse_error ("     ");
-
   const token *tok = pe.tok ? pe.tok : last_t;
-
-  // print either pe.what() or a deferred error from the lexer
-  bool found_junk = false;
-  if (tok && tok->type == tok_junk && tok->msg != "")
-    {
-      found_junk = true;
-      cerr << _("parse error: ") << tok->msg << endl;
-    }
-  else
-    {
-      cerr << _("parse error: ") << pe.what() << endl;      
-    }
-
-  // NB: It makes sense for lexer errors to always override parser
-  // errors, since the original obvious scheme was for the lexer to
-  // throw an exception before the token reached the parser.
-
-  if (pe.tok || found_junk)
-    {
-      cerr << _("\tat: ") << *tok << endl;
-      session.print_error_source (cerr, align_parse_error, tok);
-    }
-  else if (tok) // "expected" type error
-    {
-      cerr << _("\tsaw: ") << *tok << endl;
-      session.print_error_source (cerr, align_parse_error, tok);
-    }
-  else
-    {
-      cerr << _("\tsaw: ") << input_name << " EOF" << endl;
-    }
-
-  // print chained macro invocations
-  while (tok && tok->chain) {
-    tok = tok->chain;
-    cerr << _("\tin expansion of macro: ") << *tok << endl;
-    session.print_error_source (cerr, align_parse_error, tok);
-  }
-
+  session.print_error(pe, tok, input_name);
   num_errors ++;
 }
 
diff --git a/parse.h b/parse.h
index 7f8849a6b9e0eb13469f933675ccdcfb1d79bad4..801c4db35db525955735509f325701e38bb92db3 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -54,19 +54,6 @@ struct token
 std::ostream& operator << (std::ostream& o, const token& t);
 
 
-struct parse_error: public std::runtime_error
-{
-  const token* tok;
-  bool skip_some;
-  parse_error (const std::string& msg):
-    runtime_error (msg), tok (0), skip_some (true) {}
-  parse_error (const std::string& msg, const token* t):
-    runtime_error (msg), tok (t), skip_some (true) {}
-  parse_error (const std::string& msg, bool skip):
-    runtime_error (msg), tok (0), skip_some (skip) {}
-};
-
-
 typedef enum { ctx_library, ctx_local } macro_ctx;
 
 /* structs from session.h: */
index 87ba52a3603ada919c8eacc294253865adf0d2ce..9364e1071603073120b53461e4029438d364dd21 100644 (file)
@@ -1918,6 +1918,52 @@ systemtap_session::print_warning (const string& message_str, const token* tok)
     }
 }
 
+void
+systemtap_session::print_error (const parse_error &pe,
+                                const token* tok,
+                                const std::string &input_name)
+{
+  string align_parse_error ("     ");
+
+  // print either pe.what() or a deferred error from the lexer
+  bool found_junk = false;
+  if (tok && tok->type == tok_junk && tok->msg != "")
+    {
+      found_junk = true;
+      cerr << _("parse error: ") << tok->msg << endl;
+    }
+  else
+    {
+      cerr << _("parse error: ") << pe.what() << endl;
+    }
+
+  // NB: It makes sense for lexer errors to always override parser
+  // errors, since the original obvious scheme was for the lexer to
+  // throw an exception before the token reached the parser.
+
+  if (pe.tok || found_junk)
+    {
+      cerr << _("\tat: ") << *tok << endl;
+      print_error_source (cerr, align_parse_error, tok);
+    }
+  else if (tok) // "expected" type error
+    {
+      cerr << _("\tsaw: ") << *tok << endl;
+      print_error_source (cerr, align_parse_error, tok);
+    }
+  else
+    {
+      cerr << _("\tsaw: ") << input_name << " EOF" << endl;
+    }
+
+  // print chained macro invocations
+  while (tok && tok->chain) {
+    tok = tok->chain;
+    cerr << _("\tin expansion of macro: ") << *tok << endl;
+    print_error_source (cerr, align_parse_error, tok);
+  }
+}
+
 void
 systemtap_session::create_tmp_dir()
 {
index dd29db9c94a740c682b4adbc271ea0666495f915..952e938e73a08a349895205743cd2ff653edde40 100644 (file)
--- a/session.h
+++ b/session.h
@@ -90,6 +90,19 @@ struct statistic_decl
 
 struct macrodecl; // defined in parse.h
 
+struct parse_error: public std::runtime_error
+{
+  const token* tok;
+  bool skip_some;
+  parse_error (const std::string& msg):
+    runtime_error (msg), tok (0), skip_some (true) {}
+  parse_error (const std::string& msg, const token* t):
+    runtime_error (msg), tok (t), skip_some (true) {}
+  parse_error (const std::string& msg, bool skip):
+    runtime_error (msg), tok (0), skip_some (skip) {}
+};
+
+
 struct systemtap_session
 {
 private:
@@ -362,11 +375,13 @@ public:
 
   translator_output* op_create_auxiliary();
 
-  // void print_error (const parse_error& e);
   const token* last_token;
   void print_token (std::ostream& o, const token* tok);
   void print_error (const semantic_error& e);
   void print_error_source (std::ostream&, std::string&, const token* tok);
+  void print_error (const parse_error &pe,
+                       const token* tok,
+                       const std::string &input_name);
   void print_warning (const std::string& w, const token* tok = 0);
   void printscript(std::ostream& o);
 
This page took 0.045817 seconds and 5 git commands to generate.