Skip to content

Commit d629eea

Browse files
committed
aggregate the arguments of a call into a synthetic node
1 parent 5770d02 commit d629eea

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

python/ql/src/semmle/python/PrintAst.qll

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ private predicate isNotNeeded(AstNode el) {
4646
*/
4747
private newtype TPrintAstNode =
4848
TElementNode(AstNode el) { shouldPrint(el, _) and not isNotNeeded(el) } or
49-
TFunctionParamsNode(AstNode f) { shouldPrint(f, _) and not isNotNeeded(f) } or
49+
TFunctionParamsNode(Function f) { shouldPrint(f, _) and not isNotNeeded(f) } or
50+
TCallArgumentsNode(Call c) { shouldPrint(c, _) and not isNotNeeded(c) } or
5051
TStmtListNode(StmtList list) {
5152
shouldPrint(list.getAnItem(), _) and
5253
not list = any(Module mod).getBody() and
@@ -302,6 +303,42 @@ class StmtListNode extends PrintAstNode, TStmtListNode {
302303
}
303304
}
304305

306+
/**
307+
* A print node for a `Call`.
308+
*
309+
* The arguments to this call are aggregated into a `CallArgumentsNode`.
310+
*/
311+
class CallPrintNode extends AstElementNode {
312+
override Call element;
313+
314+
override PrintAstNode getChild(int childIndex) {
315+
childIndex = 0 and result.(AstElementNode).getAstNode() = element.getFunc()
316+
or
317+
childIndex = 1 and result.(CallArgumentsNode).getCall() = element
318+
}
319+
}
320+
321+
/**
322+
* A synthetic print node for the arguments to `call`.
323+
*/
324+
class CallArgumentsNode extends PrintAstNode, TCallArgumentsNode {
325+
Call call;
326+
327+
CallArgumentsNode() { this = TCallArgumentsNode(call) }
328+
329+
/**
330+
* Gets the call for which this print node represents the arguments.
331+
*/
332+
Call getCall() { result = call }
333+
334+
override string toString() { result = "(arguments)" }
335+
336+
override PrintAstNode getChild(int childIndex) {
337+
result.(AstElementNode).getAstNode() = getChild(call, childIndex) and
338+
not result.(AstElementNode).getAstNode() = call.getFunc()
339+
}
340+
}
341+
305342
/**
306343
* A print node for a `Function`.
307344
*/
@@ -418,7 +455,7 @@ private module PrettyPrinting {
418455
string getQlCustomClass(AstNode a) {
419456
a instanceof Name and
420457
result = "Name" and
421-
not a instanceof Parameter and
458+
not a instanceof Parameter and
422459
not a instanceof NameConstant
423460
or
424461
a instanceof Parameter and result = "Parameter"

0 commit comments

Comments
 (0)