Exemple #1
0
        /// <summary>Perform onestep forward and return the state of the regular branch</summary>
        public static State SimpleStep_Backward(string line, State state)
        {
            string prevKey = Tools.CreateKey(state.Tools.Rand);
            var    content = AsmSourceTools.ParseLine(line);

            using (var opcodeBase = Runner.InstantiateOpcode(content.Mnemonic, content.Args, (prevKey, state.TailKey, state.TailKey), state.Tools))
            {
                if (opcodeBase == null)
                {
                    return(null);
                }
                if (opcodeBase.IsHalted)
                {
                    return(null);
                }

                opcodeBase.Execute();
                State stateOut = new State(state);
                stateOut.Update_Backward(opcodeBase.Updates.Regular, prevKey);

                opcodeBase.Updates.Regular?.Dispose();
                opcodeBase.Updates.Branch?.Dispose();

                if (!state.Tools.Quiet)
                {
                    Console.WriteLine("INFO: Runner:SimpleStep_Backward: after \"" + line + "\" we know:");
                }
                if (!state.Tools.Quiet)
                {
                    Console.WriteLine(stateOut);
                }
                return(stateOut);
            }
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                SnapshotPoint currentPoint = this._textView.Caret.Position.BufferPosition;
                if ((currentPoint != null) && (currentPoint > 0))
                {
                    SnapshotPoint point = currentPoint - 1;
                    if (point.Position > 1)
                    {
                        ITextSnapshotLine line    = point.Snapshot.GetLineFromPosition(point.Position);
                        string            lineStr = line.GetText();

                        int pos = point.Position - line.Start;
                        if (!AsmSourceTools.IsInRemark(pos, lineStr))
                        { //check if current position is in a remark; if we are in a remark, no signature help
                            if ((pguidCmdGroup == VSConstants.VSStd2K) && (nCmdID == (uint)VSConstants.VSStd2KCmdID.TYPECHAR))
                            {
                                char typedChar = this.GetTypeChar(pvaIn);
                                if (char.IsWhiteSpace(typedChar) || typedChar.Equals(','))
                                {
                                    var t = AsmSourceTools.ParseLine(lineStr);
                                    if (this._session != null)
                                    {
                                        this._session.Dismiss();                        // cleanup previous session
                                    }
                                    if (t.Mnemonic != Mnemonic.NONE)
                                    {
                                        this._session = this._broker.TriggerSignatureHelp(this._textView);
                                    }
                                }
                                else if (AsmSourceTools.IsRemarkChar(typedChar) && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                            else
                            {
                                bool enterPressed = nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN;
                                if (enterPressed && (this._session != null))
                                {
                                    this._session.Dismiss();
                                    this._session = null;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:Exec; e={1}", this.ToString(), e.ToString()));
            }
            return(this._nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
        }
Exemple #3
0
        /// <summary>Perform one step forward and return the regular branch</summary>
        public static State SimpleStep_Forward(string line, State state)
        {
            if (state == null)
            {
                Console.WriteLine("WARNING: Runner:SimpleStep_Forward: provided state is null");
                return(null);
            }
            try
            {
                Tools  tools         = state.Tools;
                string nextKey       = Tools.CreateKey(tools.Rand);
                string nextKeyBranch = "DUMMY_NOT_USED";
                (string label, Mnemonic mnemonic, string[] args, string remark) = AsmSourceTools.ParseLine(line);
                using (OpcodeBase opcodeBase = InstantiateOpcode(mnemonic, args, (state.HeadKey, nextKey, nextKeyBranch), tools))
                {
                    if (opcodeBase == null)
                    {
                        return(null);
                    }

                    if (opcodeBase.IsHalted)
                    {
                        Console.WriteLine("WARNING: Runner:SimpleStep_Forward: line: " + line + " is halted. Message: " + opcodeBase.SyntaxError);
                        return(null);
                    }
                    opcodeBase.Execute();
                    State stateOut = new State(state);
                    stateOut.Update_Forward(opcodeBase.Updates.regular);
                    stateOut.Frozen = true;

                    opcodeBase.Updates.regular?.Dispose();
                    opcodeBase.Updates.branch?.Dispose();

                    if (!tools.Quiet)
                    {
                        Console.WriteLine("INFO: Runner:SimpleStep_Forward: after \"" + line + "\" we know:");
                    }

                    if (!tools.Quiet)
                    {
                        Console.WriteLine(stateOut);
                    }

                    return(stateOut);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("WARNING: Runner:SimpleStep_Forward: Exception at line: " + line + "; e=" + e.Message);
                return(new State(state));
            }
        }
Exemple #4
0
        /// <summary>Perform one step forward and return states for both branches</summary>
        public static (State Regular, State Branch) Step_Forward(string line, State state)
        {
            try
            {
                string nextKey       = Tools.CreateKey(state.Tools.Rand);
                string nextKeyBranch = nextKey + "!BRANCH";
                var    content       = AsmSourceTools.ParseLine(line);
                using (var opcodeBase = Runner.InstantiateOpcode(content.Mnemonic, content.Args, (state.HeadKey, nextKey, nextKeyBranch), state.Tools))
                {
                    if (opcodeBase == null)
                    {
                        return(Regular : null, Branch : null);
                    }
                    if (opcodeBase.IsHalted)
                    {
                        return(Regular : null, Branch : null);
                    }

                    opcodeBase.Execute();
                    State stateRegular = null;
                    if (opcodeBase.Updates.Regular != null)
                    {
                        stateRegular = new State(state);
                        stateRegular.Update_Forward(opcodeBase.Updates.Regular);
                        opcodeBase.Updates.Regular.Dispose();
                    }
                    State stateBranch = null;
                    if (opcodeBase.Updates.Branch != null)
                    {
                        stateBranch = new State(state);
                        stateBranch.Update_Forward(opcodeBase.Updates.Branch);
                        opcodeBase.Updates.Branch.Dispose();
                    }
                    return(Regular : stateRegular, Branch : stateBranch);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("WARNING: Runner:Step_Forward: Exception at line: " + line + "; e=" + e.Message);
                return(null, null);
            }
        }
        public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures)
        {
            //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession");

            //if (true) return;
            if (!Settings.Default.SignatureHelp_On)
            {
                return;
            }

            try
            {
                DateTime      time1            = DateTime.Now;
                ITextSnapshot snapshot         = this._buffer.CurrentSnapshot;
                int           position         = session.GetTriggerPoint(this._buffer).GetPosition(snapshot);
                ITrackingSpan applicableToSpan = this._buffer.CurrentSnapshot.CreateTrackingSpan(new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0);

                ITextSnapshotLine line    = snapshot.GetLineFromPosition(position);
                string            lineStr = line.GetText();
                //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession: lineStr=" + lineStr+ "; positionInLine=" + positionInLine);

                var             t        = AsmSourceTools.ParseLine(lineStr);
                IList <Operand> operands = AsmSourceTools.MakeOperands(t.Args);
                Mnemonic        mnemonic = t.Mnemonic;

                ISet <Arch> selectedArchitectures = AsmDudeToolsStatic.Get_Arch_Swithed_On();
                //AsmDudeToolsStatic.Output_INFO("AsmSignatureHelpSource: AugmentSignatureHelpSession: selected architectures=" + ArchTools.ToString(selectedArchitectures));

                foreach (AsmSignatureElement se in AsmSignatureHelpSource.Constrain_Signatures(this._store.GetSignatures(mnemonic), operands, selectedArchitectures))
                {
                    signatures.Add(Create_Signature(this._buffer, se, applicableToSpan));
                }
                AsmDudeToolsStatic.Print_Speed_Warning(time1, "Signature Help");
            }
            catch (Exception e)
            {
                AsmDudeToolsStatic.Output_ERROR(string.Format("{0}:AugmentSignatureHelpSession; e={1}", ToString(), e.ToString()));
            }
        }
Exemple #6
0
        /// <summary>Perform one step forward and return the regular branch</summary>
        public static State SimpleStep_Forward(string line, State state)
        {
            Tools  tools         = state.Tools;
            string nextKey       = Tools.CreateKey(tools.Rand);
            string nextKeyBranch = "DUMMY_NOT_USED";
            var    content       = AsmSourceTools.ParseLine(line);

            using (var opcodeBase = Runner.InstantiateOpcode(content.Mnemonic, content.Args, (state.HeadKey, nextKey, nextKeyBranch), tools))
            {
                if (opcodeBase == null)
                {
                    return(null);
                }
                if (opcodeBase.IsHalted)
                {
                    Console.WriteLine("WARNING: Runner:SimpleStep_Forward: line: " + line + " is halted. Message: " + opcodeBase.SyntaxError);
                    return(null);
                }
                opcodeBase.Execute();
                State stateOut = new State(state);
                stateOut.Update_Forward(opcodeBase.Updates.Regular);
                stateOut.Frozen = true;

                opcodeBase.Updates.Regular?.Dispose();
                opcodeBase.Updates.Branch?.Dispose();

                if (!tools.Quiet)
                {
                    Console.WriteLine("INFO: Runner:SimpleStep_Forward: after \"" + line + "\" we know:");
                }
                if (!tools.Quiet)
                {
                    Console.WriteLine(stateOut);
                }
                return(stateOut);
            }
        }
Exemple #7
0
        /// <summary>Perform one step forward and return states for both branches</summary>
        public static (State Regular, State Branch) Step_Forward(string line, State state)
        {
            string nextKey       = Tools.CreateKey(state.Tools.Rand);
            string nextKeyBranch = nextKey + "!BRANCH";
            var    content       = AsmSourceTools.ParseLine(line);

            using (var opcodeBase = Runner.InstantiateOpcode(content.Mnemonic, content.Args, (state.HeadKey, nextKey, nextKeyBranch), state.Tools))
            {
                if (opcodeBase == null)
                {
                    return(Regular : null, Branch : null);
                }
                if (opcodeBase.IsHalted)
                {
                    return(Regular : null, Branch : null);
                }

                opcodeBase.Execute();
                State stateRegular = null;
                if (opcodeBase.Updates.Regular != null)
                {
                    stateRegular = new State(state);
                    stateRegular.Update_Forward(opcodeBase.Updates.Regular);
                    opcodeBase.Updates.Regular.Dispose();
                }
                State stateBranch = null;
                if (opcodeBase.Updates.Branch != null)
                {
                    stateBranch = new State(state);
                    stateBranch.Update_Forward(opcodeBase.Updates.Branch);
                    opcodeBase.Updates.Branch.Dispose();
                }

                return(Regular : stateRegular, Branch : stateBranch);
            }
        }
Exemple #8
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()));
            }
        }
Exemple #9
0
        /// <summary>Perform onestep forward and return the state of the regular branch</summary>
        public static State SimpleStep_Backward(string line, State state)
        {
            try
            {
                string prevKey = Tools.CreateKey(state.Tools.Rand);
                (string Label, Mnemonic Mnemonic, string[] Args, string Remark)content = AsmSourceTools.ParseLine(line);
                using (OpcodeBase opcodeBase = InstantiateOpcode(content.Mnemonic, content.Args, (prevKey, state.TailKey, state.TailKey), state.Tools))
                {
                    if (opcodeBase == null)
                    {
                        return(null);
                    }

                    if (opcodeBase.IsHalted)
                    {
                        return(null);
                    }

                    opcodeBase.Execute();
                    State stateOut = new State(state);
                    stateOut.Update_Backward(opcodeBase.Updates.Regular, prevKey);

                    opcodeBase.Updates.Regular?.Dispose();
                    opcodeBase.Updates.Branch?.Dispose();

                    if (!state.Tools.Quiet)
                    {
                        Console.WriteLine("INFO: Runner:SimpleStep_Backward: after \"" + line + "\" we know:");
                    }

                    if (!state.Tools.Quiet)
                    {
                        Console.WriteLine(stateOut);
                    }

                    return(stateOut);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("WARNING: Runner:SimpleStep_Backward: Exception at line: " + line + "; e=" + e.Message);
                return(new State(state));
            }
        }
Exemple #10
0
        /// <summary>Perform one step forward and return states for both branches</summary>
        public static (State regular, State branch) Step_Forward(string line, State state)
        {
            Contract.Requires(state != null);

            try
            {
                string nextKey       = Tools.CreateKey(state.Tools.Rand);
                string nextKeyBranch = nextKey + "!BRANCH";
                (string label, Mnemonic mnemonic, string[] args, string remark)content = AsmSourceTools.ParseLine(line);
                using (OpcodeBase opcodeBase = InstantiateOpcode(content.mnemonic, content.args, (state.HeadKey, nextKey, nextKeyBranch), state.Tools))
                {
                    if (opcodeBase == null)
                    {
                        return(regular : null, branch : null);
                    }

                    if (opcodeBase.IsHalted)
                    {
                        return(regular : null, branch : null);
                    }

                    opcodeBase.Execute();
                    State stateRegular = null;
                    if (opcodeBase.Updates.regular != null)
                    {
                        stateRegular = new State(state);
                        stateRegular.Update_Forward(opcodeBase.Updates.regular);
                        opcodeBase.Updates.regular.Dispose();
                    }
                    State stateBranch = null;
                    if (opcodeBase.Updates.branch != null)
                    {
                        stateBranch = new State(state);
                        stateBranch.Update_Forward(opcodeBase.Updates.branch);
                        opcodeBase.Updates.branch.Dispose();
                    }
                    return(regular : stateRegular, branch : stateBranch);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("WARNING: Runner:Step_Forward: Exception at line: " + line + "; e=" + e.Message);
                return(regular : null, branch : null);
            }
        }
Exemple #11
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()));
            }
        }