Skip to content

Commit

Permalink
More code refactoring (#1019)
Browse files Browse the repository at this point in the history
* Merge into pattern

* Remove redundant initializers

* Fix body style

* Revert for Korlib

* Merge master into ch-06

* Fix formatting

---------

Co-authored-by: AnErrupTion <anerruption@disroot.org>
  • Loading branch information
AnErrupTion and AnErrupTion committed Feb 14, 2023
1 parent afa7e5f commit 8840278
Show file tree
Hide file tree
Showing 199 changed files with 1,024 additions and 1,312 deletions.
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Common/Configuration/Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static Settings ParseArguments(string[] args, List<Argument> arguments)
{
var arg = args[at];

if (arg == "-s" || arg == "-p" || arg == "-setting" || arg == "-property")
if (arg is "-s" or "-p" or "-setting" or "-property")
{
var parts = args[++at].Split('=');

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Common/IncludeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class IncludeFile

public byte[] Content { get; set; }

public int Length { get { return Content.Length; } }
public int Length => Content.Length;

public bool ReadOnly { get; set; } = false;
public bool Hidden { get; set; } = false;
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Common/KeyedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class KeyedList<T, V>
{
public readonly Dictionary<T, List<V>> Collection;

public Dictionary<T, List<V>>.KeyCollection Keys { get { return Collection.Keys; } }
public Dictionary<T, List<V>>.KeyCollection Keys => Collection.Keys;

public List<V> this[T index] { get { return Collection.ContainsKey(index) ? Collection[index] : null; } }
public List<V> this[T index] => Collection.ContainsKey(index) ? Collection[index] : null;

public KeyedList()
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Common/SparseBitArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class SparseBitArray
{
private ulong[] Bits;

private int Length { get { return Bits == null ? 0 : Bits.Length * 8; } }
private int Length => Bits == null ? 0 : Bits.Length * 8;

public SparseBitArray()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ public sealed class ExtendedBlock2
{
public BasicBlock BasicBlock { get; }

public int Sequence { get { return BasicBlock.Sequence; } }
public int Sequence => BasicBlock.Sequence;

public int LoopDepth { get; }

public Range Range { get; set; }

public int Start { get { return Range.Start; } }
public int Start => Range.Start;

public int End { get { return Range.End; } }
public int End => Range.End;

public BitArray LiveGen { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public sealed class LiveRanges
{
public List<Range> Ranges { get; } = new List<Range>(1);

public int Count { get { return Ranges.Count; } }
public int Count => Ranges.Count;

public Range LastRange { get { return Ranges[Count - 1]; } }
public Range LastRange => Ranges[Count - 1];

public Range FirstRange { get { return Ranges[0]; } set { Ranges[0] = value; } }
public Range FirstRange { get => Ranges[0];
set => Ranges[0] = value;
}

public void Add(int start, int end)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace Mosa.Compiler.Framework.Analysis.LiveVariableAnalysis;
public class LivenessAnalysis
{
protected BaseLivenessAnalysisEnvironment Environment;
protected BasicBlocks BasicBlocks { get { return Environment.BasicBlocks; } }
protected int IndexCount { get { return Environment.IndexCount; } }
protected BasicBlocks BasicBlocks => Environment.BasicBlocks;
protected int IndexCount => Environment.IndexCount;

protected List<ExtendedBlock2> ExtendedBlocks;
public LiveRanges[] LiveRanges;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Range(int start, int end)
End = end;
}

public int Length { get { return End - Start; } }
public int Length => End - Start;

public bool Intersects(int start, int end)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,55 +29,45 @@ private enum ReferenceStatusType

private ReferenceStatusType ReferenceStatus;

public int ConstantCount
{ get { return Constants?.Count ?? 0; } }
public int ConstantCount => Constants?.Count ?? 0;

public List<ulong> Constants { get; private set; }

public ulong ConstantUnsignedLongInteger
{ get { return Constants[0]; } }
public ulong ConstantUnsignedLongInteger => Constants[0];

public long ConstantSignedLongInteger
{ get { return (long)Constants[0]; } }
public long ConstantSignedLongInteger => (long)Constants[0];

public bool ConstantsContainZero { get; set; }

public Operand Operand { get; }

public bool IsOverDefined
{
get { return Status == VariableStatusType.OverDefined; }
get => Status == VariableStatusType.OverDefined;
set { Status = VariableStatusType.OverDefined; Constants = null; Debug.Assert(value); }
}

public bool IsUnknown
{ get { return Status == VariableStatusType.Unknown; } }
public bool IsUnknown => Status == VariableStatusType.Unknown;

public bool IsSingleConstant
{
get { return Status == VariableStatusType.SingleConstant; }
get => Status == VariableStatusType.SingleConstant;
set { Status = VariableStatusType.SingleConstant; Debug.Assert(value); }
}

public bool HasMultipleConstants
{ get { return Status == VariableStatusType.MultipleConstants; } }
public bool HasMultipleConstants => Status == VariableStatusType.MultipleConstants;

public bool HasOnlyConstants
{ get { return Status == VariableStatusType.SingleConstant || Status == VariableStatusType.MultipleConstants; } }
public bool HasOnlyConstants => Status is VariableStatusType.SingleConstant or VariableStatusType.MultipleConstants;

public bool IsVirtualRegister { get; set; }

public bool IsReferenceType { get; set; }

public bool IsReferenceDefinedUnknown
{ get { return ReferenceStatus == ReferenceStatusType.Unknown; } }
public bool IsReferenceDefinedUnknown => ReferenceStatus == ReferenceStatusType.Unknown;

public bool IsReferenceDefinedNotNull
{
get
{
return ReferenceStatus == ReferenceStatusType.DefinedNotNull;
}
get => ReferenceStatus == ReferenceStatusType.DefinedNotNull;
set
{
Debug.Assert(value);
Expand All @@ -87,10 +77,7 @@ public bool IsReferenceDefinedNotNull

public bool IsReferenceOverDefined
{
get
{
return ReferenceStatus == ReferenceStatusType.OverDefined;
}
get => ReferenceStatus == ReferenceStatusType.OverDefined;
set
{
Debug.Assert(value);
Expand Down Expand Up @@ -1171,7 +1158,7 @@ private void IfThenElse(InstructionNode node)
if (result.IsOverDefined)
return;

if (operand1.IsOverDefined || operand1.IsOverDefined)
if (operand1.IsOverDefined is true or true)
{
UpdateToOverDefined(result);
}
Expand Down
12 changes: 6 additions & 6 deletions Source/Mosa.Compiler.Framework/BaseArchitecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public abstract class BaseArchitecture
/// <summary>
/// Gets the native alignment of the architecture in bytes.
/// </summary>
public uint NativeAlignment { get { return NativePointerSize; } }
public uint NativeAlignment => NativePointerSize;

/// <summary>
/// Gets the native size of architecture in bytes.
Expand All @@ -86,30 +86,30 @@ public abstract class BaseArchitecture
/// <summary>
/// Gets the size of the native instruction.
/// </summary>
public virtual InstructionSize NativeInstructionSize { get { return NativePointerSize == 4 ? InstructionSize.Size32 : InstructionSize.Size64; } }
public virtual InstructionSize NativeInstructionSize => NativePointerSize == 4 ? InstructionSize.Size32 : InstructionSize.Size64;

/// <summary>
/// Is the platform is 32 bit
/// </summary>
/// <value>
/// <c>true</c> if [is32 bit]; otherwise, <c>false</c>.
/// </value>
public virtual bool Is32BitPlatform { get { return NativePointerSize == 4; } }
public virtual bool Is32BitPlatform => NativePointerSize == 4;

/// <summary>
/// Is the platform is 64 bit
/// </summary>
public virtual bool Is64BitPlatform { get { return NativePointerSize == 8; } }
public virtual bool Is64BitPlatform => NativePointerSize == 8;

/// <summary>
/// Gets the offset of first local.
/// </summary>
public virtual int OffsetOfFirstLocal { get { return 0; } }
public virtual int OffsetOfFirstLocal => 0;

/// <summary>
/// Gets the offset of first parameter.
/// </summary>
public virtual int OffsetOfFirstParameter { get { return (int)NativePointerSize * 2; } }
public virtual int OffsetOfFirstParameter => (int)NativePointerSize * 2;

/// <summary>
/// Gets the instructions.
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Framework/BaseIRInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ protected BaseIRInstruction(byte operandCount, byte resultCount)
/// <value>
/// The name of the instruction family.
/// </value>
public override string FamilyName { get { return "IR"; } }
public override string FamilyName => "IR";

public override bool IsIRInstruction { get { return true; } }
public override bool IsIRInstruction => true;

#endregion Properties
}
4 changes: 1 addition & 3 deletions Source/Mosa.Compiler.Framework/BasicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ public InstructionNode BeforeBranch
var node = BeforeLast;

while (node.IsEmpty
|| node.Instruction.FlowControl == FlowControl.UnconditionalBranch
|| node.Instruction.FlowControl == FlowControl.ConditionalBranch
|| node.Instruction.FlowControl == FlowControl.Return)
|| node.Instruction.FlowControl is FlowControl.UnconditionalBranch or FlowControl.ConditionalBranch or FlowControl.Return)
{
node = node.Previous;
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Mosa.Compiler.Framework/BasicBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public sealed class BasicBlocks : IEnumerable<BasicBlock>
/// <summary>
/// The prologue block
/// </summary>
private BasicBlock prologueBlock = null;
private BasicBlock prologueBlock;

/// <summary>
/// The epilogue block
/// </summary>
private BasicBlock epilogueBlock = null;
private BasicBlock epilogueBlock;

private int nextAvailableLabel = BasicBlock.CompilerBlockStartLabel;

Expand Down Expand Up @@ -81,8 +81,8 @@ public IEnumerator<BasicBlock> GetEnumerator()
/// <returns></returns>
public BasicBlock this[int index]
{
get { return basicBlocks[index]; }
set { basicBlocks[index] = value; }
get => basicBlocks[index];
set => basicBlocks[index] = value;
}

/// <summary>
Expand Down
9 changes: 3 additions & 6 deletions Source/Mosa.Compiler.Framework/CIL/BaseCILInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public abstract class BaseCILInstruction : BaseInstruction
/// Gets the op code.
/// </summary>
/// <value>The op code.</value>
public OpCode OpCode { get { return opcode; } }
public OpCode OpCode => opcode;

/// <summary>
/// Gets the name of the instruction family.
/// </summary>
/// <value>
/// The name of the instruction family.
/// </value>
public override string FamilyName { get { return "CIL"; } }
public override string FamilyName => "CIL";

public override string Name
{
Expand Down Expand Up @@ -103,10 +103,7 @@ public virtual void Decode(InstructionNode node, IInstructionDecoder decoder)
/// Determines if the IL decoder pushes the results of this instruction onto the IL operand stack.
/// </summary>
/// <value><c>true</c> if [push result]; otherwise, <c>false</c>.</value>
public virtual bool PushResult
{
get { return true; }
}
public virtual bool PushResult => true;

/// <summary>
/// Validates the specified instruction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BinaryBranchInstruction(OpCode opCode)
/// building. Any instruction that alters the control flow must override
/// this property and correctly identify its control flow modifications.
/// </remarks>
public override FlowControl FlowControl { get { return FlowControl.ConditionalBranch; } }
public override FlowControl FlowControl => FlowControl.ConditionalBranch;

#endregion Properties

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/CIL/BranchInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public BranchInstruction(OpCode opcode)
/// building. Any instruction that alters the control flow must override
/// this property and correctly identify its control flow modifications.
/// </remarks>
public override FlowControl FlowControl { get { return FlowControl.UnconditionalBranch; } }
public override FlowControl FlowControl => FlowControl.UnconditionalBranch;

#endregion Properties

Expand Down
5 changes: 1 addition & 4 deletions Source/Mosa.Compiler.Framework/CIL/CallInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public CallInstruction(OpCode opCode)
/// Gets the supported immediate metadata tokens in the instruction.
/// </summary>
/// <value></value>
protected override InvokeSupportFlags InvokeSupport
{
get { return InvokeSupportFlags.MemberRef | InvokeSupportFlags.MethodDef | InvokeSupportFlags.MethodSpec; }
}
protected override InvokeSupportFlags InvokeSupport => InvokeSupportFlags.MemberRef | InvokeSupportFlags.MethodDef | InvokeSupportFlags.MethodSpec;

#endregion Properties
}
5 changes: 1 addition & 4 deletions Source/Mosa.Compiler.Framework/CIL/CalliInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public CalliInstruction(OpCode opcode)
/// Gets the supported immediate metadata tokens in the instruction.
/// </summary>
/// <value></value>
protected override InvokeInstruction.InvokeSupportFlags InvokeSupport
{
get { return InvokeSupportFlags.CallSite; }
}
protected override InvokeInstruction.InvokeSupportFlags InvokeSupport => InvokeSupportFlags.CallSite;

#endregion Properties
}
5 changes: 1 addition & 4 deletions Source/Mosa.Compiler.Framework/CIL/CallvirtInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public CallvirtInstruction(OpCode opcode)
/// Gets the supported immediate metadata tokens in the instruction.
/// </summary>
/// <value></value>
protected override InvokeInstruction.InvokeSupportFlags InvokeSupport
{
get { return InvokeSupportFlags.MemberRef | InvokeSupportFlags.MethodDef | InvokeSupportFlags.MethodSpec; }
}
protected override InvokeInstruction.InvokeSupportFlags InvokeSupport => InvokeSupportFlags.MemberRef | InvokeSupportFlags.MethodDef | InvokeSupportFlags.MethodSpec;

#endregion Properties

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/CIL/EndFilterInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public EndFilterInstruction(OpCode opcode)

#endregion Construction

public override FlowControl FlowControl { get { return FlowControl.EndFilter; } }
public override FlowControl FlowControl => FlowControl.EndFilter;

#region Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ public EndFinallyInstruction(OpCode opcode)

#endregion Construction

public override FlowControl FlowControl { get { return FlowControl.EndFinally; } }
public override FlowControl FlowControl => FlowControl.EndFinally;
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/CIL/InvokeInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected InvokeInstruction(OpCode opcode)
/// building. Any instruction that alters the control flow must override
/// this property and correctly identify its control flow modifications.
/// </remarks>
public override FlowControl FlowControl { get { return FlowControl.Call; } }
public override FlowControl FlowControl => FlowControl.Call;

/// <summary>
/// Gets the supported immediate metadata tokens in the instruction.
Expand Down
5 changes: 1 addition & 4 deletions Source/Mosa.Compiler.Framework/CIL/JumpInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public JumpInstruction(OpCode opCode)
/// Gets the supported immediate metadata tokens in the instruction.
/// </summary>
/// <value></value>
protected override InvokeInstruction.InvokeSupportFlags InvokeSupport
{
get { return InvokeSupportFlags.MemberRef | InvokeSupportFlags.MethodDef; }
}
protected override InvokeInstruction.InvokeSupportFlags InvokeSupport => InvokeSupportFlags.MemberRef | InvokeSupportFlags.MethodDef;

#endregion Properties
}

0 comments on commit 8840278

Please sign in to comment.