1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56: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 2004-10-06 Mikhail Khodjaiants
Added the "getType" method to ICValue. Added the "getType" method to ICValue.
* ICValue.java * ICValue.java

View file

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

View file

@ -10,7 +10,9 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.debug.internal.core.model; 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.cdt.debug.core.model.ICValue;
import org.eclipse.debug.core.DebugException;
/** /**
* The abstract super class for the C/C++ value types. * The abstract super class for the C/C++ value types.
@ -34,6 +36,25 @@ public abstract class AbstractCValue extends CDebugElement implements ICValue {
return fParent; 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 protected void setChanged( boolean changed );
abstract public void dispose(); abstract public void dispose();

View file

@ -15,7 +15,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable; import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; 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.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException; 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() { protected ICDIVariable getCDIVariable() {
return fCDIVariable; return fCDIVariable;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.AbstractCValue#dispose()
*/
public void dispose() { public void dispose() {
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) { while( it.hasNext() ) {

View file

@ -16,7 +16,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.eclipse.cdt.core.IAddress; import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.core.IAddressFactory; import org.eclipse.cdt.core.IAddressFactory;
import org.eclipse.cdt.debug.core.cdi.CDIException; 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.cdi.model.type.ICDIWCharValue;
import org.eclipse.cdt.debug.core.model.CVariableFormat; import org.eclipse.cdt.debug.core.model.CVariableFormat;
import org.eclipse.cdt.debug.core.model.ICDebugElementStatus; 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.cdt.debug.core.model.ICType;
import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IVariable; 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() { public void dispose() {
Iterator it = fVariables.iterator(); Iterator it = fVariables.iterator();
while( it.hasNext() ) { while( it.hasNext() ) {
@ -424,26 +425,6 @@ public class CValue extends AbstractCValue {
return result; 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. * 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 2004-10-06 Mikhail Khodjaiants
Use the same approach to generate expressions and variables labels. Use the same approach to generate expressions and variables labels.
* CDTDebugModelPresentation.java * CDTDebugModelPresentation.java

View file

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

View file

@ -8,64 +8,47 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui; 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.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region; import org.eclipse.jface.text.Region;
/** /**
* * Utility methods for C/C++ Debug UI.
* Enter type comment.
*
* @since Jul 30, 2002
*/ */
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 start = -1;
int end = -1; int end = -1;
try {
try
{
int pos = offset; int pos = offset;
char c; char c;
while( pos >= 0 ) {
while( pos >= 0 )
{
c = document.getChar( pos ); c = document.getChar( pos );
if ( !Character.isJavaIdentifierPart( c ) ) if ( !Character.isJavaIdentifierPart( c ) )
break; break;
--pos; --pos;
} }
start = pos; start = pos;
pos = offset; pos = offset;
int length = document.getLength(); int length = document.getLength();
while( pos < length ) {
while( pos < length )
{
c = document.getChar( pos ); c = document.getChar( pos );
if ( !Character.isJavaIdentifierPart( c ) ) if ( !Character.isJavaIdentifierPart( c ) )
break; break;
++pos; ++pos;
} }
end = pos; end = pos;
} }
catch( BadLocationException x ) catch( BadLocationException x ) {
{
} }
if ( start > -1 && end > -1 ) {
if ( start > -1 && end > -1 )
{
if ( start == offset && end == offset ) if ( start == offset && end == offset )
return new Region( offset, 0 ); return new Region( offset, 0 );
else if ( start == offset ) else if ( start == offset )
@ -73,7 +56,20 @@ public class CDebugUIUtils
else else
return new Region( start + 1, end - start - 1 ); return new Region( start + 1, end - start - 1 );
} }
return null; 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: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui; 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.cdt.debug.core.model.ICValue;
import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.core.model.IValue;
import org.eclipse.debug.ui.IValueDetailListener; import org.eclipse.debug.ui.IValueDetailListener;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
/** /**
* Enter type comment. * Computes a detailed description of the given value.
*
* @since Jun 4, 2003
*/ */
public class CDTValueDetailProvider public class CValueDetailProvider {
{
//The shared instance.
private static CDTValueDetailProvider fInstance = null;
public static CDTValueDetailProvider getDefault() //The shared instance.
{ private static CValueDetailProvider fInstance = null;
if ( fInstance == null )
{ public static CValueDetailProvider getDefault() {
fInstance = new CDTValueDetailProvider(); if ( fInstance == null ) {
fInstance = new CValueDetailProvider();
} }
return fInstance; return fInstance;
} }
public void computeDetail( final IValue value, final IValueDetailListener listener ) public void computeDetail( final IValue value, final IValueDetailListener listener ) {
{ if ( value instanceof ICValue ) {
if ( value instanceof ICValue ) final ICStackFrame frame = CDebugUIUtils.getCurrentStackFrame();
{ if ( frame != null ) {
Display.getCurrent().asyncExec( new Runnable() Display.getCurrent().asyncExec( new Runnable() {
{
public void run() public void run() {
{ listener.detailComputed( value, ((ICValue)value).evaluateAsExpression( frame ) );
listener.detailComputed( value, ((ICValue)value).evaluateAsExpression() );
} }
} ); } );
} }
} }
} }
}

View file

@ -49,7 +49,9 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
super(); super();
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
*/ */
public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion ) { public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion ) {
@ -87,7 +89,9 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
return null; return null;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int) * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int)
*/ */
public IRegion getHoverRegion( ITextViewer viewer, int offset ) { public IRegion getHoverRegion( ITextViewer viewer, int offset ) {
@ -124,7 +128,9 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
buffer.append( "</p>" ); //$NON-NLS-1$ buffer.append( "</p>" ); //$NON-NLS-1$
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover#setEditor(org.eclipse.ui.IEditorPart) * @see org.eclipse.cdt.ui.text.c.hover.ICEditorTextHover#setEditor(org.eclipse.ui.IEditorPart)
*/ */
public void setEditor( IEditorPart editor ) { 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) * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/ */
public void selectionChanged( IWorkbenchPart part, ISelection selection ) { public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
fSelection = selection; fSelection = selection;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
*/ */
public void partActivated( IWorkbenchPart part ) { public void partActivated( IWorkbenchPart part ) {
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
*/ */
public void partBroughtToTop( IWorkbenchPart part ) { public void partBroughtToTop( IWorkbenchPart part ) {
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
*/ */
public void partClosed( IWorkbenchPart part ) { 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) * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
*/ */
public void partDeactivated( IWorkbenchPart part ) { public void partDeactivated( IWorkbenchPart part ) {
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
*/ */
public void partOpened( IWorkbenchPart part ) { public void partOpened( IWorkbenchPart part ) {
@ -206,7 +224,9 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
return null; return null;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator() * @see org.eclipse.jface.text.ITextHoverExtension#getHoverControlCreator()
*/ */
public IInformationControlCreator getHoverControlCreator() { public IInformationControlCreator getHoverControlCreator() {
@ -214,31 +234,22 @@ public class DebugTextHover implements ICEditorTextHover, ITextHoverExtension, I
} }
/** /**
* Replace any characters in the given String that would confuse an HTML * Replace any characters in the given String that would confuse an HTML parser with their escape sequences.
* parser with their escape sequences.
*/ */
private static String makeHTMLSafe( String string ) private static String makeHTMLSafe( String string ) {
{
StringBuffer buffer = new StringBuffer( string.length() ); 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 ); char ch = string.charAt( i );
switch( ch ) {
switch( ch )
{
case '&': case '&':
buffer.append( "&amp;" ); //$NON-NLS-1$ buffer.append( "&amp;" ); //$NON-NLS-1$
break; break;
case '<': case '<':
buffer.append( "&lt;" ); //$NON-NLS-1$ buffer.append( "&lt;" ); //$NON-NLS-1$
break; break;
case '>': case '>':
buffer.append( "&gt;" ); //$NON-NLS-1$ buffer.append( "&gt;" ); //$NON-NLS-1$
break; break;
default: default:
buffer.append( ch ); buffer.append( ch );
break; break;