Skip to content
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

Replace TODO() with ProblemDeclaration nodes #1663

Merged
merged 16 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ abstract class Node :
@Relationship("ANNOTATIONS") var annotationEdges = astEdgesOf<Annotation>()
var annotations by unwrapping(Node::annotationEdges)

/**
* Additional problem nodes. These nodes represent problems which occurred during processing of
* a node (i.e. only partially processed).
*/
val additionalProblems: MutableSet<ProblemNode> = mutableSetOf()
oxisto marked this conversation as resolved.
Show resolved Hide resolved

/**
* If a node should be removed from the graph, just removing it from the AST is not enough (see
* issue #60). It will most probably be referenced somewhere via DFG or EOG edges. Thus, if it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
// Wildcards luckily do not have aliases
val decl =
if (imp.name == "*") {
// In the wildcard case, our "import" is the module name and we set "wildcard"
// In the wildcard case, our "import" is the module name, and we set "wildcard"
// to true
newImportDeclaration(module, true, rawNode = imp)
} else {
Expand All @@ -139,7 +139,13 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
val ret = newWhileStatement(rawNode = node)
ret.condition = frontend.expressionHandler.handle(node.test)
ret.statement = makeBlock(node.body).codeAndLocationFromChildren(node)
node.orelse.firstOrNull()?.let { TODO("Not supported") }
if (node.orelse.isNotEmpty()) {
ret.additionalProblems +=
newProblemExpression(
problem = "Cannot handle \"orelse\" in while loops.",
rawNode = node.orelse
)
}
return ret
}

Expand All @@ -148,7 +154,13 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
ret.iterable = frontend.expressionHandler.handle(node.iter)
ret.variable = frontend.expressionHandler.handle(node.target)
ret.statement = makeBlock(node.body).codeAndLocationFromChildren(node)
node.orelse.firstOrNull()?.let { TODO("Not supported") }
if (node.orelse.isNotEmpty()) {
ret.additionalProblems +=
newProblemExpression(
problem = "Cannot handle \"orelse\" in for loops.",
rawNode = node.orelse
)
}
return ret
}

Expand All @@ -157,7 +169,13 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
ret.iterable = frontend.expressionHandler.handle(node.iter)
ret.variable = frontend.expressionHandler.handle(node.target)
ret.statement = makeBlock(node.body).codeAndLocationFromChildren(node)
node.orelse.firstOrNull()?.let { TODO("Not supported") }
if (node.orelse.isNotEmpty()) {
ret.additionalProblems +=
newProblemExpression(
problem = "Cannot handle \"orelse\" in async for loops.",
rawNode = node.orelse
)
}
return ret
}

Expand Down Expand Up @@ -241,9 +259,8 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
frontend.scopeManager.enterScope(cls)

stmt.keywords.forEach {
frontend.currentTU?.addDeclaration(
newProblemDeclaration("could not parse keyword $it in class")
)
cls.additionalProblems +=
newProblemExpression(problem = "could not parse keyword $it in class", rawNode = it)
}

for (s in stmt.body) {
Expand Down Expand Up @@ -391,20 +408,15 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
) {
// We can merge posonlyargs and args because both are positional arguments. We do not
// enforce that posonlyargs can ONLY be used in a positional style, whereas args can be used
// both in positional as well as keyword style.
// both in positional and keyword style.
var positionalArguments = args.posonlyargs + args.args
// Handle arguments
if (recordDeclaration != null) {
// first argument is the `receiver`
val recvPythonNode = positionalArguments.firstOrNull()
if (recvPythonNode == null) {
val problem =
newProblemDeclaration(
"Expected a receiver",
problemType = ProblemNode.ProblemType.TRANSLATION,
rawNode = args
)
frontend.scopeManager.addDeclaration(problem)
result.additionalProblems +=
newProblemExpression("Expected a receiver", rawNode = args)
} else {
val tpe = recordDeclaration.toType()
val recvNode =
Expand All @@ -418,15 +430,24 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
when (result) {
is ConstructorDeclaration -> result.receiver = recvNode
is MethodDeclaration -> result.receiver = recvNode
else -> TODO()
else ->
result.additionalProblems +=
newProblemExpression(
problem =
"Expected a constructor or method declaration. Got something else.",
rawNode = result
)
}
}
}

if (recordDeclaration != null) {
// first argument is the receiver
for (arg in positionalArguments.subList(1, positionalArguments.size)) {
handleArgument(arg, arg in args.posonlyargs)
if (
positionalArguments.size > 1 // more arguments than only a receiver
) { // first argument is the receiver
for (arg in positionalArguments.subList(1, positionalArguments.size)) {
handleArgument(arg, arg in args.posonlyargs)
}
}
} else {
for (arg in positionalArguments) {
Expand All @@ -437,43 +458,39 @@ class StatementHandler(frontend: PythonLanguageFrontend) :
args.vararg?.let { handleArgument(it, isPosOnly = false, isVariadic = true) }

if (args.kwonlyargs.isNotEmpty()) {
val problem =
result.additionalProblems +=
newProblemDeclaration(
"`kwonlyargs` are not yet supported",
problemType = ProblemNode.ProblemType.TRANSLATION,
rawNode = args
)
frontend.scopeManager.addDeclaration(problem)
}

if (args.kw_defaults.isNotEmpty()) {
val problem =
result.additionalProblems +=
newProblemDeclaration(
"`kw_defaults` are not yet supported",
problemType = ProblemNode.ProblemType.TRANSLATION,
rawNode = args
)
frontend.scopeManager.addDeclaration(problem)
}

args.kwarg?.let {
val problem =
result.additionalProblems +=
newProblemDeclaration(
"`kwarg` is not yet supported",
problemType = ProblemNode.ProblemType.TRANSLATION,
rawNode = it
)
frontend.scopeManager.addDeclaration(problem)
}

if (args.defaults.isNotEmpty()) {
val problem =
result.additionalProblems +=
newProblemDeclaration(
"`defaults` are not yet supported",
problemType = ProblemNode.ProblemType.TRANSLATION,
rawNode = args
)
frontend.scopeManager.addDeclaration(problem)
}
}

Expand Down
Loading