Skip to content

Commit 050bd41

Browse files
authored
Merge pull request #22618 from aschackmull/unified/ast-tostring
Unified: Improve toString of UnaryExpr, BinaryExpr, CallExpr, and MemberAccessExpr.
2 parents e46f982 + ed5fa16 commit 050bd41

5 files changed

Lines changed: 537 additions & 513 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/FacadeAst.qll‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ module Unified {
155155
}
156156

157157
class MemberAccessExpr extends G::MemberAccessExpr {
158+
override string toString() { result = "... ." + this.getMemberName() }
159+
158160
/** Gets the member name of this access. */
159161
string getMemberName() { result = this.getMemberNameNode().getValue() }
160162
}
@@ -186,12 +188,34 @@ module Unified {
186188

187189
/** A binary expression. */
188190
class BinaryExpr extends G::BinaryExpr {
191+
override string toString() { result = "... " + this.getOperator().getValue() + " ..." }
192+
189193
/** Gets an operand of this binary expression. */
190194
Expr getAnOperand() { result = [this.getLeft(), this.getRight()] }
191195
}
192196

197+
/** A unary expression. */
198+
class UnaryExpr extends G::UnaryExpr {
199+
override string toString() {
200+
result = this.getOperator().(PrefixOperator).getValue() + " ..." or
201+
result = "... " + this.getOperator().(PostfixOperator).getValue()
202+
}
203+
}
204+
193205
/** A function call */
194206
class CallExpr extends G::CallExpr {
207+
override string toString() {
208+
exists(Expr callee | callee = this.getCallee() |
209+
result = callee.(Token).getValue() + "(...)"
210+
or
211+
result = "... ." + callee.(MemberAccessExpr).getMemberName() + "(...)"
212+
or
213+
not callee instanceof Token and
214+
not callee instanceof MemberAccessExpr and
215+
result = "...(...)"
216+
)
217+
}
218+
195219
/** Gets the named argument with the given `name`. */
196220
Expr getNamedArgument(string name) {
197221
exists(Argument arg |

0 commit comments

Comments
 (0)