Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some bytecode constructors overloads #47

Open
wants to merge 1 commit into
base: metadata-provider
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Model/Bytecode/Instructions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ public class BranchInstruction : Instruction
public bool UnsignedOperands { get; set; }

public BranchInstruction(uint label, BranchOperation operation, uint target)
: this(label, operation, $"L_{target:X4}")
{
}

public BranchInstruction(uint label, BranchOperation operation, string target)
: base(label)
{
this.Target = string.Format("L_{0:X4}", target);
this.Target = target;
this.Operation = operation;
}

Expand All @@ -222,9 +227,14 @@ public class SwitchInstruction : Instruction
public IList<string> Targets { get; private set; }

public SwitchInstruction(uint label, IEnumerable<uint> targets)
: this(label, targets.Select(target => $"L_{target:X4}").ToList())
{
}

public SwitchInstruction(uint label, IEnumerable<string> targets)
: base(label)
{
this.Targets = targets.Select(target => string.Format("L_{0:X4}", target)).ToList();
this.Targets = targets.ToList();
}

public override void Accept(IInstructionVisitor visitor)
Expand Down
51 changes: 36 additions & 15 deletions Model/ExceptionHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ public class ProtectedBlock : IExceptionHandlerBlock
public string End { get; set; }
public IExceptionHandler Handler { get; set; }

public ProtectedBlock(uint start, uint end)
public ProtectedBlock(uint start, uint end) : this($"L_{start:X4}", $"L_{end:X4}")
{
}

public ProtectedBlock(string start, string end)
{
this.Kind = ExceptionHandlerBlockKind.Try;
this.Start = string.Format("L_{0:X4}", start);
this.End = string.Format("L_{0:X4}", end);
this.Start = start;
this.End = end;
}

public override string ToString()
Expand All @@ -57,11 +61,16 @@ public class FilterExceptionHandler : IExceptionHandler
public IType ExceptionType { get; set; }

public FilterExceptionHandler(uint filterStart, uint start, uint end, IType exceptionType)
: this($"L_{filterStart:X4}", $"L_{start:X4}", $"L_{end:X4}", exceptionType)
{
}

public FilterExceptionHandler(string filterStart, string start, string end, IType exceptionType)
{
this.Kind = ExceptionHandlerBlockKind.Filter;
this.FilterStart = string.Format("L_{0:X4}", filterStart);
this.Start = string.Format("L_{0:X4}", start);
this.End = string.Format("L_{0:X4}", end);
this.FilterStart = filterStart;
this.Start = start;
this.End = end;
this.ExceptionType = exceptionType;
}

Expand All @@ -78,11 +87,15 @@ public class CatchExceptionHandler : IExceptionHandler
public string End { get; set; }
public IType ExceptionType { get; set; }

public CatchExceptionHandler(uint start, uint end, IType exceptionType)
public CatchExceptionHandler(uint start, uint end, IType exceptionType) : this($"L_{start:X4}", $"L_{end:X4}", exceptionType)
{
}

public CatchExceptionHandler(string start, string end, IType exceptionType)
{
this.Kind = ExceptionHandlerBlockKind.Catch;
this.Start = string.Format("L_{0:X4}", start);
this.End = string.Format("L_{0:X4}", end);
this.Start = start;
this.End = end;
this.ExceptionType = exceptionType;
}

Expand All @@ -98,11 +111,15 @@ public class FaultExceptionHandler : IExceptionHandler
public string Start { get; set; }
public string End { get; set; }

public FaultExceptionHandler(uint start, uint end)
public FaultExceptionHandler(uint start, uint end) : this($"L_{start:X4}", $"L_{end:X4}")
{
}

public FaultExceptionHandler(string start, string end)
{
this.Kind = ExceptionHandlerBlockKind.Fault;
this.Start = string.Format("L_{0:X4}", start);
this.End = string.Format("L_{0:X4}", end);
this.Start = start;
this.End = end;
}

public override string ToString()
Expand All @@ -117,11 +134,15 @@ public class FinallyExceptionHandler : IExceptionHandler
public string Start { get; set; }
public string End { get; set; }

public FinallyExceptionHandler(uint start, uint end)
public FinallyExceptionHandler(uint start, uint end) : this($"L_{start:X4}", $"L_{end:X4}")
{
}

public FinallyExceptionHandler(string start, string end)
{
this.Kind = ExceptionHandlerBlockKind.Finally;
this.Start = string.Format("L_{0:X4}", start);
this.End = string.Format("L_{0:X4}", end);
this.Start = start;
this.End = end;
}

public override string ToString()
Expand Down