public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans) { DateTime time1 = DateTime.Now; if (spans.Count == 0) { //there is no content in the buffer yield break; } foreach (SnapshotSpan curSpan in spans) { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); string line = containingLine.GetText().ToUpper(); IList <(int, int, bool)> pos = AsmSourceTools.SplitIntoKeywordPos(line); int offset = containingLine.Start.Position; int nKeywords = pos.Count; for (int k = 0; k < nKeywords; k++) { string asmToken = Keyword(pos[k], line); AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type(asmToken); if ((keywordType == AsmTokenType.Mnemonic) || (keywordType == AsmTokenType.Jump)) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), new AsmTokenTag(keywordType))); } } } AsmDudeToolsStatic.Print_Speed_Warning(time1, "DebugTokenTagger"); }
private static string GetClassFromTokenType(AsmTokenType tokenType) { switch (tokenType) { case AsmTokenType.COLON: case AsmTokenType.COMMA: case AsmTokenType.OPENINGPAR: case AsmTokenType.CLOSINGPAR: case AsmTokenType.OPENINGBRA: case AsmTokenType.CLOSINGBRA: return("t_separator"); case AsmTokenType.PLUS: case AsmTokenType.MINUS: case AsmTokenType.MULTIPLY: return("t_operator"); case AsmTokenType.DOLLAR: return("t_dollar"); case AsmTokenType.COMMENT: return("t_comment"); case AsmTokenType.STRING: return("t_string"); case AsmTokenType.SYMBOL: return("t_symbol"); case AsmTokenType.OPCODE: return("t_opcode"); case AsmTokenType.REGISTER: case AsmTokenType.FLAGS: case AsmTokenType.REGISTER16: return("t_register"); case AsmTokenType.FLAGCONDITION: return("t_flagcondition"); case AsmTokenType.DIRECTIVE: return("t_directive"); case AsmTokenType.NUMBER: return("t_number"); case AsmTokenType.BIT: case AsmTokenType.INTERRUPTMODE: return("t_numenum"); case AsmTokenType.WHITESPACE: return("t_whitespace"); default: return(null); } }
/// <summary> /// Creates a new <seealso cref="AsmToken"/> instance /// </summary> /// <param name="token">The "name" for the token</param> /// <param name="type">The type of token this token will be</param> /// <param name="validNextTokens">Which token types are allowed to be after this token</param> public AsmToken(string token, AsmTokenType type, params AsmTokenType[] validNextTokens) { this.token = token; this.type = type; this.validNextTokens = validNextTokens is null || validNextTokens.Length == 0 ? null : validNextTokens; originalLine = -1; sourceFile = null; }
private IEnumerable <Completion> Selected_Completions(bool useCapitals, ISet <AsmTokenType> selectedTypes, bool addSpecialKeywords) { SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer()); //Add the completions of AsmDude directives (such as code folding directives) #region if (addSpecialKeywords && Settings.Default.CodeFolding_On) { this.icons_.TryGetValue(AsmTokenType.Directive, out ImageSource imageSource); { string insertionText = Settings.Default.CodeFolding_BeginTag; //the characters that start the outlining region string displayTextFull = insertionText + " - keyword to start code folding"; string displayText = Truncat(displayTextFull); completions.Add(new Completion(displayText, insertionText, displayTextFull, imageSource, string.Empty)); } { string insertionText = Settings.Default.CodeFolding_EndTag; //the characters that end the outlining region string displayTextFull = insertionText + " - keyword to end code folding"; string displayText = Truncat(displayTextFull); completions.Add(new Completion(displayText, insertionText, displayTextFull, imageSource, string.Empty)); } } #endregion AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler; #region Add completions if (selectedTypes.Contains(AsmTokenType.Mnemonic)) { this.icons_.TryGetValue(AsmTokenType.Mnemonic, out ImageSource imageSource); foreach (Mnemonic mnemonic in this.asmDudeTools_.Get_Allowed_Mnemonics()) { string keyword_upcase = mnemonic.ToString(); string description = this.asmDudeTools_.Mnemonic_Store.GetSignatures(mnemonic).First().Documentation; string insertionText = useCapitals ? keyword_upcase : keyword_upcase.ToLowerInvariant(); string archStr = ArchTools.ToString(this.asmDudeTools_.Mnemonic_Store.GetArch(mnemonic)); string descriptionStr = this.asmDudeTools_.Mnemonic_Store.GetDescription(mnemonic); descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr; string displayText = Truncat(keyword_upcase + archStr + descriptionStr); //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; completions.Add(new Completion(displayText, insertionText, description, imageSource, string.Empty)); } } //Add the completions that are defined in the xml file foreach (string keyword_upcase in this.asmDudeTools_.Get_Keywords()) { AsmTokenType type = this.asmDudeTools_.Get_Token_Type_Intel(keyword_upcase); if (selectedTypes.Contains(type)) { Arch arch = Arch.ARCH_NONE; bool selected = true; if (type == AsmTokenType.Directive) { AssemblerEnum assembler = this.asmDudeTools_.Get_Assembler(keyword_upcase); if (assembler.HasFlag(AssemblerEnum.MASM)) { if (!usedAssember.HasFlag(AssemblerEnum.MASM)) { selected = false; } } else if (assembler.HasFlag(AssemblerEnum.NASM_INTEL) || assembler.HasFlag(AssemblerEnum.NASM_ATT)) { if (!usedAssember.HasFlag(AssemblerEnum.NASM_INTEL)) { selected = false; } } } else { arch = this.asmDudeTools_.Get_Architecture(keyword_upcase); selected = AsmDudeToolsStatic.Is_Arch_Switched_On(arch); } //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:Selected_Completions; keyword=" + keyword + "; arch=" + arch + "; selected=" + selected); if (selected) { //Debug.WriteLine("INFO: CompletionSource:AugmentCompletionSession: name keyword \"" + entry.Key + "\""); // by default, the entry.Key is with capitals string insertionText = useCapitals ? keyword_upcase : keyword_upcase.ToLowerInvariant(); string archStr = (arch == Arch.ARCH_NONE) ? string.Empty : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this.asmDudeTools_.Get_Description(keyword_upcase); descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr; string displayTextFull = keyword_upcase + archStr + descriptionStr; string displayText = Truncat(displayTextFull); //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; this.icons_.TryGetValue(type, out ImageSource imageSource); completions.Add(new Completion(displayText, insertionText, displayTextFull, imageSource, string.Empty)); } } } #endregion return(completions); }
private IEnumerable <Completion> Mnemonic_Operand_Completions(bool useCapitals, ISet <AsmSignatureEnum> allowedOperands, int lineNumber) { bool use_AsmSim_In_Code_Completion = this.asmSimulator_.Enabled && Settings.Default.AsmSim_Show_Register_In_Code_Completion; bool att_Syntax = AsmDudeToolsStatic.Used_Assembler == AssemblerEnum.NASM_ATT; SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer()); foreach (Rn regName in this.asmDudeTools_.Get_Allowed_Registers()) { string additionalInfo = null; if (AsmSignatureTools.Is_Allowed_Reg(regName, allowedOperands)) { string keyword = regName.ToString(); if (use_AsmSim_In_Code_Completion && this.asmSimulator_.Tools.StateConfig.IsRegOn(RegisterTools.Get64BitsRegister(regName))) { (string value, bool bussy) = this.asmSimulator_.Get_Register_Value(regName, lineNumber, true, false, false, AsmSourceTools.ParseNumeration(Settings.Default.AsmSim_Show_Register_In_Code_Completion_Numeration, false)); if (!bussy) { additionalInfo = value; AsmDudeToolsStatic.Output_INFO("AsmCompletionSource:Mnemonic_Operand_Completions; register " + keyword + " is selected and has value " + additionalInfo); } } if (att_Syntax) { keyword = "%" + keyword; } Arch arch = RegisterTools.GetArch(regName); //AsmDudeToolsStatic.Output_INFO("AsmCompletionSource:AugmentCompletionSession: keyword \"" + keyword + "\" is added to the completions list"); // by default, the entry.Key is with capitals string insertionText = useCapitals ? keyword : keyword.ToLowerInvariant(); string archStr = (arch == Arch.ARCH_NONE) ? string.Empty : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this.asmDudeTools_.Get_Description(keyword); descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr; string displayText = Truncat(keyword + archStr + descriptionStr); this.icons_.TryGetValue(AsmTokenType.Register, out ImageSource imageSource); completions.Add(new Completion(displayText, insertionText, additionalInfo, imageSource, string.Empty)); } } foreach (string keyword in this.asmDudeTools_.Get_Keywords()) { AsmTokenType type = this.asmDudeTools_.Get_Token_Type_Intel(keyword); Arch arch = this.asmDudeTools_.Get_Architecture(keyword); string keyword2 = keyword; bool selected = true; //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:Mnemonic_Operand_Completions; keyword=" + keyword +"; selected="+selected +"; arch="+arch); string additionalInfo = null; switch (type) { case AsmTokenType.Misc: { if (!AsmSignatureTools.Is_Allowed_Misc(keyword, allowedOperands)) { selected = false; } break; } default: { selected = false; break; } } if (selected) { //AsmDudeToolsStatic.Output_INFO("AsmCompletionSource:AugmentCompletionSession: keyword \"" + keyword + "\" is added to the completions list"); // by default, the entry.Key is with capitals string insertionText = useCapitals ? keyword2 : keyword2.ToLowerInvariant(); string archStr = (arch == Arch.ARCH_NONE) ? string.Empty : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this.asmDudeTools_.Get_Description(keyword); descriptionStr = (string.IsNullOrEmpty(descriptionStr)) ? string.Empty : " - " + descriptionStr; string displayText = Truncat(keyword2 + archStr + descriptionStr); this.icons_.TryGetValue(type, out ImageSource imageSource); completions.Add(new Completion(displayText, insertionText, additionalInfo, imageSource, string.Empty)); } } return(completions); }
private static string GetClassFromTokenType(AsmTokenType tokenType) { switch (tokenType) { case AsmTokenType.COLON: case AsmTokenType.COMMA: case AsmTokenType.OPENINGPAR: case AsmTokenType.CLOSINGPAR: case AsmTokenType.OPENINGBRA: case AsmTokenType.CLOSINGBRA: return "t_separator"; case AsmTokenType.PLUS: case AsmTokenType.MINUS: case AsmTokenType.MULTIPLY: return "t_operator"; case AsmTokenType.DOLLAR: return "t_dollar"; case AsmTokenType.COMMENT: return "t_comment"; case AsmTokenType.STRING: return "t_string"; case AsmTokenType.SYMBOL: return "t_symbol"; case AsmTokenType.OPCODE: return "t_opcode"; case AsmTokenType.REGISTER: case AsmTokenType.FLAGS: case AsmTokenType.REGISTER16: return "t_register"; case AsmTokenType.FLAGCONDITION: return "t_flagcondition"; case AsmTokenType.DIRECTIVE: return "t_directive"; case AsmTokenType.NUMBER: return "t_number"; case AsmTokenType.BIT: case AsmTokenType.INTERRUPTMODE: return "t_numenum"; case AsmTokenType.WHITESPACE: return "t_whitespace"; default: return null; } }
public IEnumerable <ITagSpan <AsmTokenTag> > GetTags_NEW(NormalizedSnapshotSpanCollection spans) { DateTime time1 = DateTime.Now; if (spans.Count == 0) { //there is no content in the buffer yield break; } foreach (SnapshotSpan curSpan in spans) { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); string line_upcase = containingLine.GetText().ToUpper(CultureInfo.InvariantCulture); int offset = containingLine.Start.Position; IEnumerator <(int beginPos, int length, bool isLabel)> enumerator = AsmSourceTools.SplitIntoKeywordPos(line_upcase).GetEnumerator(); bool needToAdvance = false; bool hasNext = enumerator.MoveNext(); if (!hasNext) { break; } (int beginPos, int length, bool isLabel)prev = (0, 0, false); (int beginPos, int length, bool isLabel)current = enumerator.Current; while (hasNext) { string asmToken = AsmSourceTools.Keyword(current, line_upcase); // keyword starts with a remark char if (AsmSourceTools.IsRemarkChar(asmToken[0])) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.remark_)); continue; } // keyword k is a label definition if (current.isLabel) { SnapshotSpan labelDefSpan = NasmIntelTokenTagger.New_Span(current, offset, curSpan); //AsmDudeToolsStatic.Output_INFO("MasmTokenTagger:GetTags: found label " + asmToken +" at line "+containingLine.LineNumber); if (asmToken.Equals("@@", StringComparison.Ordinal)) { // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc. } else { yield return(new TagSpan <AsmTokenTag>(labelDefSpan, this.Make_AsmTokenTag_LabelDef(containingLine.LineNumber))); } continue; } AsmTokenType keywordType = this.asmDudeTools_.Get_Token_Type_Intel(asmToken); switch (keywordType) { case AsmTokenType.Jump: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.jump_)); { // go to the next word if (needToAdvance) { hasNext = enumerator.MoveNext(); prev = current; current = enumerator.Current; } needToAdvance = true; } string asmToken2 = AsmSourceTools.Keyword(current, line_upcase); switch (asmToken2) { case "$": case "@B": case "@F": { // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc. break; } case "WORD": case "DWORD": case "QWORD": case "SHORT": case "NEAR": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.misc_)); { // go to the next word if (needToAdvance) { hasNext = enumerator.MoveNext(); prev = current; current = enumerator.Current; } needToAdvance = true; } switch (AsmSourceTools.Keyword(current, line_upcase)) { case "$": case "@B": case "@F": { // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc. break; } case "PTR": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.misc_)); break; } default: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber))); break; } } break; } default: { if (RegisterTools.IsRegister(asmToken2)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.register_)); } else { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber))); } break; } } break; } case AsmTokenType.UNKNOWN: // asmToken is not a known keyword, check if it is numerical { //if (AsmTools.AsmSourceTools.Evaluate_Constant(asmToken, true).valid) if (AsmSourceTools.Parse_Constant(asmToken, true).valid) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.constant_)); } else if (asmToken.StartsWith("\"", StringComparison.Ordinal) && asmToken.EndsWith("\"", StringComparison.Ordinal)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.constant_)); } else { // do one word look back; see whether we can understand the current unknown word string previousKeyword = AsmSourceTools.Keyword(prev, line_upcase); switch (previousKeyword) { case "ALIAS": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.labelDef_)); break; } default: { break; } } // do one word lookahead; see whether we can understand the current unknown word // go to the next word needToAdvance = false; if (enumerator.MoveNext()) { prev = current; current = enumerator.Current; string nextKeyword = AsmSourceTools.Keyword(current, line_upcase); switch (nextKeyword) { case "PROC": case "EQU": case "LABEL": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(prev, offset, curSpan), this.labelDef_)); yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.directive_)); break; } case "PROTO": { // a proto is considered a label definition but it should not clash with other label definitions yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(prev, offset, curSpan), this.labelDef_PROTO_)); yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.directive_)); break; } default: break; } } else { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.UNKNOWN_)); } } break; } case AsmTokenType.Directive: { AssemblerEnum assember = this.asmDudeTools_.Get_Assembler(asmToken); if (assember.HasFlag(AssemblerEnum.MASM)) // this MASM token-tagger only tags MASM directives { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.directive_)); if (asmToken.Equals("INVOKE", StringComparison.Ordinal)) { { // go to the next word if (needToAdvance) { hasNext = enumerator.MoveNext(); prev = current; current = enumerator.Current; } needToAdvance = true; } //string asmToken2 = NasmTokenTagger.Keyword(current, line); yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber))); } } break; } default: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(current, offset, curSpan), new AsmTokenTag(keywordType))); break; } } { // go to the next word if (needToAdvance) { hasNext = enumerator.MoveNext(); prev = current; current = enumerator.Current; } needToAdvance = true; } } } AsmDudeToolsStatic.Print_Speed_Warning(time1, "MasmTokenTagger"); }
private void Handle(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; DateTime time1 = DateTime.Now; ITextSnapshot snapshot = this._sourceBuffer.CurrentSnapshot; var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot); if (triggerPoint == null) { AsmDudeToolsStatic.Output_WARNING("AsmQuickInfoSource:AugmentQuickInfoSession: trigger point is null"); return; } Brush foreground = AsmDudeToolsStatic.Get_Font_Color(); var enumerator = this._aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)).GetEnumerator(); if (enumerator.MoveNext()) { var asmTokenTag = enumerator.Current; var enumerator2 = asmTokenTag.Span.GetSpans(this._sourceBuffer).GetEnumerator(); if (enumerator2.MoveNext()) { SnapshotSpan tagSpan = enumerator2.Current; string keyword = tagSpan.GetText(); string keywordUpper = keyword.ToUpper(); #region Tests // TODO: multiple tags at the provided triggerPoint is most likely the result of a bug in AsmTokenTagger, but it seems harmless... if (false) { if (enumerator.MoveNext()) { var asmTokenTagX = enumerator.Current; var enumeratorX = asmTokenTagX.Span.GetSpans(this._sourceBuffer).GetEnumerator(); enumeratorX.MoveNext(); AsmDudeToolsStatic.Output_WARNING(string.Format("{0}:AugmentQuickInfoSession. current keyword " + keyword + ": but span has more than one tag! next tag=\"{1}\"", ToString(), enumeratorX.Current.GetText())); } } #endregion //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: keyword=\""+ keyword + "\"; type=" + asmTokenTag.Tag.type +"; file="+AsmDudeToolsStatic.GetFileName(session.TextView.TextBuffer)); applicableToSpan = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeInclusive); TextBlock description = null; AsmTokenType type = asmTokenTag.Tag.Type; switch (type) { case AsmTokenType.Misc: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Keyword ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Misc)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.Directive: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Directive ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Directive)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.Register: { int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan); if (keywordUpper.StartsWith("%")) { keywordUpper = keywordUpper.Substring(1); // remove the preceding % in AT&T syntax } Rn reg = RegisterTools.ParseRn(keywordUpper, true); if (this._asmDudeTools.RegisterSwitchedOn(reg)) { var registerTooltipWindow = new RegisterTooltipWindow(foreground); registerTooltipWindow.SetDescription(reg, this._asmDudeTools); registerTooltipWindow.SetAsmSim(this._asmSimulator, reg, lineNumber, true); quickInfoContent.Add(registerTooltipWindow); } break; } case AsmTokenType.Mnemonic: case AsmTokenType.Jump: { int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan); Mnemonic mnemonic = AsmSourceTools.ParseMnemonic_Att(keywordUpper, true); if (this._asmDudeTools.MnemonicSwitchedOn(mnemonic)) { var instructionTooltipWindow = new InstructionTooltipWindow(foreground) { Session = session // set the owner of this windows such that we can manually close this window }; instructionTooltipWindow.SetDescription(mnemonic, this._asmDudeTools); instructionTooltipWindow.SetPerformanceInfo(mnemonic, this._asmDudeTools, false); instructionTooltipWindow.SetAsmSim(this._asmSimulator, lineNumber, true); quickInfoContent.Add(instructionTooltipWindow); } break; } case AsmTokenType.Label: { string label = keyword; string labelPrefix = asmTokenTag.Tag.Misc; string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(labelPrefix, label, AsmDudeToolsStatic.Used_Assembler); description = new TextBlock(); description.Inlines.Add(Make_Run1("Label ", foreground)); description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label)))); string descr = Get_Label_Description(full_Qualified_Label); if (descr.Length == 0) { descr = Get_Label_Description(label); } if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.LabelDef: { string label = keyword; string extra_Tag_Info = asmTokenTag.Tag.Misc; string full_Qualified_Label; if ((extra_Tag_Info != null) && extra_Tag_Info.Equals(AsmTokenTag.MISC_KEYWORD_PROTO)) { full_Qualified_Label = label; } else { full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(extra_Tag_Info, label, AsmDudeToolsStatic.Used_Assembler); } AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: found label def " + full_Qualified_Label); description = new TextBlock(); description.Inlines.Add(Make_Run1("Label ", foreground)); description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label)))); string descr = Get_Label_Def_Description(full_Qualified_Label, label); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.Constant: { description = new TextBlock(); description.Inlines.Add(Make_Run1("Constant ", foreground)); var(Valid, Value, NBits) = AsmSourceTools.Evaluate_Constant(keyword); string constantStr = (Valid) ? Value + "d = " + Value.ToString("X") + "h = " + AsmSourceTools.ToStringBin(Value, NBits) + "b" : keyword; description.Inlines.Add(Make_Run2(constantStr, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Constant)))); break; } case AsmTokenType.UserDefined1: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 1: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined1)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.UserDefined2: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 2: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined2)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } case AsmTokenType.UserDefined3: { description = new TextBlock(); description.Inlines.Add(Make_Run1("User defined 3: ", foreground)); description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined3)))); string descr = this._asmDudeTools.Get_Description(keywordUpper); if (descr.Length > 0) { if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2)) { descr = "\n" + descr; } description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips)) { Foreground = foreground }); } break; } default: //description = new TextBlock(); //description.Inlines.Add(makeRun1("Unused tagType " + asmTokenTag.Tag.type)); break; } if (description != null) { description.FontSize = AsmDudeToolsStatic.Get_Font_Size() + 2; description.FontFamily = AsmDudeToolsStatic.Get_Font_Type(); //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily)); quickInfoContent.Add(description); } } } //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: applicableToSpan=\"" + applicableToSpan + "\"; quickInfoContent,Count=" + quickInfoContent.Count); AsmDudeToolsStatic.Print_Speed_Warning(time1, "QuickInfo"); }
public AsmTokenTag(AsmTokenType type) { this.Type = type; }
public AsmToken(string asmLine, AsmToken leadingWhitespaceToken, AsmTokenType type, int startIndex, int endIndex) : this(asmLine, leadingWhitespaceToken, type, startIndex, endIndex, null) { }
public AsmToken(string asmLine, AsmToken leadingWhitespaceToken, AsmTokenType type, int startIndex, int endIndex, object value) { this.asmLine = asmLine; this.LeadingWhiteSpace = leadingWhitespaceToken; Type = type; StartIndex = startIndex; EndIndex = endIndex; Value = value; }
public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans) { DateTime time1 = DateTime.Now; if (spans.Count == 0) { //there is no content in the buffer yield break; } foreach (SnapshotSpan curSpan in spans) { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); string line_upcase = containingLine.GetText().ToUpperInvariant(); List <(int beginPos, int length, bool isLabel)> pos = new List <(int beginPos, int length, bool isLabel)>(AsmSourceTools.SplitIntoKeywordPos(line_upcase)); int offset = containingLine.Start.Position; int nKeywords = pos.Count; #region Check if the current line is a line of source code if (IsSourceCode(line_upcase, pos)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span((0, line_upcase.Length, false), offset, curSpan), this.remark_)); continue; // go to the next line } #endregion for (int k = 0; k < nKeywords; k++) { string asmToken = AsmSourceTools.Keyword(pos[k], line_upcase); // keyword starts with a remark char if (AsmSourceTools.IsRemarkChar(asmToken[0])) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.remark_)); continue; } // keyword k is a label definition if (pos[k].isLabel) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.labelDef_)); continue; } AsmTokenType keywordType = this.asmDudeTools_.Get_Token_Type_Att(asmToken); switch (keywordType) { case AsmTokenType.Jump: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.jump_)); k++; // goto the next word if (k == nKeywords) { break; // there are no next words } string asmToken2 = AsmSourceTools.Keyword(pos[k], line_upcase); switch (asmToken2) { case "WORD": case "DWORD": case "QWORD": case "SHORT": case "NEAR": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.misc_)); k++; if (k == nKeywords) { break; } string asmToken3 = AsmSourceTools.Keyword(pos[k], line_upcase); switch (asmToken3) { case "PTR": { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this.misc_)); break; } yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.label_)); break; } break; } default: { if (RegisterTools.IsRegister(asmToken2)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.register_)); } else if (AsmSourceTools.Evaluate_Constant(asmToken2, true).valid) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_)); } else { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.label_)); } break; } } break; } case AsmTokenType.UNKNOWN: // asmToken is not a known keyword, check if it is numerical { if (AsmSourceTools.Evaluate_Constant(asmToken, true).valid) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_)); } else if (asmToken.StartsWith("$", StringComparison.Ordinal)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_)); } else if (asmToken.StartsWith("\"", StringComparison.Ordinal) && asmToken.EndsWith("\"", StringComparison.Ordinal)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.constant_)); } else { //yield return new TagSpan<AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._UNKNOWN); } break; } case AsmTokenType.Directive: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.directive_)); break; } case AsmTokenType.Mnemonic: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.mnemonic_)); break; } case AsmTokenType.Register: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.register_)); break; } default: break; } } } AsmDudeToolsStatic.Print_Speed_Warning(time1, "NasmAttDisassemblyTokenTagger"); }
private SortedSet <Completion> selectedCompletions(bool useCapitals, ISet <AsmTokenType> selectedTypes) { SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer()); //Add the completions of AsmDude directives (such as code folding directives) #region if (Settings.Default.CodeFolding_On) { { string insertionText = Settings.Default.CodeFolding_BeginTag; //the characters that start the outlining region string description = insertionText + " - keyword to start code folding"; completions.Add(new Completion(description, insertionText, null, this._icons[AsmTokenType.Directive], "")); } { string insertionText = Settings.Default.CodeFolding_EndTag; //the characters that end the outlining region string description = insertionText + " - keyword to end code folding"; completions.Add(new Completion(description, insertionText, null, this._icons[AsmTokenType.Directive], "")); } } #endregion AssemblerEnum usedAssember = AsmDudeToolsStatic.usedAssembler; #region if (selectedTypes.Contains(AsmTokenType.Mnemonic)) { ISet <Arch> selectedArchs = AsmDudeToolsStatic.getArchSwithedOn(); IList <Mnemonic> allowedMnemonics = this.getAllowedMnemonics(selectedArchs); //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:selectedCompletions; allowedMnemonics.Count=" + allowedMnemonics.Count + "; selectedArchs="+ArchTools.ToString(selectedArchs)); foreach (Mnemonic mnemonic in allowedMnemonics) { string keyword = mnemonic.ToString(); string insertionText = (useCapitals) ? keyword : keyword.ToLower(); string archStr = ArchTools.ToString(this._asmDudeTools.mnemonicStore.getArch(mnemonic)); string descriptionStr = this._asmDudeTools.mnemonicStore.getDescription(mnemonic); descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr; String displayText = keyword + archStr + descriptionStr; //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; ImageSource imageSource = null; this._icons.TryGetValue(AsmTokenType.Mnemonic, out imageSource); completions.Add(new Completion(displayText, insertionText, null, imageSource, "")); } } //Add the completions that are defined in the xml file foreach (string keyword in this._asmDudeTools.getKeywords()) { AsmTokenType type = this._asmDudeTools.getTokenType(keyword); if (selectedTypes.Contains(type)) { Arch arch = this._asmDudeTools.getArchitecture(keyword); bool selected = AsmDudeToolsStatic.isArchSwitchedOn(arch); if (selected && (type == AsmTokenType.Directive)) { AssemblerEnum assembler = this._asmDudeTools.getAssembler(keyword); switch (assembler) { case AssemblerEnum.MASM: if (usedAssember != AssemblerEnum.MASM) { selected = false; } break; case AssemblerEnum.NASM: if (usedAssember != AssemblerEnum.NASM) { selected = false; } break; case AssemblerEnum.UNKNOWN: default: break; } } //AsmDudeToolsStatic.Output(string.Format(CultureInfo.CurrentCulture, "INFO:{0}:selectedCompletions; keyword={1}; arch={2}; selected={3}", this.ToString(), keyword, arch, selected)); if (selected) { //Debug.WriteLine("INFO: CompletionSource:AugmentCompletionSession: name keyword \"" + entry.Key + "\""); // by default, the entry.Key is with capitals string insertionText = (useCapitals) ? keyword : keyword.ToLower(); string archStr = (arch == Arch.NONE) ? "" : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this._asmDudeTools.getDescription(keyword); descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr; String displayText = keyword + archStr + descriptionStr; //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; ImageSource imageSource = null; this._icons.TryGetValue(type, out imageSource); completions.Add(new Completion(displayText, insertionText, null, imageSource, "")); } } } #endregion return(completions); }
private SortedSet <Completion> mnemonicOperandCompletions(bool useCapitals, ISet <AsmSignatureEnum> allowedOperands) { SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer()); foreach (string keyword in this._asmDudeTools.getKeywords()) { Arch arch = this._asmDudeTools.getArchitecture(keyword); AsmTokenType type = this._asmDudeTools.getTokenType(keyword); bool selected = AsmDudeToolsStatic.isArchSwitchedOn(arch); //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:mnemonicOperandCompletions; keyword=" + keyword +"; selected="+selected +"; arch="+arch); if (selected) { switch (type) { case AsmTokenType.Register: //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn=" + keyword); Rn regName = RegisterTools.parseRn(keyword); if (AsmSignatureTools.isAllowedReg(regName, allowedOperands)) { //AsmDudeToolsStatic.Output(string.Format("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn="+ keyword + " is selected")); } else { selected = false; } break; case AsmTokenType.Misc: if (AsmSignatureTools.isAllowedMisc(keyword, allowedOperands)) { //AsmDudeToolsStatic.Output(string.Format("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn="+ keyword + " is selected")); } else { selected = false; } break; default: selected = false; break; } } if (selected) { //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:AugmentCompletionSession: keyword \"" + keyword + "\" is added to the completions list"); // by default, the entry.Key is with capitals string insertionText = (useCapitals) ? keyword : keyword.ToLower(); string archStr = (arch == Arch.NONE) ? "" : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this._asmDudeTools.getDescription(keyword); descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr; String displayText = keyword + archStr + descriptionStr; //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; ImageSource imageSource = null; this._icons.TryGetValue(type, out imageSource); completions.Add(new Completion(displayText, insertionText, null, imageSource, "")); } } return(completions); }
public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans) { DateTime time1 = DateTime.Now; if (spans.Count == 0) { //there is no content in the buffer yield break; } foreach (SnapshotSpan curSpan in spans) { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); string line = containingLine.GetText().ToUpper(); List <(int BeginPos, int Length, bool IsLabel)> pos = new List <(int BeginPos, int Length, bool IsLabel)>(AsmSourceTools.SplitIntoKeywordPos(line)); int offset = containingLine.Start.Position; int nKeywords = pos.Count; for (int k = 0; k < nKeywords; k++) { string asmToken = AsmSourceTools.Keyword(pos[k], line); // keyword starts with a remark char if (AsmSourceTools.IsRemarkChar(asmToken[0])) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._remark)); continue; } // keyword k is a label definition if (pos[k].IsLabel) { //AsmDudeToolsStatic.Output_INFO("NasmTokenTagger:GetTags: found label " +asmToken); if (this.IsProperLabelDef(asmToken, containingLine.LineNumber, out AsmTokenTag asmTokenTag)) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), asmTokenTag)); continue; } } AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type_Intel(asmToken); switch (keywordType) { case AsmTokenType.Jump: { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._jump)); k++; // goto the next word if (k == nKeywords) { break; // there are no next words } string asmToken2 = AsmSourceTools.Keyword(pos[k], line); switch (asmToken2) { case "WORD": case "DWORD": case "QWORD": case "SHORT": case "NEAR": { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._misc)); k++; if (k == nKeywords) { break; } string asmToken3 = AsmSourceTools.Keyword(pos[k], line); if (asmToken3.Equals("PTR")) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._misc)); } else { if (this.IsProperLabel(asmToken3, containingLine.LineNumber, out AsmTokenTag asmTokenTag)) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), asmTokenTag)); } } break; } default: { if (RegisterTools.IsRegister(asmToken2, true)) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._register)); } else { if (this.IsProperLabel(asmToken2, containingLine.LineNumber, out AsmTokenTag asmTokenTag)) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), asmTokenTag)); } } break; } } break; } case AsmTokenType.UNKNOWN: // asmToken is not a known keyword, check if it is numerical { if (AsmSourceTools.Evaluate_Constant(asmToken, true).Valid) //if (AsmSourceTools.Parse_Constant(asmToken, true).Valid) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._constant)); } else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\"")) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._constant)); } else { bool isUnknown = true; // do one word lookahead; see whether we can understand the current unknown word if ((k + 1) < nKeywords) { k++; string nextKeyword = AsmSourceTools.Keyword(pos[k], line); switch (nextKeyword) { case "LABEL": { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k - 1], offset, curSpan), this._labelDef)); yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._directive)); isUnknown = false; break; } default: { k--; break; } } } // do one word look back; see whether we can understand the current unknown word if (k > 0) { string previousKeyword = AsmSourceTools.Keyword(pos[k - 1], line); switch (previousKeyword) { case "ALIAS": { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._labelDef)); isUnknown = false; break; } case "INCLUDE": { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._constant)); isUnknown = false; break; } default: { break; } } } if (isUnknown) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._UNKNOWN)); } } break; } case AsmTokenType.Directive: { AssemblerEnum assember = this._asmDudeTools.Get_Assembler(asmToken); if (assember.HasFlag(AssemblerEnum.NASM_INTEL) || assember.HasFlag(AssemblerEnum.NASM_ATT)) { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._directive)); } break; } case AsmTokenType.Mnemonic: { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._mnemonic)); break; } case AsmTokenType.Register: { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._register)); break; } default: { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), new AsmTokenTag(keywordType))); break; } } } } AsmDudeToolsStatic.Print_Speed_Warning(time1, "NasmIntelTokenTagger"); }
public AsmTokenTag(AsmTokenType type, string misc) { this.Type = type; this.Misc = misc; }
public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans) { DateTime time1 = DateTime.Now; if (spans.Count == 0) { //there is no content in the buffer yield break; } foreach (SnapshotSpan curSpan in spans) { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); string line = containingLine.GetText().ToUpper(); var pos = new List <(int BeginPos, int Length, bool IsLabel)>(AsmSourceTools.SplitIntoKeywordPos(line)); int offset = containingLine.Start.Position; int nKeywords = pos.Count; for (int k = 0; k < nKeywords; k++) { string asmToken = NasmIntelTokenTagger.Keyword(pos[k], line); // keyword starts with a remark char if (AsmSourceTools.IsRemarkChar(asmToken[0])) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._remark)); continue; } // keyword k is a label definition if (pos[k].IsLabel) { SnapshotSpan labelDefSpan = NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan); //AsmDudeToolsStatic.Output_INFO("MasmTokenTagger:GetTags: found label " + asmToken +" at line "+containingLine.LineNumber); if (asmToken.Equals("@@")) { // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc. } else { var v = this.Make_AsmTokenTag_LabelDef(containingLine.LineNumber); yield return(new TagSpan <AsmTokenTag>(labelDefSpan, v)); } continue; } AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type_Intel(asmToken); switch (keywordType) { case AsmTokenType.Jump: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._jump)); k++; // goto the next word if (k == nKeywords) { break; } string asmToken2 = NasmIntelTokenTagger.Keyword(pos[k], line); switch (asmToken2) { case "$": case "@B": case "@F": { // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc. break; } case "WORD": case "DWORD": case "QWORD": case "SHORT": case "NEAR": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._misc)); k++; if (k == nKeywords) { break; } string asmToken3 = NasmIntelTokenTagger.Keyword(pos[k], line); switch (asmToken3) { case "$": case "@B": case "@F": { // TODO: special MASM label, for the moment, ignore it, later: check whether it is used etc. break; } case "PTR": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._misc)); break; } default: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber))); break; } } break; } default: { if (RegisterTools.IsRegister(asmToken2)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._register)); } else { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber))); } break; } } break; } case AsmTokenType.UNKNOWN: // asmToken is not a known keyword, check if it is numerical { if (AsmTools.AsmSourceTools.Evaluate_Constant(asmToken, true).Valid) //if (AsmTools.AsmSourceTools.Parse_Constant(asmToken, true).Valid) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant)); } else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\"")) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant)); } else { bool isUnknown = true; // do one word lookahead; see whether we can understand the current unknown word if ((k + 1) < nKeywords) { k++; string nextKeyword = NasmIntelTokenTagger.Keyword(pos[k], line); switch (nextKeyword) { case "PROC": case "EQU": case "LABEL": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k - 1], offset, curSpan), this._labelDef)); yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive)); isUnknown = false; break; } case "PROTO": { // a proto is considered a label definition but it should not clash with other label definitions yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k - 1], offset, curSpan), this._labelDef_PROTO)); yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive)); isUnknown = false; break; } default: { k--; break; } } } // do one word look back; see whether we can understand the current unknown word if (k > 0) { string previousKeyword = NasmIntelTokenTagger.Keyword(pos[k - 1], line); switch (previousKeyword) { case "ALIAS": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._labelDef)); isUnknown = false; break; } case "INCLUDE": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant)); isUnknown = false; break; } default: { break; } } } if (isUnknown) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._UNKNOWN)); } } break; } case AsmTokenType.Directive: { AssemblerEnum assember = this._asmDudeTools.Get_Assembler(asmToken); if (assember.HasFlag(AssemblerEnum.MASM)) // this MASM token-tagger only tags MASM directives { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive)); switch (asmToken) { case "INVOKE": { k++; // goto the next word if (k == nKeywords) { break; } string asmToken2 = NasmIntelTokenTagger.Keyword(pos[k], line); yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this.Make_AsmTokenTag_Label(containingLine.LineNumber))); break; } case "EXTRN": case "EXTERN": { k++; // goto the next word if (k == nKeywords) { break; } string asmToken2 = NasmIntelTokenTagger.Keyword(pos[k], line); yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._labelDef_PROTO)); break; } } } } break; default: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), new AsmTokenTag(keywordType))); break; } } } } AsmDudeToolsStatic.Print_Speed_Warning(time1, "MasmTokenTagger"); }
public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans) { DateTime time1 = DateTime.Now; if (spans.Count == 0) { //there is no content in the buffer yield break; } foreach (SnapshotSpan curSpan in spans) { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); string line = containingLine.GetText().ToUpper(); IList <Tuple <int, int, bool> > pos = AsmSourceTools.splitIntoKeywordPos(line); int offset = containingLine.Start.Position; int nKeywords = pos.Count; for (int k = 0; k < nKeywords; k++) { if (pos[k].Item3) { SnapshotSpan label = newSpan(pos[k], offset, curSpan); string labelString = label.GetText(); //AsmDudeToolsStatic.Output(string.Format("INFO: found label {0}", labelString)); if (labelString.StartsWith(".")) { // TODO: special NASM local labels, for the moment, ignore them. } else { yield return(new TagSpan <AsmTokenTag>(label, this._labelDef)); } continue; } string asmToken = keyword(pos[k], line); if (AsmSourceTools.isRemarkChar(asmToken[0])) { yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._remark)); continue; } AsmTokenType keywordType = this._asmDudeTools.getTokenType(asmToken); switch (keywordType) { case AsmTokenType.Jump: #region Jump yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._jump)); k++; if (k == nKeywords) { break; } string asmToken2 = keyword(pos[k], line); if (!asmToken2[0].Equals('.')) { switch (asmToken2) { case "WORD": case "DWORD": case "QWORD": case "SHORT": case "NEAR": yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._misc)); k++; if (k == nKeywords) { break; } string asmToken3 = keyword(pos[k], line); if (!asmToken3[0].Equals('.')) { switch (asmToken3) { case "PTR": yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._misc)); break; default: yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._label)); break; } } break; default: if (RegisterTools.isRegister(asmToken2)) { yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._register)); } else { yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._label)); } break; } } break; #endregion Jump case AsmTokenType.UNKNOWN: // asmToken is not a known keyword, check if it is numerical #region UNKNOWN if (AsmTools.AsmSourceTools.isConstant(asmToken)) { yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._constant)); } else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\"")) { yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._constant)); } else { bool isUnknown = true; // do one word lookahead; see whether we can understand the current unknown word if ((k + 1) < nKeywords) { k++; string nextKeyword = keyword(pos[k], line); switch (nextKeyword) { case "LABEL": yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k - 1], offset, curSpan), this._labelDef)); yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._directive)); isUnknown = false; break; default: k--; break; } } // do one word look back; see whether we can understand the current unknown word if (k > 0) { string previousKeyword = keyword(pos[k - 1], line); switch (previousKeyword) { case "ALIAS": yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._labelDef)); isUnknown = false; break; default: break; } } if (isUnknown) { yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._UNKNOWN)); } } break; #endregion UNKNOWN case AsmTokenType.Directive: #region Directive switch (this._asmDudeTools.getAssembler(asmToken)) { case AssemblerEnum.NASM: case AssemblerEnum.UNKNOWN: yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), this._directive)); break; default: break; } break; #endregion Directive default: yield return(new TagSpan <AsmTokenTag>(newSpan(pos[k], offset, curSpan), new AsmTokenTag(keywordType))); break; } } } AsmDudeToolsStatic.printSpeedWarning(time1, "NasmTokenTagger"); }
public IEnumerable <ITagSpan <AsmTokenTag> > GetTags(NormalizedSnapshotSpanCollection spans) { DateTime time1 = DateTime.Now; if (spans.Count == 0) { //there is no content in the buffer yield break; } foreach (SnapshotSpan curSpan in spans) { ITextSnapshotLine containingLine = curSpan.Start.GetContainingLine(); string line = containingLine.GetText().ToUpper(); var pos = new List <(int BeginPos, int Length, bool IsLabel)>(AsmSourceTools.SplitIntoKeywordPos(line)); int offset = containingLine.Start.Position; int nKeywords = pos.Count; // if the line does not contain a Mnemonic, assume it is a source code line and make it a remark #region Check source code line if (IsSourceCode(line, pos)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span((0, line.Length, false), offset, curSpan), this._remark)); continue; // go to the next line } #endregion for (int k = 0; k < nKeywords; k++) { string asmToken = NasmIntelTokenTagger.Keyword(pos[k], line); // keyword k is a label definition if (pos[k].IsLabel) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._labelDef)); continue; } AsmTokenType keywordType = this._asmDudeTools.Get_Token_Type_Att(asmToken); switch (keywordType) { case AsmTokenType.Jump: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._jump)); k++; // goto the next word if (k == nKeywords) { break; // there are no next words } string asmToken2 = NasmIntelTokenTagger.Keyword(pos[k], line); switch (asmToken2) { case "WORD": case "DWORD": case "QWORD": case "SHORT": case "NEAR": { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._misc)); k++; if (k == nKeywords) { break; } string asmToken3 = NasmIntelTokenTagger.Keyword(pos[k], line); switch (asmToken3) { case "PTR": { yield return(new TagSpan <AsmTokenTag>(New_Span(pos[k], offset, curSpan), this._misc)); break; } yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._label)); break; } break; } default: { if (RegisterTools.IsRegister(asmToken2)) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._register)); } else { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._label)); } break; } } break; } case AsmTokenType.UNKNOWN: // asmToken is not a known keyword, check if it is numerical { //if (AsmTools.AsmSourceTools.Parse_Constant(asmToken, true).Valid) if (AsmSourceTools.Evaluate_Constant(asmToken, true).Valid) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant)); } else if (asmToken.StartsWith("\"") && asmToken.EndsWith("\"")) { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._constant)); } else { //yield return new TagSpan<AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._UNKNOWN); } break; } case AsmTokenType.Directive: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._directive)); break; } case AsmTokenType.Mnemonic: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._mnemonic)); break; } case AsmTokenType.Register: { yield return(new TagSpan <AsmTokenTag>(NasmIntelTokenTagger.New_Span(pos[k], offset, curSpan), this._register)); break; } default: break; } } } AsmDudeToolsStatic.Print_Speed_Warning(time1, "NasmAttDisassemblyTokenTagger"); }
private SortedSet <Completion> Selected_Completions(bool useCapitals, ISet <AsmTokenType> selectedTypes) { SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer()); //Add the completions of AsmDude directives (such as code folding directives) #region if (Settings.Default.CodeFolding_On) { { string insertionText = Settings.Default.CodeFolding_BeginTag; //the characters that start the outlining region string description = insertionText + " - keyword to start code folding"; completions.Add(new Completion(description, insertionText, null, this._icons[AsmTokenType.Directive], "")); } { string insertionText = Settings.Default.CodeFolding_EndTag; //the characters that end the outlining region string description = insertionText + " - keyword to end code folding"; completions.Add(new Completion(description, insertionText, null, this._icons[AsmTokenType.Directive], "")); } } #endregion AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler; #region if (selectedTypes.Contains(AsmTokenType.Mnemonic)) { ISet <Arch> selectedArchs = AsmDudeToolsStatic.Get_Arch_Swithed_On(); IList <Mnemonic> allowedMnemonics = Get_Allowed_Mnemonics(selectedArchs); //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:selectedCompletions; allowedMnemonics.Count=" + allowedMnemonics.Count + "; selectedArchs="+ArchTools.ToString(selectedArchs)); foreach (Mnemonic mnemonic in allowedMnemonics) { string keyword = mnemonic.ToString(); string insertionText = (useCapitals) ? keyword : keyword.ToLower(); string archStr = ArchTools.ToString(this._asmDudeTools.Mnemonic_Store.GetArch(mnemonic)); string descriptionStr = this._asmDudeTools.Mnemonic_Store.GetDescription(mnemonic); descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr; String displayText = keyword + archStr + descriptionStr; //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; this._icons.TryGetValue(AsmTokenType.Mnemonic, out var imageSource); completions.Add(new Completion(displayText, insertionText, null, imageSource, "")); } } //Add the completions that are defined in the xml file foreach (string keyword in this._asmDudeTools.Get_Keywords()) { AsmTokenType type = this._asmDudeTools.Get_Token_Type(keyword); if (selectedTypes.Contains(type)) { Arch arch = Arch.NONE; bool selected = true; if (type == AsmTokenType.Directive) { AssemblerEnum assembler = this._asmDudeTools.Get_Assembler(keyword); if (assembler.HasFlag(AssemblerEnum.MASM)) { if (!usedAssember.HasFlag(AssemblerEnum.MASM)) { selected = false; } } else if (assembler.HasFlag(AssemblerEnum.NASM)) { if (!usedAssember.HasFlag(AssemblerEnum.NASM)) { selected = false; } } } else { arch = this._asmDudeTools.Get_Architecture(keyword); selected = AsmDudeToolsStatic.Is_Arch_Switched_On(arch); } AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:Selected_Completions; keyword=" + keyword + "; arch=" + arch + "; selected=" + selected); if (selected) { //Debug.WriteLine("INFO: CompletionSource:AugmentCompletionSession: name keyword \"" + entry.Key + "\""); // by default, the entry.Key is with capitals string insertionText = (useCapitals) ? keyword : keyword.ToLower(); string archStr = (arch == Arch.NONE) ? "" : " [" + ArchTools.ToString(arch) + "]"; string descriptionStr = this._asmDudeTools.Get_Description(keyword); descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr; String displayText = keyword + archStr + descriptionStr; //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr; this._icons.TryGetValue(type, out var imageSource); completions.Add(new Completion(displayText, insertionText, null, imageSource, "")); } } } #endregion return(completions); }