X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=trace_model.cpp;h=25dc4bb487138a2e38a33f277940c733bab5ce7e;hb=3a8ffad2f31f4438e19dd5a0f1c068e1fdffdeea;hp=0d2915f01926c5bd3090373d12be43906e862db7;hpb=31b183ac653e9ba1e19cbc9b9292e36c660bcb24;p=apitrace diff --git a/trace_model.cpp b/trace_model.cpp index 0d2915f..25dc4bb 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -56,9 +56,16 @@ Array::~Array() { } Blob::~Blob() { - // TODO: Don't leak blobs. Blobs are often bound and accessed during many - // calls, so we can't delete them here. - //delete [] buf; + // Blobs are often bound and referred during many calls, so we can't delete + // them here in that case. + // + // Once bound there is no way to know when they were unbound, which + // effectively means we have to leak them. A better solution would be to + // keep a list of bound pointers, and defer the destruction to when the + // trace in question has been fully processed. + if (!bound) { + delete [] buf; + } } @@ -69,7 +76,7 @@ bool SInt ::toBool(void) const { return value != 0; } bool UInt ::toBool(void) const { return value != 0; } bool Float ::toBool(void) const { return value != 0; } bool String ::toBool(void) const { return true; } -bool Enum ::toBool(void) const { return sig->second->toBool(); } +bool Enum ::toBool(void) const { return sig->value != 0; } bool Struct ::toBool(void) const { return true; } bool Array ::toBool(void) const { return true; } bool Blob ::toBool(void) const { return true; } @@ -83,7 +90,7 @@ signed long long Bool ::toSInt(void) const { return static_cast(value) >= 0); return static_cast(value); } signed long long Float ::toSInt(void) const { return static_cast(value); } -signed long long Enum ::toSInt(void) const { return sig->second->toSInt(); } +signed long long Enum ::toSInt(void) const { return sig->value; } // unsigned integer cast @@ -93,7 +100,7 @@ unsigned long long Bool ::toUInt(void) const { return static_cast= 0); return static_cast(value); } unsigned long long UInt ::toUInt(void) const { return value; } unsigned long long Float ::toUInt(void) const { return static_cast(value); } -unsigned long long Enum ::toUInt(void) const { return sig->second->toUInt(); } +unsigned long long Enum ::toUInt(void) const { assert(sig->value >= 0); return sig->value; } // floating point cast @@ -103,7 +110,7 @@ float Bool ::toFloat(void) const { return static_cast(value); } float SInt ::toFloat(void) const { return static_cast(value); } float UInt ::toFloat(void) const { return static_cast(value); } float Float ::toFloat(void) const { return value; } -float Enum ::toFloat(void) const { return sig->second->toFloat(); } +float Enum ::toFloat(void) const { return static_cast(sig->value); } // floating point cast @@ -113,7 +120,7 @@ double Bool ::toDouble(void) const { return static_cast(value); } double SInt ::toDouble(void) const { return static_cast(value); } double UInt ::toDouble(void) const { return static_cast(value); } double Float ::toDouble(void) const { return value; } -double Enum ::toDouble(void) const { return sig->second->toDouble(); } +double Enum ::toDouble(void) const { return static_cast(sig->value); } // pointer cast @@ -122,6 +129,11 @@ void * Null ::toPointer(void) const { return NULL; } void * Blob ::toPointer(void) const { return buf; } void * Pointer::toPointer(void) const { return (void *)value; } +void * Value ::toPointer(bool bind) { assert(0); return NULL; } +void * Null ::toPointer(bool bind) { return NULL; } +void * Blob ::toPointer(bool bind) { if (bind) bound = true; return buf; } +void * Pointer::toPointer(bool bind) { return (void *)value; } + // pointer cast unsigned long long Value ::toUIntPtr(void) const { assert(0); return 0; } @@ -156,7 +168,7 @@ void Visitor::visit(SInt *) { assert(0); } void Visitor::visit(UInt *) { assert(0); } void Visitor::visit(Float *) { assert(0); } void Visitor::visit(String *) { assert(0); } -void Visitor::visit(Enum *node) { _visit(node->sig->second); } +void Visitor::visit(Enum *node) { assert(0); } void Visitor::visit(Bitmask *node) { visit(static_cast(node)); } void Visitor::visit(Struct *) { assert(0); } void Visitor::visit(Array *) { assert(0); } @@ -177,8 +189,8 @@ protected: Formatter::Attribute *literal; public: - Dumper(std::ostream &_os) : os(_os) { - formatter = Formatter::defaultFormatter(); + Dumper(std::ostream &_os, bool color) : os(_os) { + formatter = Formatter::defaultFormatter(color); normal = formatter->normal(); bold = formatter->bold(); italic = formatter->italic(); @@ -250,14 +262,14 @@ public: } void visit(Enum *node) { - os << literal << node->sig->first << normal; + os << literal << node->sig->name << normal; } void visit(Bitmask *bitmask) { unsigned long long value = bitmask->value; - const Bitmask::Signature *sig = bitmask->sig; + const BitmaskSig *sig = bitmask->sig; bool first = true; - for (Bitmask::Signature::const_iterator it = sig->begin(); value != 0 && it != sig->end(); ++it) { + for (const BitmaskFlag *it = sig->flags; value != 0 && it != sig->flags + sig->num_flags; ++it) { if ((it->value && (value & it->value) == it->value) || (!it->value && value == 0)) { if (!first) { @@ -334,27 +346,16 @@ public: }; -std::ostream & operator <<(std::ostream &os, Value *value) { - Dumper d(os); - if (value) { - value->visit(d); - } - return os; -} - - -static inline const Value *unwrap(const Value *node) { - const Enum *c = dynamic_cast(node); - if (c) - return c->sig->second; - return node; +void Value::dump(std::ostream &os, bool color) { + Dumper d(os, color); + visit(d); } static Null null; const Value & Value::operator[](size_t index) const { - const Array *array = dynamic_cast(unwrap(this)); + const Array *array = dynamic_cast(this); if (array) { if (index < array->values.size()) { return *array->values[index]; @@ -363,11 +364,10 @@ const Value & Value::operator[](size_t index) const { return null; } -std::ostream & operator <<(std::ostream &os, Call &call) { - Dumper d(os); - os << call.no << " "; - d.visit(&call); - return os; +void Call::dump(std::ostream &os, bool color) { + Dumper d(os, color); + os << no << " "; + d.visit(this); }