Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Prus2014-12-02 18:01:06 +0000
committerVladimir Prus2014-12-31 13:58:53 +0000
commit7aa9cf6efc513d7fc52ec8a8e94f3ea17bfc8863 (patch)
treef15d499b19e6fb8a5f16d9a3b2f0051545d7ea38
parent84add6a4bd5a60cc006aeb2f589180f8e8dd6273 (diff)
downloadorg.eclipse.cdt-7aa9cf6efc513d7fc52ec8a8e94f3ea17bfc8863.tar.gz
org.eclipse.cdt-7aa9cf6efc513d7fc52ec8a8e94f3ea17bfc8863.tar.xz
org.eclipse.cdt-7aa9cf6efc513d7fc52ec8a8e94f3ea17bfc8863.zip
Bug 453920: Remove code duplication between MIVar and MIVarCreateInfo.
Change-Id: I1c291fa235fe77910b6bea7ad98f269d8949fc5c Signed-off-by: Vladimir Prus <vladimir@codesourcery.com> Reviewed-on: https://git.eclipse.org/r/37475 Tested-by: Hudson CI
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java12
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVar.java12
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVarCreateInfo.java58
3 files changed, 32 insertions, 50 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java
index d5fb51b566..6aef549a15 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java
@@ -8,13 +8,16 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Wind River Systems - Modified for new DSF Reference Implementation
- * Vladimir Prus (Mentor Graphics) - Add getMIValue.
+ * Vladimir Prus (Mentor Graphics) - Add getMIFields/getMIField.
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output;
/**
* GDB/MI ResultRecord.
+ *
+ * Effectively, it's an result class (a string), plus token (also a string),
+ * plus MI tuple with actual response.
*/
public class MIResultRecord {
@@ -46,6 +49,13 @@ public class MIResultRecord {
resultClass = type;
}
+ /** Return all data fields of this record as MITuple
+ * @since 4.6
+ */
+ public MITuple getFields() {
+ return value;
+ }
+
public MIResult[] getMIResults() {
return value.getMIResults();
}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVar.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVar.java
index d9acba8661..48ccfc3bd4 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVar.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVar.java
@@ -28,6 +28,7 @@ public class MIVar {
String name = ""; //$NON-NLS-1$
String type = ""; //$NON-NLS-1$
+ String value = ""; //$NON-NLS-1$
String exp = ""; //$NON-NLS-1$
private boolean isDynamic = false;
int numchild;
@@ -89,6 +90,13 @@ public class MIVar {
return type;
}
+ /**
+ * @since 4.6
+ */
+ public String getValue() {
+ return value;
+ }
+
/**
* @return Whether the value and children of this variable are provided
* by a pretty printer.
@@ -142,7 +150,7 @@ public class MIVar {
MIValue value = results[i].getMIValue();
String str = ""; //$NON-NLS-1$
if (value != null && value instanceof MIConst) {
- str = ((MIConst)value).getCString();
+ str = ((MIConst)value).getString();
}
if (var.equals("numchild")) { //$NON-NLS-1$
@@ -154,6 +162,8 @@ public class MIVar {
name = str;
} else if (var.equals("type")) { //$NON-NLS-1$
type = str;
+ } else if (var.equals("value")) { //$NON-NLS-1$
+ this.value = str;
} else if (var.equals("exp")) { //$NON-NLS-1$
exp = str;
} else if (var.equals("dynamic") && str.trim().equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVarCreateInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVarCreateInfo.java
index 77bd416fff..0863c17ac6 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVarCreateInfo.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIVarCreateInfo.java
@@ -25,56 +25,21 @@ package org.eclipse.cdt.dsf.mi.service.command.output;
*/
public class MIVarCreateInfo extends MIInfo {
- String name = ""; //$NON-NLS-1$
- int numChild;
- String type = ""; //$NON-NLS-1$
- MIVar child;
- String value = null;
- private boolean isDynamic = false;
- private boolean hasMore = false;
- private MIDisplayHint displayHint = MIDisplayHint.NONE;
+ private MIVar child;
public MIVarCreateInfo(MIOutput record) {
super(record);
if (isDone()) {
- MIOutput out = getMIOutput();
- MIResultRecord rr = out.getMIResultRecord();
+ MIResultRecord rr = getMIOutput().getMIResultRecord();
if (rr != null) {
- MIResult[] results = rr.getMIResults();
- for (int i = 0; i < results.length; i++) {
- String var = results[i].getVariable();
- MIValue resultVal = results[i].getMIValue();
- String str = ""; //$NON-NLS-1$
- if (resultVal instanceof MIConst) {
- str = ((MIConst)resultVal).getString();
- }
-
- if (var.equals("name")) { //$NON-NLS-1$
- name = str;
- } else if (var.equals("numchild")) { //$NON-NLS-1$
- try {
- numChild = Integer.parseInt(str.trim());
- } catch (NumberFormatException e) {
- }
- } else if (var.equals("type")) { //$NON-NLS-1$
- type = str;
- } else if (var.equals("value")) { //$NON-NLS-1$
- value = str;
- } else if (var.equals("dynamic") && str.trim().equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$
- isDynamic = true;
- } else if (var.equals("has_more") && str.trim().equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$
- hasMore = true;
- } else if (var.equals("displayhint")) { //$NON-NLS-1$
- displayHint = new MIDisplayHint(str);
- }
- }
+ child = new MIVar(rr.getFields());
}
}
}
public String getType()
{
- return type;
+ return child.getType();
}
/**
@@ -84,7 +49,7 @@ public class MIVarCreateInfo extends MIInfo {
* @since 4.0
*/
public boolean isDynamic() {
- return isDynamic;
+ return child.isDynamic();
}
/**
@@ -95,7 +60,7 @@ public class MIVarCreateInfo extends MIInfo {
*/
public int getNumChildren()
{
- return numChild;
+ return child.getNumChild();
}
/**
@@ -107,17 +72,17 @@ public class MIVarCreateInfo extends MIInfo {
* @since 4.0
*/
public boolean hasMore() {
- return hasMore;
+ return child.hasMore();
}
public String getName()
{
- return name;
+ return child.getVarName();
}
public String getValue()
{
- return value;
+ return child.getValue();
}
/**
@@ -127,13 +92,10 @@ public class MIVarCreateInfo extends MIInfo {
* @since 4.0
*/
public MIDisplayHint getDisplayHint() {
- return displayHint;
+ return child.getDisplayHint();
}
public MIVar getMIVar() {
- if (child == null) {
- child = new MIVar(name, isDynamic, numChild, hasMore, type, displayHint);
- }
return child;
}
}

Back to the top