1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 12:25:35 +02:00

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>
This commit is contained in:
Vladimir Prus 2014-11-26 17:46:33 +03:00
parent 13893bc0ea
commit 34dc9a5b7d
4 changed files with 65 additions and 40 deletions

View file

@ -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();
}
}
}

View file

@ -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();
}
}

View file

@ -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) {
}
}
}

View file

@ -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();
}
}