call = p.parse_call();
while (call) {
std::cout << *call;
+ delete call;
call = p.parse_call();
}
}
}
retrace_call(*call);
+
+ delete call;
}
// Reached the end of trace
namespace Trace {
+Call::~Call() {
+ for (unsigned i = 0; i < args.size(); ++i) {
+ delete args[i];
+ }
+
+ if (ret) {
+ delete ret;
+ }
+}
+
+
+Struct::~Struct() {
+ for (std::vector<Value *>::iterator it = members.begin(); it != members.end(); ++it) {
+ delete *it;
+ }
+}
+
+
+Array::~Array() {
+ for (std::vector<Value *>::iterator it = values.begin(); it != values.end(); ++it) {
+ delete *it;
+ }
+}
+
+
void Null::visit(Visitor &visitor) { visitor.visit(this); }
void Bool::visit(Visitor &visitor) { visitor.visit(this); }
void SInt::visit(Visitor &visitor) { visitor.visit(this); }
void Blob::visit(Visitor &visitor) { visitor.visit(this); }
void Pointer::visit(Visitor &visitor) { visitor.visit(this); }
+
class Dumper : public Visitor
{
protected:
}
void visit(Enum *node) {
- os << literal << node->name << normal;
+ os << literal << node->sig->first << normal;
}
void visit(Bitmask *bitmask) {
static inline const Value *unwrap(const Value *node) {
const Enum *c = dynamic_cast<const Enum *>(node);
if (c)
- return c->value;
+ return c->sig->second;
return node;
}
class Enum : public Value
{
public:
- Enum(std::string &_name, Value *_value) : name(_name), value(_value) {}
+ typedef std::pair<std::string, Value *> Signature;
+
+ Enum(const Signature *_sig) : sig(_sig) {}
void visit(Visitor &visitor);
- std::string name;
- Value *value;
+ const Signature *sig;
};
};
Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { }
+ ~Struct();
void visit(Visitor &visitor);
{
public:
Array(size_t len) : values(len) {}
+ ~Array();
void visit(Visitor &visitor);
Value *ret;
Call(Signature *_sig) : sig(_sig), args(_sig->arg_names.size()), ret(0) { }
+ ~Call();
inline const std::string name(void) const {
return sig->name;
typedef std::vector<Struct::Signature *> StructMap;
StructMap structs;
- typedef std::vector<Enum *> EnumMap;
+ typedef std::vector<Enum::Signature *> EnumMap;
EnumMap enums;
typedef std::vector<Bitmask::Signature *> BitmaskMap;
Value *parse_enum() {
size_t id = read_uint();
- Enum *sig = lookup(enums, id);
+ Enum::Signature *sig = lookup(enums, id);
if (!sig) {
std::string name = read_string();
Value *value = parse_value();
- sig = new Enum(name, value);
+ sig = new Enum::Signature(name, value);
enums[id] = sig;
}
assert(sig);
- return sig;
+ return new Enum(sig);
}
Value *parse_bitmask() {