[haiku-commits] haiku: hrev48204 - in src/apps/debugger: source_language/expression_evaluators types

  • From: anevilyak@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 1 Nov 2014 21:12:33 +0100 (CET)

hrev48204 adds 2 changesets to branch 'master'
old head: 22ea34153f39a2f995b505173e1571e2a5d39192
new head: 46ebcc8cb4674aadbb3324341b8559ead7b7c964
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=46ebcc8+%5E22ea341

----------------------------------------------------------------------------

e2a2221: Number: Add accessor for underlying type.

46ebcc8: Debugger: Fix type issues in CLanguageExpressionEvaluator.
  
  - When using variable values in an expression, we weren't ensuring
    that the resulting value type matched up with the requested
    type for the expression, leading to unpredictable results in some
    cases.

                                         [ Rene Gollent <rene@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 87 insertions(+)
.../CLanguageExpressionEvaluator.cpp             | 82 ++++++++++++++++++++
.../CLanguageExpressionEvaluator.h               |  3 +
src/apps/debugger/types/Number.h                 |  2 +

############################################################################

Commit:      e2a22217e20a82100190f6fa6c2a105cec779cdf
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e2a2221
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Sat Nov  1 19:59:58 2014 UTC

Number: Add accessor for underlying type.

----------------------------------------------------------------------------

diff --git a/src/apps/debugger/types/Number.h b/src/apps/debugger/types/Number.h
index fcbd95f..564cb44 100644
--- a/src/apps/debugger/types/Number.h
+++ b/src/apps/debugger/types/Number.h
@@ -25,6 +25,8 @@ public:
                                                                        int32 
base = 10);
                        void                            SetTo(const BVariant& 
value);
 
+                       type_code                       Type() const { return 
fValue.Type(); }
+
                        Number&                         operator=(const Number& 
rhs);
                        Number&                         operator+=(const 
Number& rhs);
                        Number&                         operator-=(const 
Number& rhs);

############################################################################

Revision:    hrev48204
Commit:      46ebcc8cb4674aadbb3324341b8559ead7b7c964
URL:         http://cgit.haiku-os.org/haiku/commit/?id=46ebcc8
Author:      Rene Gollent <rene@xxxxxxxxxxx>
Date:        Sat Nov  1 20:09:07 2014 UTC

Debugger: Fix type issues in CLanguageExpressionEvaluator.

- When using variable values in an expression, we weren't ensuring
  that the resulting value type matched up with the requested
  type for the expression, leading to unpredictable results in some
  cases.

----------------------------------------------------------------------------

diff --git 
a/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.cpp
 
b/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.cpp
index 76563bf..8d4305a 100644
--- 
a/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.cpp
+++ 
b/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.cpp
@@ -876,6 +876,7 @@ CLanguageExpressionEvaluator::_ParseIdentifier(ValueNode* 
parentNode)
        Value* nodeValue = node->GetValue();
        nodeValue->ToVariant(variant);
        value.SetTo(variant);
+       _CoerceTypeIfNeeded(token, value);
 
        return value;
 }
@@ -989,3 +990,84 @@ CLanguageExpressionEvaluator::_RequestValueIfNeeded(const 
Token& token,
                throw ParseException(errorMessage, token.position);
        }
 }
+
+
+void
+CLanguageExpressionEvaluator::_CoerceTypeIfNeeded(const Token& token,
+       Number& _number)
+{
+       if (_number.Type() == 0) {
+               throw ParseException("Unable to resolve value type.",
+                       token.position);
+       }
+
+       BVariant value = _number.GetValue();
+       type_code valueType = value.Type();
+
+       if (valueType == fCurrentType) {
+               // nothing to do.
+               return;
+       }
+
+       if (BVariant::TypeIsInteger(fCurrentType)) {
+               if (BVariant::TypeIsFloat(valueType)) {
+                       value.SetTo((int64)value.ToDouble());
+                       valueType = value.Type();
+               }
+
+               if (BVariant::TypeIsInteger(valueType)) {
+                       switch (fCurrentType) {
+                               case B_INT8_TYPE:
+                                       value.SetTo(value.ToInt8());
+                                       break;
+
+                               case B_UINT8_TYPE:
+                                       value.SetTo(value.ToUInt8());
+                                       break;
+
+                               case B_INT16_TYPE:
+                                       value.SetTo(value.ToInt16());
+                                       break;
+
+                               case B_UINT16_TYPE:
+                                       value.SetTo(value.ToUInt16());
+                                       break;
+
+                               case B_INT32_TYPE:
+                                       value.SetTo(value.ToInt32());
+                                       break;
+
+                               case B_UINT32_TYPE:
+                                       value.SetTo(value.ToUInt32());
+                                       break;
+
+                               case B_INT64_TYPE:
+                                       value.SetTo(value.ToInt64());
+                                       break;
+
+                               case B_UINT64_TYPE:
+                                       value.SetTo(value.ToUInt64());
+                                       break;
+                       }
+               }
+       } else if (BVariant::TypeIsFloat(fCurrentType)) {
+               if (BVariant::TypeIsInteger(valueType)) {
+                       value.SetTo((double)value.ToInt64());
+                       valueType = value.Type();
+               }
+
+               switch (fCurrentType) {
+                       case B_FLOAT_TYPE:
+                               value.SetTo(value.ToFloat());
+                               break;
+
+                       case B_DOUBLE_TYPE:
+                               value.SetTo(value.ToDouble());
+                               break;
+               }
+       }
+
+       _number.SetTo(value);
+}
+
+
diff --git 
a/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.h
 
b/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.h
index f20271b..14e22e5 100644
--- 
a/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.h
+++ 
b/src/apps/debugger/source_language/expression_evaluators/CLanguageExpressionEvaluator.h
@@ -80,6 +80,9 @@ class CLanguageExpressionEvaluator {
                        void                            
_RequestValueIfNeeded(const Token& token,
                                                                        
ValueNodeChild* child);
 
+                       void                            
_CoerceTypeIfNeeded(const Token& token,
+                                                                       Number& 
_number);
+
                        Tokenizer*                      fTokenizer;
                        type_code                       fCurrentType;
                        ValueNodeManager*       fNodeManager;


Other related posts:

  • » [haiku-commits] haiku: hrev48204 - in src/apps/debugger: source_language/expression_evaluators types - anevilyak