public bool InsideRange(CodeRange cr) { // Reject the obvious cases first (codes in different files)... if (cr.StartInclusive.SourceLocation != StartInclusive.SourceLocation) { return(false); } if (cr.EndExclusive.SourceLocation != EndExclusive.SourceLocation) { return(false); } if (StartInclusive.LineNo <= cr.StartInclusive.LineNo && EndExclusive.LineNo >= cr.EndExclusive.LineNo) { if (StartInclusive.LineNo == cr.StartInclusive.LineNo && StartInclusive.CharNo > cr.StartInclusive.CharNo) { return(false); } else if (EndExclusive.LineNo == cr.EndExclusive.LineNo && EndExclusive.CharNo < cr.EndExclusive.CharNo) { return(false); } return(true); } return(false); }
internal bool GetExecutionCursor(ref ProtoCore.CodeModel.CodeRange cursor) { if ((null != internalWorker) && internalWorker.IsBusy) { return(false); } // The script is executed without a debugger attached, // therefore this call does not make sense right now. if (null != scriptRunner) { return(false); } // There is no execution cursor, either the runner is // not created, or created without having been executed. if (null == debugRunner || (null == workerParams.CurrentVmState)) { return(false); } // The old behavior demands that if we have a valid VMState, // then we should use the cursor information it provides us. cursor = workerParams.CurrentVmState.ExecutionCursor; return(true); }
internal void SetExecutionCursor(ProtoCore.CodeModel.CodeRange cursor) { highlight.SetExecutionCursor(cursor); lineHeading.SetExecutionCursor(cursor); highlight.Render(); lineHeading.Render(); }
public bool GetExecutionCursor(ref ProtoCore.CodeModel.CodeRange cursor) { if (null == vmWorker) { return(false); } return(vmWorker.GetExecutionCursor(ref cursor)); }
public bool InsideRange(CodeRange cr) { // Reject the obvious cases first (codes in different files)... if (cr.StartInclusive.SourceLocation != StartInclusive.SourceLocation) return false; if (cr.EndExclusive.SourceLocation != EndExclusive.SourceLocation) return false; if (StartInclusive.LineNo <= cr.StartInclusive.LineNo && EndExclusive.LineNo >= cr.EndExclusive.LineNo) { if (StartInclusive.LineNo == cr.StartInclusive.LineNo && StartInclusive.CharNo > cr.StartInclusive.CharNo) return false; else if (EndExclusive.LineNo == cr.EndExclusive.LineNo && EndExclusive.CharNo < cr.EndExclusive.CharNo) return false; return true; } return false; }
internal void HandleScriptActivation() { //Check if its in playback mode, as it should be treated differently due to blocking if (player == null) { if (textCore.ChangeScript(ScriptTabControl.CurrentTab)) CheckTabControlVisibility(false); else return; } else { CheckTabControlVisibility(false); TextEditorCommand command = new TextEditorCommand(TextEditorCommand.Method.ChangeScript); command.AppendArgument(ScriptTabControl.CurrentTab); textCore.PlaybackCommand(command); } // Resize canvas to fit the next script. //if (numSlider != null) // numSlider.Visibility = Visibility.Collapsed; UpdateCanvasDimension(); IExecutionSession session = Solution.Current.ExecutionSession; UpdateScriptDisplay(Solution.Current.ActiveScript); UpdateCaretPosition(false); textCanvas.BreakpointsUpdated(); if (null != session) { CodeRange executionCursor = new CodeRange(); if (session.GetExecutionCursor(ref executionCursor)) textCanvas.SetExecutionCursor(executionCursor); } if (null != textEditorControl.textCore.CurrentTextBuffer) { textCanvas.ScrollOwner.ScrollToVerticalOffset( textEditorControl.textCore.VerticalScrollPosition); } }
internal void SetExecutionCursor(ProtoCore.CodeModel.CodeRange cursor) { this.visualHost.SetExecutionCursor(cursor); }
/// <summary> /// Figure out the ClassScope, FunctionIndex, BlockId of a given position represented by the three parameters /// </summary> /// <param name="line"></param> /// <param name="col"></param> /// <param name="src">ds file name</param> /// <returns></returns> private static ScopeInfo GetScopeInfo(ProtoCore.CodeModel.CodePoint cp) { // initialize scope info to invalid values, -1 ScopeInfo si = new ScopeInfo() { BlockId = ProtoCore.DSASM.Constants.kInvalidIndex, FunctionIndex = ProtoCore.DSASM.Constants.kInvalidIndex, ClassScope = ProtoCore.DSASM.Constants.kInvalidIndex, }; // search if it is inside any class scope foreach (KeyValuePair <int, ProtoCore.CodeModel.CodeRange> cr in codeRangeTable.ClassBlock.RangeTable) { if (cr.Value.InsideRange(cp)) { // yes, inside a class scope si.ClassScope = cr.Key; // check if it is inside a function foreach (KeyValuePair <int, ProtoCore.CodeModel.CodeRange> cr2 in codeRangeTable.ClassBlock.FunctionTable[si.ClassScope].RangeTable) { if (cr2.Value.InsideRange(cp)) { // yes, it is inside a function si.FunctionIndex = cr2.Key; break; } } break; } } // search what is the block id // // usually when the class scope is not -1, the block id should be always 0 since class is only allowed at global scope // However, language block is allowed in an expression, so it is possible that the current scope is inside a language block which is inside // a member function of a class // eg: class A { def foo : int() { return = [Imperative] { return = 10; } } } // it is still necessary to figure out what is the actual block ID IEnumerable <KeyValuePair <int, ProtoCore.CodeModel.CodeRange> > blocks = codeRangeTable.CodeBlock.RangeTable.Where(x => x.Value.InsideRange(cp)); // minCr holds the inner most block range which contais the target position ProtoCore.CodeModel.CodeRange minCr = new ProtoCore.CodeModel.CodeRange(); if (blocks.Count() > 0) { minCr = blocks.ElementAt(0).Value; } foreach (KeyValuePair <int, ProtoCore.CodeModel.CodeRange> block in blocks) { if (minCr.InsideRange(block.Value)) { // more inner scope found, update minCr and si.BlockId minCr = block.Value; si.BlockId = block.Key; } } // not inside any class scope, need to figure out which function it is in // Note: it is illegal to have a function inside a language block if the language block is inside a function // eg: def foo : int() { return = [Imperative] { def foo2 : int() { return = 20 }; return = foo2(); }; } // so there is no need to search the fucntion index if it is inside a class if (si.ClassScope == ProtoCore.DSASM.Constants.kInvalidIndex) { Dictionary <int, FunctionRangeTable> functionTable = codeRangeTable.CodeBlock.FunctionTable; if (null != functionTable && (si.BlockId >= 0) && (si.BlockId < functionTable.Count)) { // search its function index foreach (KeyValuePair <int, ProtoCore.CodeModel.CodeRange> cr in codeRangeTable.CodeBlock.FunctionTable[si.BlockId].RangeTable) { if (cr.Value.InsideRange(cp)) { si.FunctionIndex = cr.Key; break; } } } } return(si); }
public void SetExecutionCursor(ProtoCore.CodeModel.CodeRange executionCursor) { this.executionCursor = executionCursor; }
public void ResetExecutionCursor() { executionCursor = new CodeRange(); }
private bool GetScopeIdentifier(CodePoint location, ref ScopeInfo scopeIdentifier) { string[] conditions = { "StartLine <= " + location.LineNo.ToString(), "EndLine >= " + location.LineNo.ToString() }; Dictionary<ScopeInfo, CodeRange> scopeIdentifiers = null; try { string statement = SelectFromStatement(TableNames.ScopeRanges, conditions); SQLiteCommand command = new SQLiteCommand(statement, connection); SQLiteDataReader reader = command.ExecuteReader(); if (null == reader || (false == reader.HasRows)) return false; // No record was found matching. while (reader.Read()) { int startLine = reader.GetInt32(1); int startColumn = reader.GetInt32(2); int endLine = reader.GetInt32(3); int endColumn = reader.GetInt32(4); bool withinRange = true; if (location.LineNo == startLine && (location.CharNo < startColumn)) withinRange = false; else if (location.LineNo == endLine && (location.CharNo >= endColumn)) withinRange = false; if (false == withinRange) continue; if (null == scopeIdentifiers) scopeIdentifiers = new Dictionary<ScopeInfo, CodeRange>(); string path = GetScriptPath(reader.GetInt32(0)); ScopeInfo scope = new ScopeInfo() { BlockId = reader.GetInt32(5), ClassScope = reader.GetInt32(6), FunctionIndex = reader.GetInt32(7) }; CodeRange range = MakeCodeRange(startLine, startColumn, endLine, endColumn, path); scopeIdentifiers.Add(scope, range); } } catch (Exception exception) { HandleException(exception); return false; } if (null == scopeIdentifiers || (scopeIdentifiers.Count <= 0)) return false; // Attempt to find the inner-most scope by seeing // if one scope completely contains another scope. // bool foundInnerMostScope = false; CodeRange innerMostScope = new CodeRange(); foreach (var identifier in scopeIdentifiers) { if (false == foundInnerMostScope) { innerMostScope = identifier.Value; scopeIdentifier = identifier.Key; foundInnerMostScope = true; continue; } if (innerMostScope.InsideRange(identifier.Value)) { innerMostScope = identifier.Value; scopeIdentifier = identifier.Key; } } return foundInnerMostScope; }
private void OnExecutionStateChanged(object sender, ExecutionStateChangedEventArgs e) { bool executionInProgress = false; bool refreshOutputPanes = false; bool refreshInspectionPane = false; bool refreshOnScreenBreakpoints = false; bool refreshExecutionCursor = false; Color textCanvasBackground = Colors.White; Color scrollViewerBackground = Colors.White; switch (e.CurrentState) { case ExecutionStateChangedEventArgs.States.None: refreshOutputPanes = true; refreshInspectionPane = true; refreshOnScreenBreakpoints = true; textCore.ReadOnlyState = false; textCanvasBackground = Colors.White; scrollViewerBackground = Colors.White; break; case ExecutionStateChangedEventArgs.States.Running: executionInProgress = true; textCore.ReadOnlyState = true; textCanvasBackground = UIColors.TextCanvasBackground; scrollViewerBackground = UIColors.ScrollViewerBackground; break; case ExecutionStateChangedEventArgs.States.Debugging: executionInProgress = true; textCore.ReadOnlyState = true; textCanvasBackground = UIColors.TextCanvasBackground; scrollViewerBackground = UIColors.ScrollViewerBackground; break; case ExecutionStateChangedEventArgs.States.Paused: refreshOutputPanes = true; refreshInspectionPane = true; refreshOnScreenBreakpoints = true; refreshExecutionCursor = true; textCore.ReadOnlyState = true; textCanvasBackground = UIColors.TextCanvasBackground; scrollViewerBackground = UIColors.ScrollViewerBackground; break; case ExecutionStateChangedEventArgs.States.Stopped: refreshOutputPanes = true; refreshInspectionPane = true; refreshOnScreenBreakpoints = true; textCore.ReadOnlyState = true; textCanvasBackground = UIColors.TextCanvasBackground; scrollViewerBackground = UIColors.ScrollViewerBackground; break; } // Display/hide execution status bar depending on the state. ShowStatusProgressBar(executionInProgress); if (false != refreshExecutionCursor) { CodeRange executionCursor = new CodeRange(); IExecutionSession session = Solution.Current.ExecutionSession; if (session.GetExecutionCursor(ref executionCursor)) { if (null != executionCursor.StartInclusive.SourceLocation) { CodePoint codePoint = executionCursor.StartInclusive; ActivateScriptByPath(codePoint.SourceLocation.FilePath); } UpdateCaretPosition(); textCanvas.SetExecutionCursor(executionCursor); } else textCanvas.ClearExecutionCursor(); // Busy? } else { // Either busy executing or not execution at all, // we don't show the execution cursor for both cases. textCanvas.ClearExecutionCursor(); } if (false != refreshOutputPanes) { IOutputStream outputStream = Solution.Current.GetMessage(false); List<ProtoCore.OutputMessage> outputMessages = outputStream.GetMessages(); Solution.Current.AddInlineMessages(outputMessages); OutputWindow.Instance.SetOutputMessage(outputMessages); ErrorWindow.Instance.SetErrorMessage(outputMessages); } if (false != refreshInspectionPane) { // Inspection window cannot be updated while the vm is running // in the background (i.e. being in 'Debugging' or 'Running' // state). Other than that we'll refresh the inspection view, // even when it is 'None', in which case the inspection view is // refreshed with 'null' values. InspectionViewControl.Instance.RefreshInspectionView(); } if (false != refreshOnScreenBreakpoints) textCanvas.BreakpointsUpdated(); #if DEBUG if (e.CurrentState == ExecutionStateChangedEventArgs.States.Debugging) { if (e.PreviousState == ExecutionStateChangedEventArgs.States.None) { List<DisassemblyEntry> instructions = new List<DisassemblyEntry>(); Solution.Current.ExecutionSession.PopulateInstructions(instructions); Disassembly.Instance.BindNewInstructionList(instructions); } } #endif textCanvas.Background = new SolidColorBrush(textCanvasBackground); scrollViewer.Background = new SolidColorBrush(scrollViewerBackground); CommandManager.InvalidateRequerySuggested(); // Refresh button states. }
System.Drawing.Point GetExecutionCursor(bool start) { System.Drawing.Point cursor = new System.Drawing.Point(); IExecutionSession session = Solution.Current.ExecutionSession; if (null != session) { CodeRange codeRange = new CodeRange(); if (session.GetExecutionCursor(ref codeRange)) { if (false != start) { cursor.X = codeRange.StartInclusive.CharNo - 1; cursor.Y = codeRange.StartInclusive.LineNo - 1; } else { cursor.X = codeRange.EndExclusive.CharNo - 1; cursor.Y = codeRange.EndExclusive.LineNo - 1; } } } return cursor; }