mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 306555: Some cleanup for Cast To Type and Display As Array
This commit is contained in:
parent
61d7272149
commit
8a3597ae0a
2 changed files with 56 additions and 50 deletions
|
@ -1046,25 +1046,67 @@ public class MIExpressions extends AbstractDsfService implements IExpressions2,
|
||||||
varManager.markAllOutOfDate();
|
varManager.markAllOutOfDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A casted or array-displayed expression.
|
/**
|
||||||
* @since 3.0 */
|
* A casted or array-displayed expression.
|
||||||
public class CastedExpressionDMC extends MIExpressionDMC implements ICastedExpressionDMContext {
|
* @since 3.0
|
||||||
|
*/
|
||||||
|
protected class CastedExpressionDMC extends MIExpressionDMC implements ICastedExpressionDMContext {
|
||||||
|
|
||||||
private final CastInfo castInfo;
|
private final CastInfo fCastInfo;
|
||||||
/** if non-null, interpret result as this type rather than the raw expression's type */
|
/** if non-null, interpret result as this type rather than the raw expression's type */
|
||||||
private String expression;
|
private String fCastExpression;
|
||||||
|
|
||||||
public CastedExpressionDMC(MIExpressionDMC exprDMC, CastInfo castInfo) {
|
public CastedExpressionDMC(MIExpressionDMC exprDMC, String castExpression, CastInfo castInfo) {
|
||||||
super(getSession().getId(), exprDMC.getExpression(), exprDMC.getRelativeExpression(), exprDMC);
|
super(getSession().getId(), exprDMC.getExpression(), exprDMC.getRelativeExpression(), exprDMC);
|
||||||
this.castInfo = castInfo;
|
fCastInfo = castInfo;
|
||||||
|
fCastExpression = castExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.dsf.debug.service.IExpressions2.ICastedExpressionDMContext#getCastInfo()
|
||||||
|
*/
|
||||||
|
public CastInfo getCastInfo() {
|
||||||
|
return fCastInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.dsf.mi.service.MIExpressions.java#getExpression()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getExpression() {
|
||||||
|
return fCastExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if the two objects are equal, false otherwise.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return super.equals(other)
|
||||||
|
&& fCastInfo.equals(((CastedExpressionDMC) other).fCastInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return baseToString() + ".expr" + "[" + //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
getExpression() +", " + getRelativeExpression() + "]"; //$NON-NLS-1$//$NON-NLS-2$
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.dsf.debug.service.IExpressions2#createCastedExpression(org.eclipse.cdt.dsf.datamodel.IDMContext, java.lang.String, org.eclipse.cdt.dsf.debug.service.IExpressions2.ICastedExpressionDMContext)
|
||||||
|
*/
|
||||||
|
/** @since 3.0 */
|
||||||
|
public ICastedExpressionDMContext createCastedExpression(IExpressionDMContext exprDMC, CastInfo castInfo) {
|
||||||
|
if (exprDMC instanceof MIExpressionDMC && castInfo != null) {
|
||||||
String castType = castInfo.getTypeString();
|
String castType = castInfo.getTypeString();
|
||||||
String castExpression = exprDMC.getExpression();
|
String castExpression = exprDMC.getExpression();
|
||||||
int castingLength = castInfo.getArrayCount();
|
int castingLength = castInfo.getArrayCount();
|
||||||
int castingIndex = castInfo.getArrayStartIndex();
|
int castingIndex = castInfo.getArrayStartIndex();
|
||||||
|
|
||||||
// cast to type
|
// cast to type
|
||||||
if (castType != null) {
|
if (castType != null && castType.length() > 0) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append('(').append(castType).append(')');
|
buffer.append('(').append(castType).append(')');
|
||||||
buffer.append('(').append(castExpression).append(')');
|
buffer.append('(').append(castExpression).append(')');
|
||||||
|
@ -1080,44 +1122,8 @@ public class MIExpressions extends AbstractDsfService implements IExpressions2,
|
||||||
buffer.append('@').append(castingLength);
|
buffer.append('@').append(castingLength);
|
||||||
castExpression = buffer.toString();
|
castExpression = buffer.toString();
|
||||||
}
|
}
|
||||||
this.expression = castExpression;
|
|
||||||
}
|
return new CastedExpressionDMC((MIExpressionDMC) exprDMC, castExpression, castInfo);
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.dsf.debug.service.IExpressions2.ICastedExpressionDMContext#getCastInfo()
|
|
||||||
*/
|
|
||||||
public CastInfo getCastInfo() {
|
|
||||||
return castInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.dsf.mi.service.MIExpressions.java#getExpression()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getExpression() {
|
|
||||||
return expression;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return True if the two objects are equal, false otherwise.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
return super.equals(other)
|
|
||||||
&& castInfo.equals(((CastedExpressionDMC) other).castInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.cdt.dsf.debug.service.IExpressions2#createCastedExpression(org.eclipse.cdt.dsf.datamodel.IDMContext, java.lang.String, org.eclipse.cdt.dsf.debug.service.IExpressions2.ICastedExpressionDMContext)
|
|
||||||
*/
|
|
||||||
/** @since 3.0 */
|
|
||||||
public ICastedExpressionDMContext createCastedExpression(
|
|
||||||
IExpressionDMContext exprDMC, CastInfo castInfo) {
|
|
||||||
if (exprDMC instanceof MIExpressionDMC) {
|
|
||||||
CastedExpressionDMC castedDMC = new CastedExpressionDMC(
|
|
||||||
(MIExpressionDMC) exprDMC, castInfo);
|
|
||||||
return castedDMC;
|
|
||||||
} else {
|
} else {
|
||||||
assert false;
|
assert false;
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions2.CastInfo;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions2.CastInfo;
|
||||||
|
import org.eclipse.cdt.dsf.debug.service.IExpressions2.ICastedExpressionDMContext;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
||||||
|
@ -49,7 +50,6 @@ import org.eclipse.cdt.dsf.gdb.GDBTypeParser;
|
||||||
import org.eclipse.cdt.dsf.gdb.GDBTypeParser.GDBType;
|
import org.eclipse.cdt.dsf.gdb.GDBTypeParser.GDBType;
|
||||||
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
|
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
|
||||||
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceRecordSelectedChangedDMEvent;
|
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceRecordSelectedChangedDMEvent;
|
||||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions.CastedExpressionDMC;
|
|
||||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions.ExpressionInfo;
|
import org.eclipse.cdt.dsf.mi.service.MIExpressions.ExpressionInfo;
|
||||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions.MIExpressionDMC;
|
import org.eclipse.cdt.dsf.mi.service.MIExpressions.MIExpressionDMC;
|
||||||
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
|
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
|
||||||
|
@ -653,8 +653,8 @@ public class MIVariableManager implements ICommandControl {
|
||||||
int castingLength = 0;
|
int castingLength = 0;
|
||||||
int castingIndex = 0;
|
int castingIndex = 0;
|
||||||
// in case of casts, need to resolve that before dereferencing, to be safe
|
// in case of casts, need to resolve that before dereferencing, to be safe
|
||||||
if ( exprDmc instanceof CastedExpressionDMC ) {
|
if (exprDmc instanceof ICastedExpressionDMContext) {
|
||||||
CastInfo castInfo = ((CastedExpressionDMC)exprDmc).getCastInfo();
|
CastInfo castInfo = ((ICastedExpressionDMContext)exprDmc).getCastInfo();
|
||||||
castingLength = castInfo.getArrayCount();
|
castingLength = castInfo.getArrayCount();
|
||||||
castingIndex = castInfo.getArrayStartIndex();
|
castingIndex = castInfo.getArrayStartIndex();
|
||||||
if (castingLength > 0)
|
if (castingLength > 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue