private string Get_Label_Description(string label) { if (this.labelGraph_.Enabled) { StringBuilder sb = new StringBuilder(); SortedSet <uint> labelDefs = this.labelGraph_.Get_Label_Def_Linenumbers(label); if (labelDefs.Count > 1) { sb.AppendLine(string.Empty); } foreach (uint id in labelDefs) { int lineNumber = LabelGraph.Get_Linenumber(id); string filename = Path.GetFileName(this.labelGraph_.Get_Filename(id)); string lineContent = (LabelGraph.Is_From_Main_File(id)) ? " :" + this.textBuffer_.CurrentSnapshot.GetLineFromLineNumber(lineNumber).GetText() : string.Empty; sb.AppendLine(AsmDudeToolsStatic.Cleanup(string.Format(AsmDudeToolsStatic.CultureUI, "Defined at LINE {0} ({1}){2}", lineNumber + 1, filename, lineContent))); } string result = sb.ToString(); return(result.TrimEnd(Environment.NewLine.ToCharArray())); } else { return("Label analysis is disabled"); } }
public void ExportGraph_GraphAndFileName_ReturnsCorrectLabelGraph() { IInterpreterGraph parent = Substitute.For <IInterpreterGraph>(); GraphHelper graphHelper = SetUpHelper(parent); graphHelper.SetASTRoot(GetAST()); parent.Function <Element>(Arg.Any <FunctionNode>(), Arg.Any <List <Object> >()).Returns(x => HandleFunctionNode(x)); parent.DispatchString(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns("File"); parent.DispatchGraph(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns(GetGraph()); List <int> src = new List <int> { 0, 1, 2 }; List <int> dst = new List <int> { 2, 1, 0 }; string[,] vertexLabels = new string[0, 3]; string[,] edgeLabels = new string[0, 3]; LabelGraph expected = new LabelGraph("File", src, dst, vertexLabels, edgeLabels, 3); LabelGraph result = graphHelper.ExportGraph(new ExportNode(new IdentifierExpression("", 0, 0), 0, 0)); result.Should().BeEquivalentTo(expected); }
public void Generate_SingleWithAdditionalLabels_() { List <int> srcList = new List <int>() { 1, 2 }; List <int> dstList = new List <int>() { 3, 4 }; string[,] vertexLabels = new string[, ] { { "nodeValue: 1", "nodeValue: 2", "nodeValue: 3", "nodeValue: 4" }, { "someLabelV: 1", "someLabelV: 2", "", "" } }; string[,] edgeLabels = new string[, ] { { "someLabelE: 1", "someLabelE: 2" } }; LabelGraph labelGraph = new LabelGraph("test2", srcList, dstList, vertexLabels, edgeLabels, 4); GmlGenerator gmlGenerator = new GmlGenerator(); string expected = expectedGmlStrings.Str2; string actual = gmlGenerator.Generate(labelGraph).Replace("\r", ""); expected.Should().BeEquivalentTo(actual); }
private string GetEdgeAsString(LabelGraph graph, int i) { StringBuilder sb = new StringBuilder($"\t{graph.SrcList[i]} -> {graph.DstList[i]} [label = \""); AddAdditionalLabels(sb, graph.EdgeLabels, i); sb.Append("\"];\n"); return(sb.ToString()); }
private string GetVertexString(LabelGraph graph, int i) { StringBuilder sb = new StringBuilder($"\t {i} [label = \""); AddAdditionalLabels(sb, graph.VertexLabels, i); sb.Append("\"];\n"); return(sb.ToString()); }
public CodeCompletionSource(ITextBuffer buffer, LabelGraph labelGraph, AsmSimulator asmSimulator) { this._buffer = buffer; this._labelGraph = labelGraph; this._icons = new Dictionary <AsmTokenType, ImageSource>(); this._asmDudeTools = AsmDudeTools.Instance; this._asmSimulator = asmSimulator; this.Load_Icons(); }
public string Generate(LabelGraph graph) { string s = ""; s += GetVerticesAsString(graph); s += "\n"; s += GetEdgesAsString(graph); return("digraph " + graph.FileName + " { \n" + s + "}\n"); }
public CodeCompletionSource(ITextBuffer buffer, LabelGraph labelGraph, AsmSimulator asmSimulator) { this.buffer_ = buffer ?? throw new ArgumentNullException(nameof(buffer)); this.labelGraph_ = labelGraph ?? throw new ArgumentNullException(nameof(labelGraph)); this.icons_ = new Dictionary <AsmTokenType, ImageSource>(); this.asmDudeTools_ = AsmDudeTools.Instance; this.asmSimulator_ = asmSimulator ?? throw new ArgumentNullException(nameof(asmSimulator)); this.Load_Icons(); }
private string GetVerticesAsString(LabelGraph graph) { string s = ""; for (int i = 0; i < graph.VertexCount; i++) { s += GetVertexString(graph, i); } return(s); }
public void Generate_SingleWithoutAdditionalLabels_DstSrcEvenNumber_() { LabelGraph labelGraph = GetStr1LabelGraph("test1"); GmlGenerator gmlGenerator = new GmlGenerator(); string expected = expectedGmlStrings.Str1; string actual = gmlGenerator.Generate(labelGraph).Replace("\r", ""); actual.Should().BeEquivalentTo(expected); }
private string GetVertexString(LabelGraph graph, int i) { StringBuilder sb = new StringBuilder(); sb.AppendLine("\tnode [ "); sb.AppendLine($"\t\tid {i}"); AddAdditionalVertexLabels(sb, graph, i); sb.AppendLine("\t]"); return(sb.ToString()); }
private string GetEdgesAsString(LabelGraph graph) { string s = ""; for (int i = 0; i < graph.SrcList.Count; i++) { s += GetEdgeAsString(graph, i); } return(s); }
private void AddAdditionalEdgeLabels(StringBuilder sb, LabelGraph graph, int i) { for (int row = 0; row < graph.EdgeLabels.GetLength(0); row++) { string label = graph.EdgeLabels[row, i]; if (label != "") { sb.AppendLine($"\t\t{label}"); } } }
private string GetEdgeAsString(LabelGraph graph, int i) { StringBuilder sb = new StringBuilder(); sb.AppendLine("\tedge [ "); sb.AppendLine($"\t\tsource {graph.SrcList[i]}"); sb.AppendLine($"\t\ttarget {graph.DstList[i]}"); AddAdditionalEdgeLabels(sb, graph, i); sb.AppendLine("\t]"); return(sb.ToString()); }
public IQuickInfoSource TryCreateQuickInfoSource(ITextBuffer buffer) { AsmQuickInfoSource sc() { LabelGraph labelGraph = AsmDudeToolsStatic.GetOrCreate_Label_Graph(buffer, this._aggregatorFactory, this._docFactory, this._contentService); AsmSimulator asmSimulator = AsmSimulator.GetOrCreate_AsmSimulator(buffer, this._aggregatorFactory); return(new AsmQuickInfoSource(buffer, this._aggregatorFactory, labelGraph, asmSimulator)); } return(buffer.Properties.GetOrCreateSingletonProperty(sc)); }
public AsmQuickInfoSource( ITextBuffer textBuffer, IBufferTagAggregatorFactoryService aggregatorFactory, LabelGraph labelGraph, AsmSimulator asmSimulator) { this.textBuffer_ = textBuffer ?? throw new ArgumentNullException(nameof(textBuffer)); this.aggregator_ = AsmDudeToolsStatic.GetOrCreate_Aggregator(textBuffer, aggregatorFactory); this.labelGraph_ = labelGraph ?? throw new ArgumentNullException(nameof(labelGraph)); this.asmSimulator_ = asmSimulator ?? throw new ArgumentNullException(nameof(asmSimulator)); this.asmDudeTools_ = AsmDudeTools.Instance; }
public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag { ITagger <T> sc() { LabelGraph labelGraph = AsmDudeToolsStatic.GetOrCreate_Label_Graph(buffer, this.aggregatorFactory_, this.docFactory_, this.contentService_); AsmSimulator asmSimulator = AsmSimulator.GetOrCreate_AsmSimulator(buffer, this.aggregatorFactory_); return(new SquigglesTagger(buffer, this.aggregatorFactory_, labelGraph, asmSimulator) as ITagger <T>); } return(buffer.Properties.GetOrCreateSingletonProperty(sc)); }
public AsmQuickInfoSource( ITextBuffer buffer, IBufferTagAggregatorFactoryService aggregatorFactory, LabelGraph labelGraph, AsmSimulator asmSimulator) { this._sourceBuffer = buffer; this._aggregator = AsmDudeToolsStatic.GetOrCreate_Aggregator(buffer, aggregatorFactory); this._labelGraph = labelGraph; this._asmSimulator = asmSimulator; this._asmDudeTools = AsmDudeTools.Instance; }
public ICompletionSource TryCreateCompletionSource(ITextBuffer buffer) { Contract.Requires(buffer != null); CodeCompletionSource sc() { LabelGraph labelGraph = AsmDudeToolsStatic.GetOrCreate_Label_Graph(buffer, this.aggregatorFactory_, this.docFactory_, this.contentService_); AsmSimulator asmSimulator = AsmSimulator.GetOrCreate_AsmSimulator(buffer, this.aggregatorFactory_); return(new CodeCompletionSource(buffer, labelGraph, asmSimulator)); } return(buffer.Properties.GetOrCreateSingletonProperty(sc)); }
//public IAsyncQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) //XYZZY NEW public IQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer) //XYZZY OLD { AsmDudeToolsStatic.Output_INFO(string.Format("{0}:TryCreateQuickInfoSource", this.ToString())); AsmQuickInfoSource sc() { LabelGraph labelGraph = AsmDudeToolsStatic.GetOrCreate_Label_Graph(textBuffer, this._aggregatorFactory, this._docFactory, this._contentService); AsmSimulator asmSimulator = AsmSimulator.GetOrCreate_AsmSimulator(textBuffer, this._aggregatorFactory); return(new AsmQuickInfoSource(textBuffer, this._aggregatorFactory, labelGraph, asmSimulator)); } return(textBuffer.Properties.GetOrCreateSingletonProperty(sc)); }
public void Generate_MultipleWithOne_AssertCorrectCount() { LabelGraph l1 = GetStr1LabelGraph("l1"); List <LabelGraph> labelGraphs = new List <LabelGraph>() { l1 }; GmlGenerator gmlGenerator = new GmlGenerator(); int expectedCount = 1; List <ExtensionalGraph> extensionalGraphs = gmlGenerator.Generate(labelGraphs); Assert.AreEqual(expectedCount, extensionalGraphs.Count); }
public void Generate_MultipleWithOne_() { LabelGraph l1 = GetStr1LabelGraph("l1"); List <LabelGraph> labelGraphs = new List <LabelGraph>() { l1 }; GmlGenerator gmlGenerator = new GmlGenerator(); string expected = expectedGmlStrings.Str1; List <ExtensionalGraph> extensionalGraphs = gmlGenerator.Generate(labelGraphs); expected.Should().BeEquivalentTo(extensionalGraphs[0].GraphString.Replace("\r", "")); }
public string Generate(LabelGraph graph) { string s = ""; s += GetVerticesAsString(graph); s += GetEdgesAsString(graph); StringBuilder sb = new StringBuilder(); sb.AppendLine("graph [ "); sb.AppendLine("\tdirected 1"); sb.Append(s); sb.AppendLine("]"); return(sb.ToString()); }
public void ExportGraph_GraphAndFileName_ReturnsCorrectLabelGraphWithLabels() { IInterpreterGraph parent = Substitute.For <IInterpreterGraph>(); GraphHelper graphHelper = SetUpHelper(parent); AST ast = GetAST(); graphHelper.SetASTRoot(ast); parent.Function <Element>(Arg.Any <FunctionNode>(), Arg.Any <List <Object> >()).Returns(new Element(5)); parent.DispatchString(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns("File"); parent.DispatchGraph(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns(GetGraph()); parent.DispatchFunction(Arg.Any <IdentifierExpression>(), Arg.Any <List <Object> >()).Returns(new Function(0)); parent.DispatchFunction(Arg.Any <FunctionCallExpression>(), Arg.Any <List <Object> >()).Returns(new Function(1)); parent.Function <string>(ast.Functions[0], Arg.Any <List <Object> >()).Returns("a"); parent.Function <string>(ast.Functions[1], Arg.Any <List <Object> >()).Returns("b"); List <int> src = new List <int> { 0, 0, 0 }; List <int> dst = new List <int> { 0, 0, 0 }; string[,] vertexLabels = new string[, ] { { "a", "a", "a" }, { "b", "b", "b" } }; string[,] edgeLabels = new string[, ] { { "a", "a", "a" } }; LabelGraph expected = new LabelGraph("File", src, dst, vertexLabels, edgeLabels, 3); IdentifierExpression identifier = new IdentifierExpression("", 0, 0); FunctionCallExpression functionCall = new FunctionCallExpression("", null, 0, 0); ExportNode node = new ExportNode(identifier, identifier, new List <ExpressionNode>() { identifier, functionCall }, new List <ExpressionNode>() { identifier }, 0, 0); LabelGraph result = graphHelper.ExportGraph(node); result.Should().BeEquivalentTo(expected); }
private TextBlock Label_Clash_Tool_Tip_Content(string label) { TextBlock textBlock = new TextBlock(); try { textBlock.Inlines.Add(new Run("Label Clash:" + Environment.NewLine) { FontWeight = FontWeights.Bold, Foreground = this.foreground_, }); StringBuilder sb = new StringBuilder(); foreach (uint id in this.labelGraph_.Get_Label_Def_Linenumbers(label)) { int lineNumber = LabelGraph.Get_Linenumber(id); string filename = Path.GetFileName(this.labelGraph_.Get_Filename(id)); string lineContent; if (LabelGraph.Is_From_Main_File(id)) { lineContent = " :" + this.sourceBuffer_.CurrentSnapshot.GetLineFromLineNumber(lineNumber).GetText(); } else { lineContent = string.Empty; } sb.AppendLine(AsmDudeToolsStatic.Cleanup(string.Format(AsmDudeToolsStatic.CultureUI, "Defined at LINE {0} ({1}){2}", lineNumber + 1, filename, lineContent))); } string msg = sb.ToString().TrimEnd(Environment.NewLine.ToCharArray()); textBlock.Inlines.Add(new Run(msg) { Foreground = this.foreground_, }); } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:labelClashToolTipContent; e={1}", this.ToString(), e.ToString())); } return(textBlock); }
internal SquigglesTagger( ITextBuffer buffer, IBufferTagAggregatorFactoryService aggregatorFactory, LabelGraph labelGraph, AsmSimulator asmSimulator) { //AsmDudeToolsStatic.Output_INFO("SquigglesTagger: constructor"); this.sourceBuffer_ = buffer ?? throw new ArgumentNullException(nameof(buffer)); this.aggregator_ = AsmDudeToolsStatic.GetOrCreate_Aggregator(buffer, aggregatorFactory); this.errorListProvider_ = AsmDudeTools.Instance.Error_List_Provider; this.foreground_ = AsmDudeToolsStatic.GetFontColor(); this.labelGraph_ = labelGraph ?? throw new ArgumentNullException(nameof(labelGraph)); if (this.labelGraph_.Enabled) { this.labelGraph_.Reset_Done_Event += (o, i) => { this.Update_Squiggles_Tasks_Async().ConfigureAwait(true); this.Update_Error_Tasks_Labels_Async().ConfigureAwait(true); }; this.labelGraph_.Reset(); } this.asmSimulator_ = asmSimulator ?? throw new ArgumentNullException(nameof(asmSimulator)); if (this.asmSimulator_.Enabled) { this.asmSimulator_.Line_Updated_Event += (o, e) => { //AsmDudeToolsStatic.Output_INFO("SquigglesTagger:Handling asmSimulator_.Line_Updated_Event: event from " + o + ". Line " + e.LineNumber + ": "+e.Message); this.Update_Squiggles_Tasks_Async(e.LineNumber).ConfigureAwait(true); this.Update_Error_Task_AsmSimAsync(e.LineNumber, e.Message).ConfigureAwait(true); }; this.asmSimulator_.Reset_Done_Event += (o, e) => { AsmDudeToolsStatic.Output_INFO("SquigglesTagger:Handling asmSimulator_.Reset_Done_Event: event from " + o); //this.Update_Error_Tasks_AsmSim_Async(); }; this.asmSimulator_.Reset(); } }
private string Get_Label_Def_Description(string full_Qualified_Label, string label) { if (!this.labelGraph_.Enabled) { return("Label analysis is disabled"); } SortedSet <uint> usage = this.labelGraph_.Label_Used_At_Info(full_Qualified_Label, label); if (usage.Count > 0) { StringBuilder sb = new StringBuilder(); if (usage.Count > 1) { sb.AppendLine(string.Empty); // add a newline if multiple usage occurances exist } foreach (uint id in usage) { int lineNumber = LabelGraph.Get_Linenumber(id); string filename = Path.GetFileName(this.labelGraph_.Get_Filename(id)); string lineContent; if (LabelGraph.Is_From_Main_File(id)) { lineContent = " :" + this.textBuffer_.CurrentSnapshot.GetLineFromLineNumber(lineNumber).GetText(); } else { lineContent = string.Empty; } sb.AppendLine(AsmDudeToolsStatic.Cleanup(string.Format(AsmDudeToolsStatic.CultureUI, "Used at LINE {0} ({1}){2}", lineNumber + 1, filename, lineContent))); //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:getLabelDefDescription; sb=\"{1}\"", this.ToString(), sb.ToString())); } string result = sb.ToString(); return(result.TrimEnd(Environment.NewLine.ToCharArray())); } else { return("Not used"); } }
internal SquigglesTagger( ITextBuffer buffer, IBufferTagAggregatorFactoryService aggregatorFactory, LabelGraph labelGraph, AsmSimulator asmSimulator) { //AsmDudeToolsStatic.Output_INFO("SquigglesTagger: constructor"); this._sourceBuffer = buffer; this._aggregator = AsmDudeToolsStatic.GetOrCreate_Aggregator(buffer, aggregatorFactory); this._errorListProvider = AsmDudeTools.Instance.Error_List_Provider; this._foreground = AsmDudeToolsStatic.GetFontColor(); this._labelGraph = labelGraph; if (this._labelGraph.Enabled) { this._labelGraph.Reset_Done_Event += (o, i) => { this.Update_Squiggles_Tasks_Async().ConfigureAwait(false); this.Update_Error_Tasks_Labels_Async().ConfigureAwait(false); }; this._labelGraph.Reset(); } this._asmSimulator = asmSimulator; if (this._asmSimulator.Enabled) { this._asmSimulator.Line_Updated_Event += (o, e) => { //AsmDudeToolsStatic.Output_INFO("SquigglesTagger:Handling _asmSimulator.Line_Updated_Event: event from " + o + ". Line " + e.LineNumber + ": "+e.Message); this.Update_Squiggles_Tasks_Async(e.LineNumber).ConfigureAwait(false); this.Update_Error_Task_AsmSimAsync(e.LineNumber, e.Message).ConfigureAwait(false); }; this._asmSimulator.Reset_Done_Event += (o, e) => { AsmDudeToolsStatic.Output_INFO("SquigglesTagger:Handling _asmSimulator.Reset_Done_Event: event from " + o); //this.Update_Error_Tasks_AsmSim_Async(); }; this._asmSimulator.Reset(); } }
private async System.Threading.Tasks.Task Update_Error_Tasks_Labels_Async() { if (!this.labelGraph_.Enabled) { return; } await System.Threading.Tasks.Task.Run(() => { lock (this.updateLock_) { try { #region Update Error Tasks if (Settings.Default.IntelliSense_Show_Clashing_Labels || Settings.Default.IntelliSense_Show_Undefined_Labels || Settings.Default.IntelliSense_Show_Undefined_Includes) { TaskProvider.TaskCollection errorTasks = this.errorListProvider_.Tasks; bool errorListNeedsRefresh = false; #region Remove stale error tasks from the error list for (int i = errorTasks.Count - 1; i >= 0; --i) { AsmMessageEnum subCategory = (AsmMessageEnum)errorTasks[i].SubcategoryIndex; if ((subCategory == AsmMessageEnum.LABEL_UNDEFINED) || (subCategory == AsmMessageEnum.LABEL_CLASH) || (subCategory == AsmMessageEnum.INCLUDE_UNDEFINED)) { errorTasks.RemoveAt(i); errorListNeedsRefresh = true; } } #endregion if (Settings.Default.IntelliSense_Show_Clashing_Labels) { foreach ((uint key, string value) in this.labelGraph_.Label_Clashes) // TODO Label_Clashes does not return the classes in any particular order, { string label = value; int lineNumber = LabelGraph.Get_Linenumber(key); //TODO retrieve the lineContent of the correct buffer! string lineContent = this.sourceBuffer_.CurrentSnapshot.GetLineFromLineNumber(lineNumber).GetText(); ErrorTask errorTask = new ErrorTask() { SubcategoryIndex = (int)AsmMessageEnum.LABEL_CLASH, Line = LabelGraph.Get_Linenumber(key), Column = Get_Keyword_Begin_End(lineContent, label), Text = "Label Clash: \"" + label + "\"", ErrorCategory = TaskErrorCategory.Warning, Document = this.labelGraph_.Get_Filename(key), }; errorTask.Navigate += AsmDudeToolsStatic.Error_Task_Navigate_Handler; errorTasks.Add(errorTask); errorListNeedsRefresh = true; } } if (Settings.Default.IntelliSense_Show_Undefined_Labels) { foreach ((uint key, string value) in this.labelGraph_.Undefined_Labels) { string label = value; int lineNumber = LabelGraph.Get_Linenumber(key); //TODO retrieve the lineContent of the correct buffer! string lineContent = this.sourceBuffer_.CurrentSnapshot.GetLineFromLineNumber(lineNumber).GetText(); ErrorTask errorTask = new ErrorTask() { SubcategoryIndex = (int)AsmMessageEnum.LABEL_UNDEFINED, Line = lineNumber, Column = Get_Keyword_Begin_End(lineContent, label), Text = "Undefined Label: \"" + label + "\"", ErrorCategory = TaskErrorCategory.Warning, Document = this.labelGraph_.Get_Filename(key), }; errorTask.Navigate += AsmDudeToolsStatic.Error_Task_Navigate_Handler; errorTasks.Add(errorTask); errorListNeedsRefresh = true; } } if (Settings.Default.IntelliSense_Show_Undefined_Includes) { foreach ((string include_Filename, string path, string source_Filename, int lineNumber)entry in this.labelGraph_.Undefined_Includes) { string include = entry.include_Filename; int lineNumber = entry.lineNumber; //TODO retrieve the lineContent of the correct buffer! string lineContent = this.sourceBuffer_.CurrentSnapshot.GetLineFromLineNumber(lineNumber).GetText(); ErrorTask errorTask = new ErrorTask() { SubcategoryIndex = (int)AsmMessageEnum.INCLUDE_UNDEFINED, Line = lineNumber, Column = Get_Keyword_Begin_End(lineContent, include), Text = "Could not resolve include \"" + include + "\" at line " + (lineNumber + 1) + " in file \"" + entry.source_Filename + "\"", ErrorCategory = TaskErrorCategory.Warning, Document = entry.source_Filename, }; errorTask.Navigate += AsmDudeToolsStatic.Error_Task_Navigate_Handler; errorTasks.Add(errorTask); errorListNeedsRefresh = true; } } if (errorListNeedsRefresh) { this.errorListProvider_.Refresh(); //this._errorListProvider.Show(); // do not use BringToFront since that will select the error window. } } #endregion Update Error Tasks } catch (Exception e) { AsmDudeToolsStatic.Output_ERROR(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:Update_Error_Tasks_Labels_Async; e={1}", this.ToString(), e.ToString())); } } }).ConfigureAwait(false); }