Exemplo n.º 1
0
        public AsmTokenType Get_Token_Type_Att(string keyword)
        {
            Contract.Requires(keyword != null);
            Contract.Requires(keyword == keyword.ToUpperInvariant());

            int length = keyword.Length;

            Contract.Requires(length > 0);

            char firstChar = keyword[0];

            #region Test if keyword is a register
            if (firstChar == '%')
            {
                string keyword2 = keyword.Substring(1);
                Rn     reg      = RegisterTools.ParseRn(keyword2, true);
                if (reg != Rn.NOREG)
                {
                    return((this.RegisterSwitchedOn(reg))
                       ? AsmTokenType.Register
                       : AsmTokenType.Register); //TODO
                }
            }
            #endregion
            #region Test if keyword is an imm
            if (firstChar == '$')
            {
                return(AsmTokenType.Constant);
            }
            #endregion
            #region Test if keyword is an instruction
            {
                (Mnemonic mnemonic, AttType type) = AsmSourceTools.ParseMnemonic_Att(keyword, true);
                if (mnemonic != Mnemonic.NONE)
                {
                    return((this.MnemonicSwitchedOn(mnemonic))
                        ? AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.Mnemonic
                        : AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.MnemonicOff);
                }
            }
            #endregion

            return(this.type_.TryGetValue(keyword, out AsmTokenType tokenType) ? tokenType : AsmTokenType.UNKNOWN);
        }
Exemplo n.º 2
0
        public AsmTokenType Get_Token_Type_Att(string keyword)
        {
            Debug.Assert(keyword == keyword.ToUpper());
            int length = keyword.Length;

            Debug.Assert(length > 0);

            char firstChar = keyword[0];

            #region Test if keyword is a register
            if (firstChar == '%')
            {
                string keyword2 = keyword.Substring(1);
                Rn     reg      = RegisterTools.ParseRn(keyword2, true);
                if (reg != Rn.NOREG)
                {
                    if (RegisterSwitchedOn(reg))
                    {
                        return(AsmTokenType.Register);
                    }
                }
            }
            #endregion
            #region Test if keyword is an imm
            if (firstChar == '$')
            {
                return(AsmTokenType.Constant);
            }
            #endregion
            #region Test if keyword is an instruction
            {
                Mnemonic mnemonic = AsmSourceTools.ParseMnemonic_Att(keyword, true);
                if (mnemonic != Mnemonic.NONE)
                {
                    if (MnemonicSwitchedOn(mnemonic))
                    {
                        return((AsmSourceTools.IsJump(mnemonic)) ? AsmTokenType.Jump : AsmTokenType.Mnemonic);
                    }
                }
            }
            #endregion

            return((this._type.TryGetValue(keyword, out var tokenType)) ? tokenType : AsmTokenType.UNKNOWN);
        }
Exemplo n.º 3
0
        public AsmTokenType Get_Token_Type(string keyword)
        {
            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(keyword);

            if (mnemonic != Mnemonic.UNKNOWN)
            {
                if (AsmSourceTools.IsJump(mnemonic))
                {
                    return(AsmTokenType.Jump);
                }
                return(AsmTokenType.Mnemonic);
            }

            if (this._type.TryGetValue(keyword.ToUpper(), out var tokenType))
            {
                return(tokenType);
            }
            return(AsmTokenType.UNKNOWN);
        }
Exemplo n.º 4
0
        public AsmTokenType Get_Token_Type_Intel(string keyword)
        {
            Debug.Assert(keyword == keyword.ToUpper());

            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(keyword, true);

            if (mnemonic != Mnemonic.NONE)
            {
                return((this.MnemonicSwitchedOn(mnemonic))
                    ? AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.Mnemonic
                    : AsmSourceTools.IsJump(mnemonic) ? AsmTokenType.Jump : AsmTokenType.MnemonicOff);
            }
            Rn reg = RegisterTools.ParseRn(keyword, true);

            if (reg != Rn.NOREG)
            {
                return((this.RegisterSwitchedOn(reg))
                    ? AsmTokenType.Register
                    : AsmTokenType.Register); //TODO
            }
            return(this._type.TryGetValue(keyword, out AsmTokenType tokenType) ? tokenType : AsmTokenType.UNKNOWN);
        }
        public void SetDescription(Mnemonic mnemonic, AsmDudeTools asmDudeTools)
        {
            string mnemonicStr = mnemonic.ToString();

            this.Description.Inlines.Add(new Run("Mnemonic ")
            {
                FontWeight = FontWeights.Bold, Foreground = this._foreground
            });
            this.Description.Inlines.Add(new Run(mnemonicStr)
            {
                FontWeight = FontWeights.Bold, Foreground = new SolidColorBrush(AsmDudeToolsStatic.ConvertColor((AsmSourceTools.IsJump(mnemonic) ? Settings.Default.SyntaxHighlighting_Jump : Settings.Default.SyntaxHighlighting_Opcode)))
            });

            string archStr    = ":" + ArchTools.ToString(asmDudeTools.Mnemonic_Store.GetArch(mnemonic)) + " ";
            string descr      = asmDudeTools.Mnemonic_Store.GetDescription(mnemonic);
            string full_Descr = AsmSourceTools.Linewrap(archStr + descr, AsmDudePackage.maxNumberOfCharsInToolTips);

            this.Description.Inlines.Add(new Run(full_Descr)
            {
                Foreground = this._foreground
            });
        }
Exemplo n.º 6
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            Contract.Requires(session != null);
            Contract.Requires(completionSets != null);

            try
            {
                //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentCompletionSession", this.ToString()));

                if (!Settings.Default.CodeCompletion_On)
                {
                    return;
                }

                DateTime      time1        = DateTime.Now;
                ITextSnapshot snapshot     = this.buffer_.CurrentSnapshot;
                SnapshotPoint triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot);
                if (triggerPoint == null)
                {
                    return;
                }
                ITextSnapshotLine line = triggerPoint.GetContainingLine();

                //1] check if current position is in a remark; if we are in a remark, no code completion
                #region
                if (triggerPoint.Position > 1)
                {
                    char currentTypedChar = (triggerPoint - 1).GetChar();
                    //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession: current char = "+ currentTypedChar);
                    if (!currentTypedChar.Equals('#'))
                    { //TODO UGLY since the user can configure this starting character
                        int pos = triggerPoint.Position - line.Start;
                        if (AsmSourceTools.IsInRemark(pos, line.GetText()))
                        {
                            //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession: currently in a remark section");
                            return;
                        }
                        else
                        {
                            // AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession: not in a remark section");
                        }
                    }
                }
                #endregion

                //2] find the start of the current keyword
                #region
                SnapshotPoint start = triggerPoint;
                while ((start > line.Start) && !AsmSourceTools.IsSeparatorChar((start - 1).GetChar()))
                {
                    start -= 1;
                }
                #endregion

                //3] get the word that is currently being typed
                #region
                ITrackingSpan applicableTo   = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive);
                string        partialKeyword = applicableTo.GetText(snapshot);
                bool          useCapitals    = AsmDudeToolsStatic.Is_All_upcase(partialKeyword);

                string lineStr = line.GetText();
                (string label, Mnemonic mnemonic, string[] args, string remark)t = AsmSourceTools.ParseLine(lineStr);
                Mnemonic mnemonic = t.mnemonic;
                string   previousKeyword_upcase = AsmDudeToolsStatic.Get_Previous_Keyword(line.Start, start).ToUpperInvariant();

                //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentCompletionSession. lineStr=\"{1}\"; previousKeyword=\"{2}\"", this.ToString(), lineStr, previousKeyword));

                if (mnemonic == Mnemonic.NONE)
                {
                    if (previousKeyword_upcase.Equals("INVOKE", StringComparison.Ordinal)) //TODO INVOKE is a MASM keyword not a NASM one...
                    {
                        // Suggest a label
                        IEnumerable <Completion> completions = this.Label_Completions(useCapitals, false);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("Labels", "Labels", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                    else
                    {
                        {
                            ISet <AsmTokenType> selected1 = new HashSet <AsmTokenType> {
                                AsmTokenType.Directive, AsmTokenType.Jump, AsmTokenType.Misc, AsmTokenType.Mnemonic
                            };
                            IEnumerable <Completion> completions1 = this.Selected_Completions(useCapitals, selected1, true);
                            if (completions1.Any())
                            {
                                completionSets.Add(new CompletionSet("All", "All", applicableTo, completions1, Enumerable.Empty <Completion>()));
                            }
                        }
                        if (false)
                        {
                            ISet <AsmTokenType> selected2 = new HashSet <AsmTokenType> {
                                AsmTokenType.Jump, AsmTokenType.Mnemonic
                            };
                            IEnumerable <Completion> completions2 = this.Selected_Completions(useCapitals, selected2, false);
                            if (completions2.Any())
                            {
                                completionSets.Add(new CompletionSet("Instr", "Instr", applicableTo, completions2, Enumerable.Empty <Completion>()));
                            }
                        }
                        if (false)
                        {
                            ISet <AsmTokenType> selected3 = new HashSet <AsmTokenType> {
                                AsmTokenType.Directive, AsmTokenType.Misc
                            };
                            IEnumerable <Completion> completions3 = this.Selected_Completions(useCapitals, selected3, true);
                            if (completions3.Any())
                            {
                                completionSets.Add(new CompletionSet("Directive", "Directive", applicableTo, completions3, Enumerable.Empty <Completion>()));
                            }
                        }
                    }
                }
                else
                { // the current line contains a mnemonic
                  //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession; mnemonic=" + mnemonic+ "; previousKeyword="+ previousKeyword);

                    if (AsmSourceTools.IsJump(AsmSourceTools.ParseMnemonic(previousKeyword_upcase, true)))
                    {
                        //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession; previous keyword is a jump mnemonic");
                        // previous keyword is jump (or call) mnemonic. Suggest "SHORT" or a label
                        IEnumerable <Completion> completions = this.Label_Completions(useCapitals, true);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("Labels", "Labels", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                    else if (previousKeyword_upcase.Equals("SHORT", StringComparison.Ordinal) || previousKeyword_upcase.Equals("NEAR", StringComparison.Ordinal))
                    {
                        // Suggest a label
                        IEnumerable <Completion> completions = this.Label_Completions(useCapitals, false);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("Labels", "Labels", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                    else
                    {
                        IList <Operand>         operands = AsmSourceTools.MakeOperands(t.args);
                        ISet <AsmSignatureEnum> allowed  = new HashSet <AsmSignatureEnum>();
                        int commaCount = AsmSignature.Count_Commas(lineStr);
                        IEnumerable <AsmSignatureElement> allSignatures = this.asmDudeTools_.Mnemonic_Store.GetSignatures(mnemonic);

                        ISet <Arch> selectedArchitectures = AsmDudeToolsStatic.Get_Arch_Swithed_On();
                        foreach (AsmSignatureElement se in AsmSignatureHelpSource.Constrain_Signatures(allSignatures, operands, selectedArchitectures))
                        {
                            if (commaCount < se.Operands.Count)
                            {
                                foreach (AsmSignatureEnum s in se.Operands[commaCount])
                                {
                                    allowed.Add(s);
                                }
                            }
                        }
                        IEnumerable <Completion> completions = this.Mnemonic_Operand_Completions(useCapitals, allowed, line.LineNumber);
                        if (completions.Any())
                        {
                            completionSets.Add(new CompletionSet("All", "All", applicableTo, completions, Enumerable.Empty <Completion>()));
                        }
                    }
                }
                #endregion
                AsmDudeToolsStatic.Print_Speed_Warning(time1, "Code Completion");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentCompletionSession; e={1}", this.ToString(), e.ToString()));
            }
        }
Exemplo n.º 7
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            //AsmDudeToolsStatic.Output(string.Format("INFO: {0}:AugmentCompletionSession", this.ToString()));

            if (this._disposed)
            {
                return;
            }
            if (!Settings.Default.CodeCompletion_On)
            {
                return;
            }

            try
            {
                DateTime      time1        = DateTime.Now;
                ITextSnapshot snapshot     = this._buffer.CurrentSnapshot;
                SnapshotPoint triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot);
                if (triggerPoint == null)
                {
                    return;
                }
                ITextSnapshotLine line = triggerPoint.GetContainingLine();

                //1] check if current position is in a remark; if we are in a remark, no code completion
                #region
                if (triggerPoint.Position > 1)
                {
                    char currentTypedChar = (triggerPoint - 1).GetChar();
                    //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:AugmentCompletionSession: current char = "+ currentTypedChar);
                    if (!currentTypedChar.Equals('#'))
                    { //TODO UGLY since the user can configure this starting character
                        int pos = triggerPoint.Position - line.Start;
                        if (AsmSourceTools.IsInRemark(pos, line.GetText()))
                        {
                            //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:AugmentCompletionSession: currently in a remark section");
                            return;
                        }
                        else
                        {
                            // AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:AugmentCompletionSession: not in a remark section");
                        }
                    }
                }
                #endregion

                //2] find the start of the current keyword
                #region
                SnapshotPoint start = triggerPoint;
                while ((start > line.Start) && !AsmTools.AsmSourceTools.IsSeparatorChar((start - 1).GetChar()))
                {
                    start -= 1;
                }
                #endregion

                //3] get the word that is currently being typed
                #region
                ITrackingSpan applicableTo   = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive);
                string        partialKeyword = applicableTo.GetText(snapshot);
                bool          useCapitals    = AsmDudeToolsStatic.Is_All_Upper(partialKeyword);

                SortedSet <Completion> completions = null;

                string   lineStr  = line.GetText();
                var      t        = AsmSourceTools.ParseLine(lineStr);
                Mnemonic mnemonic = t.Item2;

                //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession; lineStr="+ lineStr+ "; t.Item1="+t.Item1);

                string previousKeyword = AsmDudeToolsStatic.Get_Previous_Keyword(line.Start, start).ToUpper();

                if (mnemonic == Mnemonic.UNKNOWN)
                {
                    //AsmDudeToolsStatic.Output_INFO("CodeCompletionSource:AugmentCompletionSession; lineStr=" + lineStr + "; previousKeyword=" + previousKeyword);

                    if (previousKeyword.Equals("INVOKE")) //TODO INVOKE is a MASM keyword not a NASM one...
                    {
                        // Suggest a label
                        completions = Label_Completions();
                    }
                    else
                    {
                        ISet <AsmTokenType> selected = new HashSet <AsmTokenType> {
                            AsmTokenType.Directive, AsmTokenType.Jump, AsmTokenType.Misc, AsmTokenType.Mnemonic
                        };
                        completions = Selected_Completions(useCapitals, selected);
                    }
                }
                else
                { // the current line contains a mnemonic
                  //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:AugmentCompletionSession; mnemonic=" + mnemonic+ "; previousKeyword="+ previousKeyword);

                    if (AsmSourceTools.IsJump(AsmSourceTools.ParseMnemonic(previousKeyword)))
                    {
                        //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:AugmentCompletionSession; previous keyword is a jump mnemonic");
                        // previous keyword is jump (or call) mnemonic. Suggest "SHORT" or a label
                        completions = Label_Completions();
                        completions.Add(new Completion("SHORT", (useCapitals) ? "SHORT" : "short", null, this._icons[AsmTokenType.Misc], ""));
                        completions.Add(new Completion("NEAR", (useCapitals) ? "NEAR" : "near", null, this._icons[AsmTokenType.Misc], ""));
                    }
                    else if (previousKeyword.Equals("SHORT") || previousKeyword.Equals("NEAR"))
                    {
                        // Suggest a label
                        completions = Label_Completions();
                    }
                    else
                    {
                        IList <Operand>         operands = AsmSourceTools.MakeOperands(t.Item3);
                        ISet <AsmSignatureEnum> allowed  = new HashSet <AsmSignatureEnum>();
                        int commaCount = AsmSignature.Count_Commas(lineStr);
                        IList <AsmSignatureElement> allSignatures = this._asmDudeTools.Mnemonic_Store.GetSignatures(mnemonic);

                        ISet <Arch> selectedArchitectures = AsmDudeToolsStatic.Get_Arch_Swithed_On();
                        foreach (AsmSignatureElement se in AsmSignatureHelpSource.Constrain_Signatures(allSignatures, operands, selectedArchitectures))
                        {
                            if (commaCount < se.Operands.Count)
                            {
                                foreach (AsmSignatureEnum s in se.Operands[commaCount])
                                {
                                    allowed.Add(s);
                                }
                            }
                        }
                        completions = Mnemonic_Operand_Completions(useCapitals, allowed);
                    }
                }
                //AsmDudeToolsStatic.Output("INFO: CodeCompletionSource:AugmentCompletionSession; nCompletions=" + completions.Count);
                #endregion

                completionSets.Add(new CompletionSet("Tokens", "Tokens", applicableTo, completions, Enumerable.Empty <Completion>()));

                AsmDudeToolsStatic.Print_Speed_Warning(time1, "Code Completion");
            } catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:AugmentCompletionSession; e={1}", ToString(), e.ToString()));
            }
        }