+2006-01-05 Josh Stone <joshua.i.stone@intel.com>
+
+ PR 2056
+ * translate.cxx (var::~var, var::hist, var::buckets): make these
+ methods virtual, so we can use polymorphism.
+ (mapvar::hist, mapvar::buckets): Override the corresponding var
+ methods to handle pmaps correctly.
+ (c_unparser::visit_arrayindex, c_unparser::visit_print_format): Make
+ use of the new polymorphic behavior of var & mapvar when dealing with
+ histogram data.
+ * testsuite/buildok/pmap_foreach.stp: Add tests to check histogram
+ accesses with for/foreach.
+
2006-01-04 Frank Ch. Eigler <fche@elastic.org>
PR 2057.
// translation pass
// Copyright (C) 2005, 2006 Red Hat Inc.
-// Copyright (C) 2005 Intel Corporation
+// Copyright (C) 2005, 2006 Intel Corporation
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
: local(local), ty(ty), name(name)
{}
+ virtual ~var() {}
+
bool is_local() const
{
return local;
return "global_" + name;
}
- string hist() const
+ virtual string hist() const
{
assert (ty == pe_stats);
assert (sd.type != statistic_decl::none);
return "(&(" + qname() + "->hist))";
}
- string buckets() const
+ virtual string buckets() const
{
assert (ty == pe_stats);
assert (sd.type != statistic_decl::none);
else
throw semantic_error("setting a value of an unsupported map type");
}
+
+ string hist() const
+ {
+ assert (ty == pe_stats);
+ assert (sd.type != statistic_decl::none);
+ return "(&(" + fetch_existing_aggregate() + "->hist))";
+ }
+
+ string buckets() const
+ {
+ assert (ty == pe_stats);
+ assert (sd.type != statistic_decl::none);
+ return "(" + fetch_existing_aggregate() + "->hist.buckets)";
+ }
string init () const
{
assert(idx[0].type() == pe_long);
symbol *sym = get_symbol_within_expression (hist->stat);
- var v = getvar(sym->referent, sym->tok);
- v.assert_hist_compatible(*hist);
+
+ var *v;
+ if (sym->referent->arity < 1)
+ v = new var(getvar(sym->referent, e->tok));
+ else
+ v = new mapvar(getmap(sym->referent, e->tok));
+
+ v->assert_hist_compatible(*hist);
{
- varlock_w guard(*this, v);
+ varlock_w guard(*this, *v);
o->newline() << "c->last_stmt = " << lex_cast_qstring(*e->tok) << ";";
- o->newline() << "if (" << histogram_index_check(v, idx[0]) << ")";
+ o->newline() << "if (" << histogram_index_check(*v, idx[0]) << ")";
o->newline() << "{";
o->newline(1) << res << " = " << agg << "->histogram[" << idx[0] << "];";
o->newline(-1) << "}";
o->newline(-1) << "}";
}
+ delete v;
+
o->newline() << res << ";";
}
}
stmt_expr block(*this);
symbol *sym = get_symbol_within_expression (e->hist->stat);
aggvar agg = gensym_aggregate ();
- var v = getvar(sym->referent, e->tok);
- v.assert_hist_compatible(*e->hist);
- varlock_w guard(*this, v);
- load_aggregate(e->hist->stat, agg);
- o->newline() << "c->last_stmt = " << lex_cast_qstring(*e->tok) << ";";
- o->newline() << "_stp_stat_print_histogram (" << v.hist() << ", " << agg.qname() << ");";
+ var *v;
+ if (sym->referent->arity < 1)
+ v = new var(getvar(sym->referent, e->tok));
+ else
+ v = new mapvar(getmap(sym->referent, e->tok));
+
+ v->assert_hist_compatible(*e->hist);
+
+ {
+ varlock_w guard(*this, *v);
+ load_aggregate(e->hist->stat, agg);
+ o->newline() << "c->last_stmt = " << lex_cast_qstring(*e->tok) << ";";
+ o->newline() << "_stp_stat_print_histogram (" << v->hist() << ", " << agg.qname() << ");";
+ }
+
+ delete v;
}
else
{