From 72dbc9153036800cefdb5f2970666acc82cdb732 Mon Sep 17 00:00:00 2001 From: fche Date: Wed, 8 Nov 2006 17:51:32 +0000 Subject: 2006-11-08 Frank Ch. Eigler * util.h (lex_cast_qstring): Move def'n here. Also quote \. (stringify, lex_cast, lex_cast_hex): Move defn here. * buildrun.cxx, elaborate.cxx, main.cxx, staptree.cxx: Adapt. --- ChangeLog | 6 ++++++ buildrun.cxx | 33 +---------------------------- elaborate.cxx | 12 +---------- main.cxx | 12 ----------- staptree.cxx | 33 ++--------------------------- tapsets.cxx | 45 +-------------------------------------- translate.cxx | 39 ++++++---------------------------- util.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 8 files changed, 80 insertions(+), 167 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e051548..1b39027f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-11-08 Frank Ch. Eigler + + * util.h (lex_cast_qstring): Move def'n here. Also quote \. + (stringify, lex_cast, lex_cast_hex): Move defn here. + * buildrun.cxx, elaborate.cxx, main.cxx, staptree.cxx: Adapt. + 2006-11-07 Frank Ch. Eigler * tapsets.cxx (profile_derived_probe_group::emit_module_decls): diff --git a/buildrun.cxx b/buildrun.cxx index 969ba352..3673a9b0 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -9,6 +9,7 @@ #include "config.h" #include "buildrun.h" #include "session.h" +#include "util.h" #include #include @@ -28,38 +29,6 @@ extern "C" { using namespace std; -// return as quoted string, with at least '"' backslash-escaped -template inline string -lex_cast_qstring(IN const & in) -{ - stringstream ss; - string out, out2; - if (!(ss << in)) - throw runtime_error("bad lexical cast"); - out = ss.str(); - out2 += '"'; - for (unsigned i=0; i -static string -stringify(T t) -{ - ostringstream s; - s << t; - return s.str (); -} - - - int compile_pass (systemtap_session& s) { diff --git a/elaborate.cxx b/elaborate.cxx index c532d0b0..06ddaf36 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -11,6 +11,7 @@ #include "parse.h" #include "tapsets.h" #include "session.h" +#include "util.h" extern "C" { #include @@ -30,17 +31,6 @@ extern "C" { using namespace std; -template inline OUT -lex_cast(IN const & in) -{ - stringstream ss; - OUT out; - if (!(ss << in && ss >> out)) - throw runtime_error("bad lexical cast"); - return out; -} - - // ------------------------------------------------------------------------ diff --git a/main.cxx b/main.cxx index 88c55cc2..e7f5d7da 100644 --- a/main.cxx +++ b/main.cxx @@ -104,18 +104,6 @@ usage (systemtap_session& s, int exitcode) } -// little utility function - -template -static string -stringify(T t) -{ - ostringstream s; - s << t; - return s.str (); -} - - static void printscript(systemtap_session& s, ostream& o) { diff --git a/staptree.cxx b/staptree.cxx index fdfc516c..1656f64a 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -9,6 +9,8 @@ #include "config.h" #include "staptree.h" #include "parse.h" +#include "util.h" + #include #include #include @@ -17,37 +19,6 @@ using namespace std; -// return as quoted string, with at least '"' backslash-escaped -template inline string -lex_cast_qstring(IN const & in) -{ - stringstream ss; - string out, out2; - if (!(ss << in)) - throw runtime_error("bad lexical cast"); - out = ss.str(); - out2 += '"'; - for (unsigned i=0; i inline OUT -lex_cast(IN const & in) -{ - stringstream ss; - OUT out; - if (!(ss << in && ss >> out)) - throw runtime_error("bad lexical cast"); - return out; -} - expression::expression (): type (pe_unknown), tok (0) diff --git a/tapsets.cxx b/tapsets.cxx index 3de3e5bd..9d0b7ebc 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -13,6 +13,7 @@ #include "tapsets.h" #include "translate.h" #include "session.h" +#include "util.h" #include #include @@ -50,50 +51,6 @@ extern "C" { using namespace std; -// XXX: should standardize to these functions throughout translator - -template inline OUT -lex_cast(IN const & in) -{ - stringstream ss; - OUT out; - if (!(ss << in && ss >> out)) - throw runtime_error("bad lexical cast"); - return out; -} - -template inline OUT -lex_cast_hex(IN const & in) -{ - stringstream ss; - OUT out; - if (!(ss << hex << showbase << in && ss >> out)) - throw runtime_error("bad lexical cast"); - return out; -} - - -// return as quoted string, with at least '"' backslash-escaped -template inline string -lex_cast_qstring(IN const & in) -{ - stringstream ss; - string out, out2; - if (!(ss << in)) - throw runtime_error("bad lexical cast"); - out = ss.str(); - out2 += '"'; - for (unsigned i=0; i #include @@ -22,39 +23,6 @@ using namespace std; - -// little utility function - -template -static string -stringify(T t) -{ - ostringstream s; - s << t; - return s.str (); -} - -// return as quoted string, with at least '"' backslash-escaped -template inline string -lex_cast_qstring(IN const & in) -{ - stringstream ss; - string out, out2; - if (!(ss << in)) - throw runtime_error("bad lexical cast"); - out = ss.str(); - out2 += '"'; - for (unsigned i=0; ivalue; o->line() << '"'; for (unsigned i=0; iline() << '\\' << '"'; else diff --git a/util.h b/util.h index 01f254c7..2c8848bb 100644 --- a/util.h +++ b/util.h @@ -1,13 +1,72 @@ #include #include +#include +#include +#include -const char *get_home_directory(void); +const char *get_home_directory(void); int copy_file(const char *src, const char *dest); - int create_dir(const char *dir); - void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters); - bool find_executable(const char *name, std::string& retpath); + + +// stringification generics + + +template +inline std::string +stringify(T t) +{ + std::ostringstream s; + s << t; + return s.str (); +} + + +template +inline OUT lex_cast(IN const & in) +{ + std::stringstream ss; + OUT out; + if (!(ss << in && ss >> out)) + throw std::runtime_error("bad lexical cast"); + return out; +} + + +template +inline OUT +lex_cast_hex(IN const & in) +{ + std::stringstream ss; + OUT out; + if (!(ss << std::ios::hex << std::ios::showbase << in && ss >> out)) + throw std::runtime_error("bad lexical cast"); + return out; +} + + +// Return as quoted string, so that when compiled as a C literal, it +// would print to the user out nicely. +template +inline std::string +lex_cast_qstring(IN const & in) +{ + std::stringstream ss; + std::string out, out2; + if (!(ss << in)) + throw std::runtime_error("bad lexical cast"); + out = ss.str(); + out2 += '"'; + for (unsigned i=0; i