Skip to content

Commit d1ad65a

Browse files
committed
Rust: Cache Element.toString
1 parent 9a8cb1a commit d1ad65a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+117
-84
lines changed

misc/codegen/templates/ql_class.mustache

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ module Generated {
2929
/**
3030
* Gets the string representation of this element.
3131
*/
32-
string toString() { none() } // overridden by subclasses
32+
cached
33+
final string toString() { result = this.toStringImpl() }
34+
35+
/**
36+
* INTERNAL: Do not use.
37+
*
38+
* Gets the string representation of this element.
39+
*/
40+
abstract string toStringImpl();
3341

3442
/**
3543
* Gets the name of a primary CodeQL class to which this element belongs.

rust/ql/.generated.list

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/internal/ArrayListExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ module Impl {
2222
* ```
2323
*/
2424
class ArrayListExpr extends Generated::ArrayListExpr {
25-
override string toString() { result = "[...]" }
25+
override string toStringImpl() { result = "[...]" }
2626
}
2727
}

rust/ql/lib/codeql/rust/elements/internal/ArrayRepeatExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Impl {
2121
* ```
2222
*/
2323
class ArrayRepeatExpr extends Generated::ArrayRepeatExpr {
24-
override string toString() {
24+
override string toStringImpl() {
2525
result =
2626
"[" + this.getRepeatOperand().toAbbreviatedString() + "; " +
2727
this.getRepeatLength().toAbbreviatedString() + "]"

rust/ql/lib/codeql/rust/elements/internal/AwaitExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ module Impl {
2222
* ```
2323
*/
2424
class AwaitExpr extends Generated::AwaitExpr {
25-
override string toString() { result = "await " + this.getExpr().toAbbreviatedString() }
25+
override string toStringImpl() { result = "await " + this.getExpr().toAbbreviatedString() }
2626
}
2727
}

rust/ql/lib/codeql/rust/elements/internal/BecomeExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ module Impl {
2525
* ```
2626
*/
2727
class BecomeExpr extends Generated::BecomeExpr {
28-
override string toString() { result = "become " + this.getExpr().toAbbreviatedString() }
28+
override string toStringImpl() { result = "become " + this.getExpr().toAbbreviatedString() }
2929
}
3030
}

rust/ql/lib/codeql/rust/elements/internal/BinaryExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ module Impl {
2323
* ```
2424
*/
2525
class BinaryExpr extends Generated::BinaryExpr {
26-
override string toString() { result = "... " + this.getOperatorName() + " ..." }
26+
override string toStringImpl() { result = "... " + this.getOperatorName() + " ..." }
2727
}
2828
}

rust/ql/lib/codeql/rust/elements/internal/BoxPatImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ module Impl {
2222
* ```
2323
*/
2424
class BoxPat extends Generated::BoxPat {
25-
override string toString() { result = "box " + this.getPat().toAbbreviatedString() }
25+
override string toStringImpl() { result = "box " + this.getPat().toAbbreviatedString() }
2626
}
2727
}

rust/ql/lib/codeql/rust/elements/internal/BreakExprImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ module Impl {
104104
)
105105
}
106106

107-
override string toString() {
107+
override string toStringImpl() {
108108
result = strictconcat(int i | | this.toStringPart(i), " " order by i)
109109
}
110110

111111
private string toStringPart(int index) {
112112
index = 0 and result = "break"
113113
or
114-
index = 1 and result = this.getLifetime().toString()
114+
index = 1 and result = this.getLifetime().toStringImpl()
115115
or
116116
index = 2 and result = this.getExpr().toAbbreviatedString()
117117
}

rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Impl {
3434
* ```
3535
*/
3636
class CallExpr extends Generated::CallExpr {
37-
override string toString() { result = this.getFunction().toAbbreviatedString() + "(...)" }
37+
override string toStringImpl() { result = this.getFunction().toAbbreviatedString() + "(...)" }
3838

3939
override Callable getStaticTarget() { result = getResolvedFunction(this) }
4040

0 commit comments

Comments
 (0)