From e00cb374e6d7ec31fbd64e14e126c3c341e331b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A4ll=C3=A9n?= Date: Fri, 9 Aug 2024 09:19:07 +0200 Subject: [PATCH] Maintenance: reduce the number of build warnings. --- src/Arch/Telink/TC32Architecture.cs | 2 +- src/Core/IRFormat/ParserException.cs | 4 --- src/Core/Lib/SuffixArray2.cs | 6 ++-- .../Analysis/FpuStackReturnGuesser.cs | 2 +- src/Decompiler/Scanning/FetFinder.cs | 3 -- src/Decompiler/Scanning/ScanResults.cs | 18 +++++----- src/Decompiler/Scanning/ScannerInLinq.cs | 36 +++++++++---------- src/Decompiler/Scanning/ShingledScanner.cs | 4 +-- src/Environments/PalmOS/Traps.cs | 6 ---- src/Gui/ISearchResult.cs | 2 +- src/Gui/TextViewing/DisassemblyFormatter.cs | 10 +++--- src/ImageLoaders/Coff/eCoff/BeLoader.cs | 12 +++---- src/ImageLoaders/Coff/eCoff/Structures.cs | 6 ++-- .../IntelHex/IntelHexException.cs | 28 --------------- src/ImageLoaders/Ldm/LdmLoader.cs | 4 +-- src/ImageLoaders/OdbgScript/Debugger.cs | 2 ++ .../OdbgScript/OdbgScriptLoader.cs | 6 ++-- .../OllyLangInterpreter.Commands.cs | 3 +- .../OdbgScript/OllyLangInterpreter.cs | 2 ++ src/ImageLoaders/OdbgScript/var.cs | 2 ++ .../Decompiler/Scanning/ScannerInLinqTests.cs | 22 ++++++------ .../AvaloniaUI/Controls/HexViewer.cs | 29 +++++++++++---- .../AvaloniaUI/Controls/StyleStack.cs | 22 ++++++------ .../AvaloniaUI/Controls/TextPointer.cs | 4 --- .../AvaloniaUI/Controls/TextSpan.cs | 12 +++++-- .../AvaloniaUI/Controls/TextView.cs | 1 + .../AvaloniaUI/Controls/TextViewLayout.cs | 4 +-- .../AvaloniaUI/Controls/TextViewPainter.cs | 3 +- .../PropertyOptionsGridAdapter.cs | 33 ++++++++++------- .../WindowsForms/SearchResultServiceImpl.cs | 4 ++- .../WindowsForms/StackTraceService.cs | 2 +- 31 files changed, 144 insertions(+), 150 deletions(-) diff --git a/src/Arch/Telink/TC32Architecture.cs b/src/Arch/Telink/TC32Architecture.cs index 7b8f2590ee..43df3d5718 100644 --- a/src/Arch/Telink/TC32Architecture.cs +++ b/src/Arch/Telink/TC32Architecture.cs @@ -43,7 +43,7 @@ public TC32Architecture(IServiceProvider services, string archId, Dictionary 0; AddFpuToCallDefs(fpuDefs, callStm, ci); diff --git a/src/Decompiler/Scanning/FetFinder.cs b/src/Decompiler/Scanning/FetFinder.cs index 937159fd24..6c1700ce08 100644 --- a/src/Decompiler/Scanning/FetFinder.cs +++ b/src/Decompiler/Scanning/FetFinder.cs @@ -49,9 +49,6 @@ public class FetFinder : AbstractBaseAddressFinder private readonly BigInteger wordMask; private uint word_size; - private uint uAddrMax; - private uint uAddrMin; - public FetFinder( IProcessorArchitecture arch, diff --git a/src/Decompiler/Scanning/ScanResults.cs b/src/Decompiler/Scanning/ScanResults.cs index 7c6d157c70..3b9222b35e 100644 --- a/src/Decompiler/Scanning/ScanResults.cs +++ b/src/Decompiler/Scanning/ScanResults.cs @@ -45,8 +45,8 @@ public ScanResults() this.TransferTargets = new HashSet
(); this.DirectlyCalledAddresses = new Dictionary(); this.Instructions = new Dictionary(); - this.FlatInstructions = new Dictionary(); - this.FlatEdges = new List(); + this.FlatInstructions = new Dictionary(); + this.FlatEdges = new List(); this.IndirectCalls = new HashSet
(); this.IndirectJumps = new HashSet
(); this.Procedures = new List(); @@ -98,8 +98,8 @@ public ScanResults() /// This is a key end result of the scanning stage. /// public List Procedures { get; set; } - public Dictionary FlatInstructions { get; set; } - public List FlatEdges { get; set; } + public Dictionary FlatInstructions { get; set; } + public List FlatEdges { get; set; } /// /// All the places that were identified as padding. @@ -180,7 +180,7 @@ public void Dump(string caption = "Dump") #endif } - public class instr + public class Instr { public Address addr; public int size; @@ -191,14 +191,14 @@ public class instr public RtlInstructionCluster rtl; } - public class link + public class Link { public Address first; public Address second; public override bool Equals(object obj) { - if (!(obj is link that)) + if (!(obj is Link that)) return false; return that.first == this.first && that.second == this.second; } @@ -214,11 +214,11 @@ public override string ToString() } } - public class block + public class Block { public Address id; // Address of block public Address component_id; // Component we're part of. - public instr[] instrs; // The instructions of the block. + public Instr[] instrs; // The instructions of the block. } [Conditional("DEBUG")] diff --git a/src/Decompiler/Scanning/ScannerInLinq.cs b/src/Decompiler/Scanning/ScannerInLinq.cs index 3f594cfb04..4228fb8d5f 100644 --- a/src/Decompiler/Scanning/ScannerInLinq.cs +++ b/src/Decompiler/Scanning/ScannerInLinq.cs @@ -33,9 +33,9 @@ namespace Reko.Scanning { - using block = ScanResults.block; - using instr = ScanResults.instr; - using link = ScanResults.link; + using Block = ScanResults.Block; + using Instr = ScanResults.Instr; + using Link = ScanResults.Link; public class ScannerInLinq { @@ -307,7 +307,7 @@ public static void Probe(ScanResults sr) /// 1 predecessor or successors. These instructions delimit the start and /// end of the basic blocks. /// - public static Dictionary BuildBasicBlocks(ScanResults sr) + public static Dictionary BuildBasicBlocks(ScanResults sr) { // Count and save the # of successors for each instruction. foreach (var cSucc in @@ -328,14 +328,14 @@ group link by link.second into g instr.pred = cPred.Count; } - var the_excluded_edges = new HashSet(); + var the_excluded_edges = new HashSet(); foreach (var instr in sr.FlatInstructions.Values) { // All blocks must start with a linear instruction. if ((instr.type & (ushort)InstrClass.Linear) == 0) continue; // Find the instruction that is located directly after instr. - if (!sr.FlatInstructions.TryGetValue(instr.addr.ToLinear() + (uint) instr.size, out instr? succ)) + if (!sr.FlatInstructions.TryGetValue(instr.addr.ToLinear() + (uint) instr.size, out Instr? succ)) continue; // If the first instruction was padding the next one must also be padding, // otherwise we start a new block. @@ -357,7 +357,7 @@ group link by link.second into g !sr.DirectlyCalledAddresses.ContainsKey(succ.addr)) { succ.block_id = instr.block_id; - the_excluded_edges.Add(new link { first = instr.addr, second = succ.addr }); + the_excluded_edges.Add(new Link { first = instr.addr, second = succ.addr }); } } @@ -365,7 +365,7 @@ group link by link.second into g var the_blocks = (from i in sr.FlatInstructions.Values group i by i.block_id into g - select new block + select new Block { id = g.Key, instrs = g.OrderBy(ii => ii.addr).ToArray() @@ -376,7 +376,7 @@ group i by i.block_id into g (from link in sr.FlatEdges join f in sr.FlatInstructions.Values on link.first equals f.addr where !the_excluded_edges.Contains(link) - select new link { first = f.block_id, second = link.second }) + select new Link { first = f.block_id, second = link.second }) .Distinct() .ToList(); return the_blocks; @@ -387,7 +387,7 @@ join f in sr.FlatInstructions.Values on link.first equals f.addr /// are invalid. /// /// A (hopefully smaller) set of blocks. - public static Dictionary RemoveInvalidBlocks(ScanResults sr, Dictionary blocks) + public static Dictionary RemoveInvalidBlocks(ScanResults sr, Dictionary blocks) { // Find transitive closure of bad instructions @@ -444,7 +444,7 @@ public static Dictionary RemoveInvalidBlocks(ScanResults sr, Dic return blocks; } - private static bool BlockEndsWithCall(block block) + private static bool BlockEndsWithCall(Block block) { int len = block.instrs.Length; if (len < 1) @@ -457,7 +457,7 @@ private static bool BlockEndsWithCall(block block) public static DiGraph BuildIcfg( ScanResults sr, NamingPolicy namingPolicy, - Dictionary blocks) + Dictionary blocks) { var icfg = new DiGraph(); var map = new Dictionary(); @@ -501,13 +501,13 @@ select string.Format( e))); } - private void DumpBlocks(ScanResults sr, Dictionary blocks) + private void DumpBlocks(ScanResults sr, Dictionary blocks) { DumpBlocks(sr, blocks, s => Debug.WriteLine(s)); } // Writes the start and end addresses, size, and successor edges of each block, - public void DumpBlocks(ScanResults sr, Dictionary blocks, Action writeLine) + public void DumpBlocks(ScanResults sr, Dictionary blocks, Action writeLine) { writeLine( string.Join(Environment.NewLine, @@ -546,7 +546,7 @@ static string RenderType(ushort type) } } - private static void DumpBadBlocks(ScanResults sr, Dictionary blocks, IEnumerable edges, HashSet
bad_blocks) + private static void DumpBadBlocks(ScanResults sr, Dictionary blocks, IEnumerable edges, HashSet
bad_blocks) { Debug.Print( "{0}", @@ -570,7 +570,7 @@ select string.Format( } [Conditional("DEBUG")] - private static void Dump(Dictionary the_blocks) + private static void Dump(Dictionary the_blocks) { foreach (var block in the_blocks.Values) { @@ -579,7 +579,7 @@ private static void Dump(Dictionary the_blocks) } [Conditional("DEBUG")] - private static void Dump(IEnumerable edges) + private static void Dump(IEnumerable edges) { foreach (var link in edges) { @@ -588,7 +588,7 @@ private static void Dump(IEnumerable edges) } [Conditional("DEBUG")] - private static void Dump(IEnumerable blocks) + private static void Dump(IEnumerable blocks) { foreach (var i in blocks) { diff --git a/src/Decompiler/Scanning/ShingledScanner.cs b/src/Decompiler/Scanning/ShingledScanner.cs index 25f215e67a..de0524e692 100644 --- a/src/Decompiler/Scanning/ShingledScanner.cs +++ b/src/Decompiler/Scanning/ShingledScanner.cs @@ -286,7 +286,7 @@ public byte[] ScanRange(IProcessorArchitecture arch, MemoryArea mem, Address add private void AddInstruction(RtlInstructionCluster i) { - sr.FlatInstructions.Add(i.Address.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(i.Address.ToLinear(), new ScanResults.Instr { addr = i.Address, size = i.Length, @@ -303,7 +303,7 @@ public void AddEdge(Address from, Address to) { if (from == Bad) return; - sr.FlatEdges.Add(new ScanResults.link + sr.FlatEdges.Add(new ScanResults.Link { first = to, second = from, diff --git a/src/Environments/PalmOS/Traps.cs b/src/Environments/PalmOS/Traps.cs index fa14940ee7..1cf31e303d 100644 --- a/src/Environments/PalmOS/Traps.cs +++ b/src/Environments/PalmOS/Traps.cs @@ -1412,17 +1412,11 @@ private static DataType GetPointerParameter(ReadOnlySpan a) private static DataType CreateParameterType(string arg) { - bool output; int a = 0; if (arg[0] == 'o') { - output = true; a++; } - else - { - output = false; - } DataType dt; if (arg.Length == a + 1) diff --git a/src/Gui/ISearchResult.cs b/src/Gui/ISearchResult.cs index b85fac62a7..55c2fdf9b0 100644 --- a/src/Gui/ISearchResult.cs +++ b/src/Gui/ISearchResult.cs @@ -63,6 +63,6 @@ public interface ISearchResultView void AddColumn(string columnTitle, int width); void Invalidate(); - Task ShowTypeMarker(Program program, Address addr); + Task ShowTypeMarker(Program program, Address addr); } } \ No newline at end of file diff --git a/src/Gui/TextViewing/DisassemblyFormatter.cs b/src/Gui/TextViewing/DisassemblyFormatter.cs index b033946561..aaa86d2f75 100644 --- a/src/Gui/TextViewing/DisassemblyFormatter.cs +++ b/src/Gui/TextViewing/DisassemblyFormatter.cs @@ -39,7 +39,6 @@ public class DisassemblyFormatter : MachineInstructionRenderer private List line; private List annotations; private string mnemonicStyle; - private Address addrInstr; public DisassemblyFormatter( TextSpanFactory factory, @@ -57,11 +56,10 @@ public DisassemblyFormatter( this.mnemonicStyle = Gui.Services.UiStyles.DisassemblerOpcode; } - public Address Address => addrInstr; + public Address Address => instr.Address; public void BeginInstruction(Address addr) { - this.addrInstr = addr; } public void EndInstruction() @@ -130,7 +128,7 @@ public void WriteUInt32(uint n) sb.Append(n); } - public void WriteString(string s) + public void WriteString(string? s) { sb.Append(s); } @@ -140,8 +138,10 @@ public void WriteFormat(string fmt, params object[] parms) sb.AppendFormat(fmt, parms); } - public void AddAnnotation(string annotation) + public void AddAnnotation(string? annotation) { + if (annotation is null) + return; this.annotations.Add(annotation); } diff --git a/src/ImageLoaders/Coff/eCoff/BeLoader.cs b/src/ImageLoaders/Coff/eCoff/BeLoader.cs index 96a1c902ae..568077291c 100644 --- a/src/ImageLoaders/Coff/eCoff/BeLoader.cs +++ b/src/ImageLoaders/Coff/eCoff/BeLoader.cs @@ -33,7 +33,7 @@ namespace Reko.ImageLoaders.Coff.eCoff { public class BeLoader : ProgramImageLoader { - private aouthdr? opthdr; + private AOuthdr? opthdr; public BeLoader(IServiceProvider services, ImageLocation imageLocation, byte[] rawImage) : base(services, imageLocation, rawImage) @@ -46,17 +46,17 @@ public BeLoader(IServiceProvider services, ImageLocation imageLocation, byte[] r public override Program LoadProgram(Address? addrLoad) { var rdr = new BeImageReader(RawImage); - var header = rdr.ReadStruct(); + var header = rdr.ReadStruct(); if (header.f_opthdr != 0) { var sectionOffset = rdr.Offset + header.f_opthdr; - opthdr = rdr.ReadStruct(); + opthdr = rdr.ReadStruct(); rdr.Offset = sectionOffset; } - var sections = new scnhdr[header.f_nscns]; + var sections = new Scnhdr[header.f_nscns]; for (int i = 0; i < sections.Length; ++i) { - sections[i] = rdr.ReadStruct(); + sections[i] = rdr.ReadStruct(); } var imgSegments = new ImageSegment[header.f_nscns]; for (int i = 0; i < sections.Length; ++i) @@ -77,7 +77,7 @@ public override Program LoadProgram(Address? addrLoad) return program; } - private ImageSegment LoadImageSegment(in scnhdr scnhdr) + private ImageSegment LoadImageSegment(in Scnhdr scnhdr) { var bytes = new byte[scnhdr.s_size]; var availableBytes = RawImage.Length - scnhdr.s_scnptr; diff --git a/src/ImageLoaders/Coff/eCoff/Structures.cs b/src/ImageLoaders/Coff/eCoff/Structures.cs index 307f6ea4d3..5708345f30 100644 --- a/src/ImageLoaders/Coff/eCoff/Structures.cs +++ b/src/ImageLoaders/Coff/eCoff/Structures.cs @@ -42,7 +42,7 @@ namespace Reko.ImageLoaders.Coff.eCoff [StructLayout(LayoutKind.Sequential, Pack = 1)] [Endian(Endianness.BigEndian)] - public struct filehdr + public struct Filehdr { public coff_ushort f_magic; public coff_ushort f_nscns; @@ -55,7 +55,7 @@ public struct filehdr [StructLayout(LayoutKind.Sequential, Pack = 1)] [Endian(Endianness.BigEndian)] - public struct aouthdr + public struct AOuthdr { public coff_ushort magic; public coff_ushort vstamp; @@ -76,7 +76,7 @@ public struct aouthdr [StructLayout(LayoutKind.Sequential, Pack = 1)] [Endian(Endianness.BigEndian)] - public struct scnhdr + public struct Scnhdr { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] s_name; diff --git a/src/ImageLoaders/IntelHex/IntelHexException.cs b/src/ImageLoaders/IntelHex/IntelHexException.cs index 256cfa172b..5df19bbd1c 100644 --- a/src/ImageLoaders/IntelHex/IntelHexException.cs +++ b/src/ImageLoaders/IntelHex/IntelHexException.cs @@ -65,34 +65,6 @@ public IntelHexException(string message, Exception innerException, int lineNo = LineNumber = lineNo; } - /// - /// Constructor for serialization. - /// - /// The that - /// holds the serialized object data about the exception being thrown. - /// The that - /// contains contextual information about the source or destination. - public IntelHexException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - LineNumber = (int) info.GetValue(nameof(LineNumber), typeof(int))!; - } - - /// - /// When overridden in a derived class, sets the - /// with information about the - /// exception. - /// - /// The that - /// holds the serialized object data about the exception being thrown. - /// The that - /// contains contextual information about the source or destination. - public override void GetObjectData(SerializationInfo info, StreamingContext context) - { - base.GetObjectData(info, context); - info.AddValue(nameof(LineNumber), LineNumber, typeof(int)); - } - #endregion /// diff --git a/src/ImageLoaders/Ldm/LdmLoader.cs b/src/ImageLoaders/Ldm/LdmLoader.cs index 8227c918b2..417781e47e 100644 --- a/src/ImageLoaders/Ldm/LdmLoader.cs +++ b/src/ImageLoaders/Ldm/LdmLoader.cs @@ -615,7 +615,7 @@ are a copy of the least significant 12 bits of the logical address. By default, the MMU behaves just as though it were not there at all. */ - public struct mmureg + public struct Mmureg { public ushort ppa ;/* : 8;*/ public ushort reserved;/* : 3;*/ @@ -624,7 +624,7 @@ public struct mmureg public ushort Value { get; set; } } - readonly mmureg [,,] pagereg = new mmureg[2,16,16]; + readonly Mmureg [,,] pagereg = new Mmureg[2,16,16]; } } \ No newline at end of file diff --git a/src/ImageLoaders/OdbgScript/Debugger.cs b/src/ImageLoaders/OdbgScript/Debugger.cs index be6070a35a..67d0702982 100644 --- a/src/ImageLoaders/OdbgScript/Debugger.cs +++ b/src/ImageLoaders/OdbgScript/Debugger.cs @@ -3,6 +3,8 @@ using Reko.Core.Expressions; using System; +#pragma warning disable CS8981 + namespace Reko.ImageLoaders.OdbgScript { using rulong = System.UInt64; diff --git a/src/ImageLoaders/OdbgScript/OdbgScriptLoader.cs b/src/ImageLoaders/OdbgScript/OdbgScriptLoader.cs index 8b5a09757f..5e981585f1 100644 --- a/src/ImageLoaders/OdbgScript/OdbgScriptLoader.cs +++ b/src/ImageLoaders/OdbgScript/OdbgScriptLoader.cs @@ -18,17 +18,17 @@ */ #endregion +#pragma warning disable IDE1006 // Naming Styles +#pragma warning disable CS8981 + using Reko.Core; -using Reko.Core.Emulation; using Reko.Core.Loading; using Reko.Core.Services; using System; -using System.Collections.Generic; using System.IO; using System.Linq; using rulong = System.UInt64; -#pragma warning disable IDE1006 // Naming Styles namespace Reko.ImageLoaders.OdbgScript { diff --git a/src/ImageLoaders/OdbgScript/OllyLangInterpreter.Commands.cs b/src/ImageLoaders/OdbgScript/OllyLangInterpreter.Commands.cs index e4c81b67c7..8073eb8251 100644 --- a/src/ImageLoaders/OdbgScript/OllyLangInterpreter.Commands.cs +++ b/src/ImageLoaders/OdbgScript/OllyLangInterpreter.Commands.cs @@ -18,9 +18,10 @@ */ #endregion +#pragma warning disable CS8981 + using Reko.Core; using Reko.Core.Expressions; -using Reko.Core.Lib; using Reko.Core.Loading; using Reko.Core.Memory; using Reko.Core.Output; diff --git a/src/ImageLoaders/OdbgScript/OllyLangInterpreter.cs b/src/ImageLoaders/OdbgScript/OllyLangInterpreter.cs index feb4001482..0c2c07a84f 100644 --- a/src/ImageLoaders/OdbgScript/OllyLangInterpreter.cs +++ b/src/ImageLoaders/OdbgScript/OllyLangInterpreter.cs @@ -33,6 +33,8 @@ using System.Linq; using System.Text; +#pragma warning disable CS8981 + namespace Reko.ImageLoaders.OdbgScript { using rulong = System.UInt64; diff --git a/src/ImageLoaders/OdbgScript/var.cs b/src/ImageLoaders/OdbgScript/var.cs index dff5ee94a0..a4a877fcd4 100644 --- a/src/ImageLoaders/OdbgScript/var.cs +++ b/src/ImageLoaders/OdbgScript/var.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; +#pragma warning disable CS8981 + namespace Reko.ImageLoaders.OdbgScript { using System.Text; diff --git a/src/UnitTests/Decompiler/Scanning/ScannerInLinqTests.cs b/src/UnitTests/Decompiler/Scanning/ScannerInLinqTests.cs index c6a5d03bf9..778a5a9cc2 100644 --- a/src/UnitTests/Decompiler/Scanning/ScannerInLinqTests.cs +++ b/src/UnitTests/Decompiler/Scanning/ScannerInLinqTests.cs @@ -60,8 +60,8 @@ public void Setup() this.host = new Mock(); this.sr = new ScanResults { - FlatInstructions = new Dictionary(), - FlatEdges = new List(), + FlatInstructions = new Dictionary(), + FlatEdges = new List(), KnownProcedures = new HashSet
(), DirectlyCalledAddresses = new Dictionary() }; @@ -146,7 +146,7 @@ private void Given_DataBlock(uint uAddr, uint len) program.ImageMap.AddItem(addr, item); } - private void AssertBlocks(string sExp, Dictionary blocks) + private void AssertBlocks(string sExp, Dictionary blocks) { var sw = new StringWriter(); this.siq.DumpBlocks(sr, blocks, sw.WriteLine); @@ -162,7 +162,7 @@ private void AssertBlocks(string sExp, Dictionary bl private void Inst(int uAddr, int len, InstrClass rtlc) { var addr = Address.Ptr32((uint)uAddr); - sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.Instr { addr = addr, size = len, @@ -174,7 +174,7 @@ private void Inst(int uAddr, int len, InstrClass rtlc) private void Lin(int uAddr, int len, int next) { var addr = Address.Ptr32((uint)uAddr); - sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.Instr { addr = addr, size = len, @@ -187,7 +187,7 @@ private void Lin(int uAddr, int len, int next) private void Call(int uAddr, int len, int next, int uAddrDst) { var addr = Address.Ptr32((uint)uAddr); - sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.Instr { addr = addr, size = len, @@ -200,7 +200,7 @@ private void Call(int uAddr, int len, int next, int uAddrDst) private void Bra(int uAddr, int len, int a, int b) { var addr = Address.Ptr32((uint)uAddr); - sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.Instr { addr = addr, size = len, @@ -214,7 +214,7 @@ private void Bra(int uAddr, int len, int a, int b) private void Bad(int uAddr, int len) { var addr = Address.Ptr32((uint)uAddr); - sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.Instr { addr = addr, size = len, @@ -226,7 +226,7 @@ private void Bad(int uAddr, int len) private void End(int uAddr, int len) { var addr = Address.Ptr32((uint)uAddr); - sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.Instr { addr = addr, size = len, @@ -238,7 +238,7 @@ private void End(int uAddr, int len) private void Pad(uint uAddr, int len, int next) { var addr = Address.Ptr32((uint)uAddr); - sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.instr + sr.FlatInstructions.Add(addr.ToLinear(), new ScanResults.Instr { addr = addr, size = len, @@ -251,7 +251,7 @@ private void Pad(uint uAddr, int len, int next) private void Link(Address addrFrom ,int uAddrTo) { var addrTo = Address.Ptr32((uint)uAddrTo); - sr.FlatEdges.Add(new ScanResults.link { first = addrFrom, second = addrTo }); + sr.FlatEdges.Add(new ScanResults.Link { first = addrFrom, second = addrTo }); } private void Given_OverlappingLinearTraces() diff --git a/src/UserInterfaces/AvaloniaUI/Controls/HexViewer.cs b/src/UserInterfaces/AvaloniaUI/Controls/HexViewer.cs index c2615d6f96..bc52d18bb8 100644 --- a/src/UserInterfaces/AvaloniaUI/Controls/HexViewer.cs +++ b/src/UserInterfaces/AvaloniaUI/Controls/HexViewer.cs @@ -859,6 +859,12 @@ public class MemoryControlPainter public MemoryControlPainter(HexViewControl ctrl) { this.ctrl = ctrl; + GetColorPreferences(); + Debug.Assert(selectTheme is not null); + Debug.Assert(secondarySelectTheme is not null); + Debug.Assert(defaultTheme is not null); + Debug.Assert(dataTheme is not null); + Debug.Assert(codeTheme is not null); //$TODO: derive brush from SystemColors.HighLight using HSB model this.secondarySelBrush = new SolidColorBrush( Color.FromArgb(0xFF, 0xD0, 0xD0, 0xFF)); @@ -870,29 +876,38 @@ public MemoryControlPainter(HexViewControl ctrl) /// Paints the control's window area. Strategy is to find the spans that make up /// the whole segment, and paint them one at a time. ///
- /// - public (Address?, bool) PaintWindow(DrawingContext g, Size cellSize, Point ptAddr, bool render) + /// ? to draw to. + /// The extent of each cell to render. A cell is typically + /// a byte (rendered as two hex digits) but can vary in size. + /// + public (Address?, bool) PaintWindow( + DrawingContext g, + Size cellSize, + Point ptAddr, + bool render) { this.cellSize = cellSize; GetColorPreferences(); - if (ctrl.arch == null || ctrl.imageMap == null || ctrl.addrMin is null) + var addrTop = ctrl.TopAddress; + var segmap = ctrl.SegmentMap; + if (ctrl.arch is null || ctrl.imageMap is null || ctrl.addrMin is null || addrTop is null || segmap is null) return (null, ctrl.IsTextSideSelected); + // Enumerate all segments visible on screen. ulong laEnd = ctrl.addrMin.ToLinear() + ctrl.memSize; - if (ctrl.TopAddress.ToLinear() >= laEnd) + if (addrTop.ToLinear() >= laEnd) return (null, ctrl.IsTextSideSelected); - var addrStart = Address.Max(ctrl.TopAddress, ctrl.mem.BaseAddress); + var addrStart = Address.Max(addrTop, ctrl.mem.BaseAddress); EndianImageReader rdr = ctrl.arch.CreateImageReader(ctrl.mem, addrStart); Rect rcClient = ctrl.Bounds; Rect rc = rcClient.WithHeight(cellSize.Height); - Size cell = ctrl.cellSize; ulong laSegEnd = 0; while (rc.Top < rcClient.Height && (laEnd == 0 || rdr.Address.ToLinear() < laEnd)) { - if (ctrl.SegmentMap.TryFindSegment(ctrl.TopAddress, out ImageSegment? seg)) + if (segmap.TryFindSegment(addrTop, out ImageSegment? seg)) { if (rdr.Address.ToLinear() >= laSegEnd) { diff --git a/src/UserInterfaces/AvaloniaUI/Controls/StyleStack.cs b/src/UserInterfaces/AvaloniaUI/Controls/StyleStack.cs index c7cf336781..1fbb7f0f79 100644 --- a/src/UserInterfaces/AvaloniaUI/Controls/StyleStack.cs +++ b/src/UserInterfaces/AvaloniaUI/Controls/StyleStack.cs @@ -20,14 +20,11 @@ using Avalonia; using Avalonia.Controls; -using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Media; -using Reko.Gui; using Reko.Gui.Services; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; namespace Reko.UserInterfaces.AvaloniaUI.Controls @@ -41,12 +38,13 @@ public class StyleStack private IBrush? bg; private Typeface? font; private double fontSize; - private IBrush ctrlForeColor; - private IBrush ctrlBackColor; + private IBrush? ctrlForeColor; + private IBrush? ctrlBackColor; public StyleStack(IUiPreferencesService uiPrefSvc, Dictionary brushes) { - if (uiPrefSvc is null) throw new ArgumentNullException(nameof(uiPrefSvc)); + if (uiPrefSvc is null) + throw new ArgumentNullException(nameof(uiPrefSvc)); this.uiPrefSvc = uiPrefSvc; this.stack = new List(); this.classToBrushMap = brushes; @@ -66,7 +64,7 @@ internal void PopStyle() stack.RemoveAt(stack.Count - 1); } - private IBrush CacheBrush(ref IBrush? brInstance, IBrush brNew) + private IBrush? CacheBrush(ref IBrush? brInstance, IBrush? brNew) { brInstance = brNew; return brNew; @@ -76,18 +74,18 @@ private IEnumerable GetStyles(string[] styles) { foreach (var styleName in styles) { - if (uiPrefSvc.Styles.TryGetValue(styleName, out UiStyle style)) + if (uiPrefSvc.Styles.TryGetValue(styleName, out var style)) yield return style; } } - public IBrush GetForeground() + public IBrush? GetForeground() { for (int i = stack.Count - 1; i >= 0; --i) { var styles = GetStyles(stack[i]); - var ff = (IBrush) styles.Select(s => s.Foreground).LastOrDefault(f => f != null); - if (ff != null) + var ff = (IBrush?) styles.Select(s => s.Foreground).LastOrDefault(f => f != null); + if (ff is not null) return ff; } return CacheBrush(ref fg, this.ctrlForeColor); @@ -123,7 +121,7 @@ public IBrush GetForeground(IBrush fgColor) return fgColor; } - public IBrush GetBackground(IBrush bgColor) + public IBrush? GetBackground(IBrush bgColor) { for (int i = stack.Count - 1; i >= 0; --i) { diff --git a/src/UserInterfaces/AvaloniaUI/Controls/TextPointer.cs b/src/UserInterfaces/AvaloniaUI/Controls/TextPointer.cs index f10ddd2539..1a5394631f 100644 --- a/src/UserInterfaces/AvaloniaUI/Controls/TextPointer.cs +++ b/src/UserInterfaces/AvaloniaUI/Controls/TextPointer.cs @@ -18,11 +18,7 @@ */ #endregion -using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; namespace Reko.UserInterfaces.AvaloniaUI.Controls { diff --git a/src/UserInterfaces/AvaloniaUI/Controls/TextSpan.cs b/src/UserInterfaces/AvaloniaUI/Controls/TextSpan.cs index fbb38bbfc1..e820b9f9aa 100644 --- a/src/UserInterfaces/AvaloniaUI/Controls/TextSpan.cs +++ b/src/UserInterfaces/AvaloniaUI/Controls/TextSpan.cs @@ -27,7 +27,7 @@ namespace Reko.UserInterfaces.AvaloniaUI.Controls { /// - /// A SimpleTextSpan describes a span of text that has the same + /// Describes a span of text that has the same /// formatting attributes and behaviour. /// public abstract class TextSpan : ITextSpan @@ -38,13 +38,19 @@ protected TextSpan() } public abstract string GetText(); - public string Style { get; set; } + public string? Style { get; set; } public object? tag; - public object? Tag { + public object? Tag + { get { return tag; } set { tag = value; } } + + /// + /// ID of the context menu to be displayed whwn this text span + /// is right-clicked. + /// public int ContextMenuID { get; set; } public virtual Size GetSize(string text, Typeface font, double emSize) diff --git a/src/UserInterfaces/AvaloniaUI/Controls/TextView.cs b/src/UserInterfaces/AvaloniaUI/Controls/TextView.cs index 58afafc08e..3004d6f4a6 100644 --- a/src/UserInterfaces/AvaloniaUI/Controls/TextView.cs +++ b/src/UserInterfaces/AvaloniaUI/Controls/TextView.cs @@ -110,6 +110,7 @@ public TextView() { this.Selection = new TextSelection(this); this.model = new EmptyEditorModel(); + this.styleStack = new StyleStack(); } event EventHandler? ILogicalScrollable.ScrollInvalidated diff --git a/src/UserInterfaces/AvaloniaUI/Controls/TextViewLayout.cs b/src/UserInterfaces/AvaloniaUI/Controls/TextViewLayout.cs index c47d74e4fe..acc3395d59 100644 --- a/src/UserInterfaces/AvaloniaUI/Controls/TextViewLayout.cs +++ b/src/UserInterfaces/AvaloniaUI/Controls/TextViewLayout.cs @@ -366,14 +366,14 @@ public TextViewLayout Build() /// public class LayoutLine { - public LayoutLine(object Position, object tag, string style) { + public LayoutLine(object Position, object ?tag, string style) { this.Position = Position; this.Tag = tag; this.Style = style; } public object Position; - public object Tag; // extra object for this line. + public object? Tag; // extra object for this line. public string Style; public Rect Extent; public LayoutSpan[] Spans; diff --git a/src/UserInterfaces/AvaloniaUI/Controls/TextViewPainter.cs b/src/UserInterfaces/AvaloniaUI/Controls/TextViewPainter.cs index 571124ad1b..052f5fb927 100644 --- a/src/UserInterfaces/AvaloniaUI/Controls/TextViewPainter.cs +++ b/src/UserInterfaces/AvaloniaUI/Controls/TextViewPainter.cs @@ -71,6 +71,7 @@ public TextViewPainter( this.bgSelected = bgSelected; this.defaultFont = defaultFont; this.styleStack = styleStack; + this.selStart = default!; } public void SetSelection(TextPointer start, TextPointer end) @@ -99,7 +100,7 @@ private void PaintLine(LayoutLine line) double xMax = 0; if (line.Spans.Length > 0) { - xMax = line.Spans[line.Spans.Length - 1].ContentExtent.Right; + xMax = line.Spans[^1].ContentExtent.Right; } var cx = extent.Width - xMax; if (cx > 0) diff --git a/src/UserInterfaces/WindowsForms/PropertyOptionsGridAdapter.cs b/src/UserInterfaces/WindowsForms/PropertyOptionsGridAdapter.cs index 057440b44f..ad771c4604 100644 --- a/src/UserInterfaces/WindowsForms/PropertyOptionsGridAdapter.cs +++ b/src/UserInterfaces/WindowsForms/PropertyOptionsGridAdapter.cs @@ -149,9 +149,9 @@ public override Type PropertyType get { return typeof(string); } } - public static DictionaryPropertyDescriptor GetFromContext(ITypeDescriptorContext context) + public static DictionaryPropertyDescriptor? GetFromContext(ITypeDescriptorContext context) { - return (DictionaryPropertyDescriptor)context.PropertyDescriptor; + return (DictionaryPropertyDescriptor?)context.PropertyDescriptor; } public override void SetValue(object? component, object? value) @@ -195,22 +195,29 @@ public class ChoiceConverter : StringConverter { public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) { + if (context is null) + return false; var pd = GetPd(context); - return pd.Option.Choices != null && + return pd is not null && + pd.Option.Choices != null && pd.Option.Choices.Length > 0; // show combobox if there are choices } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context) { + if (context is null) + return new StandardValuesCollection(null); var pd = GetPd(context); + if (pd is null) + return new StandardValuesCollection(null); return new StandardValuesCollection( pd.Option.Choices .Select(c => c.Value).ToList()); } - private static DictionaryPropertyDescriptor GetPd(ITypeDescriptorContext? context) + private static DictionaryPropertyDescriptor? GetPd(ITypeDescriptorContext context) { - return (DictionaryPropertyDescriptor)context!.PropertyDescriptor; + return (DictionaryPropertyDescriptor?)context.PropertyDescriptor; } } @@ -223,30 +230,32 @@ private static DictionaryPropertyDescriptor GetPd(ITypeDescriptorContext? contex /// class PropertyOptionEditor : UITypeEditor { - public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext? context) { return UITypeEditorEditStyle.Modal; } - public override object? EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value) + public override object? EditValue(ITypeDescriptorContext? context, System.IServiceProvider provider, object? value) { + if (context is null) + return null; var svc = provider.RequireService(); var pd = DictionaryPropertyDescriptor.GetFromContext(context); var pluginSvc = provider.RequireService(); - if (pd.Option.TypeName is null) + if (pd is null || pd.Option.TypeName is null) return value; var dlgType = pluginSvc.GetType(pd.Option.TypeName); - if (dlgType == null) + if (dlgType is null) return value; - if (!(Activator.CreateInstance(dlgType) is Form form)) + if (Activator.CreateInstance(dlgType) is not Form form) return value; var valueProperty = dlgType.GetProperty("Value"); - if (valueProperty == null) + if (valueProperty is null) return value; valueProperty.SetValue(form, value); - if (svc.ShowDialog(form) == System.Windows.Forms.DialogResult.OK) + if (svc.ShowDialog(form) == DialogResult.OK) { value = valueProperty.GetValue(form)!; } diff --git a/src/UserInterfaces/WindowsForms/SearchResultServiceImpl.cs b/src/UserInterfaces/WindowsForms/SearchResultServiceImpl.cs index 363c7f81f1..782e597249 100644 --- a/src/UserInterfaces/WindowsForms/SearchResultServiceImpl.cs +++ b/src/UserInterfaces/WindowsForms/SearchResultServiceImpl.cs @@ -217,9 +217,11 @@ public void Invalidate() listView.Invalidate(); } - public Task ShowTypeMarker(Program program, Address addr) + public Task ShowTypeMarker(Program program, Address addr) { var i = listView.TopItem; + if (i is null) + return null; return typeMarker.ShowAsync(program, addr, i.Position); } } diff --git a/src/UserInterfaces/WindowsForms/StackTraceService.cs b/src/UserInterfaces/WindowsForms/StackTraceService.cs index 82264cefa2..2116dfb274 100644 --- a/src/UserInterfaces/WindowsForms/StackTraceService.cs +++ b/src/UserInterfaces/WindowsForms/StackTraceService.cs @@ -89,7 +89,7 @@ private DiagnosticsInteractor ShowDialog() private void PlaceStackTrace(StackTraceDialog dialog) { - var scrTabLocation = mainForm.TabControl.Parent.PointToScreen( + var scrTabLocation = mainForm.TabControl.Parent!.PointToScreen( mainForm.TabControl.Location); dialog.Location = new Point( scrTabLocation.X - dialog.Width + mainForm.TabControl.Width,