diff options
author | Ed Willink | 2014-05-24 19:46:25 +0000 |
---|---|---|
committer | Ed Willink | 2014-05-26 19:20:04 +0000 |
commit | 4445fc78e691eb901c8dace9a9c95a8d71d6d1d9 (patch) | |
tree | 5e1cecd457e91e052d212bd24f623fe883364915 | |
parent | 7c75951103e8b42c4791c776c6c1a4da7892d0fa (diff) | |
download | org.eclipse.qvtd-4445fc78e691eb901c8dace9a9c95a8d71d6d1d9.tar.gz org.eclipse.qvtd-4445fc78e691eb901c8dace9a9c95a8d71d6d1d9.tar.xz org.eclipse.qvtd-4445fc78e691eb901c8dace9a9c95a8d71d6d1d9.zip |
[422933] Push results to current evaluation environment
5 files changed, 116 insertions, 43 deletions
diff --git a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMEvaluationVisitor.java b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMEvaluationVisitor.java index a84b06fd6..04ffbf0c5 100644 --- a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMEvaluationVisitor.java +++ b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMEvaluationVisitor.java @@ -127,18 +127,18 @@ public abstract class QVTiVMEvaluationVisitor extends AbstractWrappingQVTimperat } @Override - protected Object postVisit(@NonNull Visitable visitable, @Nullable Element preState, @Nullable Object result) { + protected Object postVisit(@NonNull Visitable visitable, @Nullable Element parentElement, @Nullable Object result) { Element element = (Element)visitable; if (VMVirtualMachine.POST_VISIT.isActive()) { VMVirtualMachine.POST_VISIT.println("[" + Thread.currentThread().getName() + "] " + element.eClass().getName() + ": " + element.toString() + " => " + result); } - setCurrentEnvInstructionPointer(preState); + setCurrentEnvInstructionPointer(parentElement); IVMEvaluationEnvironment<?> evalEnv = getEvaluationEnvironment(); - postVisit(evalEnv, element, preState); + postVisit(evalEnv, element, result, parentElement); return result; } - protected abstract void postVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element, @Nullable Element preState); + protected abstract void postVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element, @Nullable Object result, @Nullable Element parentElement); @Override protected @Nullable Element preVisit(@NonNull Visitable visitable) { diff --git a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationEnvironment.java b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationEnvironment.java index 18f350c7e..eae6d8e58 100644 --- a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationEnvironment.java +++ b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationEnvironment.java @@ -12,17 +12,20 @@ package org.eclipse.qvtd.debug.evaluator; import java.util.Map; +import java.util.Stack; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ocl.examples.debug.vm.UnitLocation; import org.eclipse.ocl.examples.debug.vm.core.VMDebugCore; +import org.eclipse.ocl.examples.debug.vm.evaluator.IVMEvaluationEnvironment; import org.eclipse.ocl.examples.debug.vm.utils.ASTBindingHelper; import org.eclipse.ocl.examples.debug.vm.utils.VMRuntimeException; import org.eclipse.ocl.examples.debug.vm.utils.VMStackTraceBuilder; import org.eclipse.ocl.examples.pivot.Element; import org.eclipse.ocl.examples.pivot.NamedElement; +import org.eclipse.ocl.examples.pivot.Variable; import org.eclipse.qvtd.pivot.qvtbase.Transformation; import org.eclipse.qvtd.pivot.qvtimperative.evaluation.QVTiNestedEvaluationEnvironment; @@ -32,6 +35,7 @@ public class QVTiVMNestedEvaluationEnvironment extends QVTiNestedEvaluationEnvir private @NonNull NamedElement myOperation; private final int myStackDepth; private final long id; + private final @NonNull Stack<StepperEntry> stepperStack = new Stack<StepperEntry>(); public QVTiVMNestedEvaluationEnvironment(@NonNull IQVTiVMEvaluationEnvironment evaluationEnvironment, long id, @NonNull NamedElement operation) { super(evaluationEnvironment); @@ -100,6 +104,11 @@ public class QVTiVMNestedEvaluationEnvironment extends QVTiNestedEvaluationEnvir } @Override + @NonNull public Variable getPCVariable() { + return getRootEvaluationEnvironment().getPCVariable(); + } + + @Override public @Nullable IQVTiVMEvaluationEnvironment getParentEvaluationEnvironment() { return (IQVTiVMEvaluationEnvironment) super.getParentEvaluationEnvironment(); } @@ -109,6 +118,11 @@ public class QVTiVMNestedEvaluationEnvironment extends QVTiNestedEvaluationEnvir return (QVTiVMRootEvaluationEnvironment) rootEvaluationEnvironment; } + @Override + public @NonNull Stack<IVMEvaluationEnvironment.StepperEntry> getStepperStack() { + return stepperStack; + } + public boolean isDeferredExecution() { return getRootEvaluationEnvironment().isDeferredExecution(); } diff --git a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationVisitor.java b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationVisitor.java index 84a821d4b..6ccc43fa5 100644 --- a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationVisitor.java +++ b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMNestedEvaluationVisitor.java @@ -48,8 +48,8 @@ public class QVTiVMNestedEvaluationVisitor extends QVTiVMEvaluationVisitor return root; } - protected void postVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element, @Nullable Element preState) { - root.postVisit(evalEnv, element, preState); + protected void postVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element, @Nullable Object result, @Nullable Element parentElement) { + root.postVisit(evalEnv, element, result, parentElement); } protected @Nullable Element preVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element) { diff --git a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationEnvironment.java b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationEnvironment.java index e5ba43f39..426028d5f 100644 --- a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationEnvironment.java +++ b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationEnvironment.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Stack; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jdt.annotation.NonNull; @@ -24,8 +25,12 @@ import org.eclipse.ocl.examples.debug.vm.evaluator.IVMRootEvaluationEnvironment; import org.eclipse.ocl.examples.debug.vm.utils.ASTBindingHelper; import org.eclipse.ocl.examples.debug.vm.utils.VMRuntimeException; import org.eclipse.ocl.examples.debug.vm.utils.VMStackTraceBuilder; +import org.eclipse.ocl.examples.domain.utilities.DomainUtil; import org.eclipse.ocl.examples.pivot.Element; import org.eclipse.ocl.examples.pivot.NamedElement; +import org.eclipse.ocl.examples.pivot.PivotFactory; +import org.eclipse.ocl.examples.pivot.PivotPackage; +import org.eclipse.ocl.examples.pivot.Variable; import org.eclipse.ocl.examples.pivot.manager.MetaModelManager; import org.eclipse.qvtd.debug.core.QVTiDebugCore; import org.eclipse.qvtd.pivot.qvtbase.Transformation; @@ -44,11 +49,17 @@ public class QVTiVMRootEvaluationEnvironment extends QVTiRootEvaluationEnvironme // private Trace myTraces; private @NonNull Element myCurrentIP; private final long id; + private final @NonNull Variable pcVariable; + private final @NonNull Stack<StepperEntry> stepperStack = new Stack<StepperEntry>(); public QVTiVMRootEvaluationEnvironment(@NonNull MetaModelManager metaModelManager, @NonNull QVTiModelManager modelManager, @NonNull Transformation transformation, long id) { super(metaModelManager, modelManager, transformation); myCurrentIP = transformation; this.id = id; + pcVariable = DomainUtil.nonNullEMF(PivotFactory.eINSTANCE.createVariable()); + pcVariable.setName("$pc"); + String typeName = DomainUtil.nonNullEMF(PivotPackage.Literals.OCL_EXPRESSION.getName()); + pcVariable.setType(metaModelManager.getPivotType(typeName)); } @Override @@ -143,10 +154,20 @@ public class QVTiVMRootEvaluationEnvironment extends QVTiRootEvaluationEnvironme } @Override + @NonNull public Variable getPCVariable() { + return pcVariable; + } + + @Override public @NonNull QVTiVMRootEvaluationEnvironment getRootEvaluationEnvironment() { return this; } + @Override + public @NonNull Stack<org.eclipse.ocl.examples.debug.vm.evaluator.IVMEvaluationEnvironment.StepperEntry> getStepperStack() { + return stepperStack; + } + @Override public boolean isDeferredExecution() { return myIsDeferedExecution; @@ -189,7 +210,7 @@ public class QVTiVMRootEvaluationEnvironment extends QVTiRootEvaluationEnvironme saveThrownException(exception); exception.setStackVMTrace(new VMStackTraceBuilder(this).buildStackTrace()); } catch (Exception e) { - getDebugCore().error("Failed to build QVT stack trace", e); //$NON-NLS-1$ + getDebugCore().error("Failed to build VM stack trace", e); //$NON-NLS-1$ } throw exception; diff --git a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationVisitor.java b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationVisitor.java index ecf0a23fd..120d2b43d 100644 --- a/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationVisitor.java +++ b/plugins/org.eclipse.qvtd.debug/src/org/eclipse/qvtd/debug/evaluator/QVTiVMRootEvaluationVisitor.java @@ -28,10 +28,10 @@ import org.eclipse.ocl.examples.debug.vm.VMBreakpointManager; import org.eclipse.ocl.examples.debug.vm.VMVirtualMachine; import org.eclipse.ocl.examples.debug.vm.data.VMStackFrameData; import org.eclipse.ocl.examples.debug.vm.data.VMSuspension; -import org.eclipse.ocl.examples.debug.vm.evaluator.IVMRootEvaluationVisitor; import org.eclipse.ocl.examples.debug.vm.evaluator.IStepper; import org.eclipse.ocl.examples.debug.vm.evaluator.IStepperVisitor; import org.eclipse.ocl.examples.debug.vm.evaluator.IVMEvaluationEnvironment; +import org.eclipse.ocl.examples.debug.vm.evaluator.IVMRootEvaluationVisitor; import org.eclipse.ocl.examples.debug.vm.event.VMResumeEvent; import org.eclipse.ocl.examples.debug.vm.event.VMStartEvent; import org.eclipse.ocl.examples.debug.vm.event.VMSuspendEvent; @@ -46,6 +46,8 @@ import org.eclipse.ocl.examples.debug.vm.utils.VMInterruptedExecutionException; import org.eclipse.ocl.examples.domain.utilities.DomainUtil; import org.eclipse.ocl.examples.pivot.Element; import org.eclipse.ocl.examples.pivot.LoopExp; +import org.eclipse.ocl.examples.pivot.NamedElement; +import org.eclipse.ocl.examples.pivot.OCLExpression; import org.eclipse.qvtd.debug.core.QVTiDebugCore; import org.eclipse.qvtd.debug.stepper.QVTiStepperVisitor; import org.eclipse.qvtd.debug.vm.QVTiVMVirtualMachine; @@ -55,12 +57,11 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme { private final @NonNull IVMDebuggerShell fDebugShell; private final @NonNull VMBreakpointManager fBPM; - private UnitLocation fCurrentLocation; + private @NonNull UnitLocation fCurrentLocation; private final @NonNull IterateBreakpointHelper fIterateBPHelper; // private final List<UnitLocation> fLocationStack; private @NonNull VMSuspension fCurrentStepMode; private @NonNull Stack<QVTiVMEvaluationVisitor> visitorStack = new Stack<QVTiVMEvaluationVisitor>(); - private final @NonNull Stack<IStepper> stepperStack = new Stack<IStepper>(); public QVTiVMRootEvaluationVisitor(@NonNull QVTiVMEnvironment env, @NonNull IQVTiVMEvaluationEnvironment evalEnv, @NonNull IVMDebuggerShell shell) { super(new QVTiVMEvaluationVisitorImpl(env, evalEnv)); @@ -70,12 +71,13 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme // fLocationStack = new ArrayList<UnitLocation>(); fCurrentStepMode = VMSuspension.UNSPECIFIED; pushVisitor(this); - fCurrentLocation = null; //getCurrentLocation(); + fCurrentLocation = getCurrentLocation(); } @Override protected @Nullable Object badVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element, Object preState, @NonNull Throwable e) { + Stack<IVMEvaluationEnvironment.StepperEntry> stepperStack = evalEnv.getStepperStack(); if (!stepperStack.isEmpty()) { stepperStack.pop(); } @@ -109,7 +111,8 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme } if (request instanceof VMResumeRequest) { VMResumeRequest resumeRequest = (VMResumeRequest) request; - fCurrentLocation = getCurrentLocation(); +// fCurrentLocation = getCurrentLocation(); +// fCurrentLocation = fCurrentStepMode == VMSuspension.STEP_INTO ? null : getCurrentLocation(); fCurrentStepMode = resumeRequest.suspension; if (fCurrentStepMode == VMSuspension.UNSPECIFIED) { fIterateBPHelper.removeAllIterateBreakpoints(); @@ -154,10 +157,15 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme private @NonNull String getMainModuleName() { CompiledUnit mainUnit = fBPM.getUnitManager().getMainUnit(); - if (mainUnit.getModules().isEmpty()) { + List<NamedElement> modules = mainUnit.getModules(); + if (modules.isEmpty()) { return "<null>"; //$NON-NLS-1$ } - return DomainUtil.nonNullState(mainUnit.getModules().get(0).getName()); + String name = modules.get(0).getName(); + if (name == null) { + return "<null>"; //$NON-NLS-1$ + } + return DomainUtil.nonNullState(name); } public @NonNull QVTiVMRootEvaluationVisitor getRootEvaluationVisitor() { @@ -169,7 +177,7 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme return QVTiStepperVisitor.INSTANCE; } - protected void handleLocationChanged(@NonNull Element element, UnitLocation location, boolean isElementEnd) { + protected void handleLocationChanged(@NonNull Element element, @NonNull UnitLocation location, boolean isElementEnd) { if (VMVirtualMachine.LOCATION.isActive()) { VMVirtualMachine.LOCATION.println("[" + Thread.currentThread().getName() + "] " + element.eClass().getName() + ": " + element.toString() + " @ " + location + " " + (isElementEnd ? "start" : "end")); } @@ -184,30 +192,24 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme // validbreakpointlocator.isBreakpointableElementEnd(element))) { // return; // } - - if (fCurrentStepMode == VMSuspension.STEP_OVER) { - if (location.getStackDepth() <= fCurrentLocation.getStackDepth() - && (!location.isTheSameLine(fCurrentLocation) - /*|| repeatedInIterator(location, fCurrentLocation)*/ )) { - fCurrentLocation = null; - suspendAndWaitForResume(location, fCurrentStepMode); - return; - } + boolean doSuspendAndResume = false; + if (fCurrentStepMode == VMSuspension.STEP_INTO) { + doSuspendAndResume = true; } - else if (fCurrentStepMode == VMSuspension.STEP_INTO) { - if (!location.isTheSameLocation(fCurrentLocation) /*|| repeatedInIterator(location, fCurrentLocation)*/) { - fCurrentLocation = null; - suspendAndWaitForResume(location, fCurrentStepMode); - return; + else if (fCurrentStepMode == VMSuspension.STEP_OVER) { + if (isSmallerStackDepth(location) || isNewLine(location) /*|| repeatedInIterator(location, fCurrentLocation)*/ ) { + doSuspendAndResume = true; } } else if (fCurrentStepMode == VMSuspension.STEP_RETURN) { - if (location.getStackDepth() < fCurrentLocation.getStackDepth()) { - fCurrentLocation = null; - suspendAndWaitForResume(location, fCurrentStepMode); - return; + if (isSmallerStackDepth(location)) { + doSuspendAndResume = true; } } + if (doSuspendAndResume) { + suspendAndWaitForResume(location, fCurrentStepMode); + return; + } // check if we trigger a registered breakpoint for (VMBreakpoint breakpoint : fBPM.getBreakpoints(element)) { // FIXME Use Adapters to avoid potentially long loop @@ -260,6 +262,34 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme } + /** + * Return true if a call (stack push) has occurred on location wrt the last displayed location. + */ + protected boolean isLargerStackDepth(@NonNull UnitLocation location) { + return location.getStackDepth() > fCurrentLocation.getStackDepth(); + } + + /** + * Return true if a line change has occurred on location wrt the last displayed location. + */ + protected boolean isNewLine(@NonNull UnitLocation location) { + return !location.isTheSameLine(fCurrentLocation); + } + + /** + * Return true if a position change has occurred on location wrrt the last displayed location. + */ + protected boolean isNewLocation(@NonNull UnitLocation location) { + return !location.isTheSameLocation(fCurrentLocation); + } + + /** + * Return true if a return (stack pop) has occurred on location wrt the last displayed location. + */ + protected boolean isSmallerStackDepth(@NonNull UnitLocation location) { + return location.getStackDepth() < fCurrentLocation.getStackDepth(); + } + private @NonNull UnitLocation newLocalLocation(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element node, int startPosition, int endPosition) { return new UnitLocation(startPosition, endPosition, evalEnv, node); } @@ -278,20 +308,27 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme // } } - protected void postVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element, @Nullable Element preState) { + protected void postVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element, @Nullable Object result, @Nullable Element parentElement) { + Stack<IVMEvaluationEnvironment.StepperEntry> stepperStack = evalEnv.getStepperStack(); if (stepperStack.isEmpty()) { return; } - stepperStack.pop(); + IVMEvaluationEnvironment.StepperEntry childStepperEntry = stepperStack.pop(); + childStepperEntry.popFrom(evalEnv); if (stepperStack.isEmpty()) { return; } - IStepper parentStepper = stepperStack.peek(); - Element postElement = parentStepper.isPostStoppable(this, element, preState); + IVMEvaluationEnvironment.StepperEntry parentStepperEntry = stepperStack.peek(); + if (element instanceof OCLExpression) { // NB not REalizedVariable + parentStepperEntry.pushTo(evalEnv, (OCLExpression) element, result); + } + IStepper parentStepper = parentStepperEntry.stepper; + Element postElement = parentStepper.isPostStoppable(this, element, parentElement); if (postElement != null) { - UnitLocation unitLocation = parentStepper.createUnitLocation(evalEnv, postElement); - setCurrentLocation(postElement, unitLocation, false); - processDebugRequest(unitLocation); + UnitLocation unitLocation = parentStepper.createUnitLocation(evalEnv, postElement); + setCurrentLocation(postElement, unitLocation, false); + processDebugRequest(unitLocation); +// } } /* if (element instanceof Transformation) { // @@ -318,8 +355,7 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme public void preIterate(@NonNull LoopExp loopExp) { UnitLocation topLocation = getCurrentLocation(); boolean skipIterate = (fCurrentStepMode == VMSuspension.UNSPECIFIED) - || ((fCurrentStepMode == VMSuspension.STEP_OVER) && - (topLocation.getStackDepth() > fCurrentLocation.getStackDepth())); + || ((fCurrentStepMode == VMSuspension.STEP_OVER) && isLargerStackDepth(topLocation)); if (!skipIterate) { /*return*/ fIterateBPHelper.stepIterateElement(loopExp, topLocation); @@ -327,8 +363,9 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme } protected @Nullable Element preVisit(@NonNull IVMEvaluationEnvironment<?> evalEnv, @NonNull Element element) { + Stack<IVMEvaluationEnvironment.StepperEntry> stepperStack = evalEnv.getStepperStack(); IStepper stepper = getStepperVisitor().getStepper(element); - stepperStack.push(stepper); + stepperStack.push(new IVMEvaluationEnvironment.StepperEntry(stepper, element)); if (stepper.isPreStoppable(this, element)) { UnitLocation unitLocation = stepper.createUnitLocation(evalEnv, element); setCurrentLocation(element, unitLocation, false); @@ -432,6 +469,7 @@ public class QVTiVMRootEvaluationVisitor extends QVTiVMEvaluationVisitor impleme } private void suspendAndWaitForResume(@NonNull UnitLocation location, @NonNull VMSuspendEvent suspendEvent) { + fCurrentLocation = location; try { VMSuspendEvent vmSuspend = suspendEvent; |