Python: Start scaffold for magic methods

This commit is contained in:
Rasmus Lerchedahl Petersen
2020-08-14 11:12:23 +02:00
parent 8891ae70b6
commit 5ed3107045

View File

@@ -0,0 +1,36 @@
import python
module MagicMethod {
abstract class Potential extends ControlFlowNode {
abstract string getMagicMethodName();
abstract ControlFlowNode getArg(int n);
ControlFlowNode getSelf() { result = this.getArg(1) }
}
class Actual extends ControlFlowNode {
Object resolvedMagicMethod;
Actual() {
exists(Potential pot |
this.(Potential) = pot and
pot.getSelf().(ClassObject).lookupAttribute(pot.getMagicMethodName()) = resolvedMagicMethod
)
}
}
}
class MagicBinOp extends MagicMethod::Potential, BinaryExprNode {
Operator operator;
MagicBinOp() { this.getOp() = operator}
override string getMagicMethodName() {
result = operator.getSpecialMethodName()
}
override ControlFlowNode getArg(int n) {
n = 1 and result = this.getLeft()
or
n = 2 and result = this.getRight()
}
}