mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 21:35:40 +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:
parent
13893bc0ea
commit
34dc9a5b7d
4 changed files with 65 additions and 40 deletions
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -9,6 +9,7 @@
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
* Wind River Systems - Modified for new DSF Reference Implementation
|
* Wind River Systems - Modified for new DSF Reference Implementation
|
||||||
* Mathias Kunter - use MIConst.getString which is for human consumption (Bug 307311)
|
* 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;
|
package org.eclipse.cdt.dsf.mi.service.command.output;
|
||||||
|
@ -27,19 +28,13 @@ public class MIDataEvaluateExpressionInfo extends MIInfo {
|
||||||
MIOutput out = getMIOutput();
|
MIOutput out = getMIOutput();
|
||||||
MIResultRecord outr = out.getMIResultRecord();
|
MIResultRecord outr = out.getMIResultRecord();
|
||||||
if (outr != null) {
|
if (outr != null) {
|
||||||
MIResult[] results = outr.getMIResults();
|
MIValue value = outr.getField("value"); //$NON-NLS-1$
|
||||||
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) {
|
if (value instanceof MIConst) {
|
||||||
fValue = ((MIConst)value).getString();
|
fValue = ((MIConst)value).getString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return fValue;
|
return fValue;
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
* Wind River Systems - Modified for new DSF Reference 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;
|
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 ERROR ="error"; //$NON-NLS-1$
|
||||||
public final static String EXIT ="exit"; //$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$
|
String resultClass = ""; //$NON-NLS-1$
|
||||||
int token = -1;
|
int token = -1;
|
||||||
|
MITuple value = new MITuple();
|
||||||
|
|
||||||
public int getToken() {
|
public int getToken() {
|
||||||
return token;
|
return token;
|
||||||
|
@ -47,11 +47,18 @@ public class MIResultRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
public MIResult[] getMIResults() {
|
public MIResult[] getMIResults() {
|
||||||
return results;
|
return value.getMIResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMIResults(MIResult[] res) {
|
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
|
@Override
|
||||||
|
@ -61,9 +68,9 @@ public class MIResultRecord {
|
||||||
buffer.append(token);
|
buffer.append(token);
|
||||||
}
|
}
|
||||||
buffer.append('^').append(resultClass);
|
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();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Ericsson - Initial Implementation
|
* Ericsson - Initial Implementation
|
||||||
|
* Vladimir Prus (Mentor Graphics) - Use MITuple.getMIValue.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.dsf.mi.service.command.output;
|
package org.eclipse.cdt.dsf.mi.service.command.output;
|
||||||
|
@ -27,12 +28,7 @@ public class MIStackInfoDepthInfo extends MIInfo {
|
||||||
MIOutput out = getMIOutput();
|
MIOutput out = getMIOutput();
|
||||||
MIResultRecord rr = out.getMIResultRecord();
|
MIResultRecord rr = out.getMIResultRecord();
|
||||||
if (rr != null) {
|
if (rr != null) {
|
||||||
MIResult[] results = rr.getMIResults();
|
MIValue value = rr.getField("depth"); //$NON-NLS-1$
|
||||||
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) {
|
if (value instanceof MIConst) {
|
||||||
String str = ((MIConst)value).getString();
|
String str = ((MIConst)value).getString();
|
||||||
try {
|
try {
|
||||||
|
@ -43,8 +39,6 @@ public class MIStackInfoDepthInfo extends MIInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
return depth;
|
return depth;
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,19 +8,25 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
* Wind River Systems - Modified for new DSF Reference 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;
|
package org.eclipse.cdt.dsf.mi.service.command.output;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GDB/MI tuple value.
|
* GDB/MI tuple value.
|
||||||
*/
|
*/
|
||||||
public class MITuple extends MIValue {
|
public class MITuple extends MIValue {
|
||||||
|
|
||||||
final static MIResult[] nullResults = new MIResult[0];
|
final private static MIResult[] NULL_RESULTS = new MIResult[0];
|
||||||
final static MIValue[] nullValues = new MIValue[0];
|
final private static MIValue[] NULL_VALUES = new MIValue[0];
|
||||||
MIResult[] results = nullResults;
|
|
||||||
MIValue[] values = nullValues;
|
private MIResult[] results = NULL_RESULTS;
|
||||||
|
private MIValue[] values = NULL_VALUES;
|
||||||
|
private Map<String, MIValue> name2value;
|
||||||
|
|
||||||
public MIResult[] getMIResults() {
|
public MIResult[] getMIResults() {
|
||||||
return results;
|
return results;
|
||||||
|
@ -28,20 +34,43 @@ public class MITuple extends MIValue {
|
||||||
|
|
||||||
public void setMIResults(MIResult[] res) {
|
public void setMIResults(MIResult[] res) {
|
||||||
results = res;
|
results = res;
|
||||||
|
name2value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MIValue[] getMIValues() {
|
public MIValue[] getMIValues() {
|
||||||
return values;
|
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) {
|
public void setMIValues(MIValue[] vals) {
|
||||||
values = vals;
|
values = vals;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append('{');
|
buffer.append(start);
|
||||||
for (int i = 0; i < results.length; i++) {
|
for (int i = 0; i < results.length; i++) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
buffer.append(',');
|
buffer.append(',');
|
||||||
|
@ -54,7 +83,7 @@ public class MITuple extends MIValue {
|
||||||
}
|
}
|
||||||
buffer.append(values[i].toString());
|
buffer.append(values[i].toString());
|
||||||
}
|
}
|
||||||
buffer.append('}');
|
buffer.append(end);
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue