namespace Trace {
-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 UInt::visit(Visitor &visitor) {
- visitor.visit(this);
-}
-
-void Float::visit(Visitor &visitor) {
- visitor.visit(this);
-}
-
-void String::visit(Visitor &visitor) {
- visitor.visit(this);
-}
-
-void Const::visit(Visitor &visitor) {
- visitor.visit(this);
-}
-
-void Array::visit(Visitor &visitor) {
- visitor.visit(this);
-}
-
-void Blob::visit(Visitor &visitor) {
- visitor.visit(this);
-}
-
+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 UInt::visit(Visitor &visitor) { visitor.visit(this); }
+void Float::visit(Visitor &visitor) { visitor.visit(this); }
+void String::visit(Visitor &visitor) { visitor.visit(this); }
+void Enum::visit(Visitor &visitor) { visitor.visit(this); }
+void Bitmask::visit(Visitor &visitor) { visitor.visit(this); }
+void Struct::visit(Visitor &visitor) { visitor.visit(this); }
+void Array::visit(Visitor &visitor) { visitor.visit(this); }
+void Blob::visit(Visitor &visitor) { visitor.visit(this); }
class Dumper : public Visitor
{
delete formatter;
}
- void visit(Null *node) {
+ void visit(Null *) {
os << "NULL";
}
os << literal << '"' << node->value << '"' << normal;
}
- void visit(Const *node) {
+ void visit(Enum *node) {
os << literal << node->name << normal;
}
+ void visit(Bitmask *bitmask) {
+ unsigned long long value = bitmask->value;
+ const Bitmask::Signature *sig = bitmask->sig;
+ bool first = true;
+ for (Bitmask::Signature::const_iterator it = sig->begin(); value != 0 && it != sig->end(); ++it) {
+ assert(it->second);
+ if ((value & it->second) == it->second) {
+ if (!first) {
+ os << " | ";
+ }
+ os << literal << it->first << normal;
+ value &= ~it->second;
+ first = false;
+ }
+ }
+ if (value || first) {
+ if (!first) {
+ os << " | ";
+ }
+ os << literal << std::hex << value << std::dec << normal;
+ }
+ }
+
+ void visit(Struct *s) {
+ const char *sep = "";
+ os << "{";
+ for (unsigned i = 0; i < s->members.size(); ++i) {
+ os << sep << italic << s->sig->member_names[i] << normal << " = ";
+ _visit(s->members[i]);
+ sep = ", ";
+ }
+ os << "}";
+ }
+
void visit(Array *array) {
if (array->values.size() == 1) {
os << "&";
void visit(Call *call) {
const char *sep = "";
- os << bold << call->name << normal << "(";
- for (std::list<Arg>::iterator it = call->args.begin(); it != call->args.end(); ++it) {
- os << sep << italic << it->first << normal << " = ";
- _visit(it->second);
+ os << bold << call->sig->name << normal << "(";
+ for (unsigned i = 0; i < call->args.size(); ++i) {
+ os << sep << italic << call->sig->arg_names[i] << normal << " = ";
+ _visit(call->args[i]);
sep = ", ";
}
os << ")";
static inline const Value *unwrap(const Value *node) {
- const Const *c = dynamic_cast<const Const *>(node);
+ const Enum *c = dynamic_cast<const Enum *>(node);
if (c)
return c->value;
return node;
}
+Value::operator bool(void) const {
+ const Bool *b = dynamic_cast<const Bool *>(unwrap(this));
+ if (b)
+ return b->value;
+ assert(0);
+ return false;
+}
+
Value::operator signed long long(void) const {
const SInt *sint = dynamic_cast<const SInt *>(unwrap(this));
if (sint)
if (blob)
return blob->buf;
const Null *null = dynamic_cast<const Null *>(unwrap(this));
- if (null);
+ if (null)
return NULL;
assert(0);
return NULL;
if (string)
return string->value.c_str();
const Null *null = dynamic_cast<const Null *>(unwrap(this));
- if (null);
+ if (null)
return NULL;
assert(0);
return NULL;
}
-Value & Call::arg(const char *name) {
- for (std::list<Arg>::iterator it = args.begin(); it != args.end(); ++it) {
- if (it->first == name) {
- return *it->second;
- }
- }
- return null;
-}
-
std::ostream & operator <<(std::ostream &os, Call &call) {
Dumper d(os);
d.visit(&call);