]> git.cworth.org Git - apitrace/commitdiff
Replace dynamic_cast with virtual functions.
authorNigel Stewart <nstewart@nvidia.com>
Wed, 10 Jul 2013 14:01:01 +0000 (09:01 -0500)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 11 Jul 2013 17:14:59 +0000 (18:14 +0100)
apitrace can be built with without RTTI (runtime type information)
providing that dynamic_cast isn't used.

cli/trace_analyzer.cpp
common/trace_dump.cpp
common/trace_model.cpp
common/trace_model.hpp
retrace/glretrace_cgl.cpp
retrace/glretrace_egl.cpp
retrace/glretrace_glx.cpp
retrace/glretrace_ws.cpp
retrace/retrace.hpp
retrace/retrace.py

index 374e6ceffedcc545c86aa11b8403679cce27a7bd..79f95579eb2626be39a3aa724542367147f2de04 100644 (file)
@@ -279,7 +279,7 @@ bool
 TraceAnalyzer::recordTextureSideEffects(trace::Call *call, const char *name)
 {
     if (strcmp(name, "glGenTextures") == 0) {
-        const trace::Array *textures = dynamic_cast<const trace::Array *>(&call->arg(1));
+        const trace::Array *textures = call->arg(1).toArray();
         size_t i;
         GLuint texture;
 
index 655b023d55c97b7bbcf5c236be9b4949a4b3844d..6e67e08ab53e0f2585d5a1e952b9d00bae220b02 100644 (file)
@@ -178,7 +178,7 @@ public:
 
             if (!memberName || !*memberName) {
                 // Anonymous structure
-                Struct *memberStruct = dynamic_cast<Struct *>(memberValue);
+                Struct *memberStruct = memberValue->toStruct();
                 assert(memberStruct);
                 if (memberStruct) {
                     sep = visitMembers(memberStruct, sep);
index 2c0fafaabbc6e81240d95eba251ebe9a9a434abf..3f19bc6c60b27c43f82f66acd976fdee364871dc 100644 (file)
@@ -210,7 +210,7 @@ void Visitor::visit(StackFrame *) { assert(0); }
 static Null null;
 
 const Value & Value::operator[](size_t index) const {
-    const Array *array = dynamic_cast<const Array *>(this);
+    const Array *array = toArray();
     if (array) {
         if (index < array->values.size()) {
             return *array->values[index];
index 4a9ca476f262580f6c32a83ce6ba882f41630935..36f0a03eff83cb15d5919fb86b661eb0cd271513 100644 (file)
@@ -91,6 +91,9 @@ struct BitmaskSig {
 
 
 class Visitor;
+class Null;
+class Struct;
+class Array;
 
 
 class Value
@@ -110,6 +113,15 @@ public:
     virtual unsigned long long toUIntPtr(void) const;
     virtual const char *toString(void) const;
 
+    virtual const Null *toNull(void) const { return NULL; }
+    virtual Null *toNull(void) { return NULL; }
+
+    virtual const Array *toArray(void) const { return NULL; }
+    virtual Array *toArray(void) { return NULL; }
+
+    virtual const Struct *toStruct(void) const { return NULL; }
+    virtual Struct *toStruct(void) { return NULL; }
+
     const Value & operator[](size_t index) const;
 };
 
@@ -127,6 +139,9 @@ public:
     unsigned long long toUIntPtr(void) const;
     const char *toString(void) const;
     void visit(Visitor &visitor);
+
+    const Null *toNull(void) const { return this; }
+    Null *toNull(void) { return this; }
 };
 
 
@@ -266,6 +281,9 @@ public:
     bool toBool(void) const;
     void visit(Visitor &visitor);
 
+    const Struct *toStruct(void) const { return this; }
+    Struct *toStruct(void) { return this; }
+
     const StructSig *sig;
     std::vector<Value *> members;
 };
@@ -280,6 +298,9 @@ public:
     bool toBool(void) const;
     void visit(Visitor &visitor);
 
+    const Array *toArray(void) const { return this; }
+    Array *toArray(void) { return this; }
+
     std::vector<Value *> values;
 
     inline size_t
index f0d0e2d7d5b29ff4ee0232d479fab8b408374de9..73bb250c4a4b58bf5b19d63337fa6bcadff58739 100644 (file)
@@ -127,7 +127,7 @@ getContext(unsigned long long ctx) {
 static void retrace_CGLChoosePixelFormat(trace::Call &call) {
     int profile = kCGLOGLPVersion_Legacy;
 
-    const trace::Array * attribs = dynamic_cast<const trace::Array *>(&call.arg(0));
+    const trace::Array * attribs = call.arg(0).toArray();
     if (attribs) {
         size_t i = 0;
         while (i < attribs->values.size()) {
@@ -201,7 +201,7 @@ static void retrace_CGLCreateContext(trace::Call &call) {
     unsigned long long share = call.arg(1).toUIntPtr();
     Context *sharedContext = getContext(share);
 
-    const trace::Array *ctx_ptr = dynamic_cast<const trace::Array *>(&call.arg(2));
+    const trace::Array *ctx_ptr = call.arg(2).toArray();
     unsigned long long ctx = ctx_ptr->values[0]->toUIntPtr();
 
     Context *context = glretrace::createContext(sharedContext);
index 27c5bb8e39531a8534f63542e76a2cfaa392e400..c03d04c2d4fc16743e6b71665c42de5f4d518bcd 100644 (file)
@@ -145,7 +145,7 @@ static void retrace_eglCreateContext(trace::Call &call) {
     unsigned long long orig_context = call.ret->toUIntPtr();
     unsigned long long orig_config = call.arg(1).toUIntPtr();
     Context *share_context = getContext(call.arg(2).toUIntPtr());
-    trace::Array *attrib_array = dynamic_cast<trace::Array *>(&call.arg(3));
+    trace::Array *attrib_array = call.arg(3).toArray();
     glws::Profile profile;
 
     switch (current_api) {
index fe88a59406ab285c0ace7327077bbbe4f929406e..3179c1ea7ff34d779635fdcb86d3b1c25dc58979 100644 (file)
@@ -133,7 +133,7 @@ static void retrace_glXCreateNewContext(trace::Call &call) {
 }
 
 static void retrace_glXCreatePbuffer(trace::Call &call) {
-    const trace::Value *attrib_list = dynamic_cast<const trace::Array *>(&call.arg(2));
+    const trace::Value *attrib_list = call.arg(2).toArray();
     int width = glretrace::parseAttrib(attrib_list, GLX_PBUFFER_WIDTH, 0);
     int height = glretrace::parseAttrib(attrib_list, GLX_PBUFFER_HEIGHT, 0);
 
index ab3c41af388009583be26f5190abf0a7f44d8ec1..d1e85f824d08815d4a511c06197725051e85062d 100644 (file)
@@ -233,7 +233,7 @@ updateDrawable(int width, int height) {
 
 int
 parseAttrib(const trace::Value *attribs, int param, int default_ = 0) {
-    const trace::Array *attribs_ = dynamic_cast<const trace::Array *>(attribs);
+    const trace::Array *attribs_ = attribs ? attribs->toArray() : NULL;
 
     if (attribs_) {
         for (size_t i = 0; i + 1 < attribs_->values.size(); i += 2) {
index f37f2494d7ca05b2acc27eb03791bdbecbcc6e5a..6e6bf131c6dc82eed5710db6df6b5e8fb0328633 100644 (file)
@@ -63,11 +63,11 @@ public:
      */
     inline void *
     alloc(const trace::Value *value, size_t size) {
-        const trace::Array *array = dynamic_cast<const trace::Array *>(value);
+        const trace::Array *array = value->toArray();
         if (array) {
             return ::ScopedAllocator::alloc(array->size() * size);
         }
-        const trace::Null *null = dynamic_cast<const trace::Null *>(value);
+        const trace::Null *null = value->toNull();
         if (null) {
             return NULL;
         }
index 25fa62a51f4644c7141b9a664c359d9d81ddbed1..1cdb092efcfc7b9f3d0610e3a8e0ef2abaa1b2bc 100644 (file)
@@ -129,7 +129,7 @@ class ValueDeserializer(stdapi.Visitor, stdapi.ExpanderMixin):
         self.seq += 1
 
         print '    if (%s) {' % (lvalue,)
-        print '        const trace::Array *%s = dynamic_cast<const trace::Array *>(&%s);' % (tmp, rvalue)
+        print '        const trace::Array *%s = (%s).toArray();' % (tmp, rvalue)
         length = '%s->values.size()' % (tmp,)
         index = '_j' + array.tag
         print '        for (size_t {i} = 0; {i} < {length}; ++{i}) {{'.format(i = index, length = length)
@@ -144,7 +144,7 @@ class ValueDeserializer(stdapi.Visitor, stdapi.ExpanderMixin):
         self.seq += 1
 
         print '    if (%s) {' % (lvalue,)
-        print '        const trace::Array *%s = dynamic_cast<const trace::Array *>(&%s);' % (tmp, rvalue)
+        print '        const trace::Array *%s = (%s).toArray();' % (tmp, rvalue)
         try:
             self.visit(pointer.type, '%s[0]' % (lvalue,), '*%s->values[0]' % (tmp,))
         finally:
@@ -190,7 +190,7 @@ class ValueDeserializer(stdapi.Visitor, stdapi.ExpanderMixin):
         tmp = '_s_' + struct.tag + '_' + str(self.seq)
         self.seq += 1
 
-        print '    const trace::Struct *%s = dynamic_cast<const trace::Struct *>(&%s);' % (tmp, rvalue)
+        print '    const trace::Struct *%s = (%s).toStruct();' % (tmp, rvalue)
         print '    assert(%s);' % (tmp)
         for i in range(len(struct.members)):
             member = struct.members[i]
@@ -251,7 +251,7 @@ class SwizzledValueRegistrator(stdapi.Visitor, stdapi.ExpanderMixin):
         pass
 
     def visitArray(self, array, lvalue, rvalue):
-        print '    const trace::Array *_a%s = dynamic_cast<const trace::Array *>(&%s);' % (array.tag, rvalue)
+        print '    const trace::Array *_a%s = (%s).toArray();' % (array.tag, rvalue)
         print '    if (_a%s) {' % (array.tag)
         length = '_a%s->values.size()' % array.tag
         index = '_j' + array.tag
@@ -263,7 +263,7 @@ class SwizzledValueRegistrator(stdapi.Visitor, stdapi.ExpanderMixin):
             print '    }'
     
     def visitPointer(self, pointer, lvalue, rvalue):
-        print '    const trace::Array *_a%s = dynamic_cast<const trace::Array *>(&%s);' % (pointer.tag, rvalue)
+        print '    const trace::Array *_a%s = (%s).toArray();' % (pointer.tag, rvalue)
         print '    if (_a%s) {' % (pointer.tag)
         try:
             self.visit(pointer.type, '%s[0]' % (lvalue,), '*_a%s->values[0]' % (pointer.tag,))
@@ -325,7 +325,7 @@ class SwizzledValueRegistrator(stdapi.Visitor, stdapi.ExpanderMixin):
         tmp = '_s_' + struct.tag + '_' + str(self.seq)
         self.seq += 1
 
-        print '    const trace::Struct *%s = dynamic_cast<const trace::Struct *>(&%s);' % (tmp, rvalue)
+        print '    const trace::Struct *%s = (%s).toStruct();' % (tmp, rvalue)
         print '    assert(%s);' % (tmp,)
         print '    (void)%s;' % (tmp,)
         for i in range(len(struct.members)):