Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ed3107

Browse files
committed
Python: Start scaffold for magic methods
1 parent 8891ae7 commit 5ed3107

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import python
2+
3+
module MagicMethod {
4+
abstract class Potential extends ControlFlowNode {
5+
abstract string getMagicMethodName();
6+
abstract ControlFlowNode getArg(int n);
7+
ControlFlowNode getSelf() { result = this.getArg(1) }
8+
}
9+
10+
class Actual extends ControlFlowNode {
11+
Object resolvedMagicMethod;
12+
13+
Actual() {
14+
exists(Potential pot |
15+
this.(Potential) = pot and
16+
pot.getSelf().(ClassObject).lookupAttribute(pot.getMagicMethodName()) = resolvedMagicMethod
17+
)
18+
}
19+
}
20+
}
21+
22+
class MagicBinOp extends MagicMethod::Potential, BinaryExprNode {
23+
Operator operator;
24+
25+
MagicBinOp() { this.getOp() = operator}
26+
27+
override string getMagicMethodName() {
28+
result = operator.getSpecialMethodName()
29+
}
30+
31+
override ControlFlowNode getArg(int n) {
32+
n = 1 and result = this.getLeft()
33+
or
34+
n = 2 and result = this.getRight()
35+
}
36+
}

0 commit comments

Comments
 (0)