Пример #1
0
        /// <summary>
        /// Converts a label to displayable form by stripping the uniquification tag (if any),
        /// inserting the non-unique label prefix if appropriate, and appending the optional
        /// annotation character.
        /// </summary>
        /// <remarks>
        /// There's generally two ways to display a label:
        ///  (1) When displaying labels on-screen, we get a label with the uniquification tag,
        ///      and we want to show the non-unique label prefix ('@' or ':') and annotation.
        ///  (2) When generating assembly source, we get a remapped label with no uniquification
        ///      tag, and we don't want to show the prefix or annotation.
        /// For case #2, there's no reason to call here.  (We're currently doing so because
        /// remapping isn't happening yet, but that should change soon.  When that happens, we
        /// should be able to eliminate the showNonUnique arg.)
        /// </remarks>
        /// <param name="label">Base label string.  Has the uniquification tag, but no
        ///   annotation char or non-unique prefix.</param>
        /// <param name="anno">Annotation; may be None.</param>
        /// <param name="showNonUnique">Set true if the returned label should show the
        ///   non-unique label prefix.</param>
        /// <param name="formatter">Format object that holds the non-unique label prefix
        ///   string.</param>
        /// <returns>Formatted label.</returns>
        public static string ConvertLabelForDisplay(string label, LabelAnnotation anno,
                                                    bool showNonUnique, Asm65.Formatter formatter)
        {
            StringBuilder sb = new StringBuilder(label.Length + 2);

            if (label.Length > NON_UNIQUE_LEN &&
                label[label.Length - NON_UNIQUE_LEN] == UNIQUE_TAG_CHAR)
            {
                // showNonUnique may be false if generating assembly code (but by this
                // point the unique tag should be remapped away)
                if (showNonUnique)
                {
                    sb.Append(formatter.NonUniqueLabelPrefix);
                }
                sb.Append(label.Substring(0, label.Length - NON_UNIQUE_LEN));
            }
            else
            {
                sb.Append(label);
            }

            char annoChar = GetLabelAnnoChar(anno);

            if (annoChar != NO_ANNO_CHAR)
            {
                sb.Append(annoChar);
            }
            return(sb.ToString());
        }
Пример #2
0
        public EditLongComment(Asm65.Formatter formatter)
        {
            InitializeComponent();

            mFormatter  = formatter;
            LongComment = new MultiLineComment(string.Empty);
        }
Пример #3
0
        /// <summary>
        /// Formats a message for display.
        /// </summary>
        public static MainWindow.MessageListItem FormatMessage(MessageEntry entry,
                                                               Asm65.Formatter formatter)
        {
            string severity = entry.Severity.ToString();        // enum
            string offset   = formatter.FormatOffset24(entry.Offset);

            string problem;

            switch (entry.MsgType)
            {
            case MessageEntry.MessageType.HiddenLabel:
                problem = Res.Strings.MSG_HIDDEN_LABEL;
                break;

            case MessageEntry.MessageType.UnresolvedWeakRef:
                problem = Res.Strings.MSG_UNRESOLVED_WEAK_REF;
                break;

            case MessageEntry.MessageType.InvalidOffsetOrLength:
                problem = Res.Strings.MSG_INVALID_OFFSET_OR_LENGTH;
                break;

            case MessageEntry.MessageType.InvalidDescriptor:
                problem = Res.Strings.MSG_INVALID_DESCRIPTOR;
                break;

            default:
                problem = "???";
                break;
            }

            string context = entry.Context.ToString();

            string resolution;

            switch (entry.Resolution)
            {
            case MessageEntry.ProblemResolution.None:
                resolution = string.Empty;
                break;

            case MessageEntry.ProblemResolution.LabelIgnored:
                resolution = Res.Strings.MSG_LABEL_IGNORED;
                break;

            case MessageEntry.ProblemResolution.FormatDescriptorIgnored:
                resolution = Res.Strings.MSG_FORMAT_DESCRIPTOR_IGNORED;
                break;

            default:
                resolution = "???";
                break;
            }

            return(new MainWindow.MessageListItem(severity, entry.Offset, offset, problem,
                                                  context, resolution));
        }
Пример #4
0
        public EditLongComment(Window owner, Asm65.Formatter formatter)
        {
            InitializeComponent();
            Owner       = owner;
            DataContext = this;

            mFormatter  = formatter;
            LongComment = new MultiLineComment(string.Empty);
        }
Пример #5
0
        public EditData(byte[] fileData, SymbolTable symbolTable, Asm65.Formatter formatter)
        {
            InitializeComponent();

            mFileData    = fileData;
            mSymbolTable = symbolTable;
            mFormatter   = formatter;

            //Results = new List<Result>();
        }
Пример #6
0
 /// <summary>
 /// Generates a displayable form of the label.  This will have the non-unique label
 /// prefix and annotation suffix, and will have the non-unique tag removed.
 /// </summary>
 /// <param name="formatter">Formatter object.</param>
 /// <returns>Label suitable for display.</returns>
 public string GenerateDisplayLabel(Asm65.Formatter formatter)
 {
     return(ConvertLabelForDisplay(Label, LabelAnno, true, formatter));
 }
Пример #7
0
        /// <summary>
        /// Generates one or more lines of formatted text.
        /// </summary>
        /// <param name="formatter">Formatter, with comment delimiters.</param>
        /// <param name="textPrefix">String to prepend to text before formatting.  If this
        ///   is non-empty, comment delimiters aren't emitted.  (Used for notes.)</param>
        /// <returns>Array of formatted strings.</returns>
        public List <string> FormatText(Asm65.Formatter formatter, string textPrefix)
        {
            const char    boxChar    = '*';
            const char    spcRep     = '\u2219';
            string        workString = string.IsNullOrEmpty(textPrefix) ? Text : textPrefix + Text;
            List <string> lines      = new List <string>();

            string linePrefix;

            if (!string.IsNullOrEmpty(textPrefix))
            {
                linePrefix = string.Empty;
            }
            else if (BoxMode)
            {
                linePrefix = formatter.BoxLineCommentDelimiter;
            }
            else
            {
                linePrefix = formatter.FullLineCommentDelimiter;
            }

            StringBuilder sb = new StringBuilder(MaxWidth);

            if (DebugShowRuler)
            {
                for (int i = 0; i < MaxWidth; i++)
                {
                    sb.Append((i % 10).ToString());
                }
                lines.Add(sb.ToString());
                sb.Clear();
            }
            string boxLine, spaces;

            if (BoxMode)
            {
                for (int i = 0; i < MaxWidth - linePrefix.Length; i++)
                {
                    sb.Append(boxChar);
                }
                boxLine = sb.ToString();
                sb.Clear();
                for (int i = 0; i < MaxWidth; i++)
                {
                    sb.Append(' ');
                }
                spaces = sb.ToString();
                sb.Clear();
            }
            else
            {
                boxLine = spaces = null;
            }

            if (BoxMode && workString.Length > 0)
            {
                lines.Add(linePrefix + boxLine);
            }

            int lineWidth = BoxMode ?
                            MaxWidth - linePrefix.Length - 4 :
                            MaxWidth - linePrefix.Length;
            int startIndex = 0;
            int breakIndex = -1;

            for (int i = 0; i < workString.Length; i++)
            {
                // Spaces and hyphens are different.  For example, if width is 10,
                // "long words<space>more words" becomes:
                //   0123456789
                //   long words
                //   more words
                // However, "long words-more words" becomes:
                //   long
                //   words-more
                //   words
                // because the hyphen is retained but the space is discarded.

                if (workString[i] == '\r' || workString[i] == '\n')
                {
                    // explicit line break, emit line
                    string str = workString.Substring(startIndex, i - startIndex);
                    if (DebugShowRuler)
                    {
                        str = str.Replace(' ', spcRep);
                    }
                    if (BoxMode)
                    {
                        if (str == "" + boxChar)
                        {
                            // asterisk on a line by itself means "output row of asterisks"
                            str = linePrefix + boxLine;
                        }
                        else
                        {
                            int padLen = lineWidth - str.Length;
                            str = linePrefix + boxChar + " " + str +
                                  spaces.Substring(0, padLen + 1) + boxChar;
                        }
                    }
                    else
                    {
                        str = linePrefix + str;
                    }
                    lines.Add(str);
                    // Eat the LF in CRLF.  We don't actually work right with just LF,
                    // because this will consume LFLF, but it's okay to insist that the
                    // string use CRLF for line breaks.
                    if (i < workString.Length - 1 && workString[i + 1] == '\n')
                    {
                        i++;
                    }
                    startIndex = i + 1;
                    breakIndex = -1;
                }
                else if (workString[i] == ' ')
                {
                    // can break on a space even if it's one char too far
                    breakIndex = i;
                }

                if (i - startIndex >= lineWidth)
                {
                    // this character was one too many, break line one back
                    if (breakIndex <= 0)
                    {
                        // no break found, just chop it
                        string str = workString.Substring(startIndex, i - startIndex);
                        if (DebugShowRuler)
                        {
                            str = str.Replace(' ', spcRep);
                        }
                        if (BoxMode)
                        {
                            str = linePrefix + boxChar + " " + str + " " + boxChar;
                        }
                        else
                        {
                            str = linePrefix + str;
                        }
                        lines.Add(str);
                        startIndex = i;
                    }
                    else
                    {
                        // Copy everything from start to break.  If the break was a hyphen,
                        // we want to keep it.
                        int adj = 0;
                        if (workString[breakIndex] == '-')
                        {
                            adj = 1;
                        }
                        string str = workString.Substring(startIndex,
                                                          breakIndex + adj - startIndex);
                        if (DebugShowRuler)
                        {
                            str = str.Replace(' ', spcRep);
                        }
                        if (BoxMode)
                        {
                            int padLen = lineWidth - str.Length;
                            str = linePrefix + boxChar + " " + str +
                                  spaces.Substring(0, padLen + 1) + boxChar;
                        }
                        else
                        {
                            str = linePrefix + str;
                        }
                        lines.Add(str);
                        startIndex = breakIndex + 1;
                        if (adj == 0 && startIndex < workString.Length &&
                            workString[startIndex] == ' ')
                        {
                            // We broke on a space, and are now starting a line on a space,
                            // which looks weird (and happens commonly at the end of a
                            // sentence).  Eat one more space.
                            startIndex++;
                        }
                        breakIndex = -1;
                    }
                }

                if (workString[i] == '-')
                {
                    // can break on hyphen if it fits in line
                    breakIndex = i;
                }
            }

            if (startIndex < workString.Length)
            {
                // Output remainder.
                string str = workString.Substring(startIndex, workString.Length - startIndex);
                if (DebugShowRuler)
                {
                    str = str.Replace(' ', spcRep);
                }
                if (BoxMode)
                {
                    int padLen = lineWidth - str.Length;
                    str = linePrefix + boxChar + " " + str +
                          spaces.Substring(0, padLen + 1) + boxChar;
                }
                else
                {
                    str = linePrefix + str;
                }
                lines.Add(str);
            }

            if (BoxMode && workString.Length > 0)
            {
                lines.Add(linePrefix + boxLine);
            }

            return(lines);
        }