Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Prus2014-11-26 14:46:33 +0000
committerVladimir Prus2014-12-18 19:27:29 +0000
commit34dc9a5b7d0e1ef8248cba4ca52fafbf2a72d81e (patch)
tree906adb446f0542a2ceb11c95aea764f91f589ad6
parent13893bc0ead4ad0a385f1f3e9b67590eaa065355 (diff)
downloadorg.eclipse.cdt-34dc9a5b7d0e1ef8248cba4ca52fafbf2a72d81e.tar.gz
org.eclipse.cdt-34dc9a5b7d0e1ef8248cba4ca52fafbf2a72d81e.tar.xz
org.eclipse.cdt-34dc9a5b7d0e1ef8248cba4ca52fafbf2a72d81e.zip
Bug 453321 - Convenient field access for MITuple/MIResultRecord
Change-Id: Id43f2cb9b52743792fc7f9ce40d16914d8e257b4 Signed-off-by: Vladimir Prus <vladimir@codesourcery.com> Reviewed-on: https://git.eclipse.org/r/37090 Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java15
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java25
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java22
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java43
4 files changed, 65 insertions, 40 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java
index 1fae2a6511..dbd80a030a 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 QNX Software Systems and others.
+ * Copyright (c) 2000, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* QNX Software Systems - Initial API and implementation
* Wind River Systems - Modified for new DSF Reference Implementation
* Mathias Kunter - use MIConst.getString which is for human consumption (Bug 307311)
+ * Vladimir Prus (Mentor Graphics) - use MIResultRecord.getMIValue
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output;
@@ -27,15 +28,9 @@ public class MIDataEvaluateExpressionInfo extends MIInfo {
MIOutput out = getMIOutput();
MIResultRecord outr = out.getMIResultRecord();
if (outr != null) {
- MIResult[] results = outr.getMIResults();
- for (int i = 0; i < results.length; i++) {
- String var = results[i].getVariable();
- if (var.equals("value")) { //$NON-NLS-1$
- MIValue value = results[i].getMIValue();
- if (value instanceof MIConst) {
- fValue = ((MIConst)value).getString();
- }
- }
+ MIValue value = outr.getField("value"); //$NON-NLS-1$
+ if (value instanceof MIConst) {
+ fValue = ((MIConst)value).getString();
}
}
}
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 e2f5219361..d5fb51b566 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 QNX Software Systems and others.
+ * Copyright (c) 2000, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Wind River Systems - Modified for new DSF Reference Implementation
+ * Vladimir Prus (Mentor Graphics) - Add getMIValue.
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output;
@@ -23,10 +24,9 @@ public class MIResultRecord {
public final static String ERROR ="error"; //$NON-NLS-1$
public final static String EXIT ="exit"; //$NON-NLS-1$
- static final MIResult[] nullResults = new MIResult[0];
- MIResult[] results = nullResults;
String resultClass = ""; //$NON-NLS-1$
int token = -1;
+ MITuple value = new MITuple();
public int getToken() {
return token;
@@ -47,23 +47,30 @@ public class MIResultRecord {
}
public MIResult[] getMIResults() {
- return results;
+ return value.getMIResults();
}
public void setMIResults(MIResult[] res) {
- results = res;
+ value.setMIResults(res);
+ }
+
+ /** Return the value of the named field in this record.
+ * @since 4.6
+ */
+ public MIValue getField(String name) {
+ return value.getField(name);
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
if (token > 0) {
- buffer.append(token);
+ buffer.append(token);
}
buffer.append('^').append(resultClass);
- for (int i = 0; i < results.length; i++) {
- buffer.append(',').append(results[i].toString());
- }
+
+ if (value.getMIResults().length != 0)
+ buffer.append(value.toString(",", "")); //$NON-NLS-1$ //$NON-NLS-2$
return buffer.toString();
}
}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java
index 90e6306fe0..628d036370 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 Ericsson and others.
+ * Copyright (c) 2007, 2014 Ericsson and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Ericsson - Initial Implementation
+ * Vladimir Prus (Mentor Graphics) - Use MITuple.getMIValue.
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output;
@@ -27,19 +28,12 @@ public class MIStackInfoDepthInfo extends MIInfo {
MIOutput out = getMIOutput();
MIResultRecord rr = out.getMIResultRecord();
if (rr != null) {
- MIResult[] results = rr.getMIResults();
- for (int i = 0; i < results.length; i++) {
- String var = results[i].getVariable();
-
- if (var.equals("depth")) { //$NON-NLS-1$
- MIValue value = results[i].getMIValue();
- if (value instanceof MIConst) {
- String str = ((MIConst)value).getString();
- try {
- depth = Integer.parseInt(str.trim());
- } catch (NumberFormatException e) {
- }
- }
+ MIValue value = rr.getField("depth"); //$NON-NLS-1$
+ if (value instanceof MIConst) {
+ String str = ((MIConst)value).getString();
+ try {
+ depth = Integer.parseInt(str.trim());
+ } catch (NumberFormatException e) {
}
}
}
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java
index 444a80a284..682f5b341a 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 QNX Software Systems and others.
+ * Copyright (c) 2000, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,19 +8,25 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
* Wind River Systems - Modified for new DSF Reference Implementation
+ * Vladimir Prus (Mentor Graphics) - Add getMIValue method.
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command.output;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* GDB/MI tuple value.
*/
public class MITuple extends MIValue {
- final static MIResult[] nullResults = new MIResult[0];
- final static MIValue[] nullValues = new MIValue[0];
- MIResult[] results = nullResults;
- MIValue[] values = nullValues;
+ final private static MIResult[] NULL_RESULTS = new MIResult[0];
+ final private static MIValue[] NULL_VALUES = new MIValue[0];
+
+ private MIResult[] results = NULL_RESULTS;
+ private MIValue[] values = NULL_VALUES;
+ private Map<String, MIValue> name2value;
public MIResult[] getMIResults() {
return results;
@@ -28,20 +34,43 @@ public class MITuple extends MIValue {
public void setMIResults(MIResult[] res) {
results = res;
+ name2value = null;
}
public MIValue[] getMIValues() {
return values;
}
+ /** Return the value of the specified field of this tuple.
+ *
+ * @since 4.6
+ */
+ public MIValue getField(String name) {
+ if (name2value == null) {
+ name2value = new HashMap<String, MIValue>();
+ for (MIResult r : results) {
+ name2value.put(r.getVariable(), r.getMIValue());
+ }
+ }
+ return name2value.get(name);
+ }
+
public void setMIValues(MIValue[] vals) {
values = vals;
}
@Override
public String toString() {
+ return toString("{", "}"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ // Return comma-separated values, with start and end prepended and appended
+ // Intentionally package private, should only be used by ourselves and
+ // MIResultRecord.
+ String toString(String start, String end)
+ {
StringBuffer buffer = new StringBuffer();
- buffer.append('{');
+ buffer.append(start);
for (int i = 0; i < results.length; i++) {
if (i != 0) {
buffer.append(',');
@@ -54,7 +83,7 @@ public class MITuple extends MIValue {
}
buffer.append(values[i].toString());
}
- buffer.append('}');
+ buffer.append(end);
return buffer.toString();
}
}

Back to the top