Skip to content

Commit 04b48e5

Browse files
committed
Regenerate code to fix test_cgcheck failures
- Add 'await' keyword to generate_ops.py kwlist - Add CancelledError factory-only exception to generate_exceptions.py - Regenerate TokenKind, Tokenizer, PythonWalker, PythonNameBinder - Fix CancelledError placement in ToPythonHelper to match generator order
1 parent a1c1605 commit 04b48e5

7 files changed

Lines changed: 52 additions & 57 deletions

File tree

eng/scripts/generate_exceptions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,26 @@ def gen_topython_helper(cw):
262262
cw.exit_block()
263263

264264

265+
_clr_name_overrides = {
266+
'CancelledError': 'OperationCanceledException',
267+
}
268+
265269
def get_clr_name(e):
270+
if e in _clr_name_overrides:
271+
return _clr_name_overrides[e]
266272
return e.replace('Error', '') + 'Exception'
267273

268274
FACTORY = """
269275
internal static Exception %(name)s(string message) => new %(clrname)s(message);
270276
public static Exception %(name)s(string format, params object?[] args) => new %(clrname)s(string.Format(format, args));
271277
""".rstrip()
272278

279+
# Exceptions that map to existing CLR types (no generated CLR class needed),
280+
# but still need factory methods in PythonOps.
281+
_factory_only_exceptions = ['CancelledError']
282+
273283
def factory_gen(cw):
274-
for e in pythonExcs:
284+
for e in pythonExcs + _factory_only_exceptions:
275285
cw.write(FACTORY, name=e, clrname=get_clr_name(e))
276286

277287
CLASS1 = """\

eng/scripts/generate_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
kwlist = [
1111
'and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
1212
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass',
13-
'raise', 'return', 'try', 'while', 'yield', 'as', 'with', 'async', 'nonlocal'
13+
'raise', 'return', 'try', 'while', 'yield', 'as', 'with', 'async', 'nonlocal', 'await'
1414
]
1515

1616
class Symbol:

src/core/IronPython/Compiler/Ast/PythonNameBinder.cs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,26 @@ public override bool Walk(AssertStatement node) {
346346
node.Parent = _currentScope;
347347
return base.Walk(node);
348348
}
349+
// AsyncForStatement
350+
public override bool Walk(AsyncForStatement node) {
351+
node.Parent = _currentScope;
352+
return base.Walk(node);
353+
}
349354
// AsyncStatement
350355
public override bool Walk(AsyncStatement node) {
351356
node.Parent = _currentScope;
352357
return base.Walk(node);
353358
}
359+
// AsyncWithStatement
360+
public override bool Walk(AsyncWithStatement node) {
361+
node.Parent = _currentScope;
362+
return base.Walk(node);
363+
}
364+
// AwaitExpression
365+
public override bool Walk(AwaitExpression node) {
366+
node.Parent = _currentScope;
367+
return base.Walk(node);
368+
}
354369
// BinaryExpression
355370
public override bool Walk(BinaryExpression node) {
356371
node.Parent = _currentScope;
@@ -516,36 +531,6 @@ public override bool Walk(YieldFromExpression node) {
516531
node.Parent = _currentScope;
517532
return base.Walk(node);
518533
}
519-
// AwaitExpression
520-
public override bool Walk(AwaitExpression node) {
521-
node.Parent = _currentScope;
522-
return base.Walk(node);
523-
}
524-
// AsyncForStatement
525-
public override bool Walk(AsyncForStatement node) {
526-
node.Parent = _currentScope;
527-
if (_currentScope is FunctionDefinition) {
528-
_currentScope.ShouldInterpret = false;
529-
}
530-
531-
node.Left.Walk(_define);
532-
533-
return true;
534-
}
535-
// AsyncWithStatement
536-
public override bool Walk(AsyncWithStatement node) {
537-
node.Parent = _currentScope;
538-
_currentScope.ContainsExceptionHandling = true;
539-
540-
if (node.Variable != null) {
541-
var assignError = node.Variable.CheckAssign();
542-
if (assignError != null) {
543-
ReportSyntaxError(assignError, node);
544-
}
545-
node.Variable.Walk(_define);
546-
}
547-
return true;
548-
}
549534

550535
// *** END GENERATED CODE ***
551536

src/core/IronPython/Compiler/Ast/PythonWalker.Generated.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class PythonWalker {
2020
public virtual bool Walk(AndExpression node) { return true; }
2121
public virtual void PostWalk(AndExpression node) { }
2222

23+
// AwaitExpression
24+
public virtual bool Walk(AwaitExpression node) { return true; }
25+
public virtual void PostWalk(AwaitExpression node) { }
26+
2327
// BinaryExpression
2428
public virtual bool Walk(BinaryExpression node) { return true; }
2529
public virtual void PostWalk(BinaryExpression node) { }
@@ -124,10 +128,6 @@ public virtual void PostWalk(YieldExpression node) { }
124128
public virtual bool Walk(YieldFromExpression node) { return true; }
125129
public virtual void PostWalk(YieldFromExpression node) { }
126130

127-
// AwaitExpression
128-
public virtual bool Walk(AwaitExpression node) { return true; }
129-
public virtual void PostWalk(AwaitExpression node) { }
130-
131131
// AnnotatedAssignStatement
132132
public virtual bool Walk(AnnotatedAssignStatement node) { return true; }
133133
public virtual void PostWalk(AnnotatedAssignStatement node) { }
@@ -140,14 +140,14 @@ public virtual void PostWalk(AssertStatement node) { }
140140
public virtual bool Walk(AssignmentStatement node) { return true; }
141141
public virtual void PostWalk(AssignmentStatement node) { }
142142

143-
// AsyncStatement
144-
public virtual bool Walk(AsyncStatement node) { return true; }
145-
public virtual void PostWalk(AsyncStatement node) { }
146-
147143
// AsyncForStatement
148144
public virtual bool Walk(AsyncForStatement node) { return true; }
149145
public virtual void PostWalk(AsyncForStatement node) { }
150146

147+
// AsyncStatement
148+
public virtual bool Walk(AsyncStatement node) { return true; }
149+
public virtual void PostWalk(AsyncStatement node) { }
150+
151151
// AsyncWithStatement
152152
public virtual bool Walk(AsyncWithStatement node) { return true; }
153153
public virtual void PostWalk(AsyncWithStatement node) { }
@@ -291,6 +291,10 @@ public class PythonWalkerNonRecursive : PythonWalker {
291291
public override bool Walk(AndExpression node) { return false; }
292292
public override void PostWalk(AndExpression node) { }
293293

294+
// AwaitExpression
295+
public override bool Walk(AwaitExpression node) { return false; }
296+
public override void PostWalk(AwaitExpression node) { }
297+
294298
// BinaryExpression
295299
public override bool Walk(BinaryExpression node) { return false; }
296300
public override void PostWalk(BinaryExpression node) { }
@@ -395,10 +399,6 @@ public override void PostWalk(YieldExpression node) { }
395399
public override bool Walk(YieldFromExpression node) { return false; }
396400
public override void PostWalk(YieldFromExpression node) { }
397401

398-
// AwaitExpression
399-
public override bool Walk(AwaitExpression node) { return false; }
400-
public override void PostWalk(AwaitExpression node) { }
401-
402402
// AnnotatedAssignStatement
403403
public override bool Walk(AnnotatedAssignStatement node) { return false; }
404404
public override void PostWalk(AnnotatedAssignStatement node) { }
@@ -411,14 +411,14 @@ public override void PostWalk(AssertStatement node) { }
411411
public override bool Walk(AssignmentStatement node) { return false; }
412412
public override void PostWalk(AssignmentStatement node) { }
413413

414-
// AsyncStatement
415-
public override bool Walk(AsyncStatement node) { return false; }
416-
public override void PostWalk(AsyncStatement node) { }
417-
418414
// AsyncForStatement
419415
public override bool Walk(AsyncForStatement node) { return false; }
420416
public override void PostWalk(AsyncForStatement node) { }
421417

418+
// AsyncStatement
419+
public override bool Walk(AsyncStatement node) { return false; }
420+
public override void PostWalk(AsyncStatement node) { }
421+
422422
// AsyncWithStatement
423423
public override bool Walk(AsyncWithStatement node) { return false; }
424424
public override void PostWalk(AsyncWithStatement node) { }

src/core/IronPython/Compiler/Tokenizer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,6 @@ private Token ReadName() {
10421042
MarkTokenEnd();
10431043
return Tokens.KeywordAndToken;
10441044
}
1045-
} else if (ch == 'w') {
1046-
if (NextChar() == 'a' && NextChar() == 'i' && NextChar() == 't' && !IsNamePart(Peek())) {
1047-
MarkTokenEnd();
1048-
return Tokens.KeywordAwaitToken;
1049-
}
10501045
} else if (ch == 's') {
10511046
if (!IsNamePart(Peek())) {
10521047
MarkTokenEnd();
@@ -1064,6 +1059,11 @@ private Token ReadName() {
10641059
return Tokens.KeywordAsyncToken;
10651060
}
10661061
}
1062+
} else if (ch == 'w') {
1063+
if (NextChar() == 'a' && NextChar() == 'i' && NextChar() == 't' && !IsNamePart(Peek())) {
1064+
MarkTokenEnd();
1065+
return Tokens.KeywordAwaitToken;
1066+
}
10671067
}
10681068
} else if (ch == 'b') {
10691069
if (NextChar() == 'r' && NextChar() == 'e' && NextChar() == 'a' && NextChar() == 'k' && !IsNamePart(Peek())) {

src/core/IronPython/Runtime/Exceptions/PythonExceptions.Generated.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public _StopAsyncIteration(PythonType type) : base(type) { }
119119
public static PythonType CancelledError {
120120
get {
121121
if (CancelledErrorStorage == null) {
122-
Interlocked.CompareExchange(ref CancelledErrorStorage, CreateSubType(Exception, "CancelledError", (msg, innerException) => new System.OperationCanceledException(msg, innerException)), null);
122+
Interlocked.CompareExchange(ref CancelledErrorStorage, CreateSubType(Exception, "CancelledError", (msg, innerException) => new OperationCanceledException(msg, innerException)), null);
123123
}
124124
return CancelledErrorStorage;
125125
}
@@ -923,6 +923,7 @@ public static PythonType ResourceWarning {
923923
if (clrException is ModuleNotFoundException) return new PythonExceptions._ImportError(PythonExceptions.ModuleNotFoundError);
924924
if (clrException is NotADirectoryException) return new PythonExceptions._OSError(PythonExceptions.NotADirectoryError);
925925
if (clrException is NotImplementedException) return new PythonExceptions.BaseException(PythonExceptions.NotImplementedError);
926+
if (clrException is OperationCanceledException) return new PythonExceptions.BaseException(PythonExceptions.CancelledError);
926927
if (clrException is OutOfMemoryException) return new PythonExceptions.BaseException(PythonExceptions.MemoryError);
927928
if (clrException is ProcessLookupException) return new PythonExceptions._OSError(PythonExceptions.ProcessLookupError);
928929
if (clrException is RecursionException) return new PythonExceptions.BaseException(PythonExceptions.RecursionError);
@@ -946,7 +947,6 @@ public static PythonType ResourceWarning {
946947
if (clrException is StopAsyncIterationException) return new PythonExceptions._StopAsyncIteration();
947948
if (clrException is StopIterationException) return new PythonExceptions._StopIteration();
948949
if (clrException is SyntaxErrorException) return new PythonExceptions._SyntaxError();
949-
if (clrException is OperationCanceledException) return new PythonExceptions.BaseException(PythonExceptions.CancelledError);
950950
if (clrException is SystemException) return new PythonExceptions.BaseException(PythonExceptions.SystemError);
951951
if (clrException is SystemExitException) return new PythonExceptions._SystemExit();
952952
if (clrException is UnboundNameException) return new PythonExceptions.BaseException(PythonExceptions.NameError);

src/core/IronPython/Runtime/Operations/PythonOps.Generated.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public static partial class PythonOps {
125125
internal static Exception ModuleNotFoundError(string message) => new ModuleNotFoundException(message);
126126
public static Exception ModuleNotFoundError(string format, params object?[] args) => new ModuleNotFoundException(string.Format(format, args));
127127

128-
internal static Exception CancelledError(string message) => new System.OperationCanceledException(message);
129-
public static Exception CancelledError(string format, params object?[] args) => new System.OperationCanceledException(string.Format(format, args));
128+
internal static Exception CancelledError(string message) => new OperationCanceledException(message);
129+
public static Exception CancelledError(string format, params object?[] args) => new OperationCanceledException(string.Format(format, args));
130130

131131
// *** END GENERATED CODE ***
132132

0 commit comments

Comments
 (0)