]> git.cworth.org Git - apitrace/blobdiff - trace_model.cpp
More extensions.
[apitrace] / trace_model.cpp
index f4e915d476aed87d5c27bf89ed56a8ada7b53d8d..d0bf31d5ae905fcb86de1b5fa823bf2f9a40a2c1 100644 (file)
 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
 {
@@ -101,7 +76,7 @@ public:
       delete formatter;
    }
 
-   void visit(Null *node) {
+   void visit(Null *) {
       os << "NULL";
    }
 
@@ -125,10 +100,44 @@ public:
       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 << "&";
@@ -152,10 +161,10 @@ public:
 
    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 << ")";
@@ -178,13 +187,21 @@ std::ostream & operator <<(std::ostream &os, Value *value) {
 
 
 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)
@@ -228,7 +245,7 @@ void * Value::blob(void) const {
    if (blob)
        return blob->buf;
    const Null *null = dynamic_cast<const Null *>(unwrap(this));
-   if (null);
+   if (null)
        return NULL;
    assert(0);
    return NULL;
@@ -239,21 +256,12 @@ const char * Value::string(void) const {
    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);