1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

BUG 394509 : Adding floating point renderer to the memory Browser

This is  Wind Rivers floating point renderer we are moving in to Open
SOurce.
This commit is contained in:
Randy Rohrbach 2012-11-16 18:55:17 -05:00
parent 9194376ff4
commit 2dbe81588e
36 changed files with 6907 additions and 2 deletions

View file

@ -29,7 +29,7 @@ providerName=Eclipse CDT
updateSiteName=Eclipse CDT Update Site
# "description" property - description of the feature
description=Additional features for debug Memory View - traditional rendering, Find/Replace, Import/Export.
description=Additional features for debug Memory View - traditional rendering, floating-point rendering, Find/Replace, Import/Export.
# "licenseURL" property - URL of the "Feature License"
# do not translate value - just change to point to a locale-specific HTML page

View file

@ -30,6 +30,13 @@
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.eclipse.cdt.debug.ui.memory.floatingpoint"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.eclipse.cdt.debug.ui.memory.transport"

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1 @@
/target

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.debug.ui.memory.floatingpoint</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,95 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=warning
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.6

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,32 @@
compilers.f.unresolved-features=1
compilers.f.unresolved-plugins=1
compilers.incompatible-environment=1
compilers.p.build=1
compilers.p.build.bin.includes=1
compilers.p.build.encodings=2
compilers.p.build.java.compiler=2
compilers.p.build.java.compliance=1
compilers.p.build.missing.output=2
compilers.p.build.output.library=1
compilers.p.build.source.library=1
compilers.p.build.src.includes=1
compilers.p.deprecated=1
compilers.p.discouraged-class=1
compilers.p.internal=1
compilers.p.missing-packages=1
compilers.p.missing-version-export-package=2
compilers.p.missing-version-import-package=1
compilers.p.missing-version-require-bundle=1
compilers.p.no-required-att=0
compilers.p.not-externalized-att=2
compilers.p.unknown-attribute=1
compilers.p.unknown-class=1
compilers.p.unknown-element=1
compilers.p.unknown-identifier=1
compilers.p.unknown-resource=1
compilers.p.unresolved-ex-points=0
compilers.p.unresolved-import=0
compilers.s.create-docs=false
compilers.s.doc-folder=doc
compilers.s.open-tags=1
eclipse.preferences.version=1

View file

@ -0,0 +1,17 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.debug.ui.memory.floatingpoint;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.debug.core;bundle-version="3.7.100",
org.eclipse.debug.ui;bundle-version="3.8.1",
org.eclipse.core.runtime;bundle-version="3.8.0",
org.eclipse.ui;bundle-version="3.8.0",
org.eclipse.search;bundle-version="3.8.0",
org.eclipse.cdt.debug.core;bundle-version="7.2.0"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRenderingPlugin
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.eclipse.cdt.debug.ui.memory.floatingpoint

View file

@ -0,0 +1,12 @@
source.. = src/
bin.includes = .classpath,\
.gitignore,\
.project,\
.settings/,\
bin/,\
build.properties,\
META-INF/,\
plugin.properties,\
plugin.xml,\
pom.xml,\
.

View file

@ -0,0 +1,22 @@
###############################################################################
# Copyright (c) 2012 Wind River 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
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Randy Rohrbach (Wind River) - Initial implementation
# IBM Corporation
###############################################################################
#
# Plugin information
#
pluginName = Floating Point Memory Renderer
providerName = Eclipse CDT
renderingType.name = Floating Point
page.name = Floating Point Memory Renderer
#
# Action preference text
#
FPRenderingPreferenceActionName=Floating Point Rendering Preferences ...

View file

@ -0,0 +1,51 @@
<?eclipse version="3.0"?>
<plugin>
<extension point="org.eclipse.debug.ui.memoryRenderings">
<renderingType
name="%renderingType.name"
id="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRendering"
class="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRenderingTypeDelegate">
</renderingType>
<renderingBindings
renderingIds="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRendering"
defaultIds="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRendering">
<enablement>
<instanceof value="org.eclipse.debug.core.model.IMemoryBlockExtension"/>
</enablement>
</renderingBindings>
</extension>
<extension point="org.eclipse.ui.preferencePages">
<page
category="org.eclipse.cdt.debug.ui.CDebugPreferencePage"
class="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRenderingPreferencePage"
id="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRenderingPreferencePage"
name="%page.name"/>
</extension>
<extension point="org.eclipse.core.runtime.preferences">
<initializer class="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRenderingPreferenceInitializer"/>
</extension>
<extension point="org.eclipse.ui.viewActions">
<viewContribution
targetID="org.eclipse.debug.ui.MemoryView"
id="org.eclipse.debug.ui.memoryView.toolbar">
<action
class="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRenderingPreferenceAction"
helpContextId="FPRenderingPreferenceAction_context"
id="org.eclipse.cdt.debug.ui.memory.floatingpoint.preferenceaction"
label="%FPRenderingPreferenceActionName"
menubarPath="additions"
style="push"
tooltip="%FPRenderingPreferenceActionName"/>
</viewContribution>
</extension>
<extension point="org.eclipse.core.runtime.preferences">
<!-- preferences initialization for Floating Point Renderer persistant storage -->
<initializer class="org.eclipse.cdt.debug.ui.memory.floatingpoint.FPPreferenceConstants$Initializer"/>
</extension>
</plugin>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.cdt</groupId>
<artifactId>cdt-parent</artifactId>
<version>8.1.0-SNAPSHOT</version>
<relativePath>../../../../pom/pom-all.xml</relativePath>
</parent>
<artifactId>org.eclipse.cdt.debug.ui.memory.floatingpoint</artifactId>
<version>1.0.0.qualifier</version>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,903 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import java.math.BigInteger;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.MemoryByte;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Caret;
public abstract class FPAbstractPane extends Canvas
{
protected Rendering fRendering;
// Selection state
protected boolean fSelectionStarted = false;
protected boolean fSelectionInProgress = false;
protected BigInteger fSelectionStartAddress = null;
protected int fSelectionStartAddressSubPosition;
// Caret
protected Caret fCaret = null;
// Character may not fall on byte boundary
protected int fSubCellCaretPosition = 0;
protected int fOldSubCellCaretPosition = 0;
protected boolean fCaretEnabled = false;
protected BigInteger fCaretAddress = null;
// Storage
protected int fRowCount = 0;
protected boolean fPaneVisible = true;
// Mouse listener class
class AbstractPaneMouseListener implements MouseListener
{
@Override
public void mouseUp(MouseEvent me)
{
// Move the caret
positionCaret(me.x, me.y);
fCaret.setVisible(true);
if (fSelectionInProgress && me.button == 1)
endSelection(me.x, me.y);
fSelectionInProgress = fSelectionStarted = false;
}
// Mouse down click
@Override
public void mouseDown(MouseEvent me)
{
// Any click, whether inside this cell or elsewhere, terminates the edit and acts the same as a carriage return would.
handleCarriageReturn();
// Switch focus and check for selection
FPAbstractPane.this.forceFocus();
positionCaret(me.x, me.y);
fCaret.setVisible(false);
if (me.button == 1)
{
// If shift is down and we have an existing start address, append selection
if ((me.stateMask & SWT.SHIFT) != 0 && fRendering.getSelection().getStart() != null)
{
// If the pane doesn't have a selection start (the selection was created in a different
// pane) then initialize the pane's selection start to the rendering's selection start.
if (FPAbstractPane.this.fSelectionStartAddress == null)
FPAbstractPane.this.fSelectionStartAddress = fRendering.getSelection().getStart();
FPAbstractPane.this.fSelectionStarted = true;
FPAbstractPane.this.appendSelection(me.x, me.y);
}
else
{
// Start a new selection
FPAbstractPane.this.startSelection(me.x, me.y);
}
}
}
// Double click
@Override
public void mouseDoubleClick(MouseEvent me)
{
handleMouseDoubleClick(me);
}
}
// Mouse move listener class
class AbstractPaneMouseMoveListener implements MouseMoveListener
{
@Override
public void mouseMove(MouseEvent me)
{
if (fSelectionStarted)
{
fSelectionInProgress = true;
appendSelection(me.x, me.y);
}
}
}
// Focus listener class
class AbstractPaneFocusListener implements FocusListener
{
@Override
public void focusLost(FocusEvent fe)
{
IPreferenceStore store = FPRenderingPlugin.getDefault().getPreferenceStore();
if (FPRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE_ON_ENTER_ONLY.equals(store.getString(FPRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE)))
fRendering.getViewportCache().clearEditBuffer();
else
fRendering.getViewportCache().writeEditBuffer();
// clear the pane local selection start
FPAbstractPane.this.fSelectionStartAddress = null;
}
@Override
public void focusGained(FocusEvent fe)
{
// Set the floating point edit mode indicator if the user clicked in the Data Pane; otherwise clear it
if (FPAbstractPane.this instanceof FPDataPane)
fRendering.displayEditModeIndicator(true);
else
fRendering.displayEditModeIndicator(false);
}
}
// Key listener class
class AbstractPaneKeyListener implements KeyListener
{
@Override
public void keyPressed(KeyEvent ke)
{
fOldSubCellCaretPosition = fSubCellCaretPosition;
// Shift
if ((ke.stateMask & SWT.SHIFT) != 0)
{
switch (ke.keyCode)
{
case SWT.ARROW_RIGHT:
case SWT.ARROW_LEFT:
case SWT.ARROW_UP:
case SWT.ARROW_DOWN:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
{
if (fRendering.getSelection().getStart() == null)
fRendering.getSelection().setStart(fCaretAddress.add(BigInteger.valueOf(fRendering.getAddressesPerColumn())), fCaretAddress);
break;
}
}
}
// Arrow, Page, Insert, Escape and standard characters
if (ke.keyCode == SWT.ARROW_RIGHT)
{
handleRightArrowKey();
}
else if (ke.keyCode == SWT.ARROW_LEFT || ke.keyCode == SWT.BS)
{
handleLeftArrowKey();
}
else if (ke.keyCode == SWT.ARROW_DOWN)
{
handleDownArrowKey();
}
else if (ke.keyCode == SWT.ARROW_UP)
{
handleUpArrowKey();
}
else if (ke.keyCode == SWT.PAGE_DOWN)
{
handlePageDownKey();
}
else if (ke.keyCode == SWT.PAGE_UP)
{
handlePageUpKey();
}
else if (ke.keyCode == SWT.INSERT)
{
handleInsertKey();
}
else if (ke.keyCode == SWT.ESC)
{
fRendering.getViewportCache().clearEditBuffer();
handleCTRLZ();
}
else if (ke.character == '\r')
{
fRendering.getViewportCache().writeEditBuffer();
handleCarriageReturn();
}
else if (FPutilities.validEditCharacter(ke.character))
{
// Check for selection
if (fRendering.getSelection().hasSelection())
{
setCaretAddress(fRendering.getSelection().getLow());
fSubCellCaretPosition = 0;
}
// Add the chatacter to the cell
editCell(fCaretAddress, fSubCellCaretPosition, ke.character);
}
// Control
if ((ke.stateMask & SWT.CTRL) != 0)
{
// CTRL/Z
if (ke.keyCode == 'z' || ke.keyCode == 'Z')
handleCTRLZ();
}
// Alt
if ((ke.stateMask & SWT.ALT) != 0)
{
// Future use
}
// Shift
if ((ke.stateMask & SWT.SHIFT) != 0)
{
switch (ke.keyCode)
{
case SWT.ARROW_RIGHT:
case SWT.ARROW_LEFT:
case SWT.ARROW_UP:
case SWT.ARROW_DOWN:
case SWT.PAGE_DOWN:
case SWT.PAGE_UP:
fRendering.getSelection().setEnd(fCaretAddress.add(BigInteger.valueOf(fRendering.getAddressesPerColumn())), fCaretAddress);
break;
}
}
else if (ke.keyCode != SWT.SHIFT)
{
// If it's a SHIFT key, keep the selection since we may add to it
fRendering.getSelection().clear();
}
}
@Override
public void keyReleased(KeyEvent ke)
{
// do nothing
}
}
class AbstractPanePaintListener implements PaintListener
{
@Override
public void paintControl(PaintEvent pe)
{
FPAbstractPane.this.paint(pe);
}
}
public FPAbstractPane(Rendering rendering)
{
super(rendering, SWT.DOUBLE_BUFFERED);
fRendering = rendering;
try
{
fCaretAddress = rendering.getBigBaseAddress();
}
catch (Exception e)
{
// do nothing
}
// pref
this.setFont(fRendering.getFont());
GC gc = new GC(this);
gc.setFont(this.getFont());
fCaret = new Caret(this, SWT.NONE);
fCaret.setSize(1, gc.stringExtent("|").y); //$NON-NLS-1$
gc.dispose();
this.addPaintListener(createPaintListener());
this.addMouseListener(createMouseListener());
this.addMouseMoveListener(createMouseMoveListener());
this.addKeyListener(createKeyListener());
this.addFocusListener(createFocusListener());
}
// Listener methods
protected MouseListener createMouseListener()
{
return new AbstractPaneMouseListener();
}
protected MouseMoveListener createMouseMoveListener()
{
return new AbstractPaneMouseMoveListener();
}
protected FocusListener createFocusListener()
{
return new AbstractPaneFocusListener();
}
protected KeyListener createKeyListener()
{
return new AbstractPaneKeyListener();
}
protected PaintListener createPaintListener()
{
return new AbstractPanePaintListener();
}
// Right arrow
protected void handleRightArrowKey()
{
fSubCellCaretPosition++;
if (fSubCellCaretPosition >= getCellCharacterCount())
{
// We've moved beyond the end of the cell: End the edit to the previous cell.
handleCarriageReturn();
// Move to the next cell; ensure that caret is within the addressable range
fSubCellCaretPosition = 0;
BigInteger newCaretAddress = fCaretAddress.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength()));
if (newCaretAddress.compareTo(fRendering.getMemoryBlockEndAddress()) > 0)
fSubCellCaretPosition = getCellCharacterCount();
else
setCaretAddress(newCaretAddress);
}
updateTheCaret();
ensureCaretWithinViewport();
}
// Left arrow
protected void handleLeftArrowKey()
{
fSubCellCaretPosition--;
if (fSubCellCaretPosition < 0)
{
// We've moved beyond the beginning of the cell: This action ends the edit to the previous cell.
handleCarriageReturn();
// Move to the previous cell; ensure that caret is within the addressable range
fSubCellCaretPosition = getCellCharacterCount() - 1;
BigInteger newCaretAddress = fCaretAddress.subtract(BigInteger.valueOf(fRendering.getFPDataType().getByteLength()));
if (newCaretAddress.compareTo(fRendering.getMemoryBlockStartAddress()) < 0)
fSubCellCaretPosition = 0;
else
setCaretAddress(newCaretAddress);
}
updateTheCaret();
ensureCaretWithinViewport();
}
// Down arrow
protected void handleDownArrowKey()
{
// We've moved beyond the beginning of the cell: This action ends the edit to the previous cell.
handleCarriageReturn();
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength() * fRendering.getColumnCount()));
setCaretAddress(newCaretAddress);
updateTheCaret();
ensureCaretWithinViewport();
}
// Up arrow
protected void handleUpArrowKey()
{
// We've moved beyond the beginning of the cell: This action ends the edit to the previous cell.
handleCarriageReturn();
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.subtract(BigInteger.valueOf(fRendering.getFPDataType().getByteLength() * fRendering.getColumnCount()));
setCaretAddress(newCaretAddress);
updateTheCaret();
ensureCaretWithinViewport();
}
// Page down
protected void handlePageDownKey()
{
// We've moved beyond the beginning of the cell: This action ends the edit to the previous cell.
handleCarriageReturn();
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.add(BigInteger.valueOf(fRendering.getAddressableCellsPerRow() * (fRendering.getRowCount() - 1)));
setCaretAddress(newCaretAddress);
updateTheCaret();
ensureCaretWithinViewport();
}
// Page up
protected void handlePageUpKey()
{
// We've moved beyond the beginning of the cell: This action ends the edit to the previous cell.
handleCarriageReturn();
// Ensure that caret is within the addressable range
BigInteger newCaretAddress = fCaretAddress.subtract(BigInteger.valueOf(fRendering.getAddressableCellsPerRow() * (fRendering.getRowCount() - 1)));
setCaretAddress(newCaretAddress);
updateTheCaret();
ensureCaretWithinViewport();
}
// Insert key
protected void handleInsertKey()
{
// If focus is in the Data Pane, toggle Insert/Overwrite mode and make sure the cell edit
// status line indicator is displayed. Otherwise, make clear the status line indicator.
if (FPAbstractPane.this instanceof FPDataPane)
{
if (!fRendering.isEditingCell()) fRendering.setInsertMode(!fRendering.insertMode());
fRendering.displayEditModeIndicator(true);
}
else
fRendering.displayEditModeIndicator(false);
}
// Double-click
protected void handleMouseDoubleClick(MouseEvent me)
{
try
{
BigInteger address = getViewportAddress(me.x / getCellWidth(), me.y / getCellHeight());
fRendering.getSelection().clear();
fRendering.getSelection().setStart(address.add(BigInteger.valueOf(fRendering.getAddressesPerColumn())), address);
fRendering.getSelection().setEnd(address.add(BigInteger.valueOf(fRendering.getAddressesPerColumn())), address);
}
catch (DebugException de)
{
// do nothing
}
}
// Carriage return
protected void handleCarriageReturn()
{
// If we're not editing a cell or there is no string buffer to use, nothing to do: Exit edit mode and return.
if (!fRendering.isEditingCell() || fRendering.getEditBuffer() == null)
{
fRendering.endCellEditing();
return;
}
// Remove all whitespace from the string buffer.
fRendering.setEditBuffer(new StringBuffer(fRendering.getEditBuffer().toString().trim().replaceAll(" ", ""))); //$NON-NLS-1$ //$NON-NLS-2$
// Check the string to make sure it's in valid, acceptable form.
if (FPutilities.isValidFormat(fRendering.getEditBuffer().toString()))
{
// Valid string: Convert it to a byte array and write the buffer back to memory;
// a subsequent re-draw/paint converts it to normalized scientific notation.
fRendering.convertAndUpdateCell(fRendering.getCellEditAddress(), fRendering.getEditBuffer().toString());
}
else
{
// Invalid string: Create the error text and restore the previous value
String errorText = NLS.bind(FPRenderingMessages.getString("FPRendering.ERROR_FPENTRY_POPUP_TEXT"), fRendering.getEditBuffer().toString()); //$NON-NLS-1$
try
{
fRendering.setEditBuffer(new StringBuffer(fRendering.fDataPane.bytesToSciNotation(fRendering.getBytes(fCaretAddress, fRendering.getFPDataType().getByteLength()))));
}
catch (DebugException e)
{
e.printStackTrace();
}
// Put together the pop-up window components and show the user the error
String statusString = FPRenderingMessages.getString("FPRendering.ERROR_FPENTRY_STATUS"); //$NON-NLS-1$
Status status = new Status(IStatus.ERROR, FPRenderingPlugin.getUniqueIdentifier(), statusString);
FPutilities.popupMessage(FPRenderingMessages.getString("FPRendering.ERROR_FPENTRY_POPUP_TITLE"), errorText, status); //$NON-NLS-1$
}
// Exit cell-edit mode
fRendering.endCellEditing();
}
// CTRL/Z handling
protected void handleCTRLZ()
{
// CTRL/Z: Replace the cell contents with the original value and exit "number edit mode"
try
{
fRendering.setEditBuffer(new StringBuffer(fRendering.fDataPane.bytesToSciNotation(fRendering.getBytes(fCaretAddress, fRendering.getFPDataType().getByteLength()))));
}
catch (DebugException e)
{
e.printStackTrace();
}
fRendering.endCellEditing();
}
// Other getter/setters
protected boolean isPaneVisible()
{
return fPaneVisible;
}
protected void setPaneVisible(boolean visible)
{
fPaneVisible = visible;
this.setVisible(visible);
}
protected int getNumberOfBytesRepresentedByColumn()
{
return fRendering.getCharsPerColumn();
}
protected void editCell(BigInteger cellAddress, int subCellPosition, char character)
{
// Do nothing; overridden in subclass FPDataPane
}
// Set the caret address
protected void setCaretAddress(BigInteger caretAddress)
{
// Ensure that caret is within the addressable range
if ((caretAddress.compareTo(fRendering.getMemoryBlockStartAddress()) >= 0) && (caretAddress.compareTo(fRendering.getMemoryBlockEndAddress()) <= 0))
{
fCaretAddress = caretAddress;
}
else if (caretAddress.compareTo(fRendering.getMemoryBlockStartAddress()) < 0)
{
// Calculate offset from the beginning of the row
int cellOffset = fCaretAddress.subtract(fRendering.getViewportStartAddress()).intValue();
int row = cellOffset / (fRendering.getBytesPerRow() / fRendering.getBytesPerCharacter());
cellOffset -= row * fRendering.getBytesPerRow() / fRendering.getBytesPerCharacter();
fCaretAddress = fRendering.getMemoryBlockStartAddress().add(BigInteger.valueOf(cellOffset / fRendering.getAddressableSize()));
}
else if (caretAddress.compareTo(fRendering.getMemoryBlockEndAddress()) > 0)
{
// Calculate offset from the end of the row
int cellOffset = fCaretAddress.subtract(fRendering.getViewportEndAddress()).intValue() + 1;
int row = cellOffset / (fRendering.getBytesPerRow() / fRendering.getBytesPerCharacter());
cellOffset -= row * fRendering.getBytesPerRow() / fRendering.getBytesPerCharacter();
fCaretAddress = fRendering.getMemoryBlockEndAddress().add(BigInteger.valueOf(cellOffset / fRendering.getAddressableSize()));
}
fRendering.setCaretAddress(fCaretAddress);
}
protected boolean isOdd(int value)
{
return (value / 2) * 2 == value;
}
protected void updateTheCaret()
{
try
{
if (fCaretAddress != null)
{
Point cellPosition = getCellLocation(fCaretAddress);
if (cellPosition != null)
fCaret.setLocation(cellPosition.x + fSubCellCaretPosition * getCellCharacterWidth(), cellPosition.y);
}
}
catch (Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_POSITION_CURSOR"), e); //$NON-NLS-1$
}
}
// This method scrolls the viewport to insure that the caret is within the viewable area
protected void ensureCaretWithinViewport() // TODO getAddressableSize() > 1 ?
{
// If the caret is before the viewport start if so, scroll viewport up by several rows
BigInteger rowCount = BigInteger.valueOf(getRowCount());
BigInteger rowMemBytes = BigInteger.valueOf(fRendering.getFPDataType().getByteLength() * fRendering.getColumnCount());
BigInteger viewableBytes = rowCount.multiply(rowMemBytes);
BigInteger viewableEnd = fRendering.getViewportStartAddress().add(viewableBytes);
if (fCaretAddress.compareTo(fRendering.getViewportStartAddress()) < 0)
{
fRendering.setViewportStartAddress(fRendering.getViewportStartAddress().subtract(rowMemBytes));
fRendering.ensureViewportAddressDisplayable();
fRendering.gotoAddress(fRendering.getViewportStartAddress());
}
// If the caret is after the viewport end if so, scroll viewport down by appropriate rows
else if (fCaretAddress.compareTo(viewableEnd) >= 0)
{
fRendering.setViewportStartAddress(fRendering.getViewportStartAddress().add(rowMemBytes));
fRendering.ensureViewportAddressDisplayable();
fRendering.gotoAddress(fRendering.getViewportStartAddress());
}
fRendering.setCaretAddress(fCaretAddress);
}
protected void advanceCursor()
{
handleRightArrowKey();
}
protected void positionCaret(int x, int y)
{
// do nothing
}
protected int getRowCount()
{
return fRowCount;
}
protected void setRowCount()
{
fRowCount = getBounds().height / getCellHeight();
}
protected void settingsChanged()
{
fSubCellCaretPosition = 0;
}
// Start selection
protected void startSelection(int x, int y)
{
try
{
BigInteger address = getViewportAddress(x / getCellWidth(), y / getCellHeight());
if (address != null)
{
this.fSelectionStartAddress = address;
Point cellPosition = getCellLocation(address);
if (cellPosition != null)
{
int offset = x - cellPosition.x;
fSelectionStartAddressSubPosition = offset / getCellCharacterWidth();
}
fRendering.getSelection().clear();
fRendering.getSelection().setStart(address.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength())), address);
fSelectionStarted = true;
new CopyAction(fRendering, DND.SELECTION_CLIPBOARD).run();
}
}
catch (DebugException e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_START_SELECTION"), e); //$NON-NLS-1$
}
}
// End selection
protected void endSelection(int x, int y)
{
appendSelection(x, y);
fSelectionInProgress = false;
}
protected void appendSelection(int x, int y)
{
try
{
if (this.fSelectionStartAddress == null) return;
BigInteger address = getViewportAddress(x / getCellWidth(), y / getCellHeight());
if (address.compareTo(this.fSelectionStartAddress) == 0)
{
// Sub-cell selection
Point cellPosition = getCellLocation(address);
int offset = x - cellPosition.x;
int subCellCharacterPosition = offset / getCellCharacterWidth();
if (Math.abs(subCellCharacterPosition - this.fSelectionStartAddressSubPosition) > this.getCellCharacterCount() / 4)
{
fRendering.getSelection().setEnd(address.add(BigInteger.valueOf((fRendering.getFPDataType().getByteLength()))), address);
}
else
{
fRendering.getSelection().setEnd(null, null);
}
}
else
{
fRendering.getSelection().setEnd(address.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength())), address);
}
if (fRendering.getSelection().getEnd() != null)
{
this.fCaretAddress = fRendering.getSelection().getEnd();
this.fSubCellCaretPosition = 0;
}
updateTheCaret();
new CopyAction(fRendering, DND.SELECTION_CLIPBOARD).run();
}
catch (Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_APPEND_SELECTION"), e); //$NON-NLS-1$
}
}
protected void paint(PaintEvent pe)
{
fRowCount = getBounds().height / getCellHeight();
if (fRendering.isDirty())
{
fRendering.setDirty(false);
fRendering.refresh();
}
}
abstract protected BigInteger getViewportAddress(int col, int row) throws DebugException;
protected Point getCellLocation(BigInteger address)
{
return null;
}
protected String getCellText(MemoryByte bytes[])
{
return null;
}
abstract protected int getCellWidth();
abstract protected int getCellCharacterCount();
@Override
public void setFont(Font font)
{
super.setFont(font);
fCharacterWidth = -1;
fCellHeight = -1;
fTextHeight = -1;
}
private int fCellHeight = -1; // called often, cache
protected int getCellHeight()
{
if (fCellHeight == -1)
{
fCellHeight = getCellTextHeight() + (fRendering.getCellPadding() * 2);
}
return fCellHeight;
}
private int fCharacterWidth = -1; // called often, cache
protected int getCellCharacterWidth()
{
if (fCharacterWidth == -1)
{
GC gc = new GC(this);
gc.setFont(fRendering.getFont());
fCharacterWidth = gc.getAdvanceWidth('F');
gc.dispose();
}
return fCharacterWidth;
}
private int fTextHeight = -1; // called often, cache
protected int getCellTextHeight()
{
if (fTextHeight == -1)
{
GC gc = new GC(this);
gc.setFont(fRendering.getFont());
FontMetrics fontMetrics = gc.getFontMetrics();
fTextHeight = fontMetrics.getHeight();
gc.dispose();
}
return fTextHeight;
}
}

View file

@ -0,0 +1,237 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
public class FPAddressPane extends FPAbstractPane
{
final int bytesPerColumn = fRendering.getFPDataType().getByteLength();
public FPAddressPane(Rendering parent)
{
super(parent);
}
@Override
protected BigInteger getViewportAddress(int col, int row) throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
// address = address.add(BigInteger.valueOf((row * fRendering.getColumnCount() + col) * fRendering.getAddressesPerColumn()));
address = address.add(BigInteger.valueOf((row * fRendering.getColumnCount() + col) * fRendering.getFPDataType().getByteLength()));
return address;
}
@Override
protected void appendSelection(int x, int y)
{
try
{
if (this.fSelectionStartAddress == null) return;
BigInteger address = getViewportAddress(x / getCellWidth(), y / getCellHeight());
if (address.compareTo(this.fSelectionStartAddress) == 0)
{
// The address hasn't changed
fRendering.getSelection().setEnd(null, null);
}
else
{
// The address has changed
fRendering.getSelection().setEnd(address.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength() * fRendering.getColumnCount())), address);
}
}
catch(Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_APPEND_SELECTION"), e); //$NON-NLS-1$
}
}
@Override
public Point computeSize(int wHint, int hHint)
{
return new Point(getCellWidth() + fRendering.getRenderSpacing(), 100);
}
@Override
protected int getCellCharacterCount()
{
// Two characters per byte of HEX address
return fRendering.getAddressBytes() * 2 + 2; // 0x
}
@Override
protected int getCellWidth()
{
GC gc = new GC(this);
StringBuffer buf = new StringBuffer();
for(int index = 0; index < getCellCharacterCount(); index++)
buf.append("0"); //$NON-NLS-1$
int width = gc.textExtent(buf.toString()).x;
gc.dispose();
return width;
}
private int getColumnCount()
{
return 0;
}
private BigInteger getCellAddressAt(int x, int y) throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
int col = x / getCellWidth();
int row = y / getCellHeight();
if(col > getColumnCount())
return null;
address = address.add(BigInteger.valueOf(row * fRendering.getColumnCount() * fRendering.getAddressesPerColumn() / fRendering.getBytesPerCharacter()));
address = address.add(BigInteger.valueOf(col * fRendering.getAddressesPerColumn()));
return address;
}
@Override
protected Point getCellLocation(BigInteger cellAddress)
{
try
{
BigInteger address = fRendering.getViewportStartAddress();
int cellOffset = cellAddress.subtract(address).intValue();
cellOffset *= fRendering.getAddressableSize();
if(fRendering.getColumnCount() == 0) // avoid divide by zero
return new Point(0,0);
int row = cellOffset / (fRendering.getColumnCount() * fRendering.getCharsPerColumn() / fRendering.getBytesPerCharacter());
cellOffset -= row * fRendering.getColumnCount() * fRendering.getCharsPerColumn() / fRendering.getBytesPerCharacter();
int col = cellOffset / fRendering.getCharsPerColumn() / fRendering.getBytesPerCharacter();
int x = col * getCellWidth() + fRendering.getCellPadding();
int y = row * getCellHeight() + fRendering.getCellPadding();
return new Point(x, y);
}
catch(Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_DETERMINE_CELL_LOCATION"), e); //$NON-NLS-1$
return null;
}
}
@Override
protected int getNumberOfBytesRepresentedByColumn()
{
return fRendering.getBytesPerRow();
}
@Override
protected void positionCaret(int x, int y)
{
try
{
BigInteger cellAddress = getCellAddressAt(x, y);
if(cellAddress != null)
{
Point cellPosition = getCellLocation(cellAddress);
int offset = x - cellPosition.x;
int x2 = offset / getCellCharacterWidth();
if(x2 >= this.getCellCharacterCount())
{
cellAddress = cellAddress.add(BigInteger.valueOf(this.getNumberOfBytesRepresentedByColumn()));
x2 = 0;
cellPosition = getCellLocation(cellAddress);
}
fCaret.setLocation(cellPosition.x + x2 * getCellCharacterWidth(), cellPosition.y);
this.fCaretAddress = cellAddress;
this.fSubCellCaretPosition = x2;
setCaretAddress(fCaretAddress);
}
}
catch(Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_POSITION_CURSOR"), e); //$NON-NLS-1$
}
}
@Override
protected void paint(PaintEvent pe)
{
super.paint(pe);
GC gc = pe.gc;
FontMetrics fontMetrics = gc.getFontMetrics();
int textHeight = fontMetrics.getHeight();
int cellHeight = textHeight + (fRendering.getCellPadding() * 2);
final int memBytesPerCol = fRendering.getFPDataType().getByteLength();
try
{
BigInteger start = fRendering.getViewportStartAddress();
for(int index = 0; index < this.getBounds().height / cellHeight; index++)
{
BigInteger memAddress = start.add(BigInteger.valueOf(index * fRendering.getColumnCount() * memBytesPerCol));
gc.setForeground(fRendering.getFPRendering().getColorText());
// Highlight the selected addresses if necessary; otherwise use the standard foreground/background colors
if (fRendering.getSelection().isSelected(memAddress))
{
gc.setBackground(fRendering.getFPRendering().getColorSelection());
gc.fillRectangle(fRendering.getCellPadding() * 2, cellHeight * index, getCellWidth(), cellHeight);
gc.setForeground(fRendering.getFPRendering().getColorBackground());
}
else
{
gc.setBackground(fRendering.getFPRendering().getColorBackground());
gc.fillRectangle(fRendering.getCellPadding() * 2, cellHeight * index, getCellWidth(), cellHeight);
// Allow subclass to override this method to do its own coloring
applyCustomColor(gc);
}
gc.drawText(fRendering.getAddressString(memAddress),
fRendering.getCellPadding() * 2, cellHeight * index + fRendering.getCellPadding());
}
}
catch(Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_PAINT"), e); //$NON-NLS-1$
}
}
// Allow subclass to override this method to do its own coloring
protected void applyCustomColor(GC gc)
{
gc.setForeground(fRendering.getFPRendering().getColorText());
}
}

View file

@ -0,0 +1,399 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
public class FPDataPane extends FPAbstractPane
{
public FPDataPane(Rendering parent)
{
super(parent);
}
// Returns the representation of the given memory bytes as a scientific notation string
protected String bytesToSciNotation(FPMemoryByte[] bytes)
{
return fRendering.sciNotationString(bytes, fRendering.getFPDataType(), fRendering.isDisplayLittleEndian());
}
// Cell editing: Accumulate text entry characters, replacing or inserting them at the current cursor position
@Override
protected void editCell(BigInteger cellAddress, int subCellPosition, char character)
{
try
{
// Switch to cell edit mode if not we're not currently in the middle of an edit
if (!fRendering.isEditingCell())
{
// Calculate the memory address from the cell address
BigInteger vpStart = fRendering.getViewportStartAddress();
BigInteger colChars = BigInteger.valueOf(fRendering.getCharsPerColumn());
BigInteger dtBytes = BigInteger.valueOf(fRendering.getFPDataType().getByteLength());
BigInteger memoryAddress = vpStart.add(((cellAddress.subtract(vpStart)).divide(colChars)).multiply(dtBytes));
if (!fRendering.insertMode())
{
// Overstrike/overwrite mode: Enter cell-edit mode; start with the current cell contents.
fRendering.startCellEditing(cellAddress, memoryAddress, bytesToSciNotation(fRendering.getBytes(cellAddress, fRendering.getFPDataType().getByteLength())));
}
else
{
// Insert/Replace mode: Clear the current cell contents; start
// with a blank string. Move the caret to the start of the cell.
fRendering.startCellEditing(cellAddress, memoryAddress, FPutilities.fillString(fRendering.getCharsPerColumn(), ' '));
subCellPosition = 0;
Point cellCoordinates = getCellLocation(cellAddress);
positionCaret(cellCoordinates.x, cellCoordinates.y);
fCaret.setVisible(true);
}
}
// Validate the current string: Only one decimal point and exponent character ('e' or 'E') is allowed. Number
// signs may be present up to two times - once for the number and once for the exponent, and may occur at the
// very beginning of a number or immediately after the exponent character. If an entry violates a rule, do not
// echo the character (implicitly, through replacement and re-paint) and do not advance the cursor.
String cellString = fRendering.getEditBuffer().toString().toLowerCase();
// Check to see if a second decimal point or exponent was entered
if ((character == '.' && FPutilities.countMatches(cellString, ".") > 0 && cellString.indexOf('.') != subCellPosition) || //$NON-NLS-1$
(character == 'e' && FPutilities.countMatches(cellString, "e") > 0 && cellString.indexOf('e') != subCellPosition)) //$NON-NLS-1$
return;
// Check to see if more than two number signs have been entered
if ((character == '+' && FPutilities.countMatches(cellString, "+") > 1) || //$NON-NLS-1$
(character == '-' && FPutilities.countMatches(cellString, "-") > 1)) //$NON-NLS-1$
return;
// We've passed the previous checks: Make the character substitution, if possible.
// Advance the cursor as long as we're inside the column. Re-paint the view.
if (subCellPosition < fRendering.getEditBuffer().length())
fRendering.getEditBuffer().setCharAt(subCellPosition, character);
if (subCellPosition < fRendering.getCharsPerColumn())
advanceCursor();
redraw();
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Returns cell width, in pixels
@Override
protected int getCellWidth()
{
return getCellCharacterCount() * getCellCharacterWidth() + (fRendering.getCellPadding() * 2);
}
@Override
protected int getCellCharacterCount()
{
return fRendering.getCharsPerColumn();
}
@Override
public Point computeSize(int wHint, int hHint)
{
return new Point(fRendering.getColumnCount() * getCellWidth() + fRendering.getRenderSpacing(), 100);
}
private BigInteger getCellAddressAt(int x, int y) throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
int col = x / getCellWidth();
int row = y / getCellHeight();
if (col >= fRendering.getColumnCount())
return null;
address = address.add(BigInteger.valueOf(row * fRendering.getColumnCount() * fRendering.getFPDataType().getByteLength()));
address = address.add(BigInteger.valueOf(col * fRendering.getFPDataType().getByteLength()));
return address;
}
// Return a Point representing the cell address
@Override
protected Point getCellLocation(BigInteger cellAddress)
{
try
{
BigInteger address = fRendering.getViewportStartAddress();
int cellOffset = cellAddress.subtract(address).intValue();
cellOffset *= fRendering.getAddressableSize();
int row = cellOffset / (fRendering.getColumnCount() * fRendering.getFPDataType().getByteLength());
cellOffset -= row * fRendering.getColumnCount() * fRendering.getFPDataType().getByteLength();
int col = cellOffset / fRendering.getFPDataType().getByteLength();
int x = col * getCellWidth() + fRendering.getCellPadding();
int y = row * getCellHeight() + fRendering.getCellPadding();
return new Point(x, y);
}
catch (Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_DETERMINE_CELL_LOCATION"), e); //$NON-NLS-1$
return null;
}
}
@Override
protected void positionCaret(int x, int y)
{
try
{
BigInteger cellAddress = getCellAddressAt(x, y);
if (cellAddress != null)
{
Point cellPosition = getCellLocation(cellAddress);
int offset = x - cellPosition.x;
int subCellCharacterPosition = offset / getCellCharacterWidth();
if (subCellCharacterPosition == this.getCellCharacterCount())
{
cellAddress = cellAddress.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength()));
subCellCharacterPosition = 0;
cellPosition = getCellLocation(cellAddress);
}
fCaret.setLocation(cellPosition.x + subCellCharacterPosition * getCellCharacterWidth(), cellPosition.y);
this.fCaretAddress = cellAddress;
this.fSubCellCaretPosition = subCellCharacterPosition;
setCaretAddress(fCaretAddress);
}
}
catch (Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_POSITION_CURSOR"), e); //$NON-NLS-1$
}
}
@Override
protected BigInteger getViewportAddress(int col, int row) throws DebugException
{
BigInteger address = fRendering.getViewportStartAddress();
address = address.add(BigInteger.valueOf((row * fRendering.getColumnCount() + col) * fRendering.getFPDataType().getByteLength()));
return address;
}
@Override
protected void paint(PaintEvent pe)
{
super.paint(pe);
// Allow subclasses to override this method to do their own painting
doPaintData(pe);
}
// Display text in the cell
protected void doPaintData(PaintEvent pe)
{
GC gc = pe.gc;
gc.setFont(fRendering.getFont());
int cellHeight = getCellHeight();
int cellWidth = getCellWidth();
int boundsHeight = this.getBounds().height;
int columns = fRendering.getColumnCount();
int cellX = 0;
int cellY = 0;
String displayString = FPutilities.fillString(fRendering.getCharsPerColumn(), '.');
try
{
BigInteger vpStart = fRendering.getViewportStartAddress();
BigInteger cellStartAddr = vpStart;
BigInteger memoryAddr = vpStart;
BigInteger cellEndAddr;
for(int row = 0; row < boundsHeight / cellHeight; row++)
{
for (int column = 0; column < columns; column++)
{
// Set alternating colors for every other column and display the text
// FIXME: There is duplicate code in applyCustomColor() in this class
if (isOdd(column))
gc.setForeground(fRendering.getFPRendering().getColorText());
else
gc.setForeground(fRendering.getFPRendering().getColorTextAlternate());
// Calculate the cell starting address and X/Y coordinates
cellStartAddr = vpStart.add(BigInteger.valueOf((row * fRendering.getColumnCount() + column) * fRendering.getFPDataType().getByteLength()));
cellEndAddr = cellStartAddr.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength()).subtract(BigInteger.ONE));
cellX = (cellWidth * column) + fRendering.getCellPadding();
cellY = (cellHeight * row ) + fRendering.getCellPadding();
// Cell editing: If we're in edit mode, change the cell color and then set the
// edit buffer as the string to display. Otherwise, just use the memory contents.
if (fRendering.isEditingCell() && cellStartAddr.equals(fRendering.getCellEditAddress()))
{
gc.setForeground(fRendering.getFPRendering().getColorEdit());
FPMemoryByte[] memoryBytes = fRendering.getBytes(cellStartAddr, fRendering.getFPDataType().getByteLength());
for (FPMemoryByte memoryByte : memoryBytes)
memoryByte.setEdited(true);
applyCustomColor(gc, memoryBytes, column);
displayString = fRendering.getEditBuffer().toString();
}
else
displayString = bytesToSciNotation(fRendering.getBytes(memoryAddr, fRendering.getFPDataType().getByteLength()));
// Cell selection
if (fRendering.getSelection().isSelected(cellStartAddr))
{
gc.setBackground(fRendering.getFPRendering().getColorSelection());
gc.fillRectangle(cellX, row * cellHeight, cellWidth, cellHeight);
gc.setForeground(fRendering.getFPRendering().getColorBackground());
}
else
{
gc.setBackground(fRendering.getFPRendering().getColorBackground());
gc.fillRectangle(cellX, row * cellHeight, cellWidth, cellHeight);
// Allow subclasses to override this method to do their own coloring
applyCustomColor(gc, fRendering.getBytes(cellStartAddr, fRendering.getFPDataType().getByteLength()), column);
}
gc.drawText(displayString, cellX, cellY);
// Move the caret if appropriate
if (fCaretEnabled)
{
if(cellStartAddr.compareTo(fCaretAddress) <= 0 && cellEndAddr.compareTo(fCaretAddress) >= 0)
{
int x = cellWidth * column + fRendering.getCellPadding() + fSubCellCaretPosition * this.getCellCharacterWidth();
int y = cellHeight * row + fRendering.getCellPadding();
fCaret.setLocation(x, y);
}
}
// For debugging
if (fRendering.isDebug())
gc.drawRectangle(cellX, cellY, cellWidth, cellHeight);
// Increment the memory address by the length of the data type
memoryAddr = memoryAddr.add(BigInteger.valueOf(fRendering.getFPDataType().getByteLength()));
}
}
}
catch(Exception e)
{
fRendering.logError(FPRenderingMessages.getString("FPRendering.FAILURE_PAINT"), e); //$NON-NLS-1$
e.printStackTrace();
}
}
// Allow subclasses to override this method to do their own coloring
protected void applyCustomColor(GC gc, FPMemoryByte bytes[], int col)
{
// Check to see if any byte has been changed and whether we're actually in edit mode
boolean anyByteEditing = false;
for (int n = 0; n < bytes.length && !anyByteEditing; n++)
if (bytes[n].isEdited()) anyByteEditing = true;
anyByteEditing = anyByteEditing && fRendering.isEditingCell();
// Even/odd column coloring
if (isOdd(col))
gc.setForeground(fRendering.getFPRendering().getColorText());
else
gc.setForeground(fRendering.getFPRendering().getColorTextAlternate());
// Background
gc.setBackground(fRendering.getFPRendering().getColorBackground());
if (anyByteEditing)
{
gc.setForeground(fRendering.getFPRendering().getColorEdit());
}
else
{
boolean isColored = false;
for (int index = 0; index < fRendering.getHistoryDepth() && !isColored; index++)
{
// TODO consider adding finer granularity?
for (int n = 0; n < bytes.length; n++)
{
if (bytes[n].isChanged(index))
{
if (index == 0)
gc.setForeground(fRendering.getFPRendering().getColorsChanged()[index]);
else
gc.setBackground(fRendering.getFPRendering().getColorsChanged()[index]);
isColored = true;
break;
}
}
}
}
}
// Draw a box around the specified cell
public void highCellBox(BigInteger memoryAddress)
{
// if (fRendering.isDebug())
// gc.drawRectangle(cellX, cellY, cellWidth, cellHeight);
}
// Clear the box around the specified cell
public void clearCellBox(BigInteger memoryAddress)
{
}
}

View file

@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.cdt.debug.ui.memory.floatingpoint.FPutilities.Endian;
import org.eclipse.cdt.debug.ui.memory.floatingpoint.FPutilities.FPDataType;
import org.eclipse.cdt.debug.ui.memory.floatingpoint.FPutilities.Justification;
public class FPDisplayCharacteristics
{
private FPDataType dataType;
private Endian endian;
private int displayedPrecision;
private Justification justification;
// Constructors
FPDisplayCharacteristics()
{
// Default values
this.dataType = FPDataType.FLOAT;
this.endian = Endian.LITTLE;
this.displayedPrecision = FPDataType.FLOAT.getDisplayedPrecision();
this.justification = Justification.LEFT;
}
public FPDisplayCharacteristics(FPDataType dataType, Endian endian, Justification justification)
{
this.dataType = dataType;
this.endian = endian;
this.justification = justification;
}
// Getters and Setters
public FPDataType getDataType()
{
return dataType;
}
public void setDataType(FPDataType dataType)
{
this.dataType = dataType;
}
public Endian getEndian()
{
return endian;
}
public void setEndian(Endian endian)
{
this.endian = endian;
}
public int getDisplayedPrecision()
{
return displayedPrecision;
}
public void setDisplayedPrecision(int displayedPrecision)
{
this.displayedPrecision = displayedPrecision;
}
public Justification getJustification()
{
return justification;
}
public void setJustification(Justification justification)
{
this.justification = justification;
}
}

View file

@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
public interface FPIMemoryByte
{
public boolean isEdited();
public void setEdited(boolean edited);
}

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import java.math.BigInteger;
public interface FPIMemorySelection
{
public boolean hasSelection();
public boolean isSelected(BigInteger address);
public BigInteger getStart();
public BigInteger getEnd();
public BigInteger getStartLow();
public void setStart(BigInteger high, BigInteger low);
public void setEnd(BigInteger high, BigInteger low);
public BigInteger getHigh();
public BigInteger getLow();
public void clear();
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import java.math.BigInteger;
import org.eclipse.debug.core.DebugException;
public interface FPIViewportCache {
public void dispose();
public void refresh();
public FPMemoryByte[] getBytes(BigInteger address, int bytesRequested) throws DebugException;
public void archiveDeltas();
public void setEditedValue(BigInteger address, FPMemoryByte[] bytes);
public void clearEditBuffer();
public void writeEditBuffer();
public boolean containsEditedCell(BigInteger address);
// private void queueRequest(BigInteger startAddress, BigInteger endAddress);
}

View file

@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.debug.core.model.MemoryByte;
public class FPMemoryByte extends MemoryByte implements FPIMemoryByte
{
private boolean isEdited = false;
private boolean[] changeHistory = new boolean[0];
public FPMemoryByte()
{
super();
}
public FPMemoryByte(byte byteValue)
{
super(byteValue);
}
public FPMemoryByte(byte byteValue, byte byteFlags)
{
super(byteValue, byteFlags);
}
@Override
public boolean isEdited()
{
return isEdited;
}
@Override
public void setEdited(boolean edited)
{
isEdited = edited;
}
public boolean isChanged(int historyDepth)
{
return changeHistory.length > historyDepth && changeHistory[historyDepth];
}
public void setChanged(int historyDepth, boolean changed)
{
if(historyDepth >= changeHistory.length)
{
boolean newChangeHistory[] = new boolean[historyDepth + 1];
System.arraycopy(changeHistory, 0, newChangeHistory, 0, changeHistory.length);
changeHistory = newChangeHistory;
}
changeHistory[historyDepth] = changed;
if(historyDepth == 0)
this.setChanged(changed);
}
}

View file

@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.cdt.debug.ui.memory.floatingpoint.FPutilities.FPDataType;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
public class FPPreferenceConstants
{
private FPPreferenceConstants()
{
// Prevent subclassing or instantiation
}
/**
* Initialize preference default values.
*
* @param store
*/
public static void initializeDefaults(IPreferenceStore store)
{
// Set default values
store.setDefault(IFPRConstants.ENDIAN_KEY, -1); // -1 = No default set
store.setDefault(IFPRConstants.DATATYPE_KEY, FPDataType.FLOAT.getValue());
store.setDefault(IFPRConstants.FLOAT_DISP_KEY, 8);
store.setDefault(IFPRConstants.DOUBLE_DISP_KEY, 8);
store.setDefault(IFPRConstants.COLUMN_COUNT_KEY, Rendering.COLUMNS_AUTO_SIZE_TO_FIT);
store.setDefault(IFPRConstants.UPDATEMODE_KEY, Rendering.UPDATE_ALWAYS);
}
public static class Initializer extends AbstractPreferenceInitializer
{
@Override
public void initializeDefaultPreferences()
{
IPreferenceStore store = FPRenderingPlugin.getDefault().getPreferenceStore();
initializeDefaults(store);
}
}
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class FPRenderingMessages
{
private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.ui.memory.floatingpoint.messages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
private FPRenderingMessages()
{
}
public static String getString(String key)
{
// TODO Auto-generated method stub
try
{
return RESOURCE_BUNDLE.getString(key);
}
catch(MissingResourceException e)
{
return '!' + key + '!';
}
}
}

View file

@ -0,0 +1,96 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
public class FPRenderingPlugin extends AbstractUIPlugin
{
public static final String PLUGIN_ID = "org.eclipse.cdt.debug.ui.memory.floatingpoint"; //$NON-NLS-1$
private static FPRenderingPlugin plugin;
public FPRenderingPlugin()
{
super();
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance.
*/
public static FPRenderingPlugin getDefault()
{
return plugin;
}
/**
* Returns the unique identifier for this plugin.
*/
public static String getUniqueIdentifier()
{
return PLUGIN_ID;
}
/**
* Returns the workbench's display.
*/
public static Display getStandardDisplay()
{
return PlatformUI.getWorkbench().getDisplay();
}
/**
* Returns the currently active workbench window shell or <code>null</code>
* if none.
*
* @return the currently active workbench window shell or <code>null</code>
*/
public static Shell getShell()
{
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null)
{
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
if (windows.length > 0)
{
return windows[0].getShell();
}
}
else
{
return window.getShell();
}
return null;
}
}

View file

@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.IPreferenceNode;
import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.ActionDelegate;
public class FPRenderingPreferenceAction extends ActionDelegate implements IViewActionDelegate
{
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action)
{
IPreferencePage page = new FPRenderingPreferencePage();
showPreferencePage("org.eclipse.cdt.debug.ui.memory.floatingpoint.FPRenderingPreferencePage", page); //$NON-NLS-1$
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
*/
@Override
public void init(IViewPart view)
{
}
protected void showPreferencePage(String id, IPreferencePage page)
{
final IPreferenceNode targetNode = new PreferenceNode(id, page);
PreferenceManager manager = new PreferenceManager();
manager.addToRoot(targetNode);
final PreferenceDialog dialog = new PreferenceDialog(FPRenderingPlugin.getShell(), manager);
final boolean[] result = new boolean[] { false };
BusyIndicator.showWhile(FPRenderingPlugin.getStandardDisplay(), new Runnable()
{
@Override
public void run()
{
dialog.create();
dialog.setMessage(targetNode.getLabelText());
result[0] = (dialog.open() == Window.OK);
}
});
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
/**
* Constant definitions for plug-in preferences
*/
public class FPRenderingPreferenceConstants
{
public static final String MEM_COLOR_CHANGED = "memoryColorChanged"; //$NON-NLS-1$
public static final String MEM_USE_GLOBAL_BACKGROUND = "memUseGlobalBackground"; //$NON-NLS-1$
public static final String MEM_COLOR_BACKGROUND = "memoryColorBackground"; //$NON-NLS-1$
public static final String MEM_COLOR_EDIT = "memoryColorEdit"; //$NON-NLS-1$
public static final String MEM_COLOR_TEXT = "memoryColorText"; //$NON-NLS-1$
public static final String MEM_USE_GLOBAL_SELECTION = "memUseGlobalSelection"; //$NON-NLS-1$
public static final String MEM_COLOR_SELECTION = "memoryColorSelection"; //$NON-NLS-1$
public static final String MEM_USE_GLOBAL_TEXT = "memUseGlobalText"; //$NON-NLS-1$
public static final String MEM_LIGHTEN_DARKEN_ALTERNATE_CELLS = "memoryColorScaleTextAlternate"; //$NON-NLS-1$
public static final String MEM_EDIT_BUFFER_SAVE = "memoryEditBufferSave"; //$NON-NLS-1$
public static final String MEM_EDIT_BUFFER_SAVE_ON_ENTER_ONLY = "saveOnEnterCancelOnFocusLost"; //$NON-NLS-1$
public static final String MEM_EDIT_BUFFER_SAVE_ON_ENTER_OR_FOCUS_LOST = "saveOnEnterOrFocusLost"; //$NON-NLS-1$
public static final String MEM_HISTORY_TRAILS_COUNT = "memoryHistoryTrailsCount"; //$NON-NLS-1$
}

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
/**
* Class used to initialize default preference values.
*/
public class FPRenderingPreferenceInitializer extends AbstractPreferenceInitializer
{
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
* initializeDefaultPreferences()
*/
@Override
public void initializeDefaultPreferences()
{
IPreferenceStore store = FPRenderingPlugin.getDefault().getPreferenceStore();
store.setDefault(FPRenderingPreferenceConstants.MEM_USE_GLOBAL_TEXT, true);
store.setDefault(FPRenderingPreferenceConstants.MEM_USE_GLOBAL_BACKGROUND, true);
store.setDefault(FPRenderingPreferenceConstants.MEM_USE_GLOBAL_SELECTION, true);
store.setDefault(FPRenderingPreferenceConstants.MEM_COLOR_CHANGED, "255,0,0"); //$NON-NLS-1$
Color systemSelection = Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION);
store.setDefault(FPRenderingPreferenceConstants.MEM_COLOR_SELECTION, systemSelection.getRed() + "," + systemSelection.getGreen() + "," //$NON-NLS-1$ //$NON-NLS-2$
+ systemSelection.getBlue());
store.setDefault(FPRenderingPreferenceConstants.MEM_LIGHTEN_DARKEN_ALTERNATE_CELLS, "5"); //$NON-NLS-1$
store.setDefault(FPRenderingPreferenceConstants.MEM_COLOR_EDIT, "0,255,0"); //$NON-NLS-1$
Color systemText = Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
store.setDefault(FPRenderingPreferenceConstants.MEM_COLOR_TEXT, systemText.getRed() + "," + systemText.getGreen() + "," + systemText.getBlue()); //$NON-NLS-1$ //$NON-NLS-2$
Color systemBackground = Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
store.setDefault(FPRenderingPreferenceConstants.MEM_COLOR_BACKGROUND, systemBackground.getRed() + "," + systemBackground.getGreen() + "," //$NON-NLS-1$ //$NON-NLS-2$
+ systemBackground.getBlue());
store.setDefault(FPRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE, FPRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE_ON_ENTER_ONLY);
store.setDefault(FPRenderingPreferenceConstants.MEM_HISTORY_TRAILS_COUNT, "1"); //$NON-NLS-1$
}
}

View file

@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.preference.ScaleFieldEditor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
/**
* This class represents a preference page that is contributed to the
* Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we
* can use the field support built into JFace that allows us to create a page
* that is small and knows how to save, restore and apply itself.
* <p>
* This page is used to modify preferences only. They are stored in the
* preference store that belongs to the main plug-in class. That way,
* preferences can be accessed directly via the preference store.
*/
public class FPRenderingPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
{
public FPRenderingPreferencePage()
{
super(GRID);
setPreferenceStore(FPRenderingPlugin.getDefault().getPreferenceStore());
setDescription("Floating Point Memory Rendering"); //$NON-NLS-1$
}
@Override
public void createControl(Composite parent)
{
super.createControl(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), FPRenderingPlugin.getUniqueIdentifier() + ".FPRenderingPreferencePage_context"); //$NON-NLS-1$
}
/**
* Creates the field editors. Field editors are abstractions of the common
* GUI blocks needed to manipulate various types of preferences. Each field
* editor knows how to save and restore itself.
*/
@Override
public void createFieldEditors()
{
addField(new BooleanFieldEditor(FPRenderingPreferenceConstants.MEM_USE_GLOBAL_TEXT, "Use Global Te&xt Color", getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorFieldEditor(FPRenderingPreferenceConstants.MEM_COLOR_TEXT, "&Text Color:", getFieldEditorParent())); //$NON-NLS-1$
addField(new ScaleFieldEditor(FPRenderingPreferenceConstants.MEM_LIGHTEN_DARKEN_ALTERNATE_CELLS, "Brighten Alternate Cells", getFieldEditorParent(), 0, 8, 1, 1)); //$NON-NLS-1$
addField(new BooleanFieldEditor(FPRenderingPreferenceConstants.MEM_USE_GLOBAL_BACKGROUND, "Use Global B&ackground Color", getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorFieldEditor(FPRenderingPreferenceConstants.MEM_COLOR_BACKGROUND, "&Background Color:", getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorFieldEditor(FPRenderingPreferenceConstants.MEM_COLOR_CHANGED, "&Changed Color:", getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorFieldEditor(FPRenderingPreferenceConstants.MEM_COLOR_EDIT, "&Edit Color:", getFieldEditorParent())); //$NON-NLS-1$
addField(new BooleanFieldEditor(FPRenderingPreferenceConstants.MEM_USE_GLOBAL_SELECTION, "Use Global Se&lection Color", getFieldEditorParent())); //$NON-NLS-1$
addField(new ColorFieldEditor(FPRenderingPreferenceConstants.MEM_COLOR_SELECTION, "&Selection Color:", getFieldEditorParent())); //$NON-NLS-1$
addField(new RadioGroupFieldEditor(FPRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE, "Edit Buffer", 1, new String[][] //$NON-NLS-1$
{ { "Save on E&nter, Cancel on Focus Lost", "saveOnEnterCancelOnFocusLost" }, //$NON-NLS-1$ //$NON-NLS-2$
{ "Save on Enter or Focus L&ost", "saveOnEnterOrFocusLost" } }, getFieldEditorParent())); //$NON-NLS-1$ //$NON-NLS-2$
addField(new ScaleFieldEditor(FPRenderingPreferenceConstants.MEM_HISTORY_TRAILS_COUNT, "History &Trail Levels", getFieldEditorParent(), 1, 10, 1, 1)); //$NON-NLS-1$
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
@Override
public void init(IWorkbench workbench)
{
}
}

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2006, 2010, 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingTypeDelegate;
public class FPRenderingTypeDelegate implements IMemoryRenderingTypeDelegate
{
@Override
public IMemoryRendering createRendering(String id) throws CoreException
{
return new FPRendering(id);
}
}

View file

@ -0,0 +1,492 @@
/*******************************************************************************
* Copyright (c) 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.UIJob;
public class FPutilities
{
private static final int BYTE_MASK = 0xFF;
// ANSI C "Smallest" and "largest" negative and positive float and double values
public static final float floatNegMax = -3.40282347E+38f; // Largest negative float value; farthest from zero
public static final float floatNegMin = -1.17549435E-38f; // Smallest negative float value; closest to zero
public static final float floatPosMax = 1.17549435E+38f; // Largest positive float value; farthest from zero
public static final float floatPosMin = 3.40282347E-38f; // Smallest positive float value; closest to zero
public static final double doubleNegMax = -1.7976931348623157E+308; // Largest positive double value
public static final double doubleNegMin = -2.2250738585072014E-308; // Smallest positive double value
public static final double doublePosMax = 1.7976931348623157E+308; // Largest positive double value
public static final double doublePosMin = 2.2250738585072014E-308; // Smallest positive double value
public enum FPDataType
{
// Value (for persisteance), Bitsize of type, Number of internal precision decimal digits, Default displayed precision
FLOAT ( 10, 32, 7, 8), // C/C++ single-precision "float"
DOUBLE ( 20, 64, 15, 8), // C/C++ double-precision "double"
FLOAT_80 ( 30, 80, 19, 16), // Extended precision
FLOAT_96 ( 40, 96, 0, 0), // TODO: unknown internal decimal digit precision; C/C++ extended-precision "long double"
// Future work
FLOAT_128 (50, 128, 33, 16), // TODO: known values, but not currently implmented
FLOAT_256 (60, 256, 0, 0), // TODO: unknown internal decimal digit precision
FLOAT_512 (70, 512, 0, 0); // TODO: unknown internal decimal digit precision
// Member variables
private int value;
private int bitsize;
private int decimalPrecision;
private int displayedPrecision;
// Constructor
private FPDataType(int value, int bitSize, int precisionDigits, int defaultDisplayPrecision)
{
this.value = value;
this.bitsize = bitSize;
this.decimalPrecision = precisionDigits;
this.displayedPrecision = defaultDisplayPrecision;
}
// Getters
public int getValue() { return value; }
public int getBitsize() { return bitsize; }
public int getDecimalPrecision() { return decimalPrecision; }
public int getDisplayedPrecision() { return displayedPrecision; }
public int getInternalPrecision() { return decimalPrecision; }
public int getByteLength()
{
return bitsize/Byte.SIZE;
}
}
// Byte ordering
public enum Endian
{
// Value
LITTLE (10),
BIG (20);
// Member variables
private int value;
// Constructor
private Endian(int value)
{
this.value = value;
}
// Getters
public int getValue() { return value; }
}
// Justification (latent support)
public enum Justification
{
LEFT,
RIGHT,
CENTER;
}
// Convert raw float bits to a byte array
public static byte[] rawFloatBitsToByteArray(int floatBits)
{
int byteCount = Integer.SIZE/Byte.SIZE;
byte[] result = new byte[byteCount];
for (int index = 0; index < byteCount; index++)
{
int offset = (result.length - 1 - index) * 8;
result[index] = (byte) ((floatBits >>> offset) & BYTE_MASK);
}
return result;
}
// Convert raw double bits to a byte array
public static byte[] rawDoubleBitsToByteArray(long doubleBits)
{
int byteCount = Long.SIZE/Byte.SIZE;
byte[] result = new byte[byteCount];
for (int index = 0; index < byteCount; index++)
{
int offset = (result.length - 1 - index) * 8;
result[index] = (byte) ((doubleBits >>> offset) & BYTE_MASK);
}
return result;
}
// Return a byte array that is in reverse order of the passed-in array parameter
public static byte[] reverseByteOrder(byte[] byteArray)
{
if (byteArray.length == 0) return new byte[0];
byte tempByte = 0;
byte[] reversedByteArray = new byte[byteArray.length];
// Copy the array that is passed in to the array that will be returned
System.arraycopy(byteArray, 0, reversedByteArray, 0, byteArray.length);
// Reverse the bytes
for(int start = 0, end = reversedByteArray.length - 1; start < end; ++start, --end)
{
tempByte = reversedByteArray[start];
reversedByteArray[start] = reversedByteArray[end];
reversedByteArray[end] = tempByte;
}
return reversedByteArray;
}
// Convert a representation of a float or double in a byte array to a scientific notation string (Should we use BigDecimal here???)
public static String byteArrayToSciNotation(FPDataType dt, boolean isLittleEndian, FPMemoryByte[] memByteArray, int maxDisplayDigits) throws ArithmeticException
{
int displayedDigits = 8;
// If the byte array is not a 32-bit float or 64-bit double, throw an exception.
if (memByteArray.length != (FPDataType.FLOAT.getByteLength()) &&
memByteArray.length != (FPDataType.DOUBLE.getByteLength()))
throw new ArithmeticException("Conversion of the floating point number cannot be performed; invalid data type or byte array length."); //$NON-NLS-1$
// Create and initialize a DecimalFormat object for scientific notation. Specify a space
// for the preceding plus-sign, which lines up the first significant digit, decimal point
// and exponent character. Define the symbol strings for "Not a Number" and "Infinity."
DecimalFormat df = new DecimalFormat("0.0E0"); //$NON-NLS-1$
df.setPositivePrefix(" "); //$NON-NLS-1$
DecimalFormatSymbols dfSymbols = new DecimalFormatSymbols();
dfSymbols.setNaN(" "+ FPRenderingMessages.getString("FPRendering.NAN")); //$NON-NLS-1$ //$NON-NLS-2$
dfSymbols.setInfinity(FPRenderingMessages.getString("FPRendering.INFINITY")); //$NON-NLS-1$
df.setDecimalFormatSymbols(dfSymbols);
// Set the integer and fraction digits for normalized scientific notation.
df.setMinimumIntegerDigits(1);
df.setMaximumIntegerDigits(1);
if (dt == FPDataType.FLOAT)
displayedDigits = Math.min(maxDisplayDigits, FPDataType.FLOAT.getInternalPrecision());
if (dt == FPDataType.DOUBLE)
displayedDigits = Math.min(maxDisplayDigits, FPDataType.DOUBLE.getInternalPrecision());
df.setMinimumFractionDigits(displayedDigits - 1);
df.setMaximumFractionDigits(displayedDigits - 1);
// Convert the byte array to a scientific notation floating point number string (only floats and doubles currently supported)
ByteOrder byteOrder = isLittleEndian ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
return df.format(dt == FPDataType.FLOAT ?
ByteBuffer.wrap(memoryBytesToByteArray(memByteArray)).order(byteOrder).getFloat() :
ByteBuffer.wrap(memoryBytesToByteArray(memByteArray)).order(byteOrder).getDouble());
}
// Convert a floating point string to a byte array (*** only 'floats' and 'doubles' currently supported ***)
public static byte[] floatingStringToByteArray(FPDataType dt, String valueString, int dataTypeBitCount) throws NumberFormatException
{
// Remove whitespace and check for non-zero length
valueString = valueString.trim().replaceAll(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
if (valueString.length() != 0)
{
// Float handling
if (dt == FPDataType.FLOAT || FPDataType.FLOAT.getBitsize() == dataTypeBitCount)
{
// Convert the string to a float. Check the range. Convert to byte array.
float floatValue = new Float(valueString).floatValue();
floatValue = floatLimitCheck(floatValue);
return rawFloatBitsToByteArray(Float.floatToRawIntBits(floatValue));
}
// Double handling
if (dt == FPDataType.DOUBLE || FPDataType.DOUBLE.getBitsize() == dataTypeBitCount)
{
// Convert the string to a double. Check the range. Convert to byte array.
double doubleValue = new Double(valueString).doubleValue();
doubleValue = doubleLimitCheck(doubleValue);
return rawDoubleBitsToByteArray(Double.doubleToRawLongBits(doubleValue));
}
}
return new byte[0];
}
// Convert from an FPMemoryByte array to a byte array
public static byte[] memoryBytesToByteArray(FPMemoryByte[] memoryByteArray)
{
byte[] byteArray = new byte[memoryByteArray.length];
for (int index = 0; index < memoryByteArray.length; index++)
byteArray[index] = memoryByteArray[index].getValue();
return byteArray;
}
// Convert from a byte array to a MemoryByte array
public static FPMemoryByte[] byteArrayToMemoryBytes(Endian endian, byte[] byteArray)
{
FPMemoryByte[] memoryBytes = new FPMemoryByte[byteArray.length];
for (int index = 0; index < byteArray.length; index++)
{
memoryBytes[index] = new FPMemoryByte();
memoryBytes[index].setBigEndian(endian == Endian.BIG);
memoryBytes[index].setValue(byteArray[index]);
}
return memoryBytes;
}
// Check the character for being valid for number entry, both standard and scientific notation
public static boolean validEditCharacter(char character)
{
return (character >= '0' && character <= '9') ||
character == '+' || character == '-' ||
character == 'e' || character == 'E' ||
character == '.' || character == ' ';
}
// Validate floating point number string
public static boolean isValidFormat(String string)
{
// Rules:
// - A minimum of one digit preceding the optional exponent character is required.
// - Allowable characters: 0-9, a decimal point, '+' and '-' number
// signs, exponent characters 'e' and 'E', and spaces.
//
// Strings may also have:
// - One [optional] decimal point
// - A maximum of two [optional] number signs (one before the number and one after the exponent character)
// - Only one [optional] exponent character is allowed
boolean digit = false;
char[] charArray = string.toCharArray();
// Phase I check:
String scientificNotationPattern = "^[-+]??(\\d++[.]\\d*?|[.]?\\d+?|\\d+(?=[eE]))([eE][-+]??\\d++)?$"; //$NON-NLS-1$
if (!Pattern.matches(scientificNotationPattern, string))
return false;
// Phase II check
for (int index = 0; index < string.length(); index++)
{
// Check for a digit
if (charArray[index] >= '0' && charArray[index] <= '9')
digit = true;
// Make sure it's a valid/allowable character
if (!validEditCharacter(charArray[index]))
return false;
// Only one decimal point and exponent character is allowed
if (FPutilities.countMatches(string.toLowerCase(), ".") > 1 || FPutilities.countMatches(string.toLowerCase(), "e") > 1) //$NON-NLS-1$ //$NON-NLS-2$
return false;
// Number signs are only allowed in the first position and following the exponent character.
if (((charArray[index] == '+' || charArray[index] == '-') && index != 0) &&
(charArray[index-1] != 'e' && charArray[index-1] != 'E'))
return false;
// Decimal points are not allowed after the exponent character
int eIndex = string.toLowerCase().indexOf('e');
if (charArray[index] == '.' && eIndex != -1 && eIndex < index)
return false;
}
return digit;
}
// Return a string of the specified length filled with the specified character
public static String fillString(int length, char character)
{
if (length < 1) return ""; //$NON-NLS-1$
char[] charArray = new char[length];
Arrays.fill(charArray, character);
return new String(charArray);
}
// Count the 'subString' matches in 'string'
public static int countMatches(String string, String subString)
{
if (string.length() == 0 || subString.length() == 0) return 0;
int count = 0;
int index = 0;
while ((index = string.indexOf(subString, index)) != -1)
{
count++;
index += subString.length();
}
return count;
}
// Print out a stack trace; useful for UI operations where stopping at a breakpoint causes button press context to be lost
public static void stackTrace(int depth)
{
int offset = 3; // Ignore frames contributed to the stack based on call to this method
if (depth == 0) depth = 4; // Default depth if zero supplied
// Get the stack frames for the current thread; start at the offset
StackTraceElement[] seArray = Thread.currentThread().getStackTrace();
if (seArray.length > offset)
{
System.out.println("Displaying " + depth + " of " + seArray.length + " stack trace elements"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
for (int index = offset; index < Math.min(depth + offset, seArray.length + offset); index++)
System.out.println(" " + seArray[index].getClassName() + "." + seArray[index].getMethodName() + ": line " + seArray[index].getLineNumber()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
else
System.out.println("No stack frames to display"); //$NON-NLS-1$
}
// Pop up a message inside the UI thread
public static void popupMessage(final String title, final String errorText, final Status status)
{
UIJob job = new UIJob("Floating Point Renderer") //$NON-NLS-1$
{
// Notify the user of some condition via a pop-up box.
@Override
public IStatus runInUIThread(IProgressMonitor monitor)
{
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, errorText, status);
return Status.OK_STATUS;
}
};
job.setSystem(true);
job.schedule();
}
// Check float range. Returns -Infinity, the original value or +Infinity
public static float floatLimitCheck(float floatValue)
{
if (floatValue != 0.0f && floatValue != Float.NEGATIVE_INFINITY && floatValue != Float.POSITIVE_INFINITY)
{
if (floatValue < 0)
{
if (Float.compare(floatValue, floatNegMax) < 0 || Float.compare(floatValue, floatNegMin) > 0)
return Float.NEGATIVE_INFINITY;
}
else
{
if (Float.compare(floatValue, floatPosMin) < 0 || Float.compare(floatValue, floatPosMax) > 0)
return Float.POSITIVE_INFINITY;
}
}
return floatValue;
}
// Check double range. Returns a value of RangeCheck
public static double doubleLimitCheck(double doubleValue)
{
if (doubleValue != 0.0 && doubleValue != Double.NEGATIVE_INFINITY && doubleValue != Double.POSITIVE_INFINITY)
{
if (doubleValue < 0)
{
if (Double.compare(doubleValue, doubleNegMax) < 0 || Double.compare(doubleValue, doubleNegMin) > 0)
return Double.NEGATIVE_INFINITY;
}
else
{
if (Double.compare(doubleValue, doublePosMin) < 0 || Double.compare(doubleValue, doublePosMax) > 0)
return Double.POSITIVE_INFINITY;
}
}
return doubleValue;
}
// Convert a BigInteger to a hex String and return only the ending number of specified digits.
public static String bi2HexStr(BigInteger bi, int lastDigits)
{
final int PAD_LENGTH = 12;
String base16 = bi.toString(16);
base16 = fillString(PAD_LENGTH - base16.length(), '0') + base16;
return "0x" + base16.substring(PAD_LENGTH - lastDigits).toUpperCase(); //$NON-NLS-1$
}
// Convert a BigInteger to a decimal String and return only the ending number of
// specified digits. For example: bi2HexStr(239248506, 5) = "48506"
public static String bi2DecStr(BigInteger bi, int lastDigits)
{
final int PAD_LENGTH = 12;
String base10 = bi.toString();
base10 = fillString(PAD_LENGTH - base10.length(), '0') + base10;
return base10.substring(PAD_LENGTH - lastDigits);
}
}

View file

@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2012 Wind River Systems, Inc. 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Randy Rohrbach (Wind River Systems, Inc.) - Copied and modified to create the floating point plugin
*******************************************************************************/
package org.eclipse.cdt.debug.ui.memory.floatingpoint;
public interface IFPRConstants
{
public final String ENDIAN_KEY = FPRenderingPlugin.PLUGIN_ID + ".endian"; // Endianness key //$NON-NLS-1$
public final String DATATYPE_KEY = FPRenderingPlugin.PLUGIN_ID + ".dataType"; // Currently-selected data type //$NON-NLS-1$
public final String FLOAT_DISP_KEY = FPRenderingPlugin.PLUGIN_ID + ".floatDispPrec"; // 32-bit floating point data type displayed precision //$NON-NLS-1$
public final String DOUBLE_DISP_KEY = FPRenderingPlugin.PLUGIN_ID + ".doubleDispPrec"; // 64-bit floating point data type displayed precision //$NON-NLS-1$
public final String COLUMN_COUNT_KEY = FPRenderingPlugin.PLUGIN_ID + ".columns"; // Number of columns to display //$NON-NLS-1$
public final String UPDATEMODE_KEY = FPRenderingPlugin.PLUGIN_ID + ".updateMode"; // Renderer update mode //$NON-NLS-1$
}

View file

@ -0,0 +1,68 @@
###############################################################################
# Copyright (c) 2009, 2012 Wind River 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
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Wind River Systems - initial API and implementation
###############################################################################
FPRendering.ADDRESS=Address
FPRendering.CALLED_ON_NON_DISPATCH_THREAD=Called on non-dispatch thread
FPRendering.COLUMN_COUNT=Columns
FPRendering.COLUMN_COUNT_AUTO=Auto Size to Fill
FPRendering.COLUMN_COUNT_1=1
FPRendering.COLUMN_COUNT_2=2
FPRendering.COLUMN_COUNT_4=4
FPRendering.COLUMN_COUNT_8=8
FPRendering.COLUMN_COUNT_16=16
FPRendering.COLUMN_COUNT_32=32
FPRendering.COLUMN_COUNT_64=64
FPRendering.COLUMN_COUNT_128=128
FPRendering.COLUMN_COUNT_CUSTOM=Custom ...
FPRendering.COPY_ADDRESS=Copy Address
FPRendering.DATA=Data
FPRendering.DISPLAYED_PRECISION_4=Four (4) significant digits
FPRendering.DISPLAYED_PRECISION_8=Eight (8) significant digits
FPRendering.DISPLAYED_PRECISION_16=Sixteen (16) significant digits
FPRendering.EDIT_MODE=Editing: {0}
FPRendering.EDIT_MODE_INSERT=Replace existing value
FPRendering.EDIT_MODE_OVERWRITE=Overwrite number (in-place)
FPRendering.ENDIAN=Endian
FPRendering.ENDIAN_BIG=Big
FPRendering.ENDIAN_LITTLE=Little
FPRendering.ERROR_FPENTRY_POPUP_TEXT="{0}" is an invalid floating point number.\rThe previous value has been restored.
FPRendering.ERROR_FPENTRY_POPUP_TITLE=Floating point number error
FPRendering.ERROR_FPENTRY_STATUS=Invalid floating point number
FPRendering.FAILURE_APPEND_SELECTION=Failed to append selection.
FPRendering.FAILURE_COPY_OPERATION=Failed copy operation.
FPRendering.FAILURE_DETERMINE_ADDRESS_SIZE=Failed to determine address size.
FPRendering.FAILURE_DETERMINE_CELL_LOCATION=Failed to determine cell location.
FPRendering.FAILURE_PAINT=Failed to paint.
FPRendering.FAILURE_POSITION_CURSOR=Failed to position cursor.
FPRendering.FAILURE_READ_MEMORY=Failed reading memory.
FPRendering.FAILURE_RETRIEVE_BASE_ADDRESS=Failure in retrieving base address.
FPRendering.FAILURE_RETRIEVE_START_ADDRESS=Failure in retrieving start address.
FPRendering.FAILURE_START_SELECTION=Failed to start selection.
FPRendering.FAILURE_WRITE_MEMORY=Error writing memory.
FPRendering.FLOATING_POINT_32=32-bit Single Precision
FPRendering.FLOATING_POINT_64=64-bit Double Precision
FPRendering.GO_TO_ADDRESS=Go To Address
FPRendering.INFINITY=Infinity
FPRendering.ISO-8859-1=ISO-8859-1
FPRendering.NUMBER_TYPE=Floating Point Type
FPRendering.NAN=NaN
FPRendering.PANES=Panes
FPRendering.PRECISION=Displayed Precision
FPRendering.REFRESH=Refresh
FPRendering.RENDERING_NAME=Floating Point
FPRendering.RESET_TO_BASE_ADDRESS=Reset To Base Address
FPRendering.UPDATE_ALWAYS=Always
FPRendering.UPDATE_MANUAL=Manual
FPRendering.UPDATE_ON_BREAKPOINT=On Breakpoint
FPRendering.UPDATEMODE=Update Mode
FPRendering.USASCII=US-ASCII
FPRendering.UTF16=UTF-16
FPRendering.UTF8=UTF-8l

View file

@ -24,7 +24,7 @@ providerName=Eclipse CDT
updateSiteName=Eclipse CDT update site
# "description" property - description of the feature
description=Additional features for debug Memory View - traditional rendering, Find/Replace, Import/Export. Source code.
description=Additional features for debug Memory View - traditional rendering, floating-point rendering, Find/Replace, Import/Export. Source code.
# "licenseURL" property - URL of the "Feature License"
# do not translate value - just change to point to a locale-specific HTML page

View file

@ -31,6 +31,13 @@
version="0.0.0"
unpack="false"/>
<plugin
id="org.eclipse.cdt.debug.ui.memory.floatingpoint.source"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="org.eclipse.cdt.debug.ui.memory.transport.source"
download-size="0"