Exemplo n.º 1
0
        /// <summary>
        /// Validates the breakpoint location.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="line">The line.</param>
        /// <param name="col">The col.</param>
        /// <param name="pCodeSpan">The TextSpans to update.</param>
        /// <returns></returns>
        public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
        {
            // Return noimpl by default
            int retval = VSConstants.E_NOTIMPL;

            if (pCodeSpan != null)
            {
                // Make sure the span is set to at least the current
                // position by default.
                pCodeSpan[0].iStartLine  = line;
                pCodeSpan[0].iStartIndex = 0;
                pCodeSpan[0].iEndLine    = line;
                pCodeSpan[0].iEndIndex   = col;
            }

            if (buffer != null)
            {
                IVsTextLines textLines = buffer as IVsTextLines;
                if (textLines != null)
                {
                    AsmHighlighterScanner scanner = AsmHighlighterScannerFactory.GetScanner(textLines);
                    Scanner lexer = scanner.Lexer;

                    int maxColumn;
                    textLines.GetLengthOfLine(line, out maxColumn);
                    string lineToParse;
                    textLines.GetLineText(line, 0, line, maxColumn, out lineToParse);

                    // Setup token scanner
                    lexer.SetSource(lineToParse, 0);

                    int state = 0;
                    int start, end;

                    AsmHighlighterToken token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);

                    // Set Not a valid breakpoint
                    retval = VSConstants.S_FALSE;
                    switch (token)
                    {
                    case AsmHighlighterToken.INSTRUCTION:
                    case AsmHighlighterToken.FPUPROCESSOR:
                    case AsmHighlighterToken.SIMDPROCESSOR:
                        if (pCodeSpan != null)
                        {
                            // Breakpoint covers the whole line (including comment)
                            pCodeSpan[0].iEndIndex = maxColumn;
                        }
                        // Set valid breakpoint
                        retval = VSConstants.S_OK;
                        break;
                    }
                }
            }
            return(retval);
        }
Exemplo n.º 2
0
        static AsmHighlighterScannerFactory()
        {
            mapExtensionToScanner = new Dictionary <string, AsmHighlighterScanner>();

            // MASM Scanner
            masmScanner = new AsmHighlighterScanner(new MAsmHighlighterTokenProvider());
            mapExtensionToScanner.Add(AsmHighlighterSupportedExtensions.ASM, masmScanner);
            mapExtensionToScanner.Add(AsmHighlighterSupportedExtensions.COD, masmScanner);
            mapExtensionToScanner.Add(AsmHighlighterSupportedExtensions.INC, masmScanner);
            //// GLSL Scanner
            //nasmScanner = new AsmHighlighterScanner(new GLSLAsmHighlighterTokenProvider());
        }
        static AsmHighlighterScannerFactory()
        {
            mapExtensionToScanner = new Dictionary<string, AsmHighlighterScanner>();

            // MASM Scanner
            masmScanner = new AsmHighlighterScanner(new MAsmHighlighterTokenProvider());
            mapExtensionToScanner.Add(AsmHighlighterSupportedExtensions.ASM,masmScanner);
            mapExtensionToScanner.Add(AsmHighlighterSupportedExtensions.COD, masmScanner);
            mapExtensionToScanner.Add(AsmHighlighterSupportedExtensions.INC, masmScanner);
            //// GLSL Scanner
            //nasmScanner = new AsmHighlighterScanner(new GLSLAsmHighlighterTokenProvider());
        }
Exemplo n.º 4
0
        public static List <EditSpan> ReformatCode(IVsTextLines pBuffer, TextSpan span, int tabSize)
        {
            string filePath = FilePathUtilities.GetFilePath(pBuffer);

            // Return dynamic scanner based on file extension
            List <EditSpan> changeList = new List <EditSpan>();

            string codeToFormat;

            int endOfFirstLineIndex;

            // Get 1st line and parse custom define
            pBuffer.GetLengthOfLine(0, out endOfFirstLineIndex);
            pBuffer.GetLineText(0, 0, 0, endOfFirstLineIndex, out codeToFormat);

            Dictionary <string, string> defines = ParseDefineLine(codeToFormat);

            AsmHighlighterScanner scanner = AsmHighlighterScannerFactory.GetScanner(filePath);
            Scanner lexer = scanner.Lexer;


            // Iterate on each line of the selection to format
            for (int line = span.iStartLine; line <= span.iEndLine; line++)
            {
                int lineLength;
                pBuffer.GetLengthOfLine(line, out lineLength);
                pBuffer.GetLineText(line, 0, line, lineLength, out codeToFormat);

                string codeToAssemble = ConvertToFasm(lexer, codeToFormat, defines);

                lexer.SetSource(codeToFormat, 0);
                int state = 0;
                int start, end;

                bool instructionFound = false, commentFound = false;
                int  commentStart         = 0;
                AsmHighlighterToken token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);
                while (token != AsmHighlighterToken.EOF)
                {
                    switch (token)
                    {
                    case AsmHighlighterToken.INSTRUCTION:
                    case AsmHighlighterToken.FPUPROCESSOR:
                    case AsmHighlighterToken.SIMDPROCESSOR:
                        instructionFound = true;
                        break;

                    case AsmHighlighterToken.COMMENT_LINE:
                        if (!commentFound)
                        {
                            commentFound = true;
                            commentStart = start;
                        }
                        break;
                    }

                    if (instructionFound && commentFound)
                    {
                        byte[] buffer = null;

                        try
                        {
                            buffer = ManagedFasm.Assemble(codeToAssemble);
                        }
                        catch (Exception ex)
                        {
                            // Unable to parse instruction... skip
                        }
                        if (buffer != null)
                        {
                        }

                        TextSpan editTextSpan = new TextSpan();
                        editTextSpan.iStartLine  = line;
                        editTextSpan.iEndLine    = line;
                        editTextSpan.iStartIndex = commentStart;
                        editTextSpan.iEndIndex   = commentStart + 1;
                        if ((codeToFormat.Length - commentStart) > 2 && codeToFormat.Substring(commentStart, 2) == ";#")
                        {
                            editTextSpan.iEndIndex = editTextSpan.iEndIndex + 2;
                        }

                        string text = ";#" + ((buffer == null) ? "?" : string.Format("{0:X}", buffer.Length));
                        changeList.Add(new EditSpan(editTextSpan, text));
                        break;
                    }
                    token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);
                }
            }

            return(changeList);
        }
Exemplo n.º 5
0
        public int ComputeDataTipOnContext(IVsTextLines textLines, int line, int col, ref TextSpan span, out string tipText)
        {
            int result = VSConstants.E_NOTIMPL;

            tipText          = "";
            span.iStartLine  = line;
            span.iStartIndex = col;
            span.iEndLine    = line;
            span.iEndIndex   = col;

            if (textLines != null)
            {
                // Parse tokens and search for the token below the selection
                AsmHighlighterScanner scanner = AsmHighlighterScannerFactory.GetScanner(textLines);
                string           lineOfCode;
                List <TokenInfo> tokenInfoList = scanner.ParseLine(textLines, line, int.MaxValue, out lineOfCode);

                TokenInfo selectedTokenInfo = null;
                foreach (TokenInfo info in tokenInfoList)
                {
                    if (col >= info.StartIndex && col <= info.EndIndex)
                    {
                        selectedTokenInfo = info;
                        break;
                    }
                }

                // If a valid token was found, handle it
                if (selectedTokenInfo != null)
                {
                    AsmHighlighterToken token = (AsmHighlighterToken)selectedTokenInfo.Token;

                    // Display only tip for REGISTER or IDENTIFIER
                    if ((token & AsmHighlighterToken.IS_REGISTER) != 0 || (token & AsmHighlighterToken.IS_NUMBER) != 0 || token == AsmHighlighterToken.IDENTIFIER)
                    {
                        result = VSConstants.S_OK;

                        tipText = lineOfCode.Substring(selectedTokenInfo.StartIndex,
                                                       selectedTokenInfo.EndIndex - selectedTokenInfo.StartIndex + 1);

                        if ((token & AsmHighlighterToken.IS_REGISTER) != 0)
                        {
                            tipText = tipText.ToLower();
                            if (token == AsmHighlighterToken.REGISTER_FPU)
                            {
                                tipText = tipText.Replace("(", "");
                                tipText = tipText.Replace(")", "");
                            }
                        }

                        span.iStartIndex = selectedTokenInfo.StartIndex;
                        span.iEndIndex   = selectedTokenInfo.EndIndex + 1;

                        // If in debugging mode, display the value
                        // (This is a workaround instead of going through the Debugger.ExpressionEvaluator long way...)
                        // TODO: ExpressionEvaluator is not working, this is a workaround to display values
                        if (IsDebugging() && (((token & AsmHighlighterToken.IS_REGISTER) != 0) || token == AsmHighlighterToken.IDENTIFIER))
                        {
                            Expression expression = vs.Debugger.GetExpression(tipText, true, 1000);
                            string     valueStr   = "";

                            // Make a friendly printable version for float/double and numbers
                            try
                            {
                                if (expression.Type.Contains("double"))
                                {
                                    double value = double.Parse(expression.Value);
                                    valueStr = string.Format("{0:r}", value);
                                }
                                else
                                {
                                    long value = long.Parse(expression.Value);
                                    valueStr = string.Format("0x{0:X8}", value);
                                }
                            }
                            catch
                            {
                            }

                            // Print a printable version only if it's valid
                            if (string.IsNullOrEmpty(valueStr))
                            {
                                tipText = string.Format("{0} = {1}", tipText, expression.Value);
                            }
                            else
                            {
                                tipText = string.Format("{0} = {1} = {2}", tipText, valueStr, expression.Value);
                            }
                        }
                    }
                }
            }
            return(result);
        }