-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffacf28
commit 8dcf594
Showing
7 changed files
with
135 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Abc.Zebus.MessageDsl.Ast; | ||
|
||
namespace Abc.Zebus.MessageDsl.Analysis; | ||
|
||
internal readonly struct ReservationRange(int startTag, int endTag) | ||
{ | ||
public static ReservationRange None => default; | ||
|
||
private bool IsValid => startTag > 0; | ||
|
||
public ReservationRange(int tag) | ||
: this(tag, tag) | ||
{ | ||
} | ||
|
||
public bool Contains(int tag) | ||
=> IsValid && tag >= startTag && tag <= endTag; | ||
|
||
public bool TryAddTag(int tag, out ReservationRange updatedRange) | ||
{ | ||
if (IsValid && tag == endTag + 1) | ||
{ | ||
updatedRange = new ReservationRange(startTag, tag); | ||
return true; | ||
} | ||
|
||
updatedRange = default; | ||
return false; | ||
} | ||
|
||
public void AddToMessage(MessageDefinition message) | ||
{ | ||
if (!IsValid) | ||
return; | ||
|
||
message.Attributes.Add(new AttributeDefinition(KnownTypes.ProtoReservedAttribute, startTag == endTag ? $"{startTag}" : $"{startTag}, {endTag}")); | ||
message.ReservedRanges.Add(this); | ||
} | ||
|
||
public override string ToString() | ||
=> IsValid | ||
? startTag != endTag | ||
? $"{startTag} - {endTag}" | ||
: $"{startTag}" | ||
: "None"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters