-
Notifications
You must be signed in to change notification settings - Fork 102
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
comment for Pattern #991
Merged
Merged
comment for Pattern #991
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c08348
update
chenzhitong 62b5844
update
chenzhitong e43f0a7
DeclarationPatternSyntax
chenzhitong 6b628b8
update
chenzhitong 3e503a4
Update Contract_Pattern.cs
chenzhitong 13e25ac
Apply suggestions from code review
shargon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -17,35 +17,77 @@ namespace Neo.Compiler; | |
|
||
partial class MethodConvert | ||
{ | ||
/// <summary> | ||
/// Convert pattern to OpCodes. | ||
/// </summary> | ||
/// <param name="model"></param> | ||
/// <param name="pattern"></param> | ||
/// <param name="localIndex"></param> | ||
/// <exception cref="CompilationException"></exception> | ||
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns#logical-patterns"> | ||
/// Pattern matching - the is and switch expressions, and operators and, or and not in patterns | ||
/// </seealso> | ||
private void ConvertPattern(SemanticModel model, PatternSyntax pattern, byte localIndex) | ||
{ | ||
switch (pattern) | ||
{ | ||
//Convet "and" / "or" pattern to OpCodes. | ||
//Example: return value is > 1 and < 100; | ||
//Example: return value is >= 80 or <= 20; | ||
case BinaryPatternSyntax binaryPattern: | ||
ConvertBinaryPattern(model, binaryPattern, localIndex); | ||
break; | ||
//Convet constant pattern to OpCodes. | ||
//Example: return value is > 1; | ||
//Example: return value is null; | ||
case ConstantPatternSyntax constantPattern: | ||
ConvertConstantPattern(model, constantPattern, localIndex); | ||
break; | ||
//Convet declaration pattern to OpCodes. | ||
//Example: if (greeting is string message) | ||
case DeclarationPatternSyntax declarationPattern: | ||
ConvertDeclarationPattern(model, declarationPattern, localIndex); | ||
break; | ||
//Convet discard pattern (_) to OpCodes. | ||
//Example: if (greeting2 is string _) | ||
case DiscardPatternSyntax: | ||
Push(true); | ||
break; | ||
//Convet relational pattern to OpCodes. | ||
//Example: return value is > 1; | ||
case RelationalPatternSyntax relationalPattern: | ||
ConvertRelationalPattern(model, relationalPattern, localIndex); | ||
break; | ||
//Convert type pattern to OpCodes. | ||
//Example: | ||
//switch (o1) | ||
//{ | ||
// case byte[]: break; | ||
// case string: break; | ||
//} | ||
case TypePatternSyntax typePattern: | ||
ConvertTypePattern(model, typePattern, localIndex); | ||
break; | ||
//Convet "not" pattern to OpCodes. | ||
//Example: return value is not null; | ||
case UnaryPatternSyntax unaryPattern when unaryPattern.OperatorToken.ValueText == "not": | ||
ConvertNotPattern(model, unaryPattern, localIndex); | ||
break; | ||
//Convet parenthesized to OpCodes. | ||
//Example: return value is (> 1 and < 100); | ||
case ParenthesizedPatternSyntax parenthesizedPattern: | ||
ConvertParenthesizedPatternSyntax(model, parenthesizedPattern, localIndex); | ||
break; | ||
default: | ||
//Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default? |
||
//object greeting = "Hello, World!"; | ||
//if (greeting3 is var message) { } | ||
//Example: | ||
//public static void M(object o1, object o2) | ||
//{ | ||
// var t = (o1, o2); | ||
// if (t is (int, string)) { } | ||
//} | ||
throw new CompilationException(pattern, DiagnosticId.SyntaxNotSupported, $"Unsupported pattern: {pattern}"); | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples