From 4ebb896eacf935e9fae1a901d925ea1389bfae6b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Wed, 24 Nov 2010 20:26:14 +0000 Subject: [PATCH] Handle pointers & bools correctly. --- glretrace.py | 32 +++++++++++++++++++++++++------- trace_model.cpp | 8 ++++++++ trace_model.hpp | 1 + 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/glretrace.py b/glretrace.py index 5cdcf24..09f5163 100644 --- a/glretrace.py +++ b/glretrace.py @@ -44,7 +44,13 @@ class ConstRemover(base.Rebuilder): class ValueExtractor(base.Visitor): def visit_literal(self, literal, lvalue, rvalue): - print ' %s = %s;' % (lvalue, rvalue) + if literal.format == 'Bool': + print ' %s = static_cast(%s);' % (lvalue, rvalue) + else: + print ' %s = %s;' % (lvalue, rvalue) + + def visit_const(self, const, lvalue, rvalue): + self.visit(const.type, lvalue, rvalue) def visit_alias(self, alias, lvalue, rvalue): self.visit(alias.type, lvalue, rvalue) @@ -60,7 +66,7 @@ class ValueExtractor(base.Visitor): print ' if (__a%s) {' % (array.id) length = '__a%s->values.size()' % array.id print ' %s = new %s[%s];' % (lvalue, array.type, length) - index = '__i' + array.id + index = '__j' + array.id print ' for(size_t {i} = 0; {i} < {length}; ++{i}) {{'.format(i = index, length = length) try: self.visit(array.type, '%s[%s]' % (lvalue, index), '*__a%s->values[%s]' % (array.id, index)) @@ -71,8 +77,15 @@ class ValueExtractor(base.Visitor): print ' }' def visit_pointer(self, pointer, lvalue, rvalue): - # FIXME - raise NotImplementedError + print ' const Trace::Array *__a%s = dynamic_cast(&%s);' % (pointer.id, rvalue) + print ' if (__a%s) {' % (pointer.id) + print ' %s = new %s;' % (lvalue, pointer.type) + try: + self.visit(pointer.type, '%s[0]' % (lvalue,), '*__a%s->values[0]' % (pointer.id,)) + finally: + print ' } else {' + print ' %s = NULL;' % lvalue + print ' }' def visit_handle(self, handle, lvalue, rvalue): self.visit(handle.type, lvalue, "__%s_map[%s]" %(handle.name, rvalue)); @@ -105,7 +118,7 @@ class ValueWrapper(base.Visitor): print ' const Trace::Array *__a%s = dynamic_cast(&%s);' % (array.id, rvalue) print ' if (__a%s) {' % (array.id) length = '__a%s->values.size()' % array.id - index = '__i' + array.id + index = '__j' + array.id print ' for(size_t {i} = 0; {i} < {length}; ++{i}) {{'.format(i = index, length = length) try: self.visit(array.type, '%s[%s]' % (lvalue, index), '*__a%s->values[%s]' % (array.id, index)) @@ -114,8 +127,13 @@ class ValueWrapper(base.Visitor): print ' }' def visit_pointer(self, pointer, lvalue, rvalue): - # FIXME - raise NotImplementedError + print ' const Trace::Array *__a%s = dynamic_cast(&%s);' % (pointer.id, rvalue) + print ' if (__a%s) {' % (pointer.id) + try: + self.visit(pointer.type, '%s[0]' % (lvalue,), '*__a%s->values[0]' % (pointer.id,)) + finally: + print ' }' + def visit_handle(self, handle, lvalue, rvalue): print " __%s_map[static_cast<%s>(%s)] = %s;" % (handle.name, handle.type, rvalue, lvalue) diff --git a/trace_model.cpp b/trace_model.cpp index 098656f..74f9c9f 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -185,6 +185,14 @@ static inline const Value *unwrap(const Value *node) { } +Value::operator bool(void) const { + const Bool *b = dynamic_cast(unwrap(this)); + if (b) + return b->value; + assert(0); + return false; +} + Value::operator signed long long(void) const { const SInt *sint = dynamic_cast(unwrap(this)); if (sint) diff --git a/trace_model.hpp b/trace_model.hpp index f50c6ac..8cf1951 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -49,6 +49,7 @@ class Value public: virtual void visit(Visitor &visitor) = 0; + operator bool (void) const; operator signed long long (void) const; operator unsigned long long (void) const; operator double (void) const; -- 2.45.2