예제 #1
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);
        }
예제 #2
0
        private SortedSet <Completion> mnemonicOperandCompletions(bool useCapitals, ISet <AsmSignatureEnum> allowedOperands)
        {
            SortedSet <Completion> completions = new SortedSet <Completion>(new CompletionComparer());

            foreach (string keyword in this._asmDudeTools.getKeywords())
            {
                Arch         arch = this._asmDudeTools.getArchitecture(keyword);
                AsmTokenType type = this._asmDudeTools.getTokenType(keyword);

                bool selected = AsmDudeToolsStatic.isArchSwitchedOn(arch);
                //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:mnemonicOperandCompletions; keyword=" + keyword +"; selected="+selected +"; arch="+arch);

                if (selected)
                {
                    switch (type)
                    {
                    case AsmTokenType.Register:
                        //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn=" + keyword);
                        Rn regName = RegisterTools.parseRn(keyword);
                        if (AsmSignatureTools.isAllowedReg(regName, allowedOperands))
                        {
                            //AsmDudeToolsStatic.Output(string.Format("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn="+ keyword + " is selected"));
                        }
                        else
                        {
                            selected = false;
                        }
                        break;

                    case AsmTokenType.Misc:
                        if (AsmSignatureTools.isAllowedMisc(keyword, allowedOperands))
                        {
                            //AsmDudeToolsStatic.Output(string.Format("INFO: AsmCompletionSource:mnemonicOperandCompletions; rn="+ keyword + " is selected"));
                        }
                        else
                        {
                            selected = false;
                        }
                        break;

                    default:
                        selected = false;
                        break;
                    }
                }
                if (selected)
                {
                    //AsmDudeToolsStatic.Output("INFO: AsmCompletionSource:AugmentCompletionSession: keyword \"" + keyword + "\" is added to the completions list");

                    // by default, the entry.Key is with capitals
                    string insertionText  = (useCapitals) ? keyword : keyword.ToLower();
                    string archStr        = (arch == Arch.NONE) ? "" : " [" + ArchTools.ToString(arch) + "]";
                    string descriptionStr = this._asmDudeTools.getDescription(keyword);
                    descriptionStr = (descriptionStr.Length == 0) ? "" : " - " + descriptionStr;
                    String displayText = keyword + archStr + descriptionStr;
                    //String description = keyword.PadRight(15) + archStr.PadLeft(8) + descriptionStr;

                    ImageSource imageSource = null;
                    this._icons.TryGetValue(type, out imageSource);
                    completions.Add(new Completion(displayText, insertionText, null, imageSource, ""));
                }
            }
            return(completions);
        }