1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

Provide a context for expression evaluation.

This commit is contained in:
Mikhail Khodjaiants 2004-10-07 15:23:25 +00:00
parent b973d5855f
commit e98111fb62
10 changed files with 128 additions and 124 deletions

View file

@ -1,3 +1,10 @@
2004-10-07 Mikhail Khodjaiants
Provide a context for expression evaluation.
* ICValue.java
* AbstractCValue.java
* CArrayPartitionValue.java
* CValue.java
2004-10-06 Mikhail Khodjaiants
Added the "getType" method to ICValue.
* ICValue.java

View file

@ -20,5 +20,5 @@ public interface ICValue extends IValue, ICDebugElement {
ICType getType() throws DebugException;
String evaluateAsExpression();
String evaluateAsExpression( ICStackFrame frame );
}

View file

@ -10,7 +10,9 @@
***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.ICValue;
import org.eclipse.debug.core.DebugException;
/**
* The abstract super class for the C/C++ value types.
@ -34,6 +36,25 @@ public abstract class AbstractCValue extends CDebugElement implements ICValue {
return fParent;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#evaluateAsExpression(org.eclipse.cdt.debug.core.model.ICStackFrame)
*/
public String evaluateAsExpression( ICStackFrame frame ) {
String valueString = null;
AbstractCVariable parent = getParentVariable();
if ( parent != null ) {
if ( frame != null && frame.canEvaluate() ) {
try {
valueString = frame.evaluateExpressionToString( parent.getExpressionString() );
}
catch( DebugException e ) {
valueString = e.getMessage();
}
}
}
return valueString;
}
abstract protected void setChanged( boolean changed );
abstract public void dispose();

View file

@ -15,7 +15,6 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
@ -129,27 +128,13 @@ public class CArrayPartitionValue extends AbstractCValue {
}
}
public String evaluateAsExpression() {
String valueString = null;
AbstractCVariable parent = getParentVariable();
if ( parent != null ) {
ICStackFrame frame = parent.getStackFrame();
if ( frame != null && frame.canEvaluate() ) {
try {
valueString = frame.evaluateExpressionToString( parent.getExpressionString() );
}
catch( DebugException e ) {
valueString = e.getMessage();
}
}
}
return valueString;
}
protected ICDIVariable getCDIVariable() {
return fCDIVariable;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#dispose()
*/
public void dispose() {
Iterator it = fVariables.iterator();
while( it.hasNext() ) {

View file

@ -16,7 +16,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.core.IAddressFactory;
import org.eclipse.cdt.debug.core.cdi.CDIException;
@ -34,7 +33,6 @@ import org.eclipse.cdt.debug.core.cdi.model.type.ICDIShortValue;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIWCharValue;
import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable;
@ -181,6 +179,9 @@ public class CValue extends AbstractCValue {
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#dispose()
*/
public void dispose() {
Iterator it = fVariables.iterator();
while( it.hasNext() ) {
@ -424,26 +425,6 @@ public class CValue extends AbstractCValue {
return result;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICValue#evaluateAsExpression()
*/
public String evaluateAsExpression() {
String valueString = null;
AbstractCVariable parent = getParentVariable();
if ( parent != null ) {
ICStackFrame frame = parent.getStackFrame();
if ( frame != null && frame.canEvaluate() ) {
try {
valueString = frame.evaluateExpressionToString( parent.getExpressionString() );
}
catch( DebugException e ) {
valueString = e.getMessage();
}
}
}
return valueString;
}
/**
* Invalidates the string cache.
*/

View file

@ -1,3 +1,10 @@
2004-10-07 Mikhail Khodjaiants
Provide a context for expression evaluation.
* CDebugUIUtils.java
* CDTDebugModelPresentation.java
* CDTValueDetailProvider.java renamed to CValueDetailProvider.java
* DebugTextHover.java
2004-10-06 Mikhail Khodjaiants
Use the same approach to generate expressions and variables labels.
* CDTDebugModelPresentation.java

View file

@ -133,7 +133,7 @@ public class CDTDebugModelPresentation extends LabelProvider implements IDebugMo
* @see org.eclipse.debug.ui.IDebugModelPresentation#computeDetail(IValue, IValueDetailListener)
*/
public void computeDetail( IValue value, IValueDetailListener listener ) {
CDTValueDetailProvider.getDefault().computeDetail( value, listener );
CValueDetailProvider.getDefault().computeDetail( value, listener );
}
/*

View file

@ -8,64 +8,47 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
/**
*
* Enter type comment.
*
* @since Jul 30, 2002
* Utility methods for C/C++ Debug UI.
*/
public class CDebugUIUtils
{
public class CDebugUIUtils {
static public IRegion findWord( IDocument document, int offset )
{
static public IRegion findWord( IDocument document, int offset ) {
int start = -1;
int end = -1;
try
{
try {
int pos = offset;
char c;
while( pos >= 0 )
{
while( pos >= 0 ) {
c = document.getChar( pos );
if ( !Character.isJavaIdentifierPart( c ) )
break;
--pos;
}
start = pos;
pos = offset;
int length = document.getLength();
while( pos < length )
{
while( pos < length ) {
c = document.getChar( pos );
if ( !Character.isJavaIdentifierPart( c ) )
break;
++pos;
}
end = pos;
}
catch( BadLocationException x )
{
}
if ( start > -1 && end > -1 )
{
catch( BadLocationException x ) {
}
if ( start > -1 && end > -1 ) {
if ( start == offset && end == offset )
return new Region( offset, 0 );
else if ( start == offset )
@ -73,7 +56,20 @@ public class CDebugUIUtils
else
return new Region( start + 1, end - start - 1 );
}
return null;
}
}
/**
* Returns the currently selected stack frame or the topmost frame
* in the currently selected thread in the Debug view
* of the current workbench page. Returns <code>null</code>
* if no stack frame or thread is selected, or if not called from the UI thread.
*
* @return the currently selected stack frame or the topmost frame
* in the currently selected thread
*/
static public ICStackFrame getCurrentStackFrame() {
IAdaptable context = DebugUITools.getDebugContext();
return ( context != null ) ? (ICStackFrame)context.getAdapter( ICStackFrame.class ) : null;
}
}

View file

@ -8,44 +8,40 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.ICValue;
import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.ui.IValueDetailListener;
import org.eclipse.swt.widgets.Display;
/**
* Enter type comment.
*
* @since Jun 4, 2003
* Computes a detailed description of the given value.
*/
public class CDTValueDetailProvider
{
//The shared instance.
private static CDTValueDetailProvider fInstance = null;
public class CValueDetailProvider {
public static CDTValueDetailProvider getDefault()
{
if ( fInstance == null )
{
fInstance = new CDTValueDetailProvider();
//The shared instance.
private static CValueDetailProvider fInstance = null;
public static CValueDetailProvider getDefault() {
if ( fInstance == null ) {
fInstance = new CValueDetailProvider();
}
return fInstance;
}
public void computeDetail( final IValue value, final IValueDetailListener listener )
{
if ( value instanceof ICValue )
{
Display.getCurrent().asyncExec( new Runnable()
{
public void run()
{
listener.detailComputed( value, ((ICValue)value).evaluateAsExpression() );
}
} );
public void computeDetail( final IValue value, final IValueDetailListener listener ) {
if ( value instanceof ICValue ) {
final ICStackFrame frame = CDebugUIUtils.getCurrentStackFrame();
if ( frame != null ) {
Display.getCurrent().asyncExec( new Runnable() {
public void run() {
listener.detailComputed( value, ((ICValue)value).evaluateAsExpression( frame ) );
}
} );
}
}
}
}
}

View file

@ -49,7 +49,9 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
super();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
*/
public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion ) {
@ -65,7 +67,7 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
expression = expression.trim();
if ( expression.length() == 0 )
return null;
StringBuffer buffer= new StringBuffer();
StringBuffer buffer = new StringBuffer();
String result = evaluateExpression( frame, expression );
if ( result == null )
return null;
@ -87,7 +89,9 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
return null;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int)
*/
public IRegion getHoverRegion( ITextViewer viewer, int offset ) {
@ -119,12 +123,14 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
value = value.substring( 0, MAX_HOVER_INFO_SIZE ) + " ..."; //$NON-NLS-1$
buffer.append( "<p>" ); //$NON-NLS-1$
buffer.append( "<pre>" ).append( expression ).append( "</pre>" ); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append( " =" ); //$NON-NLS-1$
buffer.append( " = " ); //$NON-NLS-1$
buffer.append( "<b><pre>" ).append( value ).append( "</pre></b>" ); //$NON-NLS-1$ //$NON-NLS-2$
buffer.append( "</p>" ); //$NON-NLS-1$
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover#setEditor(org.eclipse.ui.IEditorPart)
*/
public void setEditor( IEditorPart editor ) {
@ -144,26 +150,34 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
fSelection = selection;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
*/
public void partActivated( IWorkbenchPart part ) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
*/
public void partBroughtToTop( IWorkbenchPart part ) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
*/
public void partClosed( IWorkbenchPart part ) {
@ -176,13 +190,17 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
*/
public void partDeactivated( IWorkbenchPart part ) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
*/
public void partOpened( IWorkbenchPart part ) {
@ -206,7 +224,9 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
return null;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
*/
public IInformationControlCreator getHoverControlCreator() {
@ -214,36 +234,27 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
}
/**
* Replace any characters in the given String that would confuse an HTML
* parser with their escape sequences.
* Replace any characters in the given String that would confuse an HTML parser with their escape sequences.
*/
private static String makeHTMLSafe( String string )
{
private static String makeHTMLSafe( String string ) {
StringBuffer buffer = new StringBuffer( string.length() );
for ( int i = 0; i != string.length(); i++ )
{
for( int i = 0; i != string.length(); i++ ) {
char ch = string.charAt( i );
switch( ch )
{
switch( ch ) {
case '&':
buffer.append( "&amp;" ); //$NON-NLS-1$
break;
case '<':
buffer.append( "&lt;" ); //$NON-NLS-1$
break;
case '>':
buffer.append( "&gt;" ); //$NON-NLS-1$
break;
default:
buffer.append( ch );
break;
}
}
return buffer.toString();
return buffer.toString();
}
}