Skip to content

Commit 68da13c

Browse files
committed
Python remove a couple of small AST related modules, moving contents to more appropriate modules.
1 parent 1bd0c69 commit 68da13c

File tree

5 files changed

+68
-78
lines changed

5 files changed

+68
-78
lines changed

python/ql/src/python.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import semmle.python.Operations
33
import semmle.python.Variables
44
import semmle.python.AstGenerated
55
import semmle.python.AstExtended
6-
import semmle.python.AST
76
import semmle.python.Function
87
import semmle.python.Module
98
import semmle.python.Class
@@ -28,7 +27,6 @@ import semmle.python.types.Version
2827
import semmle.python.types.Descriptors
2928
import semmle.python.protocols
3029
import semmle.python.SSA
31-
import semmle.python.Assigns
3230
import semmle.python.SelfAttribute
3331
import semmle.python.types.Properties
3432
import semmle.python.xml.XML

python/ql/src/semmle/python/AST.qll

Lines changed: 0 additions & 57 deletions
This file was deleted.

python/ql/src/semmle/python/Assigns.qll

Lines changed: 0 additions & 19 deletions
This file was deleted.

python/ql/src/semmle/python/AstExtended.qll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,61 @@
11
import python
22

3+
/** Syntactic node (Class, Function, Module, Expr, Stmt or Comprehension) corresponding to a flow node */
4+
abstract class AstNode extends AstNode_ {
5+
6+
/** Gets the scope that this node occurs in */
7+
abstract Scope getScope();
8+
9+
/** Gets a flow node corresponding directly to this node.
10+
* NOTE: For some statements and other purely syntactic elements,
11+
* there may not be a `ControlFlowNode` */
12+
ControlFlowNode getAFlowNode() {
13+
py_flow_bb_node(result, this, _, _)
14+
}
15+
16+
/** Gets the location for this AST node */
17+
Location getLocation() {
18+
none()
19+
}
20+
21+
/** Whether this syntactic element is artificial, that is it is generated
22+
* by the compiler and is not present in the source */
23+
predicate isArtificial() {
24+
none()
25+
}
26+
27+
/** Gets a child node of this node in the AST. This predicate exists to aid exploration of the AST
28+
* and other experiments. The child-parent relation may not be meaningful.
29+
* For a more meaningful relation in terms of dependency use
30+
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
31+
* Scope.getAStmt().
32+
*/
33+
abstract AstNode getAChildNode();
34+
35+
/** Gets the parent node of this node in the AST. This predicate exists to aid exploration of the AST
36+
* and other experiments. The child-parent relation may not be meaningful.
37+
* For a more meaningful relation in terms of dependency use
38+
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
39+
* Scope.getAStmt() applied to the parent.
40+
*/
41+
AstNode getParentNode() {
42+
result.getAChildNode() = this
43+
}
44+
45+
/** Whether this contains `inner` syntactically */
46+
predicate contains(AstNode inner) {
47+
this.getAChildNode+() = inner
48+
}
49+
50+
/** Whether this contains `inner` syntactically and `inner` has the same scope as `this` */
51+
predicate containsInScope(AstNode inner) {
52+
this.contains(inner) and
53+
this.getScope() = inner.getScope() and
54+
not inner instanceof Scope
55+
}
56+
57+
}
58+
359
/* Parents */
460

561
/** Internal implementation class */

python/ql/src/semmle/python/Stmts.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ class Assign extends Assign_ {
9595
}
9696
}
9797

98+
/** An assignment statement */
99+
class AssignStmt extends Assign {
100+
101+
AssignStmt() {
102+
not this instanceof FunctionDef and not this instanceof ClassDef
103+
}
104+
105+
override string toString() {
106+
result = "AssignStmt"
107+
}
108+
}
109+
98110
/** An augmented assignment statement, such as `x += y` */
99111
class AugAssign extends AugAssign_ {
100112

0 commit comments

Comments
 (0)