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.ICDIVariableManager;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIArgument;
|
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.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.ICDIStackFrame;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
|
||||||
|
@ -92,11 +91,13 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
int depth = v.getStackDepth();
|
int depth = v.getStackDepth();
|
||||||
Variable[] vars = getVariables();
|
Variable[] vars = getVariables();
|
||||||
for (int i = 0; i < vars.length; i++) {
|
for (int i = 0; i < vars.length; i++) {
|
||||||
if (vars[i].getName().equals(name) &&
|
if (vars[i].getName().equals(name)
|
||||||
vars[i].casting_index == v.casting_index &&
|
&& vars[i].getCastingArrayStart() == v.getCastingArrayStart()
|
||||||
vars[i].casting_length == v.casting_length &&
|
&& vars[i].getCastingArrayEnd() == v.getCastingArrayEnd()
|
||||||
((vars[i].casting_type == null && v.casting_type == null) ||
|
&& ((vars[i].getCastingType() == null && v.getCastingType() == null)
|
||||||
(vars[i].casting_type != null && v.casting_type != null && vars[i].casting_type.equals(v.casting_type)))) {
|
|| (vars[i].getCastingType() != null
|
||||||
|
&& v.getCastingType() != null
|
||||||
|
&& vars[i].getCastingType().equals(v.getCastingType())))) {
|
||||||
ICDIStackFrame frame = vars[i].getStackFrame();
|
ICDIStackFrame frame = vars[i].getStackFrame();
|
||||||
if (stack == null && frame == null) {
|
if (stack == null && frame == null) {
|
||||||
return vars[i];
|
return vars[i];
|
||||||
|
@ -123,6 +124,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
* Check the type
|
* Check the type
|
||||||
*/
|
*/
|
||||||
public void checkType(String type) throws CDIException {
|
public void checkType(String type) throws CDIException {
|
||||||
|
if (type != null && type.length() > 0) {
|
||||||
try {
|
try {
|
||||||
MISession mi = ((Session) getSession()).getMISession();
|
MISession mi = ((Session) getSession()).getMISession();
|
||||||
CommandFactory factory = mi.getCommandFactory();
|
CommandFactory factory = mi.getCommandFactory();
|
||||||
|
@ -135,30 +137,9 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
} catch (MIException e) {
|
} catch (MIException e) {
|
||||||
throw new MI2CDIException(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 {
|
} 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;
|
argument = (Argument) variable;
|
||||||
}
|
}
|
||||||
if (argument == null) {
|
if (argument == null) {
|
||||||
String name = encodeVariable(argObj);
|
String name = argObj.getQualifiedName();
|
||||||
ICDIStackFrame stack = argObj.getStackFrame();
|
ICDIStackFrame stack = argObj.getStackFrame();
|
||||||
Session session = (Session) getSession();
|
Session session = (Session) getSession();
|
||||||
ICDIThread currentThread = null;
|
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)
|
* @see org.eclipse.cdt.debug.core.cdi.ICDIVariableManager#getArgumentObject(ICDIStackFrame, String)
|
||||||
*/
|
*/
|
||||||
public ICDIArgumentObject getArgumentObject(ICDIStackFrame stack, String name)
|
public ICDIArgumentObject getArgumentObject(ICDIStackFrame stack, String name) throws CDIException {
|
||||||
throws CDIException {
|
|
||||||
ICDIArgumentObject[] argsObjects = getArgumentObjects(stack);
|
ICDIArgumentObject[] argsObjects = getArgumentObjects(stack);
|
||||||
for (int i = 0; i < argsObjects.length; i++) {
|
for (int i = 0; i < argsObjects.length; i++) {
|
||||||
if (argsObjects[i].getName().equals(name)) {
|
if (argsObjects[i].getName().equals(name)) {
|
||||||
|
@ -273,8 +253,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
int level = frame.getLevel();
|
int level = frame.getLevel();
|
||||||
// Need the GDB/MI view of leve which the reverse i.e. Highest frame is 0
|
// Need the GDB/MI view of leve which the reverse i.e. Highest frame is 0
|
||||||
int miLevel = depth - level;
|
int miLevel = depth - level;
|
||||||
MIStackListArguments listArgs =
|
MIStackListArguments listArgs = factory.createMIStackListArguments(false, miLevel, miLevel);
|
||||||
factory.createMIStackListArguments(false, miLevel, miLevel);
|
|
||||||
MIArg[] args = null;
|
MIArg[] args = null;
|
||||||
mi.postCommand(listArgs);
|
mi.postCommand(listArgs);
|
||||||
MIStackListArgumentsInfo info = listArgs.getMIStackListArgumentsInfo();
|
MIStackListArgumentsInfo info = listArgs.getMIStackListArgumentsInfo();
|
||||||
|
@ -288,8 +267,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
ICDITarget tgt = frame.getThread().getTarget();
|
ICDITarget tgt = frame.getThread().getTarget();
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
ArgumentObject arg = new ArgumentObject(tgt, args[i].getName(),
|
ArgumentObject arg = new ArgumentObject(tgt, args[i].getName(), frame, args.length - i, level);
|
||||||
frame, args.length - i, level);
|
|
||||||
argObjects.add(arg);
|
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)
|
* @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;
|
VariableObject obj = null;
|
||||||
if (object instanceof VariableObject) {
|
if (object instanceof VariableObject) {
|
||||||
obj = (VariableObject) object;
|
obj = (VariableObject) object;
|
||||||
}
|
}
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
// Check if the type is valid.
|
// Check if the type is valid.
|
||||||
if (type != null && type.length() > 0) {
|
checkType(type);
|
||||||
try {
|
VariableObject vo = new VariableObject(obj.getTarget(),
|
||||||
MISession mi = ((Session)getSession()).getMISession();
|
obj.getQualifiedName(), obj.getStackFrame(), obj.getPosition(), obj.getStackDepth());
|
||||||
CommandFactory factory = mi.getCommandFactory();
|
vo.setCastingType(type);
|
||||||
MIPType ptype = factory.createMIPType(type);
|
vo.setCastingArrayStart(start);
|
||||||
mi.postCommand(ptype);
|
vo.setCastingArrayEnd(length);
|
||||||
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;
|
|
||||||
|
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
throw new CDIException("Unknown variable object");
|
throw new CDIException("Unknown variable object");
|
||||||
|
@ -401,31 +348,17 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
obj = (VariableObject) object;
|
obj = (VariableObject) object;
|
||||||
}
|
}
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
// throw an exception if not a good type.
|
||||||
if (type != null && type.length() > 0) {
|
checkType(type);
|
||||||
// Check if the type is valid.
|
VariableObject vo =
|
||||||
try {
|
new VariableObject(
|
||||||
MISession mi = ((Session)getSession()).getMISession();
|
obj.getTarget(),
|
||||||
CommandFactory factory = mi.getCommandFactory();
|
obj.getQualifiedName(),
|
||||||
MIPType ptype = factory.createMIPType(type);
|
obj.getStackFrame(),
|
||||||
mi.postCommand(ptype);
|
obj.getPosition(),
|
||||||
MIPTypeInfo info = ptype.getMIPtypeInfo();
|
obj.getStackDepth());
|
||||||
if (info == null) {
|
vo.setCastingType(type);
|
||||||
throw new CDIException("No answer");
|
return vo;
|
||||||
}
|
|
||||||
} 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 new CDIException("Unknown variable object");
|
throw new CDIException("Unknown variable object");
|
||||||
}
|
}
|
||||||
|
@ -455,8 +388,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
ICDITarget tgt = frame.getThread().getTarget();
|
ICDITarget tgt = frame.getThread().getTarget();
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
VariableObject varObj = new VariableObject(tgt, args[i].getName(),
|
VariableObject varObj = new VariableObject(tgt, args[i].getName(), frame, args.length - i, level);
|
||||||
frame, args.length - i, level);
|
|
||||||
varObjects.add(varObj);
|
varObjects.add(varObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,7 +423,7 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
if (varObj != null) {
|
if (varObj != null) {
|
||||||
Variable variable = findVariable(varObj);
|
Variable variable = findVariable(varObj);
|
||||||
if (variable == null) {
|
if (variable == null) {
|
||||||
String name = encodeVariable(varObj);
|
String name = varObj.getQualifiedName();
|
||||||
Session session = (Session) getSession();
|
Session session = (Session) getSession();
|
||||||
ICDIStackFrame stack = varObj.getStackFrame();
|
ICDIStackFrame stack = varObj.getStackFrame();
|
||||||
ICDIThread currentThread = null;
|
ICDIThread currentThread = null;
|
||||||
|
@ -634,7 +566,8 @@ public class VariableManager extends SessionObject implements ICDIVariableManage
|
||||||
* @param frames
|
* @param frames
|
||||||
* @return
|
* @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();
|
ICDIStackFrame varStack = variable.getStackFrame();
|
||||||
boolean inScope = false;
|
boolean inScope = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue