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

[237858] - fixed expression evaluation for complex c++ data structures

This commit is contained in:
Alena Laskavaia 2008-07-09 14:44:50 +00:00
parent b52f11e5cf
commit 89050be0e1

View file

@ -240,71 +240,54 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl
if (info == null) { if (info == null) {
throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$
} }
MIVar[] vars = info.getMIVars(); final MIVar[] vars = info.getMIVars();
List childrenList = new ArrayList(vars.length); final List childrenList = new ArrayList(vars.length);
final ICDIType t = getType();
final boolean cpp = isCPPLanguage();
for (int i = 0; i < vars.length; i++) { for (int i = 0; i < vars.length; i++) {
String fn = getQualifiedName(); String fn = getQualifiedName();
String childName = vars[i].getExp(); String childName = vars[i].getExp();
ICDIType childType = null;
boolean childFake = false; boolean childFake = false;
ICDIType t = getType(); if (cpp && isAccessQualifier(childName)) {
if (t instanceof ICDIArrayType) { // since access qualifier is keyword this only possible when gdb returns this as fake fields
// so it is pretty safe without to do without any other type checks
childFake = true;
// fn remains unchanged otherwise it would be like x->public
} else if (t instanceof ICDIArrayType) {
// For Array gdb varobj only return the index, override here. // For Array gdb varobj only return the index, override here.
int index = castingIndex + i; int index = castingIndex + i;
fn = "(" + fn + ")[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ fn = "(" + fn + ")[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$
} else if (t instanceof ICDIPointerType) { } else if (t instanceof ICDIPointerType) {
ICDIType subType = ((ICDIPointerType)t).getComponentType(); ICDIType subType = ((ICDIPointerType) t).getComponentType();
if (subType instanceof ICDIStructType || t instanceof IncompleteType) { if (subType instanceof ICDIStructType || subType instanceof IncompleteType) {
if (isCPPLanguage()) { fn = "(" + fn + ")->" + childName; //$NON-NLS-1$ //$NON-NLS-2$
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 {
fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$ fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$
} }
} else if (t instanceof ICDIReferenceType) { } else if (t instanceof ICDIReferenceType) {
ICDIType subType = ((ICDIReferenceType)t).getComponentType(); ICDIType subType = ((ICDIReferenceType) t).getComponentType();
if (subType instanceof ICDIStructType || t instanceof IncompleteType) { if (subType instanceof ICDIStructType || subType instanceof IncompleteType) {
if (isCPPLanguage()) { fn = "(" + fn + ")." + childName; //$NON-NLS-1$ //$NON-NLS-2$
if (!isFake() || (isFake() && !isAccessQualifier(fName))) { } else if (subType instanceof ICDIPointerType) {
childFake = true; fn = "(" + fn + ")->" + childName; //$NON-NLS-1$ //$NON-NLS-2$
childType = t; } else if (subType instanceof ICDIArrayType) {
} else { int index = castingIndex + i;
fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$ fn = "(" + fn + ")[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} // set this to look pretty
} else { // If not C++ language childName = getName() + "[" + index + "]"; //$NON-NLS-1$ //$NON-NLS-2$
fn = "(" + fn + ")." + vars[i].getExp(); //$NON-NLS-1$ //$NON-NLS-2$
}
} else { } else {
fn = "(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$ fn = "*(" + fn + ")"; //$NON-NLS-1$ //$NON-NLS-2$
} }
} else if (t instanceof ICDIStructType || t instanceof IncompleteType) { } else if (t instanceof ICDIStructType || t instanceof IncompleteType) {
if (isCPPLanguage()) { fn = "(" + fn + ")." + childName; //$NON-NLS-1$ //$NON-NLS-2$
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$
}
} }
Variable v = createVariable((Target)getTarget(), (Thread)getThread(), (StackFrame)getStackFrame(), Variable v = createVariable((Target)getTarget(), (Thread)getThread(), (StackFrame)getStackFrame(),
childName, fn, getPosition(), getStackDepth(), vars[i]); childName, fn, getPosition(), getStackDepth(), vars[i]);
if (childType != null) { if (childFake) {
v.setIsFake(childFake);
// Hack to reset the typename to a known value // Hack to reset the typename to a known value
v.fType = childType; v.fType = t;
}
v.setIsFake(childFake);
if (childFake && isAccessQualifier(childName)) {
// don't add these, add their kids // don't add these, add their kids
ICDIVariable[] grandchildren = v.getChildren(); ICDIVariable[] grandchildren = v.getChildren();
for (int j = 0; j < grandchildren.length; ++j) for (int j = 0; j < grandchildren.length; ++j)
@ -321,6 +304,7 @@ public abstract class Variable extends VariableDescriptor implements ICDIVariabl
} }
boolean isAccessQualifier(String foo) { boolean isAccessQualifier(String foo) {
if (foo==null) return false;
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$
} }