summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--buildrun.cxx10
-rw-r--r--dwflpp.cxx30
-rw-r--r--elaborate.cxx6
-rw-r--r--main.cxx4
-rw-r--r--parse.cxx5
-rw-r--r--staptree.cxx2
-rw-r--r--tapset-mark.cxx12
-rw-r--r--tapset-perfmon.cxx6
-rw-r--r--tapset-procfs.cxx2
-rw-r--r--tapset-timers.cxx4
-rw-r--r--tapset-utrace.cxx6
-rw-r--r--tapsets.cxx22
-rw-r--r--translate.cxx36
-rw-r--r--util.h68
14 files changed, 108 insertions, 105 deletions
diff --git a/buildrun.cxx b/buildrun.cxx
index a40dab15..6bef4095 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -363,10 +363,10 @@ run_pass (systemtap_session& s)
staprun_cmd += "-c " + cmdstr_quoted(s.cmd) + " ";
if (s.target_pid)
- staprun_cmd += "-t " + stringify(s.target_pid) + " ";
+ staprun_cmd += "-t " + lex_cast(s.target_pid) + " ";
if (s.buffer_size)
- staprun_cmd += "-b " + stringify(s.buffer_size) + " ";
+ staprun_cmd += "-b " + lex_cast(s.buffer_size) + " ";
if (s.need_uprobes)
staprun_cmd += "-u ";
@@ -390,7 +390,7 @@ make_tracequery(systemtap_session& s, string& name,
const vector<string>& extra_headers)
{
static unsigned tick = 0;
- string basename("tracequery_kmod_" + lex_cast<string>(++tick));
+ string basename("tracequery_kmod_" + lex_cast(++tick));
// create a subdirectory for the module
string dir(s.tmpdir + "/" + basename);
@@ -461,7 +461,7 @@ static int
make_typequery_kmod(systemtap_session& s, const string& header, string& name)
{
static unsigned tick = 0;
- string basename("typequery_kmod_" + lex_cast<string>(++tick));
+ string basename("typequery_kmod_" + lex_cast(++tick));
// create a subdirectory for the module
string dir(s.tmpdir + "/" + basename);
@@ -519,7 +519,7 @@ make_typequery_umod(systemtap_session& s, const string& header, string& name)
{
static unsigned tick = 0;
- name = s.tmpdir + "/typequery_umod_" + lex_cast<string>(++tick) + ".so";
+ name = s.tmpdir + "/typequery_umod_" + lex_cast(++tick) + ".so";
// make the module
//
diff --git a/dwflpp.cxx b/dwflpp.cxx
index ba8dcec7..9dcfd002 100644
--- a/dwflpp.cxx
+++ b/dwflpp.cxx
@@ -1243,7 +1243,7 @@ dwflpp::die_entrypc (Dwarf_Die * die, Dwarf_Addr * addr)
while ((offset = dwarf_ranges (die, offset, &base, &begin, &end)) > 0)
extra ++;
if (extra)
- lookup_method += ", ignored " + lex_cast<string>(extra) + " more";
+ lookup_method += ", ignored " + lex_cast(extra) + " more";
}
}
@@ -1437,7 +1437,7 @@ dwflpp::find_variable_and_frame_base (Dwarf_Die *scope_die,
if (nscopes <= 0)
{
throw semantic_error ("unable to find any scopes containing "
- + lex_cast_hex<string>(pc)
+ + lex_cast_hex(pc)
+ ((scope_die == NULL) ? ""
: (string (" in ")
+ (dwarf_diename(scope_die) ?: "<unknown>")
@@ -1456,7 +1456,7 @@ dwflpp::find_variable_and_frame_base (Dwarf_Die *scope_die,
stringstream alternatives;
print_locals (scopes, alternatives);
throw semantic_error ("unable to find local '" + local + "'"
- + " near pc " + lex_cast_hex<string>(pc)
+ + " near pc " + lex_cast_hex(pc)
+ ((scope_die == NULL) ? ""
: (string (" in ")
+ (dwarf_diename(scope_die) ?: "<unknown>")
@@ -1727,7 +1727,7 @@ dwflpp::translate_components(struct obstack *pool,
#if 0
// Emit a marker to note which field is being access-attempted, to give
// better error messages if deref() fails.
- string piece = string(...target_symbol token...) + string ("#") + stringify(components[i].second);
+ string piece = string(...target_symbol token...) + string ("#") + lex_cast(components[i].second);
obstack_printf (pool, "c->last_stmt = %s;", lex_cast_qstring(piece).c_str());
#endif
@@ -1749,7 +1749,7 @@ dwflpp::translate_components(struct obstack *pool,
case DW_TAG_pointer_type:
/* A pointer with no type is a void* -- can't dereference it. */
if (!dwarf_hasattr_integrate (die, DW_AT_type))
- throw semantic_error ("invalid access '" + lex_cast<string>(c)
+ throw semantic_error ("invalid access '" + lex_cast(c)
+ "' vs. " + dwarf_type_name(die),
c.tok);
@@ -1768,14 +1768,14 @@ dwflpp::translate_components(struct obstack *pool,
}
else if (c.type == target_symbol::comp_expression_array_index)
{
- string index = "THIS->index" + lex_cast<string>(i);
+ string index = "THIS->index" + lex_cast(i);
c_translate_array (pool, 1, 0 /* PR9768 */, die, tail,
index.c_str(), 0);
++i;
}
else
throw semantic_error ("invalid access '"
- + lex_cast<string>(c)
+ + lex_cast(c)
+ "' for array type",
c.tok);
break;
@@ -1785,7 +1785,7 @@ dwflpp::translate_components(struct obstack *pool,
case DW_TAG_class_type:
if (c.type != target_symbol::comp_struct_member)
throw semantic_error ("invalid access '"
- + lex_cast<string>(c)
+ + lex_cast(c)
+ "' for " + dwarf_type_name(die),
c.tok);
@@ -1811,7 +1811,7 @@ dwflpp::translate_components(struct obstack *pool,
const char *file = dwarf_decl_file(&parentdie);
if (file && dwarf_decl_line(&parentdie, &line) == 0)
source = " (" + string(file) + ":"
- + lex_cast<string>(line) + ")";
+ + lex_cast(line) + ")";
}
string alternatives;
@@ -1836,7 +1836,7 @@ dwflpp::translate_components(struct obstack *pool,
case DW_TAG_enumeration_type:
case DW_TAG_base_type:
throw semantic_error ("invalid access '"
- + lex_cast<string>(c)
+ + lex_cast(c)
+ "' vs. " + dwarf_type_name(die),
c.tok);
break;
@@ -1848,7 +1848,7 @@ dwflpp::translate_components(struct obstack *pool,
default:
throw semantic_error (dwarf_type_name(die) + ": unexpected type tag "
- + lex_cast<string>(dwarf_tag (die)),
+ + lex_cast(dwarf_tag (die)),
c.tok);
break;
}
@@ -1936,7 +1936,7 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool,
{
default:
throw semantic_error ("unsupported type tag "
- + lex_cast<string>(typetag)
+ + lex_cast(typetag)
+ " for " + dwarf_type_name(typedie), e->tok);
break;
@@ -1959,7 +1959,7 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool,
if (encoding < 0)
{
// clog << "bad type1 " << encoding << " diestr" << endl;
- throw semantic_error ("unsupported type (mystery encoding " + lex_cast<string>(encoding) + ")" +
+ throw semantic_error ("unsupported type (mystery encoding " + lex_cast(encoding) + ")" +
" for " + dwarf_type_name(typedie), e->tok);
}
@@ -1968,7 +1968,7 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool,
/* XXX || many others? */)
{
// clog << "bad type " << encoding << " diestr" << endl;
- throw semantic_error ("unsupported type (encoding " + lex_cast<string>(encoding) + ")" +
+ throw semantic_error ("unsupported type (encoding " + lex_cast(encoding) + ")" +
" for " + dwarf_type_name(typedie), e->tok);
}
}
@@ -2097,7 +2097,7 @@ dwflpp::literal_stmt_for_local (Dwarf_Die *scope_die,
throw semantic_error("failed to retrieve location "
"attribute for local '" + local
+ "' (dieoffset: "
- + lex_cast_hex<string>(dwarf_dieoffset (&vardie))
+ + lex_cast_hex(dwarf_dieoffset (&vardie))
+ ")",
e->tok);
}
diff --git a/elaborate.cxx b/elaborate.cxx
index 17f335d0..c1a2e898 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -331,7 +331,7 @@ match_node::find_and_build (systemtap_session& s,
alternatives += string(" ") + i->first.str();
throw semantic_error (string("probe point truncated at position ") +
- lex_cast<string> (pos) +
+ lex_cast (pos) +
" (follow:" + alternatives + ")", loc->tok);
}
@@ -416,7 +416,7 @@ match_node::find_and_build (systemtap_session& s,
alternatives += string(" ") + i->first.str();
throw semantic_error(string("probe point mismatch at position ") +
- lex_cast<string> (pos) +
+ lex_cast (pos) +
" (alternatives:" + alternatives + ")" +
" didn't find any wildcard matches",
loc->tok);
@@ -433,7 +433,7 @@ match_node::find_and_build (systemtap_session& s,
alternatives += string(" ") + i->first.str();
throw semantic_error (string("probe point mismatch at position ") +
- lex_cast<string> (pos) +
+ lex_cast (pos) +
" (alternatives:" + alternatives + ")",
loc->tok);
}
diff --git a/main.cxx b/main.cxx
index b97d0092..d8c780c2 100644
--- a/main.cxx
+++ b/main.cxx
@@ -486,8 +486,8 @@ main (int argc, char * const argv [])
s.buffer_size = 0;
s.last_pass = 5;
- s.module_name = "stap_" + stringify(getpid());
- s.stapconf_name = "stapconf_" + stringify(getpid()) + ".h";
+ s.module_name = "stap_" + lex_cast(getpid());
+ s.stapconf_name = "stapconf_" + lex_cast(getpid()) + ".h";
s.output_file = ""; // -o FILE
s.keep_tmpdir = false;
s.cmd = "";
diff --git a/parse.cxx b/parse.cxx
index a2e2b656..bfd7600f 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -754,9 +754,8 @@ lexer::scan (bool wildcard)
idx <= session.args.size()); // prevent overflow
if (idx == 0 ||
idx-1 >= session.args.size())
- throw parse_error ("command line argument index " + lex_cast<string>(idx)
- + " out of range [1-" + lex_cast<string>(session.args.size()) + "]", n);
-
+ throw parse_error ("command line argument index " + lex_cast(idx)
+ + " out of range [1-" + lex_cast(session.args.size()) + "]", n);
string arg = session.args[idx-1];
if (c == '$') input_put (arg);
else input_put (lex_cast_qstring (arg));
diff --git a/staptree.cxx b/staptree.cxx
index b4975017..090f0bd3 100644
--- a/staptree.cxx
+++ b/staptree.cxx
@@ -101,7 +101,7 @@ probe::probe ():
body (0), tok (0)
{
static unsigned last_probeidx = 0;
- this->name = string ("probe_") + lex_cast<string>(last_probeidx ++);
+ this->name = string ("probe_") + lex_cast(last_probeidx ++);
}
diff --git a/tapset-mark.cxx b/tapset-mark.cxx
index 6b4f47c5..b70098e3 100644
--- a/tapset-mark.cxx
+++ b/tapset-mark.cxx
@@ -108,7 +108,7 @@ mark_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e)
// Remember that we've seen a target variable.
target_symbol_seen = true;
- e->probe_context_var = "__mark_arg" + lex_cast<string>(argnum);
+ e->probe_context_var = "__mark_arg" + lex_cast(argnum);
e->type = mark_args[argnum-1]->stp_type;
provide (e);
}
@@ -156,10 +156,10 @@ mark_var_expanding_visitor::visit_target_symbol_context (target_symbol* e)
{
if (i > 0)
pf->raw_components += " ";
- pf->raw_components += "$arg" + lex_cast<string>(i+1);
+ pf->raw_components += "$arg" + lex_cast(i+1);
target_symbol *tsym = new target_symbol;
tsym->tok = e->tok;
- tsym->base_name = "$arg" + lex_cast<string>(i+1);
+ tsym->base_name = "$arg" + lex_cast(i+1);
tsym->saved_conversion_error = 0;
expression *texp = require (tsym); //same treatment as tracepoint
@@ -414,7 +414,7 @@ mark_derived_probe::emit_probe_context_vars (translator_output* o)
for (unsigned i = 0; i < mark_args.size(); i++)
{
- string localname = "__mark_arg" + lex_cast<string>(i+1);
+ string localname = "__mark_arg" + lex_cast(i+1);
switch (mark_args[i]->stp_type)
{
case pe_long:
@@ -441,7 +441,7 @@ mark_derived_probe::initialize_probe_context_vars (translator_output* o)
bool deref_fault_needed = false;
for (unsigned i = 0; i < mark_args.size(); i++)
{
- string localname = "l->__mark_arg" + lex_cast<string>(i+1);
+ string localname = "l->__mark_arg" + lex_cast(i+1);
switch (mark_args[i]->stp_type)
{
case pe_long:
@@ -475,7 +475,7 @@ mark_derived_probe::printargs(std::ostream &o) const
{
for (unsigned i = 0; i < mark_args.size(); i++)
{
- string localname = "$arg" + lex_cast<string>(i+1);
+ string localname = "$arg" + lex_cast(i+1);
switch (mark_args[i]->stp_type)
{
case pe_long:
diff --git a/tapset-perfmon.cxx b/tapset-perfmon.cxx
index 827e88ca..56abb997 100644
--- a/tapset-perfmon.cxx
+++ b/tapset-perfmon.cxx
@@ -59,7 +59,7 @@ perfmon_var_expanding_visitor::visit_target_symbol (target_symbol *e)
string fname = string("_perfmon_tvar_get")
+ "_" + e->base_name.substr(1)
- + "_" + lex_cast<string>(counter_number);
+ + "_" + lex_cast(counter_number);
if (e->base_name != "$counter")
throw semantic_error ("target variables not available to perfmon probes");
@@ -70,7 +70,7 @@ perfmon_var_expanding_visitor::visit_target_symbol (target_symbol *e)
e->assert_no_components("perfmon");
ec->code = "THIS->__retvalue = _pfm_pmd_x[" +
- lex_cast<string>(counter_number) + "].reg_num;";
+ lex_cast(counter_number) + "].reg_num;";
ec->code += "/* pure */";
fdecl->name = fname;
fdecl->body = ec;
@@ -390,7 +390,7 @@ perfmon_derived_probe_group::emit_module_init (translator_output* o)
/* output the needed bits for pmc here */
for (unsigned i=0; i < outp.pfp_pmc_count; i++) {
o->newline() << "{.reg_num=" << pc[i].reg_num << ", "
- << ".reg_value=" << lex_cast_hex<string>(pc[i].reg_value)
+ << ".reg_value=" << lex_cast_hex(pc[i].reg_value)
<< "},";
}
diff --git a/tapset-procfs.cxx b/tapset-procfs.cxx
index 527b4486..fd8ad62a 100644
--- a/tapset-procfs.cxx
+++ b/tapset-procfs.cxx
@@ -379,7 +379,7 @@ procfs_var_expanding_visitor::visit_target_symbol (target_symbol* e)
ec->tok = e->tok;
string fname = (string(lvalue ? "_procfs_value_set" : "_procfs_value_get")
- + "_" + lex_cast<string>(tick++));
+ + "_" + lex_cast(tick++));
string locvalue = "CONTEXT->data";
if (! lvalue)
diff --git a/tapset-timers.cxx b/tapset-timers.cxx
index 565a54e8..16dcefcb 100644
--- a/tapset-timers.cxx
+++ b/tapset-timers.cxx
@@ -193,10 +193,10 @@ struct hrtimer_derived_probe: public derived_probe
{
if ((i < min_ns_interval) || (i > max_ns_interval))
throw semantic_error(string("interval value out of range (")
- + lex_cast<string>(scale < min_ns_interval
+ + lex_cast(scale < min_ns_interval
? min_ns_interval/scale : 1)
+ ","
- + lex_cast<string>(max_ns_interval/scale) + ")");
+ + lex_cast(max_ns_interval/scale) + ")");
// randomize = 0 means no randomization
if ((r < 0) || (r > i))
diff --git a/tapset-utrace.cxx b/tapset-utrace.cxx
index 6872c87c..c6214e70 100644
--- a/tapset-utrace.cxx
+++ b/tapset-utrace.cxx
@@ -224,7 +224,7 @@ utrace_var_expanding_visitor::visit_target_symbol_cached (target_symbol* e)
// _utrace_tvar_{name}_{num}
string aname = (string("_utrace_tvar_")
+ e->base_name.substr(1)
- + "_" + lex_cast<string>(tick++));
+ + "_" + lex_cast(tick++));
vardecl* vd = new vardecl;
vd->name = aname;
vd->tok = e->tok;
@@ -429,10 +429,10 @@ utrace_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e)
{
if (i > 0)
pf->raw_components += " ";
- pf->raw_components += "$arg" + lex_cast<string>(i+1);
+ pf->raw_components += "$arg" + lex_cast(i+1);
target_symbol *tsym = new target_symbol;
tsym->tok = e->tok;
- tsym->base_name = "$arg" + lex_cast<string>(i+1);
+ tsym->base_name = "$arg" + lex_cast(i+1);
tsym->saved_conversion_error = 0;
pf->raw_components += "=%#x"; //FIXME: missing type info
diff --git a/tapsets.cxx b/tapsets.cxx
index 9651426e..d5c89a02 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -1845,7 +1845,7 @@ dwarf_var_expanding_visitor::visit_target_symbol_saved_return (target_symbol* e)
string aname = (string("_dwarf_tvar_")
+ e->base_name.substr(1)
- + "_" + lex_cast<string>(tick++));
+ + "_" + lex_cast(tick++));
vardecl* vd = new vardecl;
vd->name = aname;
vd->tok = e->tok;
@@ -2256,7 +2256,7 @@ dwarf_var_expanding_visitor::visit_target_symbol (target_symbol *e)
string fname = (string(lvalue ? "_dwarf_tvar_set" : "_dwarf_tvar_get")
+ "_" + e->base_name.substr(1)
- + "_" + lex_cast<string>(tick++));
+ + "_" + lex_cast(tick++));
try
{
@@ -2322,7 +2322,7 @@ dwarf_var_expanding_visitor::visit_target_symbol (target_symbol *e)
{
vardecl *v = new vardecl;
v->type = pe_long;
- v->name = "index" + lex_cast<string>(i);
+ v->name = "index" + lex_cast(i);
v->tok = e->tok;
fdecl->formal_args.push_back(v);
}
@@ -2568,7 +2568,7 @@ void dwarf_cast_expanding_visitor::visit_cast_op (cast_op* e)
string fname = (string(lvalue ? "_dwarf_tvar_set" : "_dwarf_tvar_get")
+ "_" + e->base_name.substr(1)
- + "_" + lex_cast<string>(tick++));
+ + "_" + lex_cast(tick++));
// Synthesize a function.
functiondecl *fdecl = new functiondecl;
@@ -2594,7 +2594,7 @@ void dwarf_cast_expanding_visitor::visit_cast_op (cast_op* e)
{
vardecl *v = new vardecl;
v->type = pe_long;
- v->name = "index" + lex_cast<string>(i);
+ v->name = "index" + lex_cast(i);
v->tok = e->tok;
fdecl->formal_args.push_back(v);
}
@@ -2707,7 +2707,7 @@ dwarf_derived_probe::dwarf_derived_probe(const string& funcname,
// Range limit maxactive() value
if (q.has_maxactive && (q.maxactive_val < 0 || q.maxactive_val > USHRT_MAX))
throw semantic_error ("maxactive value out of range [0,"
- + lex_cast<string>(USHRT_MAX) + "]",
+ + lex_cast(USHRT_MAX) + "]",
q.base_loc->tok);
// Expand target variables in the probe body
@@ -2764,7 +2764,7 @@ dwarf_derived_probe::dwarf_derived_probe(const string& funcname,
{
retro_name += ("@" + string (filename));
if (line > 0)
- retro_name += (":" + lex_cast<string> (line));
+ retro_name += (":" + lex_cast (line));
}
comps.push_back
(new probe_point::component
@@ -3364,7 +3364,7 @@ sdt_var_expanding_visitor::visit_target_symbol (target_symbol *e)
cast->tok = e->tok;
cast->operand = fc;
cast->components = e->components;
- cast->type = probe_name + "_arg" + lex_cast<string>(argno);
+ cast->type = probe_name + "_arg" + lex_cast(argno);
cast->module = process_name;
cast->visit(this);
@@ -4252,7 +4252,7 @@ uprobe_derived_probe::uprobe_derived_probe (const string& function,
{
retro_name += ("@" + string (filename));
if (line > 0)
- retro_name += (":" + lex_cast<string> (line));
+ retro_name += (":" + lex_cast (line));
}
comps.push_back
(new probe_point::component
@@ -5388,7 +5388,7 @@ tracepoint_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e)
string fname = (string(lvalue ? "_tracepoint_tvar_set" : "_tracepoint_tvar_get")
+ "_" + e->base_name.substr(1)
- + "_" + lex_cast<string>(tick++));
+ + "_" + lex_cast(tick++));
fdecl->name = fname;
fdecl->body = ec;
@@ -5427,7 +5427,7 @@ tracepoint_var_expanding_visitor::visit_target_symbol_arg (target_symbol* e)
{
vardecl *v = new vardecl;
v->type = pe_long;
- v->name = "index" + lex_cast<string>(i);
+ v->name = "index" + lex_cast(i);
v->tok = e->tok;
fdecl->formal_args.push_back(v);
}
diff --git a/translate.cxx b/translate.cxx
index 65acd2ca..ffe6d489 100644
--- a/translate.cxx
+++ b/translate.cxx
@@ -384,9 +384,9 @@ public:
case statistic_decl::linear:
prefix += string("HIST_LINEAR")
- + ", " + stringify(sd.linear_low)
- + ", " + stringify(sd.linear_high)
- + ", " + stringify(sd.linear_step);
+ + ", " + lex_cast(sd.linear_low)
+ + ", " + lex_cast(sd.linear_high)
+ + ", " + lex_cast(sd.linear_step);
break;
case statistic_decl::logarithmic:
@@ -456,7 +456,7 @@ protected:
public:
tmpvar(exp_type ty,
unsigned & counter)
- : var(true, ty, ("__tmp" + stringify(counter++))), overridden(false)
+ : var(true, ty, ("__tmp" + lex_cast(counter++))), overridden(false)
{}
tmpvar(const var& source)
@@ -487,7 +487,7 @@ struct aggvar
: public var
{
aggvar(unsigned & counter)
- : var(true, pe_stats, ("__tmp" + stringify(counter++)))
+ : var(true, pe_stats, ("__tmp" + lex_cast(counter++)))
{}
string init() const
@@ -625,8 +625,8 @@ struct mapvar
throw semantic_error("adding a value of an unsupported map type");
res += "; if (unlikely(rc)) { c->last_error = \"Array overflow, check " +
- stringify(maxsize > 0 ?
- "size limit (" + stringify(maxsize) + ")" : "MAXMAPENTRIES")
+ lex_cast(maxsize > 0 ?
+ "size limit (" + lex_cast(maxsize) + ")" : "MAXMAPENTRIES")
+ "\"; goto out; }}";
return res;
@@ -646,8 +646,8 @@ struct mapvar
throw semantic_error("setting a value of an unsupported map type");
res += "; if (unlikely(rc)) { c->last_error = \"Array overflow, check " +
- stringify(maxsize > 0 ?
- "size limit (" + stringify(maxsize) + ")" : "MAXMAPENTRIES")
+ lex_cast(maxsize > 0 ?
+ "size limit (" + lex_cast(maxsize) + ")" : "MAXMAPENTRIES")
+ "\"; goto out; }}";
return res;
@@ -671,7 +671,7 @@ struct mapvar
{
string mtype = is_parallel() ? "pmap" : "map";
string prefix = value() + " = _stp_" + mtype + "_new_" + keysym() + " (" +
- (maxsize > 0 ? stringify(maxsize) : "MAXMAPENTRIES") ;
+ (maxsize > 0 ? lex_cast(maxsize) : "MAXMAPENTRIES") ;
// See also var::init().
@@ -689,9 +689,9 @@ struct mapvar
case statistic_decl::linear:
// FIXME: check for "reasonable" values in linear stats
prefix = prefix + ", HIST_LINEAR"
- + ", " + stringify(sdecl().linear_low)
- + ", " + stringify(sdecl().linear_high)
- + ", " + stringify(sdecl().linear_step);
+ + ", " + lex_cast(sdecl().linear_low)
+ + ", " + lex_cast(sdecl().linear_high)
+ + ", " + lex_cast(sdecl().linear_step);
break;
case statistic_decl::logarithmic:
@@ -728,7 +728,7 @@ public:
itervar (symbol* e, unsigned & counter)
: referent_ty(e->referent->type),
- name("__tmp" + stringify(counter++))
+ name("__tmp" + lex_cast(counter++))
{
if (referent_ty == pe_unknown)
throw semantic_error("iterating over unknown reference type", e->tok);
@@ -775,11 +775,11 @@ public:
switch (ty)
{
case pe_long:
- return "_stp_key_get_int64 ("+ value() + ", " + stringify(i+1) + ")";
+ return "_stp_key_get_int64 ("+ value() + ", " + lex_cast(i+1) + ")";
case pe_string:
// impedance matching: NULL -> empty strings
return "({ char *v = "
- "_stp_key_get_str ("+ value() + ", " + stringify(i+1) + "); "
+ "_stp_key_get_str ("+ value() + ", " + lex_cast(i+1) + "); "
"if (! v) v = \"\"; "
"v; })";
default:
@@ -2464,7 +2464,7 @@ c_tmpcounter::visit_for_loop (for_loop *s)
void
c_unparser::visit_for_loop (for_loop *s)
{
- string ctr = stringify (label_counter++);
+ string ctr = lex_cast (label_counter++);
string toplabel = "top_" + ctr;
string contlabel = "continue_" + ctr;
string breaklabel = "break_" + ctr;
@@ -2617,7 +2617,7 @@ c_unparser::visit_foreach_loop (foreach_loop *s)
itervar iv = getiter (array);
vector<var> keys;
- string ctr = stringify (label_counter++);
+ string ctr = lex_cast (label_counter++);
string toplabel = "top_" + ctr;
string contlabel = "continue_" + ctr;
string breaklabel = "break_" + ctr;
diff --git a/util.h b/util.h
index 1577bb54..b38d01fd 100644
--- a/util.h
+++ b/util.h
@@ -23,38 +23,35 @@ int kill_stap_spawn(int sig);
// stringification generics
-template <typename T>
-inline std::string
-stringify(T t)
+template <typename IN>
+inline std::string lex_cast(IN const & in)
{
- std::ostringstream s;
- s << t;
- return s.str ();
+ std::ostringstream ss;
+ if (!(ss << in))
+ throw std::runtime_error("bad lexical cast");
+ return ss.str();
}
-template <typename OUT, typename IN>
-inline OUT lex_cast(IN const & in)
+template <typename OUT>
+inline OUT lex_cast(std::string const & in)
{
- std::stringstream ss;
+ std::istringstream ss(in);
OUT out;
- // NB: ss >> string out assumes that "in" renders to one word
- if (!(ss << in && ss >> out))
+ if (!(ss >> out && ss.eof()))
throw std::runtime_error("bad lexical cast");
return out;
}
-template <typename OUT, typename IN>
-inline OUT
+template <typename IN>
+inline std::string
lex_cast_hex(IN const & in)
{
- std::stringstream ss;
- OUT out;
- // NB: ss >> string out assumes that "in" renders to one word
- if (!(ss << "0x" << std::hex << in && ss >> out))
+ std::ostringstream ss;
+ if (!(ss << std::showbase << std::hex << in))
throw std::runtime_error("bad lexical cast");
- return out;
+ return ss.str();
}
@@ -65,32 +62,39 @@ 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(); // "in" is expected to render to more than one word
- out2 += '"';
- for (unsigned i=0; i<out.length(); i++)
+ return lex_cast_qstring(ss.str());
+}
+
+
+template <>
+inline std::string
+lex_cast_qstring(std::string const & in)
+{
+ std::string out;
+ out += '"';
+ for (const char *p = in.c_str(); *p; ++p)
{
- unsigned char c = out[i];
+ unsigned char c = *p;
if (! isprint(c))
{
- out2 += '\\';
+ out += '\\';
// quick & dirty octal converter
- out2 += "01234567" [(c >> 6) & 0x07];
- out2 += "01234567" [(c >> 3) & 0x07];
- out2 += "01234567" [(c >> 0) & 0x07];
+ out += "01234567" [(c >> 6) & 0x07];
+ out += "01234567" [(c >> 3) & 0x07];
+ out += "01234567" [(c >> 0) & 0x07];
}
else if (c == '"' || c == '\\')
{
- out2 += '\\';
- out2 += c;
+ out += '\\';
+ out += c;
}
else
- out2 += c;
+ out += c;
}
- out2 += '"';
- return out2;
+ out += '"';
+ return out;
}
/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */