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

Skip to content

Commit 810e91e

Browse files
committed
Python: Autoformat semmle/python top-level.
1 parent f406a45 commit 810e91e

23 files changed

Lines changed: 1986 additions & 4677 deletions

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

Lines changed: 60 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -2,189 +2,139 @@ import python
22

33
/** Syntactic node (Class, Function, Module, Expr, Stmt or Comprehension) corresponding to a flow node */
44
abstract class AstNode extends AstNode_ {
5-
6-
/* Special comment for documentation generation.
5+
/*
6+
* Special comment for documentation generation.
77
* All subclasses of `AstNode` that represent concrete syntax should have
8-
* a comment of the form: */
9-
/* syntax: ... */
8+
* a comment of the form:
9+
*/
1010

11+
/* syntax: ... */
1112
/** Gets the scope that this node occurs in */
1213
abstract Scope getScope();
1314

14-
/** Gets a flow node corresponding directly to this node.
15+
/**
16+
* Gets a flow node corresponding directly to this node.
1517
* NOTE: For some statements and other purely syntactic elements,
16-
* there may not be a `ControlFlowNode` */
17-
ControlFlowNode getAFlowNode() {
18-
py_flow_bb_node(result, this, _, _)
19-
}
18+
* there may not be a `ControlFlowNode`
19+
*/
20+
ControlFlowNode getAFlowNode() { py_flow_bb_node(result, this, _, _) }
2021

2122
/** Gets the location for this AST node */
22-
Location getLocation() {
23-
none()
24-
}
25-
26-
/** Whether this syntactic element is artificial, that is it is generated
27-
* by the compiler and is not present in the source */
28-
predicate isArtificial() {
29-
none()
30-
}
31-
32-
/** Gets a child node of this node in the AST. This predicate exists to aid exploration of the AST
33-
* and other experiments. The child-parent relation may not be meaningful.
34-
* For a more meaningful relation in terms of dependency use
35-
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
36-
* Scope.getAStmt().
37-
*/
23+
Location getLocation() { none() }
24+
25+
/**
26+
* Whether this syntactic element is artificial, that is it is generated
27+
* by the compiler and is not present in the source
28+
*/
29+
predicate isArtificial() { none() }
30+
31+
/**
32+
* Gets a child node of this node in the AST. This predicate exists to aid exploration of the AST
33+
* and other experiments. The child-parent relation may not be meaningful.
34+
* For a more meaningful relation in terms of dependency use
35+
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
36+
* Scope.getAStmt().
37+
*/
3838
abstract AstNode getAChildNode();
3939

40-
/** Gets the parent node of this node in the AST. This predicate exists to aid exploration of the AST
41-
* and other experiments. The child-parent relation may not be meaningful.
42-
* For a more meaningful relation in terms of dependency use
43-
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
44-
* Scope.getAStmt() applied to the parent.
45-
*/
46-
AstNode getParentNode() {
47-
result.getAChildNode() = this
48-
}
40+
/**
41+
* Gets the parent node of this node in the AST. This predicate exists to aid exploration of the AST
42+
* and other experiments. The child-parent relation may not be meaningful.
43+
* For a more meaningful relation in terms of dependency use
44+
* Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or
45+
* Scope.getAStmt() applied to the parent.
46+
*/
47+
AstNode getParentNode() { result.getAChildNode() = this }
4948

5049
/** Whether this contains `inner` syntactically */
51-
predicate contains(AstNode inner) {
52-
this.getAChildNode+() = inner
53-
}
50+
predicate contains(AstNode inner) { this.getAChildNode+() = inner }
5451

5552
/** Whether this contains `inner` syntactically and `inner` has the same scope as `this` */
5653
predicate containsInScope(AstNode inner) {
5754
this.contains(inner) and
5855
this.getScope() = inner.getScope() and
5956
not inner instanceof Scope
6057
}
61-
6258
}
6359

6460
/* Parents */
65-
6661
/** Internal implementation class */
67-
library class FunctionParent extends FunctionParent_ {
68-
69-
}
62+
library class FunctionParent extends FunctionParent_ { }
7063

7164
/** Internal implementation class */
72-
library class ArgumentsParent extends ArgumentsParent_ {
73-
74-
}
65+
library class ArgumentsParent extends ArgumentsParent_ { }
7566

7667
/** Internal implementation class */
77-
library class ExprListParent extends ExprListParent_ {
78-
79-
}
68+
library class ExprListParent extends ExprListParent_ { }
8069

8170
/** Internal implementation class */
82-
library class ExprContextParent extends ExprContextParent_ {
83-
84-
}
71+
library class ExprContextParent extends ExprContextParent_ { }
8572

8673
/** Internal implementation class */
87-
library class StmtListParent extends StmtListParent_ {
88-
89-
}
74+
library class StmtListParent extends StmtListParent_ { }
9075

9176
/** Internal implementation class */
92-
library class StrListParent extends StrListParent_ {
93-
94-
}
77+
library class StrListParent extends StrListParent_ { }
9578

9679
/** Internal implementation class */
97-
library class ExprParent extends ExprParent_ {
98-
99-
}
80+
library class ExprParent extends ExprParent_ { }
10081

10182
library class DictItem extends DictItem_, AstNode {
102-
103-
override string toString() {
104-
result = DictItem_.super.toString()
105-
}
83+
override string toString() { result = DictItem_.super.toString() }
10684

10785
override AstNode getAChildNode() { none() }
10886

10987
override Scope getScope() { none() }
110-
11188
}
11289

11390
/** A comprehension part, the 'for a in seq' part of [ a * a for a in seq ] */
11491
class Comprehension extends Comprehension_, AstNode {
115-
11692
/** Gets the scope of this comprehension */
11793
override Scope getScope() {
11894
/* Comprehensions exists only in Python 2 list comprehensions, so their scope is that of the list comp. */
119-
exists(ListComp l |
120-
this = l.getAGenerator() |
121-
result = l.getScope()
122-
)
95+
exists(ListComp l | this = l.getAGenerator() | result = l.getScope())
12396
}
12497

125-
override string toString() {
126-
result = "Comprehension"
127-
}
98+
override string toString() { result = "Comprehension" }
12899

129-
override Location getLocation() {
130-
result = Comprehension_.super.getLocation()
131-
}
100+
override Location getLocation() { result = Comprehension_.super.getLocation() }
132101

133-
override AstNode getAChildNode() {
134-
result = this.getASubExpression()
135-
}
102+
override AstNode getAChildNode() { result = this.getASubExpression() }
136103

137104
Expr getASubExpression() {
138105
result = this.getIter() or
139106
result = this.getAnIf() or
140107
result = this.getTarget()
141108
}
142-
143109
}
144110

145-
class BytesOrStr extends BytesOrStr_ {
146-
147-
}
111+
class BytesOrStr extends BytesOrStr_ { }
148112

149-
/** Part of a string literal formed by implicit concatenation.
113+
/**
114+
* Part of a string literal formed by implicit concatenation.
150115
* For example the string literal "abc" expressed in the source as `"a" "b" "c"`
151116
* would be composed of three `StringPart`s.
152-
*
153117
*/
154118
class StringPart extends StringPart_, AstNode {
155-
156119
override Scope getScope() {
157120
exists(Bytes b | this = b.getAnImplicitlyConcatenatedPart() | result = b.getScope())
158121
or
159122
exists(Unicode u | this = u.getAnImplicitlyConcatenatedPart() | result = u.getScope())
160123
}
161124

162-
override AstNode getAChildNode() {
163-
none()
164-
}
165-
166-
override string toString() {
167-
result = StringPart_.super.toString()
168-
}
125+
override AstNode getAChildNode() { none() }
169126

170-
override Location getLocation() {
171-
result = StringPart_.super.getLocation()
172-
}
127+
override string toString() { result = StringPart_.super.toString() }
173128

129+
override Location getLocation() { result = StringPart_.super.getLocation() }
174130
}
175131

176-
class StringPartList extends StringPartList_ {
177-
178-
}
132+
class StringPartList extends StringPartList_ { }
179133

180134
/* **** Lists ***/
181-
182135
/** A parameter list */
183136
class ParameterList extends @py_parameter_list {
184-
185-
Function getParent() {
186-
py_parameter_lists(this, result)
187-
}
137+
Function getParent() { py_parameter_lists(this, result) }
188138

189139
/** Gets a parameter */
190140
Parameter getAnItem() {
@@ -198,40 +148,23 @@ class ParameterList extends @py_parameter_list {
198148
py_exprs(result, _, this, index)
199149
}
200150

201-
string toString() {
202-
result = "ParameterList"
203-
}
151+
string toString() { result = "ParameterList" }
204152
}
205153

206154
/** A list of Comprehensions (for generating parts of a set, list or dictionary comprehension) */
207-
class ComprehensionList extends ComprehensionList_ {
208-
209-
}
155+
class ComprehensionList extends ComprehensionList_ { }
210156

211157
/** A list of expressions */
212158
class ExprList extends ExprList_ {
213-
214159
/* syntax: Expr, ... */
215-
216160
}
217161

162+
library class DictItemList extends DictItemList_ { }
218163

219-
library class DictItemList extends DictItemList_ {
220-
221-
}
222-
223-
library class DictItemListParent extends DictItemListParent_ {
224-
225-
}
164+
library class DictItemListParent extends DictItemListParent_ { }
226165

227166
/** A list of strings (the primitive type string not Bytes or Unicode) */
228-
class StringList extends StringList_ {
229-
230-
}
167+
class StringList extends StringList_ { }
231168

232169
/** A list of aliases in an import statement */
233-
class AliasList extends AliasList_ {
234-
235-
}
236-
237-
170+
class AliasList extends AliasList_ { }

0 commit comments

Comments
 (0)