1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Refactoring: moved the type and value related methods from ICVariable to ICType and ICValue.

This commit is contained in:
Mikhail Khodjaiants 2003-06-10 22:33:56 +00:00
parent ed640e09ab
commit 52f06ad88c
10 changed files with 342 additions and 216 deletions

View file

@ -1,3 +1,13 @@
2003-06-10 Mikhail Khodjaiants
Refactoring: moved the type and value related methods from ICVariable to ICType and ICValue.
* ICType.java: new
* ICVariable.java
* ICValue.java
* CArrayPartitionValue.java
* CType.java
* CValue.java
* CVariable.java
2003-06-09 Mikhail Khodjaiants 2003-06-09 Mikhail Khodjaiants
Added default format preferences for variables, registers and expressions. Added default format preferences for variables, registers and expressions.
* CExpression.java * CExpression.java

View file

@ -0,0 +1,33 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.core.model;
import org.eclipse.core.runtime.IAdaptable;
/**
* Enter type comment.
*
* @since Jun 10, 2003
*/
public interface ICType extends IAdaptable
{
String getName();
boolean isArray();
int[] getArrayDimensions();
boolean isStructure();
boolean isCharacter();
boolean isFloatingPointType();
boolean isPointer();
void dispose();
}

View file

@ -31,4 +31,10 @@ public interface ICValue extends IValue
String evaluateAsExpression(); String evaluateAsExpression();
void setChanged( boolean changed ) throws DebugException; void setChanged( boolean changed ) throws DebugException;
boolean isNaN();
boolean isPositiveInfinity();
boolean isNegativeInfinity();
} }

View file

@ -22,27 +22,11 @@ public interface ICVariable extends IVariable
void reset() throws DebugException; void reset() throws DebugException;
ICType getType() throws DebugException;
boolean isEditable(); boolean isEditable();
boolean hasChildren(); boolean hasChildren();
boolean isArray();
int[] getArrayDimensions();
boolean isStructure();
boolean isCharacter();
boolean isFloatingPointType();
boolean isNaN();
boolean isPositiveInfinity();
boolean isNegativeInfinity();
boolean isPointer();
String getQualifiedName() throws DebugException; String getQualifiedName() throws DebugException;
} }

View file

@ -163,4 +163,28 @@ public class CArrayPartitionValue extends CDebugElement implements ICValue
{ {
return fParent; return fParent;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#isNaN()
*/
public boolean isNaN()
{
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#isNegativeInfinity()
*/
public boolean isNegativeInfinity()
{
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#isPositiveInfinity()
*/
public boolean isPositiveInfinity()
{
return false;
}
} }

View file

@ -0,0 +1,129 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDerivedType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
import org.eclipse.cdt.debug.core.model.ICType;
/**
* Enter type comment.
*
* @since Jun 10, 2003
*/
public class CType implements ICType
{
private ICDIType fCDIType;
public CType( ICDIType cdiType )
{
setCDIType( cdiType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#getName()
*/
public String getName()
{
return ( fCDIType != null ) ? fCDIType.getTypeName() : null;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter( Class adapter )
{
if ( ICType.class.equals( adapter ) )
return this;
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#dispose()
*/
public void dispose()
{
fCDIType = null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#getArrayDimensions()
*/
public int[] getArrayDimensions()
{
int length = 0;
ICDIType type = getCDIType();
while( type instanceof ICDIArrayType )
{
++length;
type = ( type instanceof ICDIDerivedType ) ? ((ICDIDerivedType)type).getComponentType() : null;
}
int[] dims = new int[length];
type = getCDIType();
for ( int i = length; i > 0; --i )
{
dims[i - 1] = ((ICDIArrayType)type).getDimension();
type = ((ICDIDerivedType)type).getComponentType();
}
return dims;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isArray()
*/
public boolean isArray()
{
return ( getCDIType() instanceof ICDIArrayType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isCharacter()
*/
public boolean isCharacter()
{
return ( getCDIType() instanceof ICDICharType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isFloatingPointType()
*/
public boolean isFloatingPointType()
{
return ( getCDIType() instanceof ICDIFloatingPointType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isPointer()
*/
public boolean isPointer()
{
return ( getCDIType() instanceof ICDIPointerType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.type.ICType#isStructure()
*/
public boolean isStructure()
{
return ( getCDIType() instanceof ICDIStructType );
}
protected ICDIType getCDIType()
{
return fCDIType;
}
protected void setCDIType( ICDIType type )
{
fCDIType = type;
}
}

View file

@ -79,9 +79,9 @@ public class CValue extends CDebugElement implements ICValue
String typeName = null; String typeName = null;
try try
{ {
if ( fCDIValue != null ) if ( getUnderlyingValue() != null )
{ {
typeName = fCDIValue.getTypeName(); typeName = getUnderlyingValue().getTypeName();
} }
} }
catch( CDIException e ) catch( CDIException e )
@ -567,4 +567,77 @@ public class CValue extends CDebugElement implements ICValue
((CVariable)it.next()).reset(); ((CVariable)it.next()).reset();
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#isNaN()
*/
public boolean isNaN()
{
try
{
ICDIValue value = getUnderlyingValue();
if ( value instanceof ICDIDoubleValue )
{
return Double.isNaN( ((ICDIDoubleValue)value).doubleValue() );
}
if ( value instanceof ICDIFloatValue )
{
return Float.isNaN( ((ICDIFloatValue)value).floatValue() );
}
}
catch( CDIException e )
{
}
return false;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#isNegativeInfinity()
*/
public boolean isNegativeInfinity()
{
try
{
ICDIValue value = getUnderlyingValue();
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.ICValue#isPositiveInfinity()
*/
public boolean isPositiveInfinity()
{
try
{
ICDIValue value = getUnderlyingValue();
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;
}
} }

View file

@ -19,15 +19,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue; import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType; import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDerivedType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatingPointType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIPointerType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIStructType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIType;
import org.eclipse.cdt.debug.core.model.ICValue; import org.eclipse.cdt.debug.core.model.ICValue;
import org.eclipse.cdt.debug.core.model.ICVariable; import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.core.model.ICastToArray; import org.eclipse.cdt.debug.core.model.ICastToArray;
@ -97,9 +89,9 @@ public abstract class CVariable extends CDebugElement
protected boolean fChanged = false; protected boolean fChanged = false;
/** /**
* The type name of this variable. * The type of this variable.
*/ */
private String fTypeName = null; private ICType fType = null;
/** /**
* The current format of this variable. * The current format of this variable.
@ -363,7 +355,7 @@ public abstract class CVariable extends CDebugElement
{ {
parent = parent.getParentVariable(); parent = parent.getParentVariable();
} }
if ( parent instanceof CVariable && parent.getType() instanceof ICDIArrayType ) if ( parent instanceof CVariable && parent.getType().isArray() )
{ {
fName = parent.getName() + '[' + cdiName + ']'; fName = parent.getName() + '[' + cdiName + ']';
} }
@ -377,18 +369,7 @@ public abstract class CVariable extends CDebugElement
*/ */
public String getReferenceTypeName() throws DebugException public String getReferenceTypeName() throws DebugException
{ {
if ( fTypeName == null ) return getType().getName();
{
try
{
fTypeName = getCDIVariable().getTypeName();
}
catch( CDIException e )
{
targetRequestFailed( e.getMessage(), null );
}
}
return fTypeName;
} }
protected void updateParentVariable( CValue parentValue ) throws DebugException protected void updateParentVariable( CValue parentValue ) throws DebugException
@ -447,7 +428,9 @@ public abstract class CVariable extends CDebugElement
fValue = null; fValue = null;
} }
fEditable = null; fEditable = null;
fTypeName = null; if ( fType != null )
fType.dispose();
fType = null;
fireChangeEvent( DebugEvent.STATE ); fireChangeEvent( DebugEvent.STATE );
} }
} }
@ -483,7 +466,9 @@ public abstract class CVariable extends CDebugElement
fValue = null; fValue = null;
} }
fEditable = null; fEditable = null;
fTypeName = null; if ( fType != null )
fType.dispose();
fType = null;
fireChangeEvent( DebugEvent.STATE ); fireChangeEvent( DebugEvent.STATE );
} }
@ -584,7 +569,9 @@ public abstract class CVariable extends CDebugElement
fValue = null; fValue = null;
} }
fEditable = null; fEditable = null;
fTypeName = null; if ( fType != null )
fType.dispose();
fType = null;
fireChangeEvent( DebugEvent.STATE ); fireChangeEvent( DebugEvent.STATE );
} }
} }
@ -632,143 +619,6 @@ public abstract class CVariable extends CDebugElement
} }
return ( fEditable != null ) ? fEditable.booleanValue() : false; return ( fEditable != null ) ? fEditable.booleanValue() : false;
} }
public boolean isPointer()
{
return ( getType() instanceof ICDIPointerType );
}
public boolean isArray()
{
return ( getType() instanceof ICDIArrayType );
}
public int[] getArrayDimensions()
{
int length = 0;
ICDIType type = getType();
while( type instanceof ICDIArrayType )
{
++length;
type = ( type instanceof ICDIDerivedType ) ? ((ICDIDerivedType)type).getComponentType() : null;
}
int[] dims = new int[length];
type = getType();
for ( int i = length; i > 0; --i )
{
dims[i - 1] = ((ICDIArrayType)type).getDimension();
type = ((ICDIDerivedType)type).getComponentType();
}
return dims;
}
public boolean isStructure()
{
return ( getType() instanceof ICDIStructType );
}
private ICDIType getType()
{
ICDIType type = null;
try
{
if ( getCDIVariable() != null )
type = getCDIVariable().getType();
}
catch( CDIException e )
{
}
return type;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isCharacter()
*/
public boolean isCharacter()
{
return ( getType() instanceof ICDICharType );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#isNaN()
*/
public boolean isNaN()
{
try
{
ICDIValue value = getCDIVariable().getValue();
if ( value instanceof ICDIDoubleValue )
{
return Double.isNaN( ((ICDIDoubleValue)value).doubleValue() );
}
if ( value instanceof ICDIFloatValue )
{
return Float.isNaN( ((ICDIFloatValue)value).floatValue() );
}
}
catch( CDIException e )
{
}
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()
*/
public boolean isFloatingPointType()
{
return ( getType() instanceof ICDIFloatingPointType );
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#getQualifiedName() * @see org.eclipse.cdt.debug.core.model.ICVariable#getQualifiedName()
@ -782,7 +632,7 @@ public abstract class CVariable extends CDebugElement
CVariable var = getParentVariable(); CVariable var = getParentVariable();
while( var != null ) while( var != null )
{ {
if ( !( var.getType() instanceof ICDIArrayType ) && !( var instanceof CArrayPartition ) && !var.isAccessSpecifier() ) if ( !( var.getType().isArray() ) && !( var instanceof CArrayPartition ) && !var.isAccessSpecifier() )
list.addFirst( var ); list.addFirst( var );
var = var.getParentVariable(); var = var.getParentVariable();
} }
@ -793,7 +643,7 @@ public abstract class CVariable extends CDebugElement
sb.insert( 0, '(' ); sb.insert( 0, '(' );
if ( i > 0 ) if ( i > 0 )
{ {
if ( vars[i - 1].isPointer() ) if ( vars[i - 1].getType().isPointer() )
{ {
if ( vars[i].getName().charAt( 0 ) == '*' && vars[i-1].getName().equals( vars[i].getName().substring( 1 ) ) ) if ( vars[i].getName().charAt( 0 ) == '*' && vars[i-1].getName().equals( vars[i].getName().substring( 1 ) ) )
{ {
@ -833,4 +683,23 @@ public abstract class CVariable extends CDebugElement
return ((CArrayPartitionValue)getParent()).getParentVariable(); return ((CArrayPartitionValue)getParent()).getParentVariable();
return null; return null;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#getType()
*/
public ICType getType() throws DebugException
{
if ( fType == null && getCDIVariable() != null )
{
try
{
fType = new CType( getCDIVariable().getType() );
}
catch( CDIException e )
{
requestFailed( "Type is not available.", e );
}
}
return fType;
}
} }

View file

@ -1,3 +1,7 @@
2003-06-10 Mikhail Khodjaiants
Refactoring: moved the type and value related methods from ICVariable to ICType and ICValue.
* CDTDebugModelPresentation.java
2003-06-09 Mikhail Khodjaiants 2003-06-09 Mikhail Khodjaiants
Added default format preferences for variables, registers and expressions. Added default format preferences for variables, registers and expressions.
* CDebugPreferencePage.java * CDebugPreferencePage.java

View file

@ -25,6 +25,8 @@ import org.eclipse.cdt.debug.core.model.ICDebugTargetType;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint; import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICSharedLibrary; import org.eclipse.cdt.debug.core.model.ICSharedLibrary;
import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.cdt.debug.core.model.ICValue;
import org.eclipse.cdt.debug.core.model.ICVariable; import org.eclipse.cdt.debug.core.model.ICVariable;
import org.eclipse.cdt.debug.core.model.ICWatchpoint; import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.core.model.IDummyStackFrame; import org.eclipse.cdt.debug.core.model.IDummyStackFrame;
@ -542,15 +544,16 @@ public class CDTDebugModelPresentation extends LabelProvider
StringBuffer label = new StringBuffer(); StringBuffer label = new StringBuffer();
if ( var instanceof ICVariable ) if ( var instanceof ICVariable )
{ {
if ( isShowVariableTypeNames() ) ICType type = ((ICVariable)var).getType();
if ( type != null && isShowVariableTypeNames() )
{ {
String type = getVariableTypeName( var ); String typeName = getVariableTypeName( type );
if ( type != null && type.length() > 0 ) if ( typeName != null && typeName.length() > 0 )
{ {
label.append( type ); label.append( typeName );
if ( ((ICVariable)var).isArray() ) if ( type.isArray() )
{ {
int[] dims = ((ICVariable)var).getArrayDimensions(); int[] dims = type.getArrayDimensions();
for ( int i = 0; i < dims.length; ++i ) for ( int i = 0; i < dims.length; ++i )
{ {
label.append( '[' ); label.append( '[' );
@ -563,31 +566,29 @@ public class CDTDebugModelPresentation extends LabelProvider
} }
label.append( var.getName() ); label.append( var.getName() );
IValue value = var.getValue(); IValue value = var.getValue();
if ( value != null ) if ( value instanceof ICValue && value.getValueString() != null )
{ {
if ( ((ICVariable)var).isCharacter() && value.getValueString() != null ) String valueString = value.getValueString().trim();
if ( type != null && type.isCharacter() )
{ {
String valueString = value.getValueString().trim();
if ( valueString.length() == 0 ) if ( valueString.length() == 0 )
valueString = "."; valueString = ".";
label.append( "= " ); label.append( "= " );
label.append( valueString ); label.append( valueString );
} }
else if ( ((ICVariable)var).isFloatingPointType() && value.getValueString() != null ) else if ( type != null && type.isFloatingPointType() )
{ {
String valueString = value.getValueString().trim(); if ( ((ICValue)value).isNaN() )
if ( ((ICVariable)var).isNaN() )
valueString = "NAN"; valueString = "NAN";
if ( ((ICVariable)var).isPositiveInfinity() ) if ( ((ICValue)value).isPositiveInfinity() )
valueString = "Infinity"; valueString = "Infinity";
if ( ((ICVariable)var).isNegativeInfinity() ) if ( ((ICValue)value).isNegativeInfinity() )
valueString = "-Infinity"; valueString = "-Infinity";
label.append( "= " ); label.append( "= " );
label.append( valueString ); label.append( valueString );
} }
else if ( !((ICVariable)var).isArray() && !((ICVariable)var).isStructure() && value.getValueString() != null ) else if ( type == null || ( !type.isArray() && !type.isStructure() ) )
{ {
String valueString = value.getValueString().trim();
if ( valueString.length() > 0 ) if ( valueString.length() > 0 )
{ {
label.append( "= " ); label.append( "= " );
@ -937,23 +938,16 @@ public class CDTDebugModelPresentation extends LabelProvider
return null; return null;
} }
private String getVariableTypeName( IVariable variable ) private String getVariableTypeName( ICType type )
{ {
String type = null; String typeName = type.getName();
try if ( type.isArray() && typeName != null )
{ {
type = variable.getReferenceTypeName(); int index = typeName.indexOf( '[' );
if ( type != null ) if ( index != -1 )
{ return typeName.substring( 0, index ).trim();
int index = type.indexOf( '[' );
if ( index != -1 )
return type.substring( 0, index ).trim();
}
} }
catch( DebugException e ) return typeName;
{
}
return type;
} }
/* (non-Javadoc) /* (non-Javadoc)