From: José Fonseca Date: Sat, 7 May 2011 00:09:19 +0000 (+0100) Subject: Stop using implicit casts. X-Git-Tag: 2.0_alpha^2~944 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=56e093c39d3fdfb0e928402e7b5d5a1a23b14347;p=tools%2Fapitrace.git Stop using implicit casts. C++ implicit cast semantics don't match precisely what we need. --- diff --git a/glretrace_glx.cpp b/glretrace_glx.cpp index 74022e7..1784cf0 100644 --- a/glretrace_glx.cpp +++ b/glretrace_glx.cpp @@ -73,7 +73,7 @@ static void retrace_glXMakeCurrent(Trace::Call &call) { } } - glws::Drawable *new_drawable = getDrawable(static_cast(call.arg(1))); + glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt()); glws::Context *new_context = context_map[call.arg(2).toPointer()]; bool result = ws->makeCurrent(new_drawable, new_context); @@ -180,7 +180,7 @@ static void retrace_glXMakeContextCurrent(Trace::Call &call) { } } - glws::Drawable *new_drawable = getDrawable(static_cast(call.arg(1))); + glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt()); glws::Context *new_context = context_map[call.arg(3).toPointer()]; bool result = ws->makeCurrent(new_drawable, new_context); diff --git a/glretrace_wgl.cpp b/glretrace_wgl.cpp index bdb5f57..6a40f78 100644 --- a/glretrace_wgl.cpp +++ b/glretrace_wgl.cpp @@ -160,8 +160,8 @@ static void retrace_wglMakeContextCurrentARB(Trace::Call &call) { } static void retrace_wglCreatePbufferARB(Trace::Call &call) { - unsigned iWidth = call.arg(2); - unsigned iHeight = call.arg(3); + unsigned iWidth = call.arg(2).toUInt(); + unsigned iHeight = call.arg(3).toUInt(); unsigned long long orig_pbuffer = call.ret->toUIntPtr(); glws::Drawable *drawable = ws->createDrawable(glretrace::visual); diff --git a/retrace.py b/retrace.py index 7b8c3da..9e42be3 100644 --- a/retrace.py +++ b/retrace.py @@ -51,10 +51,8 @@ def handle_entry(handle, value): class ValueExtractor(stdapi.Visitor): def visit_literal(self, literal, lvalue, rvalue): - if literal.format == 'Bool': - print ' %s = static_cast(%s);' % (lvalue, rvalue) - else: - print ' %s = %s;' % (lvalue, rvalue) + #if literal.format in ('Bool', 'UInt'): + print ' %s = (%s).to%s();' % (lvalue, rvalue, literal.format) def visit_const(self, const, lvalue, rvalue): self.visit(const.type, lvalue, rvalue) @@ -63,7 +61,7 @@ class ValueExtractor(stdapi.Visitor): self.visit(alias.type, lvalue, rvalue) def visit_enum(self, enum, lvalue, rvalue): - print ' %s = %s;' % (lvalue, rvalue) + print ' %s = (%s).toSInt();' % (lvalue, rvalue) def visit_bitmask(self, bitmask, lvalue, rvalue): self.visit(bitmask.type, lvalue, rvalue) diff --git a/trace_model.cpp b/trace_model.cpp index f8801ce..21b8a14 100644 --- a/trace_model.cpp +++ b/trace_model.cpp @@ -63,47 +63,47 @@ Blob::~Blob() { // bool cast -Null ::operator bool(void) const { return false; } -Bool ::operator bool(void) const { return value; } -SInt ::operator bool(void) const { return value != 0; } -UInt ::operator bool(void) const { return value != 0; } -Float ::operator bool(void) const { return value != 0; } -String ::operator bool(void) const { return true; } -Enum ::operator bool(void) const { return static_cast(*sig->second); } -Struct ::operator bool(void) const { return true; } -Array ::operator bool(void) const { return true; } -Blob ::operator bool(void) const { return true; } -Pointer::operator bool(void) const { return value != 0; } +bool Null ::toBool(void) const { return false; } +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 String ::toBool(void) const { return true; } +bool Enum ::toBool(void) const { return sig->second->toBool(); } +bool Struct ::toBool(void) const { return true; } +bool Array ::toBool(void) const { return true; } +bool Blob ::toBool(void) const { return true; } +bool Pointer::toBool(void) const { return value != 0; } // signed integer cast -Value ::operator signed long long (void) const { assert(0); return 0; } -Null ::operator signed long long (void) const { return 0; } -Bool ::operator signed long long (void) const { return static_cast(value); } -SInt ::operator signed long long (void) const { return value; } -UInt ::operator signed long long (void) const { assert(static_cast(value) >= 0); return static_cast(value); } -Float ::operator signed long long (void) const { return static_cast(value); } -Enum ::operator signed long long (void) const { return static_cast(*sig->second); } +signed long long Value ::toSInt(void) const { assert(0); return 0; } +signed long long Null ::toSInt(void) const { return 0; } +signed long long Bool ::toSInt(void) const { return static_cast(value); } +signed long long SInt ::toSInt(void) const { return value; } +signed long long UInt ::toSInt(void) const { assert(static_cast(value) >= 0); return static_cast(value); } +signed long long Float ::toSInt(void) const { return static_cast(value); } +signed long long Enum ::toSInt(void) const { return sig->second->toSInt(); } // unsigned integer cast -Value ::operator unsigned long long (void) const { assert(0); return 0; } -Null ::operator unsigned long long (void) const { return 0; } -Bool ::operator unsigned long long (void) const { return static_cast(value); } -SInt ::operator unsigned long long (void) const { assert(value >= 0); return static_cast(value); } -UInt ::operator unsigned long long (void) const { return value; } -Float ::operator unsigned long long (void) const { return static_cast(value); } -Enum ::operator unsigned long long (void) const { return static_cast(*sig->second); } +unsigned long long Value ::toUInt(void) const { assert(0); return 0; } +unsigned long long Null ::toUInt(void) const { return 0; } +unsigned long long Bool ::toUInt(void) const { return static_cast(value); } +unsigned long long SInt ::toUInt(void) const { assert(value >= 0); return static_cast(value); } +unsigned long long UInt ::toUInt(void) const { return value; } +unsigned long long Float ::toUInt(void) const { return static_cast(value); } +unsigned long long Enum ::toUInt(void) const { return sig->second->toUInt(); } // floating point cast -Value ::operator double (void) const { assert(0); return 0; } -Null ::operator double (void) const { return 0; } -Bool ::operator double (void) const { return static_cast(value); } -SInt ::operator double (void) const { return static_cast(value); } -UInt ::operator double (void) const { return static_cast(value); } -Float ::operator double (void) const { return value; } -Enum ::operator double (void) const { return static_cast(*sig->second); } +double Value ::toFloat(void) const { assert(0); return 0; } +double Null ::toFloat(void) const { return 0; } +double Bool ::toFloat(void) const { return static_cast(value); } +double SInt ::toFloat(void) const { return static_cast(value); } +double UInt ::toFloat(void) const { return static_cast(value); } +double Float ::toFloat(void) const { return value; } +double Enum ::toFloat(void) const { return sig->second->toFloat(); } // pointer cast diff --git a/trace_model.hpp b/trace_model.hpp index d5b9950..324fc2c 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -54,51 +54,15 @@ public: virtual ~Value() {} virtual void visit(Visitor &visitor) = 0; - virtual operator bool (void) const = 0; - virtual operator signed long long (void) const; - virtual operator unsigned long long (void) const; - virtual operator double (void) const; + virtual bool toBool(void) const = 0; + virtual signed long long toSInt(void) const; + virtual unsigned long long toUInt(void) const; + virtual double toFloat(void) const; virtual void *toPointer(void) const; virtual unsigned long long toUIntPtr(void) const; virtual const char *toString(void) const; - inline operator signed char (void) const { - return static_cast(*this); - } - - inline operator unsigned char (void) const { - return static_cast(*this); - } - - inline operator signed short (void) const { - return static_cast(*this); - } - - inline operator unsigned short (void) const { - return static_cast(*this); - } - - inline operator signed (void) const { - return static_cast(*this); - } - - inline operator unsigned (void) const { - return static_cast(*this); - } - - inline operator signed long (void) const { - return static_cast(*this); - } - - inline operator unsigned long (void) const { - return static_cast(*this); - } - - inline operator float (void) const { - return static_cast(*this); - } - const Value & operator[](size_t index) const; }; @@ -106,10 +70,10 @@ public: class Null : public Value { public: - operator bool (void) const; - operator signed long long (void) const; - operator unsigned long long (void) const; - operator double (void) const; + bool toBool(void) const; + signed long long toSInt(void) const; + unsigned long long toUInt(void) const; + double toFloat(void) const; void *toPointer(void) const; unsigned long long toUIntPtr(void) const; const char *toString(void) const; @@ -122,10 +86,10 @@ class Bool : public Value public: Bool(bool _value) : value(_value) {} - operator bool (void) const; - operator signed long long (void) const; - operator unsigned long long (void) const; - operator double (void) const; + bool toBool(void) const; + signed long long toSInt(void) const; + unsigned long long toUInt(void) const; + double toFloat(void) const; void visit(Visitor &visitor); bool value; @@ -137,10 +101,10 @@ class SInt : public Value public: SInt(signed long long _value) : value(_value) {} - operator bool (void) const; - operator signed long long (void) const; - operator unsigned long long (void) const; - operator double (void) const; + bool toBool(void) const; + signed long long toSInt(void) const; + unsigned long long toUInt(void) const; + double toFloat(void) const; void visit(Visitor &visitor); signed long long value; @@ -152,10 +116,10 @@ class UInt : public Value public: UInt(unsigned long long _value) : value(_value) {} - operator bool (void) const; - operator signed long long (void) const; - operator unsigned long long (void) const; - operator double (void) const; + bool toBool(void) const; + signed long long toSInt(void) const; + unsigned long long toUInt(void) const; + double toFloat(void) const; void visit(Visitor &visitor); unsigned long long value; @@ -167,10 +131,10 @@ class Float : public Value public: Float(double _value) : value(_value) {} - operator bool (void) const; - operator signed long long (void) const; - operator unsigned long long (void) const; - operator double (void) const; + bool toBool(void) const; + signed long long toSInt(void) const; + unsigned long long toUInt(void) const; + double toFloat(void) const; void visit(Visitor &visitor); double value; @@ -182,7 +146,7 @@ class String : public Value public: String(std::string _value) : value(_value) {} - operator bool (void) const; + bool toBool(void) const; const char *toString(void) const; void visit(Visitor &visitor); @@ -209,10 +173,10 @@ public: Enum(const Signature *_sig) : sig(_sig) {} - operator bool (void) const; - operator signed long long (void) const; - operator unsigned long long (void) const; - operator double (void) const; + bool toBool(void) const; + signed long long toSInt(void) const; + unsigned long long toUInt(void) const; + double toFloat(void) const; void visit(Visitor &visitor); const Signature *sig; @@ -244,7 +208,7 @@ public: Struct(Signature *_sig) : sig(_sig), members(_sig->member_names.size()) { } ~Struct(); - operator bool (void) const; + bool toBool(void) const; void visit(Visitor &visitor); const Signature *sig; @@ -258,7 +222,7 @@ public: Array(size_t len) : values(len) {} ~Array(); - operator bool (void) const; + bool toBool(void) const; void visit(Visitor &visitor); std::vector values; @@ -275,7 +239,7 @@ public: ~Blob(); - operator bool (void) const; + bool toBool(void) const; void *toPointer(void) const; void visit(Visitor &visitor); @@ -289,7 +253,7 @@ class Pointer : public UInt public: Pointer(unsigned long long value) : UInt(value) {} - operator bool (void) const; + bool toBool(void) const; void *toPointer(void) const; unsigned long long toUIntPtr(void) const; void visit(Visitor &visitor);