forked from zompinc/sync-method-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
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
28761db
commit 605c5cc
Showing
15 changed files
with
199 additions
and
5 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,33 @@ | ||
namespace Zomp.SyncMethodGenerator.Visitors; | ||
|
||
internal sealed class BreakVisitor : CSharpSyntaxVisitor<bool> | ||
{ | ||
public static readonly BreakVisitor Instance = new(); | ||
|
||
public override bool VisitBreakStatement(BreakStatementSyntax node) => true; | ||
|
||
public override bool VisitGotoStatement(GotoStatementSyntax node) => false; | ||
|
||
public override bool VisitWhileStatement(WhileStatementSyntax node) => false; | ||
|
||
public override bool VisitDoStatement(DoStatementSyntax node) => false; | ||
|
||
public override bool VisitForStatement(ForStatementSyntax node) => false; | ||
|
||
public override bool VisitForEachStatement(ForEachStatementSyntax node) => false; | ||
|
||
public override bool VisitForEachVariableStatement(ForEachVariableStatementSyntax node) => false; | ||
|
||
public override bool DefaultVisit(SyntaxNode node) | ||
{ | ||
foreach (var child in node.ChildNodes()) | ||
{ | ||
if (Visit(child)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Zomp.SyncMethodGenerator/Visitors/StopIterationVisitor.cs
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,23 @@ | ||
namespace Zomp.SyncMethodGenerator.Visitors; | ||
|
||
internal sealed class StopIterationVisitor : CSharpSyntaxVisitor<bool> | ||
{ | ||
public static readonly StopIterationVisitor Instance = new(); | ||
|
||
public override bool VisitReturnStatement(ReturnStatementSyntax node) => true; | ||
|
||
public override bool VisitThrowExpression(ThrowExpressionSyntax node) => true; | ||
|
||
public override bool DefaultVisit(SyntaxNode node) | ||
{ | ||
foreach (var child in node.ChildNodes()) | ||
{ | ||
if (Visit(child)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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,19 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace GenerationSandbox.Tests; | ||
|
||
internal static partial class WhileNotCancelled | ||
{ | ||
[Zomp.SyncMethodGenerator.CreateSyncVersion] | ||
public static async ValueTask SleepAsync(CancellationToken ct) | ||
{ | ||
while (!ct.IsCancellationRequested) | ||
{ | ||
await Task.Delay(120000, ct); | ||
} | ||
|
||
throw new OperationCanceledException(); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
tests/Generator.Tests/Snapshots/IsCancellationRequestedTests.WhileNotCancelled.verified.txt
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,14 @@ | ||
{ | ||
Diagnostics: [ | ||
{ | ||
Id: ZSMGEN004, | ||
Title: The while loop will never end after transformation, | ||
Severity: Warning, | ||
WarningLevel: 1, | ||
Location: : (1,8)-(1,13), | ||
MessageFormat: After transformation, it is detected that the while loop will never end, | ||
Message: After transformation, it is detected that the while loop will never end, | ||
Category: SyncMethodGenerator | ||
} | ||
] | ||
} |
8 changes: 8 additions & 0 deletions
8
...or.Tests/Snapshots/IsCancellationRequestedTests.WhileNotCancelledBreakThrow#g.verified.cs
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,8 @@ | ||
//HintName: Test.Class.MethodAsync.g.cs | ||
while (true) | ||
{ | ||
global::System.Threading.Thread.Sleep(120000); | ||
break; | ||
} | ||
|
||
throw new global::System.OperationCanceledException(); |
6 changes: 6 additions & 0 deletions
6
...s/Snapshots/IsCancellationRequestedTests.WhileNotCancelledInvalidBreakThrow#g.verified.cs
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,6 @@ | ||
//HintName: Test.Class.MethodAsync.g.cs | ||
while (true) | ||
{ | ||
global::System.Threading.Thread.Sleep(120000); | ||
while (true) break; | ||
} |
14 changes: 14 additions & 0 deletions
14
...ts/Snapshots/IsCancellationRequestedTests.WhileNotCancelledInvalidBreakThrow.verified.txt
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,14 @@ | ||
{ | ||
Diagnostics: [ | ||
{ | ||
Id: ZSMGEN004, | ||
Title: The while loop will never end after transformation, | ||
Severity: Warning, | ||
WarningLevel: 1, | ||
Location: : (1,8)-(1,13), | ||
MessageFormat: After transformation, it is detected that the while loop will never end, | ||
Message: After transformation, it is detected that the while loop will never end, | ||
Category: SyncMethodGenerator | ||
} | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
...nerator.Tests/Snapshots/IsCancellationRequestedTests.WhileNotCancelledThrow#g.verified.cs
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,5 @@ | ||
//HintName: Test.Class.MethodAsync.g.cs | ||
while (true) | ||
{ | ||
global::System.Threading.Thread.Sleep(120000); | ||
} |
14 changes: 14 additions & 0 deletions
14
...enerator.Tests/Snapshots/IsCancellationRequestedTests.WhileNotCancelledThrow.verified.txt
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,14 @@ | ||
{ | ||
Diagnostics: [ | ||
{ | ||
Id: ZSMGEN004, | ||
Title: The while loop will never end after transformation, | ||
Severity: Warning, | ||
WarningLevel: 1, | ||
Location: : (1,8)-(1,13), | ||
MessageFormat: After transformation, it is detected that the while loop will never end, | ||
Message: After transformation, it is detected that the while loop will never end, | ||
Category: SyncMethodGenerator | ||
} | ||
] | ||
} |