예제 #1
0
        private int Is_End_Keyword(string lineContent, int lineNumber)
        {
            int i1 = this.Is_End_Directive_Keyword(lineContent);

            if (i1 != -1)
            {
                return(i1);
            }
            else
            {
                AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;
                if (usedAssember.HasFlag(AssemblerEnum.MASM))
                {
                    return(this.Is_End_Masm_Keyword(lineContent, lineNumber));
                }
                else if (usedAssember.HasFlag(AssemblerEnum.NASM_INTEL) || usedAssember.HasFlag(AssemblerEnum.NASM_ATT))
                {
                    return(this.Is_End_Nasm_Keyword(lineContent, lineNumber));
                }
                else
                {
                    return(-1);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Return start positions of the provided line content. tup has: 1) start of the folding position; 2) start of the description position.
        /// </summary>
        private (int StartPosFolding, int StartPosDescription) Is_Start_Keyword(string lineContent, int lineNumber)
        {
            var tup = Is_Start_Directive_Keyword(lineContent);

            if (tup.StartPos != -1)
            {
                return(tup);
            }
            else
            {
                AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;
                if (usedAssember.HasFlag(AssemblerEnum.MASM))
                {
                    return(Is_Start_Masm_Keyword(lineContent, lineNumber));
                }
                else if (usedAssember.HasFlag(AssemblerEnum.NASM_INTEL) || usedAssember.HasFlag(AssemblerEnum.NASM_ATT))
                {
                    return(Is_Start_Nasm_Keyword(lineContent, lineNumber));
                }
                else
                {
                    return(-1, -1);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Return start positions of the provided line content. tup has: 1) start of the folding position; 2) start of the description position.
        /// </summary>
        private (int, int) Is_Start_Keyword(string lineContent, int lineNumber)
        {
            var tup = Is_Start_Directive_Keyword(lineContent);

            if (tup.Item1 != -1)
            {
                return(tup);
            }
            else
            {
                AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;
                if (usedAssember.HasFlag(AssemblerEnum.MASM))
                {
                    return(Is_Start_Masm_Keyword(lineContent, lineNumber));
                }
                else if (usedAssember.HasFlag(AssemblerEnum.NASM))
                {
                    return(Is_Start_Nasm_Keyword(lineContent, lineNumber));
                }
                else
                {
                    return(-1, -1);
                }
            }
        }
예제 #4
0
        public SortedSet <uint> Label_Used_At_Info(string full_Qualified_Label, string label)
        {
            AsmDudeToolsStatic.Output_INFO("LabelGraph:Label_Used_At_Info: full_Qualified_Label=" + full_Qualified_Label + "; label=" + label);
            SortedSet <uint> results = new SortedSet <uint>();

            {
                if (this._usedAt.TryGetValue(full_Qualified_Label, out var lines))
                {
                    results.UnionWith(lines);
                }
            }
            {
                if (this._usedAt.TryGetValue(label, out var lines))
                {
                    results.UnionWith(lines);
                }
            }
            if (full_Qualified_Label.Equals(label))
            {
                AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;
                foreach (KeyValuePair <string, IList <uint> > entry in this._usedAt)
                {
                    string regular_Label = AsmDudeToolsStatic.Retrieve_Regular_Label(entry.Key, usedAssember);
                    if (label.Equals(regular_Label))
                    {
                        results.UnionWith(entry.Value);
                    }
                }
            }
            return(results);
        }
예제 #5
0
        private SortedSet <Completion> Label_Completions()
        {
            SortedSet <Completion> completions  = new SortedSet <Completion>(new CompletionComparer());
            ImageSource            imageSource  = this._icons[AsmTokenType.Label];
            AssemblerEnum          usedAssember = AsmDudeToolsStatic.Used_Assembler;

            SortedDictionary <string, string> labels = this._labelGraph.Get_Label_Descriptions;

            foreach (KeyValuePair <string, string> entry in labels)
            {
                //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO:{0}:AugmentCompletionSession; label={1}; description={2}", this.ToString(), entry.Key, entry.Value));
                string displayText   = entry.Key + " - " + entry.Value;
                string insertionText = AsmDudeToolsStatic.Retrieve_Regular_Label(entry.Key, usedAssember);
                completions.Add(new Completion(displayText, insertionText, null, imageSource, ""));
            }
            return(completions);
        }
예제 #6
0
        public static AssemblerEnum ParseAssembler(string str)
        {
            if ((str == null) || (str.Length == 0))
            {
                return(AssemblerEnum.UNKNOWN);
            }
            AssemblerEnum result = AssemblerEnum.UNKNOWN;

            foreach (string str2 in str.ToUpper().Split(','))
            {
                switch (str2.Trim())
                {
                case "MASM": result |= AssemblerEnum.MASM; break;

                case "NASM": result |= AssemblerEnum.NASM; break;
                }
            }
            return(result);
        }
예제 #7
0
        public static AssemblerEnum ParseAssembler(string str, bool strIsCapitals)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(AssemblerEnum.UNKNOWN);
            }
            AssemblerEnum result = AssemblerEnum.UNKNOWN;

            foreach (string str2 in ToCapitals(str, strIsCapitals).Split(','))
            {
                switch (str2.Trim())
                {
                case "MASM": result |= AssemblerEnum.MASM; break;

                case "NASM": result |= AssemblerEnum.NASM_INTEL; break;
                }
            }
            return(result);
        }
예제 #8
0
        private IEnumerable <Completion> Label_Completions(bool useCapitals, bool addSpecialKeywords)
        {
            if (addSpecialKeywords)
            {
                yield return(new Completion("SHORT", useCapitals ? "SHORT" : "short", null, this.icons_[AsmTokenType.Misc], string.Empty));

                yield return(new Completion("NEAR", useCapitals ? "NEAR" : "near", null, this.icons_[AsmTokenType.Misc], string.Empty));
            }

            ImageSource   imageSource  = this.icons_[AsmTokenType.Label];
            AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;

            SortedDictionary <string, string> labels = this.labelGraph_.Label_Descriptions;

            foreach (KeyValuePair <string, string> entry in labels)
            {
                //Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "INFO:{0}:AugmentCompletionSession; label={1}; description={2}", this.ToString(), entry.Key, entry.Value));
                string displayTextFull = entry.Key + " - " + entry.Value;
                string displayText     = Truncat(displayTextFull);
                string insertionText   = AsmDudeToolsStatic.Retrieve_Regular_Label(entry.Key, usedAssember);
                yield return(new Completion(displayText, insertionText, displayTextFull, imageSource, string.Empty));
            }
        }
예제 #9
0
        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");
        }
예제 #10
0
        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");
        }
예제 #11
0
        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);
        }
예제 #12
0
        public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {  // there is no content in the buffer
                yield break;
            }

            bool labelGraph_Enabled   = this._labelGraph.Enabled;
            bool asmSimulator_Enabled = this._asmSimulator.Enabled;

            if (!labelGraph_Enabled && !asmSimulator_Enabled)
            {   // nothing to decorate
                yield break;
            }

            DateTime time1 = DateTime.Now;

            //TODO move the followign boolean to constructor
            bool Decorate_Undefined_Labels   = labelGraph_Enabled && Settings.Default.IntelliSense_Decorate_Undefined_Labels;
            bool Decorate_Clashing_Labels    = labelGraph_Enabled && Settings.Default.IntelliSense_Decorate_Clashing_Labels;
            bool Decorate_Undefined_Includes = labelGraph_Enabled && Settings.Default.IntelliSense_Show_Undefined_Includes;

            bool Decorate_Registers_Known_Register_Values = asmSimulator_Enabled && Settings.Default.AsmSim_Decorate_Registers;
            bool Decorate_Syntax_Errors            = asmSimulator_Enabled && Settings.Default.AsmSim_Decorate_Syntax_Errors;
            bool Decorate_Unimplemented            = asmSimulator_Enabled && Settings.Default.AsmSim_Decorate_Unimplemented;
            bool Decorate_Usage_Of_Undefined       = asmSimulator_Enabled && Settings.Default.AsmSim_Decorate_Usage_Of_Undefined;
            bool Decorate_Redundant_Instructions   = asmSimulator_Enabled && Settings.Default.AsmSim_Decorate_Redundant_Instructions;
            bool Decorate_Unreachable_Instructions = asmSimulator_Enabled && Settings.Default.AsmSim_Decorate_Unreachable_Instructions;

            bool Show_Syntax_Error_Error_List = asmSimulator_Enabled && Settings.Default.AsmSim_Show_Syntax_Errors;
            bool Show_Usage_Of_Undefined      = asmSimulator_Enabled && Settings.Default.AsmSim_Show_Usage_Of_Undefined;

            AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;

            foreach (IMappingTagSpan <AsmTokenTag> asmTokenTag in this._aggregator.GetTags(spans))
            {
                SnapshotSpan tagSpan = asmTokenTag.Span.GetSpans(this._sourceBuffer)[0];
                //AsmDudeToolsStatic.Output_INFO(string.Format("SquigglesTagger:GetTags: found keyword \"{0}\"", tagSpan.GetText()));

                int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan);

                switch (asmTokenTag.Tag.Type)
                {
                case AsmTokenType.Label:
                {
                    if (Decorate_Undefined_Labels)
                    {
                        string label = tagSpan.GetText();
                        string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(asmTokenTag.Tag.Misc, label, usedAssember);

                        if (this._labelGraph.Has_Label(full_Qualified_Label))
                        {
                            // Nothing to report
                        }
                        else
                        {
                            //AsmDudeToolsStatic.Output_INFO(string.Format("SquigglesTagger:GetTags: found label \"{0}\"; full-label \"{1}\"", label, full_Qualified_Label));

                            if (usedAssember == AssemblerEnum.MASM)
                            {
                                if (this._labelGraph.Has_Label(label))
                                {
                                    // TODO: is this always a valid label? Nothing to report
                                }
                                else
                                {
                                    TextBlock toolTipContent = this.Undefined_Label_Tool_Tip_Content();
                                    yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, toolTipContent)));
                                }
                            }
                            else
                            {
                                TextBlock toolTipContent = this.Undefined_Label_Tool_Tip_Content();
                                yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, toolTipContent)));
                            }
                        }
                    }
                    break;
                }

                case AsmTokenType.LabelDef:
                {
                    if (Decorate_Clashing_Labels)
                    {
                        string label = tagSpan.GetText();
                        string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(asmTokenTag.Tag.Misc, label, usedAssember);

                        if (this._labelGraph.Has_Label_Clash(full_Qualified_Label))
                        {
                            TextBlock toolTipContent = this.Label_Clash_Tool_Tip_Content(full_Qualified_Label);

                            //PredefinedErrorTypeNames.Warning is green
                            //PredefinedErrorTypeNames.SyntaxError is red
                            //PredefinedErrorTypeNames.CompilerError is blue
                            //PredefinedErrorTypeNames.Suggestion is NOTHING
                            //PredefinedErrorTypeNames.OtherError is purple

                            yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, toolTipContent)));
                        }
                    }
                    break;
                }

                case AsmTokenType.Register:
                {
                    if (Decorate_Registers_Known_Register_Values)
                    {
                        Rn regName = RegisterTools.ParseRn(tagSpan.GetText());
                        //AsmDudeToolsStatic.Output_INFO("SquigglesTagger:GetTags: found register " + regName + " at line " + lineNumber);
                        bool preCompute = false;
                        (bool HasValue1, bool Bussy1) = this._asmSimulator.Has_Register_Value(regName, lineNumber, true, preCompute);
                        if (!Bussy1)
                        {
                            (bool HasValue2, bool Bussy2) = this._asmSimulator.Has_Register_Value(regName, lineNumber, false, preCompute);
                            if (!Bussy2)
                            {
                                if (HasValue1 || HasValue2)
                                {           // only show squiggles to indicate that information is available
                                            //AsmDudeToolsStatic.Output_INFO("SquigglesTagger:GetTags: adding squiggles for register " + regName + " at line " + lineNumber);
                                    yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.Warning)));
                                }
                            }
                        }
                    }
                    break;
                }

                case AsmTokenType.Mnemonic:
                {
                    if (Decorate_Syntax_Errors || Decorate_Unimplemented)
                    {
                        if (this._asmSimulator.Is_Implemented(lineNumber))
                        {
                            if (Decorate_Syntax_Errors && this._asmSimulator.Has_Syntax_Error(lineNumber))
                            {
                                string message = AsmSourceTools.Linewrap("Syntax Error: " + this._asmSimulator.Get_Syntax_Error(lineNumber).Message, AsmDudePackage.maxNumberOfCharsInToolTips);
                                yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, message)));
                            }
                        }
                        else if (Decorate_Unimplemented)
                        {
                            string message = AsmSourceTools.Linewrap("Info: Instruction " + tagSpan.GetText() + " is not (yet) supported by the simulator.", AsmDudePackage.maxNumberOfCharsInToolTips);
                            yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.CompilerError, message)));
                        }
                    }
                    if (Decorate_Usage_Of_Undefined)
                    {
                        if (this._asmSimulator.Has_Usage_Undefined_Warning(lineNumber))
                        {
                            string message = AsmSourceTools.Linewrap("Semantic Warning: " + this._asmSimulator.Get_Usage_Undefined_Warning(lineNumber).Message, AsmDudePackage.maxNumberOfCharsInToolTips);
                            yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.OtherError, message)));
                        }
                    }
                    if (Decorate_Redundant_Instructions)
                    {
                        if (this._asmSimulator.Has_Redundant_Instruction_Warning(lineNumber))
                        {
                            string message = AsmSourceTools.Linewrap("Semantic Warning: " + this._asmSimulator.Get_Redundant_Instruction_Warning(lineNumber).Message, AsmDudePackage.maxNumberOfCharsInToolTips);
                            yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.OtherError, message)));
                        }
                    }
                    if (Decorate_Unreachable_Instructions)
                    {
                        if (this._asmSimulator.Has_Unreachable_Instruction_Warning(lineNumber))
                        {
                            string message = AsmSourceTools.Linewrap("Semantic Warning: " + this._asmSimulator.Get_Unreachable_Instruction_Warning(lineNumber).Message, AsmDudePackage.maxNumberOfCharsInToolTips);
                            yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.OtherError, message)));
                        }
                    }
                    break;
                }

                case AsmTokenType.Constant:
                {
                    if (Decorate_Undefined_Includes)
                    {
                        foreach ((string Include_Filename, string Path, string Source_Filename, int LineNumber)tup in this._labelGraph.Undefined_Includes)
                        {
                            if (tup.LineNumber == lineNumber)         //TODO this is inefficient!
                            {
                                string toolTipContent = "Could not resolve include \"" + tagSpan.GetText() + "\"";
                                yield return(new TagSpan <IErrorTag>(tagSpan, new ErrorTag(PredefinedErrorTypeNames.SyntaxError, toolTipContent)));

                                break;         // leave the foreach loop
                            }
                        }
                    }
                    break;
                }

                default: break;
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "SquiggleTagger");
        }
예제 #13
0
        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");
        }
예제 #14
0
        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);
        }
예제 #15
0
        public IEnumerable<ITagSpan<ErrorTag>> GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {  // there is no content in the buffer
                yield break;
            }
            if (!this._labelGraph.Is_Enabled)
            {   // the label graph is disabled
                yield break;
            }

            DateTime time1 = DateTime.Now;

            bool Decorate_Undefined_Labels = Settings.Default.IntelliSense_Decorate_UndefinedLabels;
            bool Decorate_Clashing_Labels = Settings.Default.IntelliSense_Decorate_ClashingLabels;

            if (Decorate_Undefined_Labels || Decorate_Clashing_Labels)
            {
                AssemblerEnum usedAssember = AsmDudeToolsStatic.Used_Assembler;

                foreach (IMappingTagSpan<AsmTokenTag> asmTokenTag in this._aggregator.GetTags(spans))
                {
                    SnapshotSpan tagSpan = asmTokenTag.Span.GetSpans(this._sourceBuffer)[0];
                    //AsmDudeToolsStatic.Output_INFO(string.Format("LabelErrorTagger:GetTags: found keyword \"{0}\"", tagSpan.GetText()));

                    switch (asmTokenTag.Tag.Type)
                    {
                        case AsmTokenType.Label:
                            {
                                if (Decorate_Undefined_Labels)
                                {
                                    string label = tagSpan.GetText();
                                    string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(asmTokenTag.Tag.Misc, label, usedAssember);

                                    if (this._labelGraph.Has_Label(full_Qualified_Label))
                                    {
                                        // Nothing to report
                                    } else
                                    {
                                        AsmDudeToolsStatic.Output_INFO(string.Format("LabelErrorTagger:GetTags: found label \"{0}\"; full-label \"{1}\"", label, full_Qualified_Label));

                                        if (usedAssember == AssemblerEnum.MASM)
                                        {
                                            if (this._labelGraph.Has_Label(label))
                                            {
                                                // TODO: is this always a valid label? Nothing to report
                                            } else {
                                                var toolTipContent = Undefined_Label_Tool_Tip_Content();
                                                yield return new TagSpan<ErrorTag>(tagSpan, new ErrorTag("warning", toolTipContent));
                                            }
                                        } else
                                        {
                                            var toolTipContent = Undefined_Label_Tool_Tip_Content();
                                            yield return new TagSpan<ErrorTag>(tagSpan, new ErrorTag("warning", toolTipContent));
                                        }
                                    }
                                }
                                break;
                            }
                        case AsmTokenType.LabelDef:
                            {
                                if (Decorate_Clashing_Labels)
                                {
                                    string label = tagSpan.GetText();
                                    string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(asmTokenTag.Tag.Misc, label, usedAssember);

                                    if (this._labelGraph.Has_Label_Clash(full_Qualified_Label))
                                    {
                                        var toolTipContent = Label_Clash_Tool_Tip_Content(full_Qualified_Label);
                                        yield return new TagSpan<ErrorTag>(tagSpan, new ErrorTag("warning", toolTipContent));
                                    }
                                }
                                break;
                            }
                        default: break;
                    }
                }
            }
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "LabelErrorTagger");
        }
예제 #16
0
        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);
        }