]> git.cworth.org Git - apitrace/blobdiff - common/trace_model.cpp
Trace enum signatures as a whole.
[apitrace] / common / trace_model.cpp
index 306b9e7a64da745384f06ee050eeddc97e9a1b4b..2ceb81074a846ce494951b10918fb14f840aa034 100644 (file)
@@ -28,7 +28,7 @@
 #include "trace_model.hpp"
 
 
-namespace Trace {
+namespace trace {
 
 
 Call::~Call() {
@@ -80,8 +80,8 @@ bool Bool   ::toBool(void) const { return value; }
 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 Double ::toBool(void) const { return value != 0; }
 bool String ::toBool(void) const { return true; }
-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; }
@@ -95,7 +95,7 @@ signed long long Bool   ::toSInt(void) const { return static_cast<signed long lo
 signed long long SInt   ::toSInt(void) const { return value; }
 signed long long UInt   ::toSInt(void) const { assert(static_cast<signed long long>(value) >= 0); return static_cast<signed long long>(value); }
 signed long long Float  ::toSInt(void) const { return static_cast<signed long long>(value); }
-signed long long Enum   ::toSInt(void) const { return sig->value; }
+signed long long Double ::toSInt(void) const { return static_cast<signed long long>(value); }
 
 
 // unsigned integer cast
@@ -105,7 +105,7 @@ unsigned long long Bool   ::toUInt(void) const { return static_cast<unsigned lon
 unsigned long long SInt   ::toUInt(void) const { assert(value >= 0); return static_cast<signed long long>(value); }
 unsigned long long UInt   ::toUInt(void) const { return value; }
 unsigned long long Float  ::toUInt(void) const { return static_cast<unsigned long long>(value); }
-unsigned long long Enum   ::toUInt(void) const { assert(sig->value >= 0); return sig->value; }
+unsigned long long Double ::toUInt(void) const { return static_cast<unsigned long long>(value); }
 
 
 // floating point cast
@@ -115,7 +115,7 @@ float Bool   ::toFloat(void) const { return static_cast<float>(value); }
 float SInt   ::toFloat(void) const { return static_cast<float>(value); }
 float UInt   ::toFloat(void) const { return static_cast<float>(value); }
 float Float  ::toFloat(void) const { return value; }
-float Enum   ::toFloat(void) const { return static_cast<float>(sig->value); }
+float Double ::toFloat(void) const { return value; }
 
 
 // floating point cast
@@ -125,7 +125,7 @@ double Bool   ::toDouble(void) const { return static_cast<double>(value); }
 double SInt   ::toDouble(void) const { return static_cast<double>(value); }
 double UInt   ::toDouble(void) const { return static_cast<double>(value); }
 double Float  ::toDouble(void) const { return value; }
-double Enum   ::toDouble(void) const { return static_cast<double>(sig->value); }
+double Double ::toDouble(void) const { return value; }
 
 
 // pointer cast
@@ -158,6 +158,7 @@ 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 Double ::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); }
@@ -172,6 +173,7 @@ void Visitor::visit(Bool *) { assert(0); }
 void Visitor::visit(SInt *) { assert(0); }
 void Visitor::visit(UInt *) { assert(0); }
 void Visitor::visit(Float *) { assert(0); }
+void Visitor::visit(Double *) { assert(0); }
 void Visitor::visit(String *) { assert(0); }
 void Visitor::visit(Enum *node) { assert(0); }
 void Visitor::visit(Bitmask *node) { visit(static_cast<UInt *>(node)); }
@@ -185,29 +187,32 @@ 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;
+    formatter::Formatter *formatter;
+    formatter::Attribute *normal;
+    formatter::Attribute *bold;
+    formatter::Attribute *italic;
+    formatter::Attribute *strike;
+    formatter::Attribute *red;
+    formatter::Attribute *pointer;
+    formatter::Attribute *literal;
 
 public:
     Dumper(std::ostream &_os, bool color) : os(_os) {
-        formatter = Formatter::defaultFormatter(color);
+        formatter = formatter::defaultFormatter(color);
         normal = formatter->normal();
         bold = formatter->bold();
         italic = formatter->italic();
-        red = formatter->color(Formatter::RED);
-        pointer = formatter->color(Formatter::GREEN);
-        literal = formatter->color(Formatter::BLUE);
+        strike = formatter->strike();
+        red = formatter->color(formatter::RED);
+        pointer = formatter->color(formatter::GREEN);
+        literal = formatter->color(formatter::BLUE);
     }
 
     ~Dumper() {
         delete normal;
         delete bold;
         delete italic;
+        delete strike;
         delete red;
         delete pointer;
         delete literal;
@@ -234,6 +239,10 @@ public:
         os << literal << node->value << normal;
     }
 
+    void visit(Double *node) {
+        os << literal << node->value << normal;
+    }
+
     void visit(String *node) {
         os << literal << "\"";
         for (const char *it = node->value; *it; ++it) {
@@ -267,7 +276,14 @@ public:
     }
 
     void visit(Enum *node) {
-        os << literal << node->sig->name << normal;
+        const EnumSig *sig = node->sig;
+        for (const EnumValue *it = sig->values; it != sig->values + sig->num_values; ++it) {
+            if (it->value == node->value) {
+                os << literal << it->name << normal;
+                return;
+            }
+        }
+        os << literal << node->value << normal;
     }
 
     void visit(Bitmask *bitmask) {
@@ -330,8 +346,19 @@ public:
     }
 
     void visit(Call *call) {
+        CallFlags flags = call->flags;
+
+        if (flags & CALL_FLAG_NON_REPRODUCIBLE) {
+            os << strike;
+        } else if (flags & (CALL_FLAG_FAKE | CALL_FLAG_NO_SIDE_EFFECTS)) {
+            os << normal;
+        } else {
+            os << bold;
+        }
+        os << call->sig->name << normal;
+
+        os << "(";
         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 << " = ";
             if (call->args[i]) {
@@ -342,11 +369,21 @@ public:
             sep = ", ";
         }
         os << ")";
+
         if (call->ret) {
             os << " = ";
             _visit(call->ret);
         }
+        
+        if (flags & CALL_FLAG_INCOMPLETE) {
+            os << " // " << red << "incomplete" << normal;
+        }
+        
         os << "\n";
+
+        if (flags & CALL_FLAG_END_FRAME) {
+            os << "\n";
+        }
     }
 };
 
@@ -376,4 +413,4 @@ void Call::dump(std::ostream &os, bool color) {
 }
 
 
-} /* namespace Trace */
+} /* namespace trace */