From 4890f5b3c1e0bd3c0ac5679658c31d254e180141 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Thu, 5 Jun 2003 21:18:25 +0000 Subject: [PATCH] Infinite values of the floating point types. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 5 ++ .../cdt/debug/core/model/ICVariable.java | 4 ++ .../debug/internal/core/model/CVariable.java | 50 +++++++++++++++++++ debug/org.eclipse.cdt.debug.mi.core/ChangeLog | 6 +++ .../mi/core/cdi/model/type/DoubleValue.java | 18 ------- .../mi/core/cdi/model/type/FloatValue.java | 18 ------- .../cdi/model/type/FloatingPointValue.java | 34 +++++++++---- debug/org.eclipse.cdt.debug.ui/ChangeLog | 4 ++ .../ui/CDTDebugModelPresentation.java | 21 ++++++-- 9 files changed, 112 insertions(+), 48 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 3b4dca06bc4..356865e1654 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,8 @@ +2003-06-05 Mikhail Khodjaiants + Core support of infinite values of the floating point types. + * ICVariable.java + * CVariable.java + 2003-06-05 Mikhail Khodjaiants Renamed the 'computeDetail' method of the 'ICValue' interface to 'evaluateAsExpression'. * ICValue.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java index 5f6b2a541d0..2ac7a93a222 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICVariable.java @@ -38,6 +38,10 @@ public interface ICVariable extends IVariable boolean isNaN(); + boolean isPositiveInfinity(); + + boolean isNegativeInfinity(); + boolean isPointer(); String getQualifiedName() throws DebugException; diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java index c21c5fac127..74569b0df6c 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CVariable.java @@ -693,6 +693,56 @@ public abstract class CVariable extends CDebugElement return false; } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICVariable#isNegativeInfinity() + */ + public boolean isNegativeInfinity() + { + try + { + ICDIValue value = getCDIVariable().getValue(); + if ( value instanceof ICDIDoubleValue ) + { + double dbl = ((ICDIDoubleValue)value).doubleValue(); + return ( Double.isInfinite( dbl ) && Double.NEGATIVE_INFINITY == dbl ); + } + if ( value instanceof ICDIFloatValue ) + { + float flt = ((ICDIFloatValue)value).floatValue(); + return ( Float.isInfinite( flt ) && Float.NEGATIVE_INFINITY == flt ); + } + } + catch( CDIException e ) + { + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICVariable#isPositiveInfinity() + */ + public boolean isPositiveInfinity() + { + try + { + ICDIValue value = getCDIVariable().getValue(); + if ( value instanceof ICDIDoubleValue ) + { + double dbl = ((ICDIDoubleValue)value).doubleValue(); + return ( Double.isInfinite( dbl ) && Double.POSITIVE_INFINITY == dbl ); + } + if ( value instanceof ICDIFloatValue ) + { + float flt = ((ICDIFloatValue)value).floatValue(); + return ( Float.isInfinite( flt ) && Float.POSITIVE_INFINITY == flt ); + } + } + catch( CDIException e ) + { + } + return false; + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.ICVariable#isFloatingPointType() */ diff --git a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog index 2cf2eb71e39..e2c966f3078 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.mi.core/ChangeLog @@ -1,3 +1,9 @@ +2003-06-05 Mikhail Khodjaiants + gdb/mi support of infinite values of the floating point types. + * DoubleValue.java + * FloatingPointValue.java + * FloatValue.java + 2003-06-05 Mikhail Khodjaiants Removed the redundant methods from the 'ICDIFloatingPointValue' interface. * src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatingPointValue.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/DoubleValue.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/DoubleValue.java index c5453d8ed50..f25b06d9875 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/DoubleValue.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/DoubleValue.java @@ -5,7 +5,6 @@ package org.eclipse.cdt.debug.mi.core.cdi.model.type; -import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue; import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; @@ -19,21 +18,4 @@ public class DoubleValue extends FloatingPointValue implements ICDIDoubleValue { public DoubleValue(Variable v) { super(v); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointValue#isNaN() - */ - public boolean isNaN() { - // Identify this value as Not-a-Number if parsing fails. - try { - Double.parseDouble( getValueString() ); - } - catch (NumberFormatException e) { - return true; - } - catch (CDIException e) { - return true; - } - return false; - } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatValue.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatValue.java index 6ffbe66ccec..a2ff54ca178 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatValue.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatValue.java @@ -5,7 +5,6 @@ package org.eclipse.cdt.debug.mi.core.cdi.model.type; -import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue; import org.eclipse.cdt.debug.mi.core.cdi.model.Variable; @@ -19,21 +18,4 @@ public class FloatValue extends FloatingPointValue implements ICDIFloatValue { public FloatValue(Variable v) { super(v); } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointValue#isNaN() - */ - public boolean isNaN() { - // Identify this value as Not-a-Number if parsing fails. - try { - Float.parseFloat( getValueString() ); - } - catch (NumberFormatException e) { - return true; - } - catch (CDIException e) { - return true; - } - return false; - } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatingPointValue.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatingPointValue.java index 9ebcd950b73..e64b814ff49 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatingPointValue.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/model/type/FloatingPointValue.java @@ -26,13 +26,16 @@ public abstract class FloatingPointValue extends Value implements ICDIFloatingPo */ public double doubleValue() throws CDIException { double result = 0; - if ( isNaN() ) + if (isNaN()) result = Double.NaN; + else if (isNegativeInfinity()) + result = Double.NEGATIVE_INFINITY; + else if (isPositiveInfinity()) + result = Double.POSITIVE_INFINITY; else { try { - result = Double.parseDouble( getValueString() ); - } - catch (NumberFormatException e) { + result = Double.parseDouble(getValueString()); + } catch (NumberFormatException e) { } } return result; @@ -43,20 +46,33 @@ public abstract class FloatingPointValue extends Value implements ICDIFloatingPo */ public float floatValue() throws CDIException { float result = 0; - if ( isNaN() ) + if (isNaN()) result = Float.NaN; + else if (isNegativeInfinity()) + result = Float.NEGATIVE_INFINITY; + else if (isPositiveInfinity()) + result = Float.POSITIVE_INFINITY; else { try { - result = Float.parseFloat( getValueString() ); - } - catch (NumberFormatException e) { + result = Float.parseFloat(getValueString()); + } catch (NumberFormatException e) { } } return result; } + private boolean isPositiveInfinity() throws CDIException { + String valueString = getValueString(); + return (valueString != null) ? valueString.indexOf("inf") != -1 : false; + } + + private boolean isNegativeInfinity() throws CDIException { + String valueString = getValueString(); + return (valueString != null) ? valueString.indexOf("-inf") != -1 : false; + } + private boolean isNaN() throws CDIException { String valueString = getValueString(); - return ( valueString != null ) ? valueString.indexOf( "nan" ) != -1 : false; + return (valueString != null) ? valueString.indexOf("nan") != -1 : false; } } diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 50a5f275a64..30ab0f0c24b 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,7 @@ +2003-06-05 Mikhail Khodjaiants + UI support of infinite values of the floating point types. + * CDTDebugModelPresentation.java + 2003-06-05 Mikhail Khodjaiants Evaluate expressions of detail panel asynchronously. * CDTValueDetailProvider.java diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java index 7ad0838c9a7..895daebb241 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDTDebugModelPresentation.java @@ -565,14 +565,29 @@ public class CDTDebugModelPresentation extends LabelProvider label.append( ']' ); } } - - else if ( !((ICVariable)var).isStructure() && value.getValueString() != null ) + else if ( ((ICVariable)var).isCharacter() && value.getValueString() != null ) { String valueString = value.getValueString().trim(); - if ( valueString.length() == 0 && ((ICVariable)var).isCharacter() ) + if ( valueString.length() == 0 ) valueString = "."; + label.append( "= " ); + label.append( valueString ); + } + else if ( ((ICVariable)var).isFloatingPointType() && value.getValueString() != null ) + { + String valueString = value.getValueString().trim(); if ( ((ICVariable)var).isNaN() ) valueString = "NAN"; + if ( ((ICVariable)var).isPositiveInfinity() ) + valueString = "Infinity"; + if ( ((ICVariable)var).isNegativeInfinity() ) + valueString = "-Infinity"; + label.append( "= " ); + label.append( valueString ); + } + else if ( !((ICVariable)var).isStructure() && value.getValueString() != null ) + { + String valueString = value.getValueString().trim(); if ( valueString.length() > 0 ) { label.append( "= " );