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;
if (!memberName || !*memberName) {
// Anonymous structure
- Struct *memberStruct = dynamic_cast<Struct *>(memberValue);
+ Struct *memberStruct = memberValue->toStruct();
assert(memberStruct);
if (memberStruct) {
sep = visitMembers(memberStruct, sep);
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];
class Visitor;
+class Null;
+class Struct;
+class Array;
class Value
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;
};
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; }
};
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;
};
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
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()) {
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);
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) {
}
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);
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) {
*/
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;
}
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)
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:
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]
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
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,))
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)):