2019-09-21 20:38:16 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2019 faddenSoft
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
2019-10-20 21:40:32 +00:00
|
|
|
|
using MainWindow = SourceGen.WpfGui.MainWindow;
|
|
|
|
|
|
2019-09-21 20:38:16 +00:00
|
|
|
|
namespace SourceGen {
|
|
|
|
|
/// <summary>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
/// List of problems and oddities noted during analysis of the project.
|
2019-09-21 20:38:16 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Could also make a place for load-time problems, though those tend to be resolved by
|
|
|
|
|
/// discarding the offending data, so not much value in continuing to report them.
|
|
|
|
|
/// </remarks>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public class MessageList : IEnumerable<MessageList.MessageEntry> {
|
2019-09-21 20:38:16 +00:00
|
|
|
|
/// <summary>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
/// One message entry.
|
2019-09-21 20:38:16 +00:00
|
|
|
|
///
|
|
|
|
|
/// Instances are immutable.
|
|
|
|
|
/// </summary>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public class MessageEntry {
|
2019-09-21 20:38:16 +00:00
|
|
|
|
public enum SeverityLevel {
|
|
|
|
|
Unknown = 0,
|
|
|
|
|
Info,
|
|
|
|
|
Warning,
|
|
|
|
|
Error
|
|
|
|
|
}
|
|
|
|
|
public SeverityLevel Severity { get; private set; }
|
|
|
|
|
|
|
|
|
|
public int Offset { get; private set; }
|
|
|
|
|
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public enum MessageType {
|
2019-09-21 20:38:16 +00:00
|
|
|
|
Unknown = 0,
|
|
|
|
|
HiddenLabel,
|
2019-10-28 23:54:01 +00:00
|
|
|
|
HiddenLocalVariableTable,
|
2019-12-25 19:12:59 +00:00
|
|
|
|
HiddenVisualization,
|
2019-09-21 20:38:16 +00:00
|
|
|
|
UnresolvedWeakRef,
|
2019-10-04 23:53:31 +00:00
|
|
|
|
InvalidOffsetOrLength,
|
|
|
|
|
InvalidDescriptor,
|
2019-11-05 21:29:51 +00:00
|
|
|
|
BankOverrun,
|
2019-09-21 20:38:16 +00:00
|
|
|
|
}
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public MessageType MsgType { get; private set; }
|
2019-09-21 20:38:16 +00:00
|
|
|
|
|
|
|
|
|
// Context object. Could be a label string, a format descriptor, etc.
|
|
|
|
|
public object Context { get; private set; }
|
|
|
|
|
|
|
|
|
|
public enum ProblemResolution {
|
|
|
|
|
Unknown = 0,
|
2019-10-20 21:40:32 +00:00
|
|
|
|
None,
|
2019-09-21 20:38:16 +00:00
|
|
|
|
LabelIgnored,
|
2019-10-28 23:54:01 +00:00
|
|
|
|
LocalVariableTableIgnored,
|
2019-12-25 19:12:59 +00:00
|
|
|
|
VisualizationIgnored,
|
2019-09-21 20:38:16 +00:00
|
|
|
|
FormatDescriptorIgnored,
|
|
|
|
|
}
|
|
|
|
|
public ProblemResolution Resolution { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public MessageEntry(SeverityLevel severity, int offset, MessageType mtype,
|
2019-09-21 20:38:16 +00:00
|
|
|
|
object context, ProblemResolution resolution) {
|
2019-12-25 19:12:59 +00:00
|
|
|
|
Debug.Assert(context != null);
|
|
|
|
|
|
2019-09-21 20:38:16 +00:00
|
|
|
|
Severity = severity;
|
|
|
|
|
Offset = offset;
|
2019-10-20 21:40:32 +00:00
|
|
|
|
MsgType = mtype;
|
2019-09-21 20:38:16 +00:00
|
|
|
|
Context = context;
|
|
|
|
|
Resolution = resolution;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return Severity.ToString() + " +" + Offset.ToString("x6") + " " +
|
2019-10-20 21:40:32 +00:00
|
|
|
|
MsgType + "(" + Context.ToString() + "): " + Resolution;
|
2019-09-21 20:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Maximum file offset. Used to flag offsets as invalid.
|
|
|
|
|
/// </summary>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
//public int MaxOffset { get; set; }
|
2019-09-21 20:38:16 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
/// List of messages. This is not kept in sorted order, because the DataGrid used to
|
2019-10-21 01:02:23 +00:00
|
|
|
|
/// display it will do the sorting for us. Call the Sort() function to establish an
|
|
|
|
|
/// initial sort.
|
2019-09-21 20:38:16 +00:00
|
|
|
|
/// </summary>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
private List<MessageEntry> mList;
|
2019-09-21 20:38:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public MessageList() {
|
|
|
|
|
mList = new List<MessageEntry>();
|
2019-09-21 20:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IEnumerable
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public IEnumerator<MessageEntry> GetEnumerator() {
|
2019-09-21 20:38:16 +00:00
|
|
|
|
// .Values is documented as O(1)
|
|
|
|
|
return mList.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IEnumerable
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() {
|
|
|
|
|
return mList.GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Count {
|
|
|
|
|
get { return mList.Count; }
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 21:40:32 +00:00
|
|
|
|
public void Add(MessageEntry entry) {
|
2019-09-21 20:38:16 +00:00
|
|
|
|
mList.Add(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear() {
|
|
|
|
|
mList.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 01:02:23 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sorts the list, by severity then offset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Sort() {
|
|
|
|
|
mList.Sort(delegate (MessageEntry a, MessageEntry b) {
|
|
|
|
|
if (a.Severity != b.Severity) {
|
|
|
|
|
return (int)b.Severity - (int)a.Severity;
|
|
|
|
|
}
|
|
|
|
|
return a.Offset - b.Offset;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-20 21:40:32 +00:00
|
|
|
|
/// <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;
|
2019-10-28 23:54:01 +00:00
|
|
|
|
case MessageEntry.MessageType.HiddenLocalVariableTable:
|
|
|
|
|
problem = Res.Strings.MSG_HIDDEN_LOCAL_VARIABLE_TABLE;
|
|
|
|
|
break;
|
2019-12-25 19:12:59 +00:00
|
|
|
|
case MessageEntry.MessageType.HiddenVisualization:
|
|
|
|
|
problem = Res.Strings.MSG_HIDDEN_VISUALIZATION;
|
|
|
|
|
break;
|
2019-10-20 21:40:32 +00:00
|
|
|
|
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;
|
2019-11-05 21:29:51 +00:00
|
|
|
|
case MessageEntry.MessageType.BankOverrun:
|
|
|
|
|
problem = Res.Strings.MSG_BANK_OVERRUN;
|
|
|
|
|
break;
|
2019-10-20 21:40:32 +00:00
|
|
|
|
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;
|
2019-10-28 23:54:01 +00:00
|
|
|
|
case MessageEntry.ProblemResolution.LocalVariableTableIgnored:
|
|
|
|
|
resolution = Res.Strings.MSG_LOCAL_VARIABLE_TABLE_IGNORED;
|
|
|
|
|
break;
|
2019-10-20 21:40:32 +00:00
|
|
|
|
case MessageEntry.ProblemResolution.FormatDescriptorIgnored:
|
|
|
|
|
resolution = Res.Strings.MSG_FORMAT_DESCRIPTOR_IGNORED;
|
|
|
|
|
break;
|
2019-12-25 19:12:59 +00:00
|
|
|
|
case MessageEntry.ProblemResolution.VisualizationIgnored:
|
|
|
|
|
resolution = Res.Strings.MSG_VISUALIZATION_IGNORED;
|
|
|
|
|
break;
|
2019-10-20 21:40:32 +00:00
|
|
|
|
default:
|
|
|
|
|
resolution = "???";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 01:02:23 +00:00
|
|
|
|
return new MainWindow.MessageListItem(severity, entry.Offset, offset, problem,
|
|
|
|
|
context, resolution);
|
2019-10-20 21:40:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-21 20:38:16 +00:00
|
|
|
|
public void DebugDump() {
|
2019-10-20 21:40:32 +00:00
|
|
|
|
Debug.WriteLine("Message list (" + mList.Count + " entries):");
|
|
|
|
|
foreach (MessageEntry entry in mList) {
|
2019-09-21 20:38:16 +00:00
|
|
|
|
Debug.WriteLine(entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|