@@ -76,6 +76,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
76
76
is Python .AST .Delete -> handleDelete(node)
77
77
is Python .AST .With ,
78
78
is Python .AST .AsyncWith -> handleWithStatement(node)
79
+
79
80
is Python .AST .Global -> handleGlobal(node)
80
81
is Python .AST .Nonlocal -> handleNonLocal(node)
81
82
is Python .AST .Raise -> handleRaise(node)
@@ -100,6 +101,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
100
101
this .lhs = newReference(name = subject)
101
102
this .rhs = frontend.expressionHandler.handle(ctx = node.value)
102
103
}
104
+
103
105
is Python .AST .MatchSingleton ->
104
106
newBinaryOperator(operatorCode = " ===" , rawNode = node).implicit().apply {
105
107
this .lhs = newReference(name = subject)
@@ -114,13 +116,15 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
114
116
)
115
117
}
116
118
}
119
+
117
120
is Python .AST .MatchOr ->
118
121
frontend.expressionHandler.joinListWithBinOp(
119
122
operatorCode = " or" ,
120
123
nodes = node.patterns.map { handlePattern(node = it, subject = subject) },
121
124
rawNode = node,
122
125
isImplicit = false ,
123
126
)
127
+
124
128
is Python .AST .MatchSequence ,
125
129
is Python .AST .MatchMapping ,
126
130
is Python .AST .MatchClass ,
@@ -130,6 +134,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
130
134
problem = " Cannot handle of type ${node::class } yet" ,
131
135
rawNode = node,
132
136
)
137
+
133
138
else ->
134
139
newProblemExpression(
135
140
problem = " Cannot handle of type ${node::class } yet" ,
@@ -367,6 +372,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
367
372
tmpValName,
368
373
)
369
374
}
375
+
370
376
val result =
371
377
newBlock().codeAndLocationFromOtherRawNode(node as ? Python .AST .BaseStmt ).implicit()
372
378
@@ -535,7 +541,11 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
535
541
return assertStatement
536
542
}
537
543
538
- private fun handleImport (node : Python .AST .Import ): Statement {
544
+ /* *
545
+ * Translates a Python [`Import`](https://docs.python.org/3/library/ast.html#ast.Import) into a
546
+ * [DeclarationStatement].
547
+ */
548
+ private fun handleImport (node : Python .AST .Import ): DeclarationStatement {
539
549
val declStmt = newDeclarationStatement(rawNode = node)
540
550
for (imp in node.names) {
541
551
val alias = imp.asname
@@ -560,7 +570,11 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
560
570
return declStmt
561
571
}
562
572
563
- private fun handleImportFrom (node : Python .AST .ImportFrom ): Statement {
573
+ /* *
574
+ * Translates a Python [`ImportFrom`](https://docs.python.org/3/library/ast.html#ast.ImportFrom)
575
+ * into a [DeclarationStatement].
576
+ */
577
+ private fun handleImportFrom (node : Python .AST .ImportFrom ): DeclarationStatement {
564
578
val declStmt = newDeclarationStatement(rawNode = node)
565
579
val level = node.level
566
580
var module = parseName(node.module ? : " " )
@@ -688,10 +702,12 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
688
702
) // add the unpacking instruction to the top of the loop body
689
703
ret.statement = body
690
704
}
705
+
691
706
is Reference -> { // only one var
692
707
ret.variable = loopVar
693
708
ret.statement = makeBlock(node.body, parentNode = node)
694
709
}
710
+
695
711
else -> {
696
712
ret.variable =
697
713
newProblemExpression(
@@ -831,6 +847,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
831
847
// statements and therefore are not triggering our automagic parent setter
832
848
stmt.astParent = cls
833
849
}
850
+
834
851
else -> cls.statements + = handleNode(s)
835
852
}
836
853
}
@@ -1031,6 +1048,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
1031
1048
when (result) {
1032
1049
is ConstructorDeclaration ,
1033
1050
is MethodDeclaration -> result.receiver = recvNode
1051
+
1034
1052
else ->
1035
1053
result.additionalProblems + =
1036
1054
newProblemExpression(
@@ -1113,6 +1131,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
1113
1131
val parsedDecorator = frontend.expressionHandler.handle(decorator)
1114
1132
newAnnotation(name = parsedDecorator.name, rawNode = decorator)
1115
1133
}
1134
+
1116
1135
is Python .AST .Attribute -> {
1117
1136
val parsedDecorator = frontend.expressionHandler.handle(decorator)
1118
1137
val name =
@@ -1123,6 +1142,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
1123
1142
}
1124
1143
newAnnotation(name = name, rawNode = decorator)
1125
1144
}
1145
+
1126
1146
is Python .AST .Call -> {
1127
1147
val parsedDecorator = frontend.expressionHandler.handle(decorator.func)
1128
1148
val name =
@@ -1151,6 +1171,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
1151
1171
}
1152
1172
annotation
1153
1173
}
1174
+
1154
1175
else -> {
1155
1176
Util .warnWithFileLocation(
1156
1177
frontend,
0 commit comments