]> git.cworth.org Git - apitrace/blobdiff - trace_model.cpp
Split glxapi.
[apitrace] / trace_model.cpp
index 213c8724ac00e182f406f8b9016c5d5b6a50b7f5..760093c780a4d1279ffd36bb88b1f04e891ee029 100644 (file)
@@ -24,6 +24,7 @@
  **************************************************************************/
 
 
+#include "formatter.hpp"
 #include "trace_model.hpp"
 
 
@@ -69,52 +70,76 @@ void Blob::visit(Visitor &visitor) {
 
 class Dumper : public Visitor
 {
-public:
+protected:
    std::ostream &os;
+   Formatter::Formatter *formatter;
+   Formatter::Attribute *normal;
+   Formatter::Attribute *bold;
+   Formatter::Attribute *italic;
+   Formatter::Attribute *red;
+   Formatter::Attribute *pointer;
+   Formatter::Attribute *literal;
 
-   Dumper() : os(std::cout) {}
+public:
+   Dumper(std::ostream &_os) : os(_os) {
+      formatter = Formatter::defaultFormatter();
+      normal = formatter->normal();
+      bold = formatter->bold();
+      italic = formatter->italic();
+      red = formatter->color(Formatter::RED);
+      pointer = formatter->color(Formatter::GREEN);
+      literal = formatter->color(Formatter::BLUE);
+   }
 
-   Dumper(std::ostream &_os) : os(_os) {}
+   ~Dumper() {
+      delete normal;
+      delete bold;
+      delete italic;
+      delete red;
+      delete pointer;
+      delete literal;
+      delete formatter;
+   }
 
-   void visit(Null *node) {
+   void visit(Null *) {
       os << "NULL";
    }
 
    void visit(Bool *node) {
-      os << (node->value ? "true" : "false");
+      os << literal << (node->value ? "true" : "false") << normal;
    }
 
    void visit(SInt *node) {
-      os << node->value;
+      os << literal << node->value << normal;
    }
 
    void visit(UInt *node) {
-      os << node->value;
+      os << literal << node->value << normal;
    }
 
    void visit(Float *node) {
-      os << node->value;
+      os << literal << node->value << normal;
    }
 
    void visit(String *node) {
-      os << '"' << node->value << '"';
+      os << literal << '"' << node->value << '"' << normal;
    }
 
    void visit(Const *node) {
-      os << node->name;
+      os << literal << node->name << normal;
    }
 
    void visit(Array *array) {
       if (array->values.size() == 1) {
          os << "&";
-         array->values[0]->visit(*this);
+         _visit(array->values[0]);
       }
       else {
          const char *sep = "";
          os << "{";
          for (std::vector<Value *>::iterator it = array->values.begin(); it != array->values.end(); ++it) {
             os << sep;
-            (*it)->visit(*this);
+            _visit(*it);
             sep = ", ";
          }
          os << "}";
@@ -122,7 +147,23 @@ public:
    }
    
    void visit(Blob *blob) {
-      os << "... " << blob->size;
+      os << pointer << "blob(" << blob->size << ")" << normal;
+   }
+
+   void visit(Call *call) {
+      const char *sep = "";
+      os << bold << call->name << normal << "(";
+      for (std::vector<Arg>::iterator it = call->args.begin(); it != call->args.end(); ++it) {
+         os << sep << italic << it->first << normal << " = ";
+         _visit(it->second);
+         sep = ", ";
+      }
+      os << ")";
+      if (call->ret) {
+         os << " = ";
+         _visit(call->ret);
+      }
+      os << "\n";
    }
 };
 
@@ -144,6 +185,14 @@ static inline const Value *unwrap(const Value *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)
@@ -187,7 +236,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;
@@ -198,33 +247,15 @@ 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) {
-   const char *sep = "";
-   os << call.name << "(";
-   for (std::list<Arg>::iterator it = call.args.begin(); it != call.args.end(); ++it) {
-      os << sep << it->first << " = " << it->second;
-      sep = ", ";
-   }
-   os << ")";
-   if (call.ret) {
-      os << " = " << call.ret;
-   }
-   os << "\n";
+   Dumper d(os);
+   d.visit(&call);
    return os;
 }