Skip to content

Commit 1f8c8b1

Browse files
committed
Unified: Improve toString of UnaryExpr, BinaryExpr, CallExpr, and MemberAccessExpr.
1 parent e80686c commit 1f8c8b1

4 files changed

Lines changed: 322 additions & 298 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
@@ -152,6 +152,8 @@ module Unified {
152152
}
153153

154154
class MemberAccessExpr extends G::MemberAccessExpr {
155+
override string toString() { result = "... ." + this.getMemberName() }
156+
155157
/** Gets the member name of this access. */
156158
string getMemberName() { result = this.getMemberNameNode().getValue() }
157159
}
@@ -183,12 +185,34 @@ module Unified {
183185

184186
/** A binary expression. */
185187
class BinaryExpr extends G::BinaryExpr {
188+
override string toString() { result = "... " + this.getOperator().getValue() + " ..." }
189+
186190
/** Gets an operand of this binary expression. */
187191
Expr getAnOperand() { result = [this.getLeft(), this.getRight()] }
188192
}
189193

194+
/** A unary expression. */
195+
class UnaryExpr extends G::UnaryExpr {
196+
override string toString() {
197+
result = this.getOperator().(PrefixOperator).getValue() + " ..." or
198+
result = "... " + this.getOperator().(PostfixOperator).getValue()
199+
}
200+
}
201+
190202
/** A function call */
191203
class CallExpr extends G::CallExpr {
204+
override string toString() {
205+
exists(Expr callee | callee = this.getCallee() |
206+
result = callee.(Token).getValue() + "(...)"
207+
or
208+
result = callee.(MemberAccessExpr).getMemberName() + "(...)"
209+
or
210+
not callee instanceof Token and
211+
not callee instanceof MemberAccessExpr and
212+
result = "...(...)"
213+
)
214+
}
215+
192216
/** Gets the named argument with the given `name`. */
193217
Expr getNamedArgument(string name) {
194218
exists(Argument arg |

0 commit comments

Comments
 (0)