Python: make compile again

also improve comment
This commit is contained in:
Rasmus Lerchedahl Petersen
2023-12-15 10:25:49 +01:00
parent c395d2d957
commit f96c52ed3b
3 changed files with 15 additions and 16 deletions

View File

@@ -1531,7 +1531,7 @@ abstract class ParameterNodeImpl extends Node {
class LambdaSelfReferenceNode extends ParameterNodeImpl, TLambdaSelfReferenceNode {
private Function callable;
LambdaSelfReferenceNode() {
LambdaSelfReferenceNode() {
this = TLambdaSelfReferenceNode(callable) and
// TODO: Remove this restriction when adding proper support for captured variables in the body of the function we generate for comprehensions
exists(TFunction(callable))
@@ -1624,10 +1624,10 @@ private class SummaryPostUpdateNode extends FlowSummaryNode, PostUpdateNodeImpl
override Node getPreUpdateNode() { result = pre }
}
private class CapturePostUpdateNode extends PostUpdateNodeImpl, CaptureNode {
private CaptureNode pre;
private class SynthCapturePostUpdateNode extends PostUpdateNodeImpl, SynthCaptureNode {
private SynthCaptureNode pre;
CapturePostUpdateNode() {
SynthCapturePostUpdateNode() {
VariableCapture::Flow::capturePostUpdateNode(this.getSynthesizedCaptureNode(),
pre.getSynthesizedCaptureNode())
}

View File

@@ -392,12 +392,13 @@ module VariableCapture {
ExprCfgNode() { isExpressionNode(this) }
}
private predicate closureFlowStep(ExprCfgNode fromNode, ExprCfgNode toNode) {
// simpleAstFlowStep(e1, e2)
// or
private predicate closureFlowStep(ExprCfgNode nodeFrom, ExprCfgNode nodeTo) {
// TODO: Other languages have an extra case here looking like
// simpleAstFlowStep(nodeFrom, nodeTo)
// we should investigate the potential benefit of adding that.
exists(SsaVariable def |
def.getAUse() = e2 and
def.getAnUltimateDefinition().getDefinition().(DefinitionNode).getValue() = e1
def.getAUse() = nodeTo and
def.getAnUltimateDefinition().getDefinition().(DefinitionNode).getValue() = nodeFrom
)
}
@@ -492,7 +493,7 @@ module VariableCapture {
module Flow = Shared::Flow<Location, CaptureInput>;
private Flow::ClosureNode asClosureNode(Node n) {
result = n.(CaptureNode).getSynthesizedCaptureNode()
result = n.(SynthCaptureNode).getSynthesizedCaptureNode()
or
result.(Flow::ExprNode).getExpr() = n.(CfgNode).getNode()
or
@@ -665,7 +666,7 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
or
summaryFlowSteps(nodeFrom, nodeTo)
or
variableCaptureFlowStep(nodeFrom, nodeTo)
variableCaptureLocalFlowStep(nodeFrom, nodeTo)
}
/**

View File

@@ -481,17 +481,15 @@ class StarPatternElementNode extends Node, TStarPatternElementNode {
* A synthesized data flow node representing a closure object that tracks
* captured variables.
*/
class CaptureNode extends Node, TCaptureNode {
class SynthCaptureNode extends Node, TSynthCaptureNode {
private VariableCapture::Flow::SynthesizedCaptureNode cn;
CaptureNode() { this = TCaptureNode(cn) }
SynthCaptureNode() { this = TSynthCaptureNode(cn) }
/** Gets the `SynthesizedCaptureNode` that this node represents. */
VariableCapture::Flow::SynthesizedCaptureNode getSynthesizedCaptureNode() { result = cn }
override Scope getScope() {
result = cn.getEnclosingCallable()
}
override Scope getScope() { result = cn.getEnclosingCallable() }
override Location getLocation() { result = cn.getLocation() }