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

New method removeExpression

This commit is contained in:
Alain Magloire 2003-02-12 05:26:24 +00:00
parent f0bfa7cf92
commit 87abcdb98a

View file

@ -18,12 +18,16 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIThread;
import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.MISession; import org.eclipse.cdt.debug.mi.core.MISession;
import org.eclipse.cdt.debug.mi.core.cdi.model.Expression; import org.eclipse.cdt.debug.mi.core.cdi.model.Expression;
import org.eclipse.cdt.debug.mi.core.cdi.model.Variable;
import org.eclipse.cdt.debug.mi.core.cdi.model.VariableObject; import org.eclipse.cdt.debug.mi.core.cdi.model.VariableObject;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory; import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIVarCreate; import org.eclipse.cdt.debug.mi.core.command.MIVarCreate;
import org.eclipse.cdt.debug.mi.core.command.MIVarDelete;
import org.eclipse.cdt.debug.mi.core.command.MIVarUpdate; import org.eclipse.cdt.debug.mi.core.command.MIVarUpdate;
import org.eclipse.cdt.debug.mi.core.event.MIEvent; import org.eclipse.cdt.debug.mi.core.event.MIEvent;
import org.eclipse.cdt.debug.mi.core.event.MIVarChangedEvent; import org.eclipse.cdt.debug.mi.core.event.MIVarChangedEvent;
import org.eclipse.cdt.debug.mi.core.event.MIVarDeletedEvent;
import org.eclipse.cdt.debug.mi.core.output.MIVar;
import org.eclipse.cdt.debug.mi.core.output.MIVarChange; import org.eclipse.cdt.debug.mi.core.output.MIVarChange;
import org.eclipse.cdt.debug.mi.core.output.MIVarCreateInfo; import org.eclipse.cdt.debug.mi.core.output.MIVarCreateInfo;
import org.eclipse.cdt.debug.mi.core.output.MIVarUpdateInfo; import org.eclipse.cdt.debug.mi.core.output.MIVarUpdateInfo;
@ -42,8 +46,35 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa
autoupdate = true; autoupdate = true;
} }
synchronized private void addExpression(Expression exp) { /**
expList.add(exp); * Tell gdb to remove the underlying var-object also.
*/
void removeMIVar(MIVar miVar) throws CDIException {
Session session = (Session)getSession();
MISession mi = session.getMISession();
CommandFactory factory = mi.getCommandFactory();
MIVarDelete var = factory.createMIVarDelete(miVar.getVarName());
try {
mi.postCommand(var);
var.getMIInfo();
} catch (MIException e) {
throw new MI2CDIException(e);
}
}
/**
* When element are remove from the cache, they are put on the OutOfScope list, oos,
* because they are still needed for the destroy events. The destroy event will
* call removeOutOfScope.
*/
public void removeExpression(String varName) throws CDIException {
Expression[] exps = (Expression[])expList.toArray(new Expression[0]);
for (int i = 0; i < exps.length; i++) {
if (exps[i].getMIVar().getVarName().equals(varName)) {
expList.remove(exps[i]);
removeMIVar(exps[i].getMIVar());
}
}
} }
/** /**
@ -64,7 +95,7 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa
} }
VariableObject varObj = new VariableObject(currentTarget, name, null, 0, 0); VariableObject varObj = new VariableObject(currentTarget, name, null, 0, 0);
expression = new Expression(varObj, info.getMIVar()); expression = new Expression(varObj, info.getMIVar());
addExpression(expression); expList.add(expression);
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} }
@ -93,7 +124,7 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa
ICDITarget tgt = frame.getThread().getTarget(); ICDITarget tgt = frame.getThread().getTarget();
VariableObject varObj = new VariableObject(tgt, name, frame, 0, 0); VariableObject varObj = new VariableObject(tgt, name, frame, 0, 0);
expression = new Expression(varObj, info.getMIVar()); expression = new Expression(varObj, info.getMIVar());
addExpression(expression); expList.add(expression);
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} finally { } finally {
@ -109,30 +140,34 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa
return (ICDIExpression[])expList.toArray(new ICDIExpression[0]); return (ICDIExpression[])expList.toArray(new ICDIExpression[0]);
} }
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#destroyExpression(ICDIExpression)
*/
synchronized public void removeExpression(ICDIExpression expression) throws CDIException {
expList.remove(expression);
}
/** /**
* @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression) * @see org.eclipse.cdt.debug.core.cdi.ICDIExpressionManager#removeExpression(ICDIExpression)
*/ */
public void destroyExpression(ICDIExpression expression) throws CDIException { public void destroyExpression(ICDIExpression expression) throws CDIException {
removeExpression(expression); if (expression instanceof Expression) {
// Fire a destroyEvent ?
Expression exp= (Expression)expression;
MIVarDeletedEvent del = new MIVarDeletedEvent(exp.getMIVar().getVarName());
Session session = (Session)getSession();
MISession mi = session.getMISession();
mi.fireEvent(del);
}
} }
/** /**
* Return the element that have the uniq varName. * Return the element that have the uniq varName.
* null is return if the element is not in the cache. * null is return if the element is not in the cache.
*/ */
public Expression getExpression(String varName) { public Variable getExpression(String varName) {
Expression[] exps = (Expression[])expList.toArray(new Expression[0]); Expression[] exps = (Expression[])expList.toArray(new Expression[0]);
for (int i = 0; i < exps.length; i++) { for (int i = 0; i < exps.length; i++) {
if (exps[i].getMIVar().getVarName().equals(varName)) { if (exps[i].getMIVar().getVarName().equals(varName)) {
return exps[i]; return exps[i];
} }
Variable v = exps[i].getChild(varName);
if (v != null) {
return v;
}
} }
return null; return null;
} }
@ -159,11 +194,17 @@ public class ExpressionManager extends SessionObject implements ICDIExpressionMa
changes = info.getMIVarChanges(); changes = info.getMIVarChanges();
} catch (MIException e) { } catch (MIException e) {
//throw new MI2CDIException(e); //throw new MI2CDIException(e);
eventList.add(new MIVarChangedEvent(0, varName, false)); eventList.add(new MIVarDeletedEvent(varName));
} }
for (int j = 0 ; j < changes.length; j++) { for (int j = 0 ; j < changes.length; j++) {
String n = changes[j].getVarName(); String n = changes[j].getVarName();
eventList.add(new MIVarChangedEvent(0, n, changes[j].isInScope())); if (changes[j].isInScope()) {
eventList.add(new MIVarChangedEvent(n));
}
// We do not implicitely delete Expressions.
//else {
// eventList.add(new MIVarDeletedEvent(n));
//}
} }
} }
MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]); MIEvent[] events = (MIEvent[])eventList.toArray(new MIEvent[0]);