mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
cleanup of the casting methods.
This commit is contained in:
parent
3c01dde2ff
commit
e25438c76b
1 changed files with 60 additions and 127 deletions
|
@ -13,7 +13,6 @@ import org.eclipse.cdt.debug.core.cdi.CDIException;
|
|||
import org.eclipse.cdt.debug.core.cdi.ICDIVariableManager;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIArgument;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIArgumentObject;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIRegisterObject;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIStackFrame;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
|
||||
|
@ -92,11 +91,13 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
int depth = v.getStackDepth();
|
||||
Variable[] vars = getVariables();
|
||||
for (int i = 0; i < vars.length; i++) {
|
||||
if (vars[i].getName().equals(name) &&
|
||||
vars[i].casting_index == v.casting_index &&
|
||||
vars[i].casting_length == v.casting_length &&
|
||||
((vars[i].casting_type == null && v.casting_type == null) ||
|
||||
(vars[i].casting_type != null && v.casting_type != null && vars[i].casting_type.equals(v.casting_type)))) {
|
||||
if (vars[i].getName().equals(name)
|
||||
&& vars[i].getCastingArrayStart() == v.getCastingArrayStart()
|
||||
&& vars[i].getCastingArrayEnd() == v.getCastingArrayEnd()
|
||||
&& ((vars[i].getCastingType() == null && v.getCastingType() == null)
|
||||
|| (vars[i].getCastingType() != null
|
||||
&& v.getCastingType() != null
|
||||
&& vars[i].getCastingType().equals(v.getCastingType())))) {
|
||||
ICDIStackFrame frame = vars[i].getStackFrame();
|
||||
if (stack == null && frame == null) {
|
||||
return vars[i];
|
||||
|
@ -123,6 +124,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
* Check the type
|
||||
*/
|
||||
public void checkType(String type) throws CDIException {
|
||||
if (type != null && type.length() > 0) {
|
||||
try {
|
||||
MISession mi = ((Session) getSession()).getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
|
@ -135,30 +137,9 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
} catch (MIException e) {
|
||||
throw new MI2CDIException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String encodeVariable(VariableObject varObj) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (varObj.casting_length > 0 || varObj.casting_index > 0) {
|
||||
buffer.append("*(");
|
||||
buffer.append('(');
|
||||
if (varObj.casting_type != null && varObj.casting_type.length() > 0) {
|
||||
buffer.append('(').append(varObj.casting_type).append(')');
|
||||
}
|
||||
buffer.append(varObj.getName());
|
||||
buffer.append(')');
|
||||
if (varObj.casting_index != 0) {
|
||||
buffer.append('+').append(varObj.casting_index);
|
||||
}
|
||||
buffer.append(')');
|
||||
buffer.append('@').append(varObj.casting_length - varObj.casting_index);
|
||||
} else if (varObj.casting_type != null && varObj.casting_type.length() > 0) {
|
||||
buffer.append('(').append(varObj.casting_type).append(')');
|
||||
buffer.append('(').append(varObj.getName()).append(')');
|
||||
} else {
|
||||
buffer.append(varObj.getName());
|
||||
throw new CDIException("Unkown type");
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +188,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
argument = (Argument) variable;
|
||||
}
|
||||
if (argument == null) {
|
||||
String name = encodeVariable(argObj);
|
||||
String name = argObj.getQualifiedName();
|
||||
ICDIStackFrame stack = argObj.getStackFrame();
|
||||
Session session = (Session) getSession();
|
||||
ICDIThread currentThread = null;
|
||||
|
@ -245,8 +226,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getArgumentObject(ICDIStackFrame, String)
|
||||
*/
|
||||
public ICDIArgumentObject getArgumentObject(ICDIStackFrame stack, String name)
|
||||
throws CDIException {
|
||||
public ICDIArgumentObject getArgumentObject(ICDIStackFrame stack, String name) throws CDIException {
|
||||
ICDIArgumentObject[] argsObjects = getArgumentObjects(stack);
|
||||
for (int i = 0; i < argsObjects.length; i++) {
|
||||
if (argsObjects[i].getName().equals(name)) {
|
||||
|
@ -273,8 +253,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
int level = frame.getLevel();
|
||||
// Need the GDB/MI view of leve which the reverse i.e. Highest frame is 0
|
||||
int miLevel = depth - level;
|
||||
MIStackListArguments listArgs =
|
||||
factory.createMIStackListArguments(false, miLevel, miLevel);
|
||||
MIStackListArguments listArgs = factory.createMIStackListArguments(false, miLevel, miLevel);
|
||||
MIArg[] args = null;
|
||||
mi.postCommand(listArgs);
|
||||
MIStackListArgumentsInfo info = listArgs.getMIStackListArgumentsInfo();
|
||||
|
@ -288,8 +267,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
if (args != null) {
|
||||
ICDITarget tgt = frame.getThread().getTarget();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
ArgumentObject arg = new ArgumentObject(tgt, args[i].getName(),
|
||||
frame, args.length - i, level);
|
||||
ArgumentObject arg = new ArgumentObject(tgt, args[i].getName(), frame, args.length - i, level);
|
||||
argObjects.add(arg);
|
||||
}
|
||||
}
|
||||
|
@ -342,51 +320,20 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
/**
|
||||
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getVariableObjectAsArray(ICDIVariableObject, String, int, int)
|
||||
*/
|
||||
public ICDIVariableObject getVariableObjectAsArray(ICDIVariableObject object, String type, int start, int length) throws CDIException {
|
||||
public ICDIVariableObject getVariableObjectAsArray(ICDIVariableObject object, String type, int start, int length)
|
||||
throws CDIException {
|
||||
VariableObject obj = null;
|
||||
if (object instanceof VariableObject) {
|
||||
obj = (VariableObject) object;
|
||||
}
|
||||
if (obj != null) {
|
||||
// Check if the type is valid.
|
||||
if (type != null && type.length() > 0) {
|
||||
try {
|
||||
MISession mi = ((Session)getSession()).getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIPType ptype = factory.createMIPType(type);
|
||||
mi.postCommand(ptype);
|
||||
MIPTypeInfo info = ptype.getMIPtypeInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new MI2CDIException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Should we provide a getRegisterObjectAsArray ?
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (obj instanceof ICDIRegisterObject) {
|
||||
buffer.append("$" + obj.getName());
|
||||
} else {
|
||||
buffer.append(obj.getName());
|
||||
}
|
||||
VariableObject vo = new VariableObject(obj, buffer.toString());
|
||||
|
||||
// Carry the the old casting type over
|
||||
buffer.setLength(0);
|
||||
if (obj.casting_type != null && obj.casting_type.length() > 0) {
|
||||
buffer.append("(").append(obj.casting_type).append(")");
|
||||
}
|
||||
if (type != null && type.length() > 0) {
|
||||
buffer.append(type);
|
||||
}
|
||||
vo.casting_type = buffer.toString();
|
||||
|
||||
// Carry any other info to the new VariableObject
|
||||
vo.casting_index = obj.casting_index + start;
|
||||
vo.casting_length = obj.casting_length + length;
|
||||
|
||||
checkType(type);
|
||||
VariableObject vo = new VariableObject(obj.getTarget(),
|
||||
obj.getQualifiedName(), obj.getStackFrame(), obj.getPosition(), obj.getStackDepth());
|
||||
vo.setCastingType(type);
|
||||
vo.setCastingArrayStart(start);
|
||||
vo.setCastingArrayEnd(length);
|
||||
return vo;
|
||||
}
|
||||
throw new CDIException("Unknown variable object");
|
||||
|
@ -401,31 +348,17 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
obj = (VariableObject) object;
|
||||
}
|
||||
if (obj != null) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
if (type != null && type.length() > 0) {
|
||||
// Check if the type is valid.
|
||||
try {
|
||||
MISession mi = ((Session)getSession()).getMISession();
|
||||
CommandFactory factory = mi.getCommandFactory();
|
||||
MIPType ptype = factory.createMIPType(type);
|
||||
mi.postCommand(ptype);
|
||||
MIPTypeInfo info = ptype.getMIPtypeInfo();
|
||||
if (info == null) {
|
||||
throw new CDIException("No answer");
|
||||
}
|
||||
} catch (MIException e) {
|
||||
throw new MI2CDIException(e);
|
||||
}
|
||||
buffer.append('(').append(type).append(')');
|
||||
}
|
||||
buffer.append('(');
|
||||
if (obj instanceof ICDIRegisterObject) {
|
||||
buffer.append("$" + obj.getName());
|
||||
} else {
|
||||
buffer.append(obj.getName());
|
||||
}
|
||||
buffer.append(')');
|
||||
return new VariableObject(obj, buffer.toString());
|
||||
// throw an exception if not a good type.
|
||||
checkType(type);
|
||||
VariableObject vo =
|
||||
new VariableObject(
|
||||
obj.getTarget(),
|
||||
obj.getQualifiedName(),
|
||||
obj.getStackFrame(),
|
||||
obj.getPosition(),
|
||||
obj.getStackDepth());
|
||||
vo.setCastingType(type);
|
||||
return vo;
|
||||
}
|
||||
throw new CDIException("Unknown variable object");
|
||||
}
|
||||
|
@ -455,8 +388,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
if (args != null) {
|
||||
ICDITarget tgt = frame.getThread().getTarget();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
VariableObject varObj = new VariableObject(tgt, args[i].getName(),
|
||||
frame, args.length - i, level);
|
||||
VariableObject varObj = new VariableObject(tgt, args[i].getName(), frame, args.length - i, level);
|
||||
varObjects.add(varObj);
|
||||
}
|
||||
}
|
||||
|
@ -491,7 +423,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
if (varObj != null) {
|
||||
Variable variable = findVariable(varObj);
|
||||
if (variable == null) {
|
||||
String name = encodeVariable(varObj);
|
||||
String name = varObj.getQualifiedName();
|
||||
Session session = (Session) getSession();
|
||||
ICDIStackFrame stack = varObj.getStackFrame();
|
||||
ICDIThread currentThread = null;
|
||||
|
@ -634,7 +566,8 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
|||
* @param frames
|
||||
* @return
|
||||
*/
|
||||
boolean isVariableNeedsToBeUpdate(Variable variable, ICDIStackFrame current, ICDIStackFrame[] frames, int low) throws CDIException {
|
||||
boolean isVariableNeedsToBeUpdate(Variable variable, ICDIStackFrame current, ICDIStackFrame[] frames, int low)
|
||||
throws CDIException {
|
||||
ICDIStackFrame varStack = variable.getStackFrame();
|
||||
boolean inScope = false;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue