Skip to content

Commit 03a114d

Browse files
committed
Add doc strings
1 parent e588a24 commit 03a114d

File tree

1 file changed

+23
-2
lines changed
  • cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python

1 file changed

+23
-2
lines changed

Diff for: cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt

+23-2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
7676
is Python.AST.Delete -> handleDelete(node)
7777
is Python.AST.With,
7878
is Python.AST.AsyncWith -> handleWithStatement(node)
79+
7980
is Python.AST.Global -> handleGlobal(node)
8081
is Python.AST.Nonlocal -> handleNonLocal(node)
8182
is Python.AST.Raise -> handleRaise(node)
@@ -100,6 +101,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
100101
this.lhs = newReference(name = subject)
101102
this.rhs = frontend.expressionHandler.handle(ctx = node.value)
102103
}
104+
103105
is Python.AST.MatchSingleton ->
104106
newBinaryOperator(operatorCode = "===", rawNode = node).implicit().apply {
105107
this.lhs = newReference(name = subject)
@@ -114,13 +116,15 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
114116
)
115117
}
116118
}
119+
117120
is Python.AST.MatchOr ->
118121
frontend.expressionHandler.joinListWithBinOp(
119122
operatorCode = "or",
120123
nodes = node.patterns.map { handlePattern(node = it, subject = subject) },
121124
rawNode = node,
122125
isImplicit = false,
123126
)
127+
124128
is Python.AST.MatchSequence,
125129
is Python.AST.MatchMapping,
126130
is Python.AST.MatchClass,
@@ -130,6 +134,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
130134
problem = "Cannot handle of type ${node::class} yet",
131135
rawNode = node,
132136
)
137+
133138
else ->
134139
newProblemExpression(
135140
problem = "Cannot handle of type ${node::class} yet",
@@ -367,6 +372,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
367372
tmpValName,
368373
)
369374
}
375+
370376
val result =
371377
newBlock().codeAndLocationFromOtherRawNode(node as? Python.AST.BaseStmt).implicit()
372378

@@ -535,7 +541,11 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
535541
return assertStatement
536542
}
537543

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 {
539549
val declStmt = newDeclarationStatement(rawNode = node)
540550
for (imp in node.names) {
541551
val alias = imp.asname
@@ -560,7 +570,11 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
560570
return declStmt
561571
}
562572

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 {
564578
val declStmt = newDeclarationStatement(rawNode = node)
565579
val level = node.level
566580
var module = parseName(node.module ?: "")
@@ -688,10 +702,12 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
688702
) // add the unpacking instruction to the top of the loop body
689703
ret.statement = body
690704
}
705+
691706
is Reference -> { // only one var
692707
ret.variable = loopVar
693708
ret.statement = makeBlock(node.body, parentNode = node)
694709
}
710+
695711
else -> {
696712
ret.variable =
697713
newProblemExpression(
@@ -831,6 +847,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
831847
// statements and therefore are not triggering our automagic parent setter
832848
stmt.astParent = cls
833849
}
850+
834851
else -> cls.statements += handleNode(s)
835852
}
836853
}
@@ -1031,6 +1048,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
10311048
when (result) {
10321049
is ConstructorDeclaration,
10331050
is MethodDeclaration -> result.receiver = recvNode
1051+
10341052
else ->
10351053
result.additionalProblems +=
10361054
newProblemExpression(
@@ -1113,6 +1131,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
11131131
val parsedDecorator = frontend.expressionHandler.handle(decorator)
11141132
newAnnotation(name = parsedDecorator.name, rawNode = decorator)
11151133
}
1134+
11161135
is Python.AST.Attribute -> {
11171136
val parsedDecorator = frontend.expressionHandler.handle(decorator)
11181137
val name =
@@ -1123,6 +1142,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
11231142
}
11241143
newAnnotation(name = name, rawNode = decorator)
11251144
}
1145+
11261146
is Python.AST.Call -> {
11271147
val parsedDecorator = frontend.expressionHandler.handle(decorator.func)
11281148
val name =
@@ -1151,6 +1171,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
11511171
}
11521172
annotation
11531173
}
1174+
11541175
else -> {
11551176
Util.warnWithFileLocation(
11561177
frontend,

0 commit comments

Comments
 (0)