1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-19 15:05:36 +02:00

Propogate fix from CDT 4.0 which from CDT 3.1.

This commit is contained in:
Doug Schaefer 2007-11-26 21:41:12 +00:00
parent fdc1f3a72f
commit ee51245443

View file

@ -21,7 +21,6 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIBoolType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIBoolType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDICharType; 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.ICDIDoubleType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIDoubleType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIEnumType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIEnumType;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatType; import org.eclipse.cdt.debug.core.cdi.model.type.ICDIFloatType;
@ -228,7 +227,6 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl
* allow the override of the timeout. * allow the override of the timeout.
*/ */
public ICDIVariable[] getChildren(int timeout) throws CDIException { public ICDIVariable[] getChildren(int timeout) throws CDIException {
children = NO_CHILDREN;
MISession mi = ((Target)getTarget()).getMISession(); MISession mi = ((Target)getTarget()).getMISession();
CommandFactory factory = mi.getCommandFactory(); CommandFactory factory = mi.getCommandFactory();
MIVarListChildren var = factory.createMIVarListChildren(getMIVar().getVarName()); MIVarListChildren var = factory.createMIVarListChildren(getMIVar().getVarName());
@ -244,105 +242,85 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl
} }
MIVar[] vars = info.getMIVars(); MIVar[] vars = info.getMIVars();
List childrenList = new ArrayList(vars.length); List childrenList = new ArrayList(vars.length);
// children = new Variable[vars.length];
// For C++ in GDB the children of the
// the structure are the scope and the inherited classes.
// For example:
// class foo: public bar {
// int x;
// public: int y;
// } foobar;
// This will map to
// - foobar
// + bar
// - private
// - x
// - public
// - y
// So we choose to ignore the first set of children
// but carry over to those "fake" variables the typename and the qualified name
boolean cppFakeLayer = isCPPLanguage() && (!isFake() || (isFake() && !isAccessQualifier(fName)));
ICDIType t = getType();
boolean container = isStructureProvider(t);
for (int i = 0; i < vars.length; i++) { for (int i = 0; i < vars.length; i++) {
// parent qualified name String fn = getQualifiedName();
String prefix = '(' + getFullName() + ')'; String childName = vars[i].getExp();
// child simple name
String childName = vars[i].getExp();
// fallback full name
String childFullName = prefix + '.' + childName;
ICDIType childType = null; ICDIType childType = null;
boolean childFake = false; boolean childFake = false;
if (cppFakeLayer && container) { ICDIType t = getType();
childFake = true; if (t instanceof ICDIArrayType) {
childType = t; // For Array gdb varobj only return the index, override here.
if (!isAccessQualifier(childName)) { int index = castingIndex + i;
// if field is not access modifier and fake - it is a basetype fn = "(" + fn + ")[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// cast to it to see reduced structure as value childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$
childFullName = '(' + childName + ')' + prefix; } else if (t instanceof ICDIPointerType) {
ICDIType subType = ((ICDIPointerType)t).getComponentType();
if (subType instanceof ICDIStructType || t instanceof IncompleteType) {
if (isCPPLanguage()) {
if (!isFake() || (isFake() && !isAccessQualifier(fName))) {
childFake = true;
childType = t;
} else {
fn = "(" + fn + ")->" + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
}
} else { // If not C++ language
fn = "(" + fn + ")->" + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
}
} else { } else {
childFullName = prefix; fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$
} }
} else { } else if (t instanceof ICDIReferenceType) {
if (t instanceof ICDIArrayType) { ICDIType subType = ((ICDIReferenceType)t).getComponentType();
// For Array gdb varobj only return the index, override here. if (subType instanceof ICDIStructType || t instanceof IncompleteType) {
int index = castingIndex + i; if (isCPPLanguage()) {
childFullName = prefix + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ if (!isFake() || (isFake() && !isAccessQualifier(fName))) {
childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ childFake = true;
} else if (t instanceof ICDIPointerType) { childType = t;
if (container) { } else {
childFullName = prefix + "->" + childName; //$NON-NLS-1$ fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
} else { }
childFullName = "*" + prefix; //$NON-NLS-1$ } else { // If not C++ language
fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
} }
} else if (t instanceof ICDIReferenceType) { } else {
if (container) { fn = "(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$
childFullName = prefix + "." + childName; //$NON-NLS-1$ }
} else if (t instanceof ICDIStructType || t instanceof IncompleteType) {
if (isCPPLanguage()) {
if (!isFake() || (isFake() && !isAccessQualifier(fName))) {
childFake = true;
childType = t;
} else { } else {
childFullName = prefix; fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
} }
} else if (t instanceof ICDIStructType) { } else { // If not C++ language
// already correct name fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
Variable v = createVariable((Target) getTarget(), (Thread) getThread(), (StackFrame) getStackFrame(), childName, Variable v = createVariable((Target)getTarget(), (Thread)getThread(), (StackFrame)getStackFrame(),
childFullName, getPosition(), getStackDepth(), vars[i]); childName, fn, getPosition(), getStackDepth(), vars[i]);
if (childType != null) { if (childType != null) {
// Hack to reset the typename to a known value // Hack to reset the typename to a known value
v.fType = childType; v.fType = childType;
} }
v.setIsFake(childFake); v.setIsFake(childFake);
if (childFake && isAccessQualifier(childName)) { if (childFake && isAccessQualifier(childName)) {
// Replace a fake variable representing an access qualifier with its children. // don't add these, add their kids
ICDIVariable[] grandchildren = v.getChildren(timeout); ICDIVariable[] grandchildren = v.getChildren();
for (int j = 0; j < grandchildren.length; j++) { for (int j = 0; j < grandchildren.length; ++j)
childrenList.add(grandchildren[j]); childrenList.add(grandchildren[j]);
} } else
} else {
childrenList.add(v); childrenList.add(v);
}
} }
if (!childrenList.isEmpty())
children = (ICDIVariable[]) childrenList.toArray(new Variable[childrenList.size()]); children = (ICDIVariable[])childrenList.toArray(new ICDIVariable[childrenList.size()]);
} catch (MIException e) { } catch (MIException e) {
throw new MI2CDIException(e); throw new MI2CDIException(e);
} }
return children; return children;
} }
private boolean isStructureProvider(ICDIType t) { boolean isAccessQualifier(String foo) {
// IncompleteType can be only struct or class, so same rules apply
if (t instanceof ICDIStructType || t instanceof IncompleteType)
return true;
if (t instanceof ICDIPointerType || t instanceof ICDIReferenceType) {
ICDIType type = ((ICDIDerivedType)t).getComponentType();
return (type instanceof ICDIStructType || type instanceof IncompleteType);
}
return false;
}
boolean isAccessQualifier(String foo) {
return foo.equals("private") || foo.equals("public") || foo.equals("protected"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return foo.equals("private") || foo.equals("public") || foo.equals("protected"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} }