]> git.cworth.org Git - apitrace/blobdiff - trace_model.cpp
Fix d3d9 bad bitmasks.
[apitrace] / trace_model.cpp
index e6ec467ad10bd3cbae8eaeaae030f41ba2b3f982..2e20b243852b3a4475a967fbd9581edb7fa52000 100644 (file)
 namespace Trace {
 
 
-void Null::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); } 
 
-void Bool::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+class Dumper : public Visitor
+{
+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;
 
-void SInt::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+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);
+    }
 
-void UInt::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+    ~Dumper() {
+        delete normal;
+        delete bold;
+        delete italic;
+        delete red;
+        delete pointer;
+        delete literal;
+        delete formatter;
+    }
 
-void Float::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+    void visit(Null *) {
+        os << "NULL";
+    }
 
-void String::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+    void visit(Bool *node) {
+        os << literal << (node->value ? "true" : "false") << normal;
+    }
 
-void Const::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+    void visit(SInt *node) {
+        os << literal << node->value << normal;
+    }
 
-void Bitmask::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+    void visit(UInt *node) {
+        os << literal << node->value << normal;
+    }
 
-void Array::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+    void visit(Float *node) {
+        os << literal << node->value << normal;
+    }
 
-void Blob::visit(Visitor &visitor) {
-   visitor.visit(this);
-}
+    void visit(String *node) {
+        os << literal << '"' << node->value << '"' << normal;
+    }
 
+    void visit(Enum *node) {
+        os << literal << node->name << normal;
+    }
 
-class Dumper : public Visitor
-{
-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;
+    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;
+        }
+    }
 
-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() {
-      delete normal;
-      delete bold;
-      delete italic;
-      delete red;
-      delete pointer;
-      delete literal;
-      delete formatter;
-   }
-
-   void visit(Null *) {
-      os << "NULL";
-   }
-
-   void visit(Bool *node) {
-      os << literal << (node->value ? "true" : "false") << normal;
-   }
-
-   void visit(SInt *node) {
-      os << literal << node->value << normal;
-   }
-
-   void visit(UInt *node) {
-      os << literal << node->value << normal;
-   }
-
-   void visit(Float *node) {
-      os << literal << node->value << normal;
-   }
-
-   void visit(String *node) {
-      os << literal << '"' << node->value << '"' << normal;
-   }
-
-   void visit(Const *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(Array *array) {
-      if (array->values.size() == 1) {
-         os << "&";
-         _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;
-            _visit(*it);
+    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 << "&";
+            _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;
+                _visit(*it);
+                sep = ", ";
+            }
+            os << "}";
+        }
+    }
+
+    void visit(Blob *blob) {
+        os << pointer << "blob(" << blob->size << ")" << normal;
+    }
+
+    void visit(Call *call) {
+        const char *sep = "";
+        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 << "}";
-      }
-   }
-   
-   void visit(Blob *blob) {
-      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";
-   }
+        }
+        os << ")";
+        if (call->ret) {
+            os << " = ";
+            _visit(call->ret);
+        }
+        os << "\n";
+    }
 };
 
 
 std::ostream & operator <<(std::ostream &os, Value *value) {
-   Dumper d(os);
-   if (value) {
-      value->visit(d);
-   }
-   return os;
+    Dumper d(os);
+    if (value) {
+        value->visit(d);
+    }
+    return os;
 }
 
 
 static inline const Value *unwrap(const Value *node) {
-   const Const *c = dynamic_cast<const Const *>(node);
-   if (c)
-      return c->value;
-   return 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;
+    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)
-      return sint->value;
-   const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
-   if (uint)
-      return uint->value;
-   assert(0);
-   return 0;
+    const SInt *sint = dynamic_cast<const SInt *>(unwrap(this));
+    if (sint)
+        return sint->value;
+    const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
+    if (uint)
+        return uint->value;
+    assert(0);
+    return 0;
 }
 
 Value::operator unsigned long long(void) const {
-   const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
-   if (uint)
-      return uint->value;
-   assert(0);
-   return 0;
+    const UInt *uint = dynamic_cast<const UInt *>(unwrap(this));
+    if (uint)
+        return uint->value;
+    assert(0);
+    return 0;
 }
 
 
 Value::operator double(void) const {
-   const Float *fl = dynamic_cast<const Float *>(unwrap(this));
-   assert(fl);
-   return fl->value;
+    const Float *fl = dynamic_cast<const Float *>(unwrap(this));
+    assert(fl);
+    return fl->value;
 }
 
 static Null null;
@@ -259,31 +241,31 @@ const Value & Value::operator[](size_t index) const {
 }
 
 void * Value::blob(void) const {
-   const Blob *blob = dynamic_cast<const Blob *>(unwrap(this));
-   if (blob)
-       return blob->buf;
-   const Null *null = dynamic_cast<const Null *>(unwrap(this));
-   if (null)
-       return NULL;
-   assert(0);
-   return NULL;
+    const Blob *blob = dynamic_cast<const Blob *>(unwrap(this));
+    if (blob)
+        return blob->buf;
+    const Null *null = dynamic_cast<const Null *>(unwrap(this));
+    if (null)
+        return NULL;
+    assert(0);
+    return NULL;
 }
 
 const char * Value::string(void) const {
-   const String *string = dynamic_cast<const String *>(unwrap(this));
-   if (string)
-       return string->value.c_str();
-   const Null *null = dynamic_cast<const Null *>(unwrap(this));
-   if (null)
-       return NULL;
-   assert(0);
-   return NULL;
+    const String *string = dynamic_cast<const String *>(unwrap(this));
+    if (string)
+        return string->value.c_str();
+    const Null *null = dynamic_cast<const Null *>(unwrap(this));
+    if (null)
+        return NULL;
+    assert(0);
+    return NULL;
 }
 
 std::ostream & operator <<(std::ostream &os, Call &call) {
-   Dumper d(os);
-   d.visit(&call);
-   return os;
+    Dumper d(os);
+    d.visit(&call);
+    return os;
 }