home *** CD-ROM | disk | FTP | other *** search
- public class JScriptDebugger extends SJMTObject implements JScriptDebugInterface {
- private JScriptRuntimeInstance aRuntimeInstance;
- private String aIDString;
- private Thread aModuleThread;
- private JScriptManager aJScriptManager;
-
- public JScriptDebugger(JScriptManager var1, JScriptRuntimeInstance var2, String var3, ThreadGroup var4) {
- super(var1, var3, var4);
- this.aJScriptManager = var1;
- this.aRuntimeInstance = var2;
- this.aRuntimeInstance.SetDebugInterface(this);
- this.aIDString = var3;
- this.aModuleThread = null;
- }
-
- public JScriptDebugger(JScriptManager var1, JScriptRuntimeInstance var2, String var3) {
- this(var1, var2, var3, (ThreadGroup)null);
- }
-
- public void HandleMessage(SJMessage var1) {
- if (var1 instanceof JScriptAction) {
- JScriptAction var2 = (JScriptAction)var1;
- if (this.CanProcessAction(var2)) {
- ((SJMTObject)this).AddToMessageQueue(var2);
- } else {
- if (var2.GetSourceObject() instanceof JScriptRuntimeInstance) {
- this.NotifyObservers(var2);
- }
-
- }
- }
- }
-
- protected void ProcessMessage(SJMessage var1) {
- this.ProcessAction(var1);
- }
-
- public final void UpdateBrowserSync() {
- this.aRuntimeInstance.YieldBrowser();
- }
-
- private final void ClearAllRTFlags() {
- this.aRuntimeInstance.ClearSingleSourceStepFlag();
- this.aRuntimeInstance.ClearSinglePCodeStepFlag();
- this.aRuntimeInstance.ClearStepOverFlag();
- this.aRuntimeInstance.ClearStepOutFlag();
- }
-
- private final void Do_Start() {
- this.StartModuleDebugThread();
- this.aRuntimeInstance.SetDebugFlag();
- this.aRuntimeInstance.SetSinglePCodeStepFlag();
- this.NotifyObservers(new JScriptAction(5003, "start"));
- }
-
- private final void Do_Step() {
- this.StartModuleDebugThread();
- this.aRuntimeInstance.SetDebugFlag();
- this.ClearAllRTFlags();
- this.aRuntimeInstance.SetSingleSourceStepFlag();
- if (this.aRuntimeInstance.IsSleeping()) {
- this.aRuntimeInstance.SetDebugContinueFlag();
- }
-
- this.NotifyObservers(new JScriptAction(5003, "step"));
- }
-
- private final void Do_StepOver() {
- this.StartModuleDebugThread();
- this.aRuntimeInstance.SetDebugFlag();
- this.ClearAllRTFlags();
- this.aRuntimeInstance.SetStepOverFlag();
- if (this.aRuntimeInstance.IsSleeping()) {
- this.aRuntimeInstance.SetDebugContinueFlag();
- }
-
- this.NotifyObservers(new JScriptAction(5003, "step over"));
- }
-
- private final void Do_StepOut() {
- this.StartModuleDebugThread();
- this.aRuntimeInstance.SetDebugFlag();
- this.ClearAllRTFlags();
- this.aRuntimeInstance.SetStepOutFlag();
- if (this.aRuntimeInstance.IsSleeping()) {
- this.aRuntimeInstance.SetDebugContinueFlag();
- }
-
- this.NotifyObservers(new JScriptAction(5003, "step over"));
- }
-
- private final void Do_PCodeStepOver() {
- this.StartModuleDebugThread();
- this.aRuntimeInstance.SetDebugFlag();
- this.ClearAllRTFlags();
- this.aRuntimeInstance.SetSinglePCodeStepFlag();
- this.aRuntimeInstance.SetStepOverFlag();
- if (this.aRuntimeInstance.IsSleeping()) {
- this.aRuntimeInstance.SetDebugContinueFlag();
- }
-
- this.NotifyObservers(new JScriptAction(5003, "P-code step over"));
- }
-
- private final void Do_PCodeStep() {
- this.StartModuleDebugThread();
- this.aRuntimeInstance.SetDebugFlag();
- this.ClearAllRTFlags();
- this.aRuntimeInstance.SetSinglePCodeStepFlag();
- if (this.aRuntimeInstance.IsSleeping()) {
- this.aRuntimeInstance.SetDebugContinueFlag();
- }
-
- this.NotifyObservers(new JScriptAction(5003, "P-code step"));
- }
-
- private final void Do_Run() {
- this.StartModuleDebugThread();
- this.aRuntimeInstance.SetDebugFlag();
- this.ClearAllRTFlags();
- if (this.aRuntimeInstance.IsSleeping()) {
- this.aRuntimeInstance.SetDebugContinueFlag();
- }
-
- this.NotifyObservers(new JScriptAction(5003, "running..."));
- }
-
- private final void Do_KillProgram() {
- if (this.aModuleThread != null) {
- this.NotifyObservers(new JScriptAction(5003, "killing..."));
- this.aRuntimeInstance.ClearDebugFlag();
- this.ClearAllRTFlags();
- this.aRuntimeInstance.SetBreakFlag();
- if (this.aRuntimeInstance.IsSleeping()) {
- this.aRuntimeInstance.SetDebugContinueFlag();
- }
-
- this.WaitForModuleThread();
- this.aRuntimeInstance.ClearBreakFlag();
- this.NotifyObservers(new JScriptAction(5003, "Program killed."));
- this.NotifyObservers(new JScriptAction(218, this, this.aRuntimeInstance));
- }
- }
-
- private final void Do_ResetProgram() {
- this.Do_KillProgram();
- }
-
- private final void Do_Halt() {
- if (!this.aRuntimeInstance.IsSleeping()) {
- this.NotifyObservers(new JScriptAction(5003, "breaking..."));
- this.aRuntimeInstance.SetDebugFlag();
- this.aRuntimeInstance.SetSinglePCodeStepFlag();
- } else {
- this.NotifyObservers(new JScriptAction(5003, "allready breaked..."));
- }
- }
-
- private final boolean CanProcessAction(Object var1) {
- return var1 instanceof JScriptAction && ((JScriptAction)var1).GetID() >= 1000 && ((JScriptAction)var1).GetID() <= 1100;
- }
-
- private final boolean ProcessAction(Object var1) {
- if (var1 instanceof JScriptAction) {
- switch (((JScriptAction)var1).GetID()) {
- case 1000:
- this.Do_Start();
- break;
- case 1001:
- this.Do_Step();
- break;
- case 1002:
- this.Do_PCodeStep();
- case 1003:
- break;
- case 1004:
- this.Do_ResetProgram();
- break;
- case 1005:
- this.Do_Run();
- break;
- case 1006:
- this.Do_Halt();
- this.NotifyObservers(new JScriptAction(5003, "program breaked."));
- break;
- case 1007:
- this.NotifyObservers(new JScriptAction(203, this, this.aRuntimeInstance));
- this.NotifyObservers(new JScriptAction(5003, "program finished."));
- this.aModuleThread = null;
- break;
- case 1008:
- this.NotifyObservers(new JScriptAction(202, this, this.aRuntimeInstance));
- this.NotifyObservers(new JScriptAction(5003, "program started..."));
- break;
- case 1009:
- default:
- return false;
- case 1010:
- this.Do_KillProgram();
- ((SJMTObject)this).StopMessageLoop();
- break;
- case 1011:
- this.Do_StepOver();
- break;
- case 1012:
- this.Do_StepOut();
- break;
- case 1013:
- this.NotifyObservers(new JScriptAction(218, this, this.aRuntimeInstance));
- this.NotifyObservers(new JScriptAction(5003, "thread finished."));
- break;
- case 1014:
- this.NotifyObservers(new JScriptAction(217, this, this.aRuntimeInstance));
- this.NotifyObservers(new JScriptAction(5003, "thread started..."));
- break;
- case 1015:
- this.Do_PCodeStepOver();
- break;
- case 1016:
- this.UpdateBrowserSync();
- }
-
- return true;
- } else {
- return false;
- }
- }
-
- private final void StartModuleDebugThread() {
- if (this.aModuleThread == null) {
- JScriptModule var1 = this.aJScriptManager.GetActModule();
- this.aRuntimeInstance.SetModule(var1);
- this.aRuntimeInstance.SetDebugFlag();
- this.aModuleThread = new Thread(this.aRuntimeInstance, new String("RT-Instance (used by: " + this.aIDString + ")"));
- this.aModuleThread.start();
- }
-
- }
-
- private final void WaitForModuleThread() {
- this.aRuntimeInstance.WaitForThreadEnd();
- this.aModuleThread = null;
- }
-
- private final void NotifyObservers(JScriptAction var1) {
- this.aJScriptManager.HandleMessage(var1);
- }
- }
-