Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion misc/codegen/templates/ql_class.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ module Generated {
/**
* Gets the string representation of this element.
*/
string toString() { none() } // overridden by subclasses
cached
final string toString() { result = this.toStringImpl() }

/**
* INTERNAL: Do not use.
*
* Gets the string representation of this element.
*/
abstract string toStringImpl();

/**
* Gets the name of a primary CodeQL class to which this element belongs.
Expand Down
2 changes: 1 addition & 1 deletion rust/ql/.generated.list

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ module Impl {
* ```
*/
class ArrayListExpr extends Generated::ArrayListExpr {
override string toString() { result = "[...]" }
override string toStringImpl() { result = "[...]" }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Impl {
* ```
*/
class ArrayRepeatExpr extends Generated::ArrayRepeatExpr {
override string toString() {
override string toStringImpl() {
result =
"[" + this.getRepeatOperand().toAbbreviatedString() + "; " +
this.getRepeatLength().toAbbreviatedString() + "]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ module Impl {
* ```
*/
class AwaitExpr extends Generated::AwaitExpr {
override string toString() { result = "await " + this.getExpr().toAbbreviatedString() }
override string toStringImpl() { result = "await " + this.getExpr().toAbbreviatedString() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ module Impl {
* ```
*/
class BecomeExpr extends Generated::BecomeExpr {
override string toString() { result = "become " + this.getExpr().toAbbreviatedString() }
override string toStringImpl() { result = "become " + this.getExpr().toAbbreviatedString() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ module Impl {
* ```
*/
class BinaryExpr extends Generated::BinaryExpr {
override string toString() { result = "... " + this.getOperatorName() + " ..." }
override string toStringImpl() { result = "... " + this.getOperatorName() + " ..." }
}
}
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/rust/elements/internal/BoxPatImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ module Impl {
* ```
*/
class BoxPat extends Generated::BoxPat {
override string toString() { result = "box " + this.getPat().toAbbreviatedString() }
override string toStringImpl() { result = "box " + this.getPat().toAbbreviatedString() }
}
}
4 changes: 2 additions & 2 deletions rust/ql/lib/codeql/rust/elements/internal/BreakExprImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ module Impl {
)
}

override string toString() {
override string toStringImpl() {
result = strictconcat(int i | | this.toStringPart(i), " " order by i)
}

private string toStringPart(int index) {
index = 0 and result = "break"
or
index = 1 and result = this.getLifetime().toString()
index = 1 and result = this.getLifetime().toStringImpl()
or
index = 2 and result = this.getExpr().toAbbreviatedString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Impl {
* ```
*/
class CallExpr extends Generated::CallExpr {
override string toString() { result = this.getFunction().toAbbreviatedString() + "(...)" }
override string toStringImpl() { result = this.getFunction().toAbbreviatedString() + "(...)" }

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Impl {
* ```
*/
class CastExpr extends Generated::CastExpr {
override string toString() {
override string toStringImpl() {
result =
this.getExpr().toAbbreviatedString() + " as " + this.getTypeRepr().toAbbreviatedString()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ module Impl {
* ```
*/
class ClosureExpr extends Generated::ClosureExpr {
override string toString() { result = "|...| " + this.getBody().toAbbreviatedString() }
override string toStringImpl() { result = "|...| " + this.getBody().toAbbreviatedString() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Impl {
* ```
*/
class Comment extends Generated::Comment {
override string toString() {
override string toStringImpl() {
result = this.getCommentMarker() + "..." + this.getCommentEndMarker()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module Impl {
* ```
*/
class ContinueExpr extends Generated::ContinueExpr {
override string toString() {
override string toStringImpl() {
result = strictconcat(int i | | this.toStringPart(i), " " order by i)
}

Expand Down
4 changes: 3 additions & 1 deletion rust/ql/lib/codeql/rust/elements/internal/CrateImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ private import codeql.rust.elements.internal.generated.Crate
*/
module Impl {
class Crate extends Generated::Crate {
override string toString() { result = strictconcat(int i | | this.toStringPart(i) order by i) }
override string toStringImpl() {
result = strictconcat(int i | | this.toStringPart(i) order by i)
}

private string toStringPart(int i) {
i = 0 and result = "Crate("
Expand Down
6 changes: 3 additions & 3 deletions rust/ql/lib/codeql/rust/elements/internal/ElementImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ private import codeql.rust.elements.internal.generated.Element
*/
module Impl {
class Element extends Generated::Element {
override string toString() { result = this.getAPrimaryQlClass() }
override string toStringImpl() { result = this.getAPrimaryQlClass() }

/**
* INTERNAL: Do not use.
*
* Returns a string suitable to be inserted into the name of the parent. Typically `"..."`,
* but may be overridden by subclasses.
*
* INTERNAL: Do not use.
*/
string toAbbreviatedString() { result = "..." }

Expand Down
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/rust/elements/internal/EnumImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ module Impl {
* ```
*/
class Enum extends Generated::Enum {
override string toString() { result = "enum " + this.getName().getText() }
override string toStringImpl() { result = "enum " + this.getName().getText() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private import codeql.rust.elements.internal.generated.ExtractorStep
*/
module Impl {
class ExtractorStep extends Generated::ExtractorStep {
override string toString() {
override string toStringImpl() {
result = this.getAction() + "(" + this.getFile().getAbsolutePath() + ")"
or
not this.hasFile() and result = this.getAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Impl {
/** Gets the tuple field that this access references, if any. */
TupleField getTupleField() { result = TypeInference::resolveTupleFieldExpr(this) }

override string toString() {
override string toStringImpl() {
exists(string abbr, string name |
abbr = this.getExpr().toAbbreviatedString() and
name = this.getNameRef().getText() and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Impl {

FormatArgument() { this = Synth::TFormatArgument(parent, index, kind, name, _, offset) }

override string toString() { result = name }
override string toStringImpl() { result = name }

override Format getParent() { result = Synth::TFormat(parent, index, _, _) }

Expand Down
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Impl {

Format() { this = Synth::TFormat(parent, index, text, offset) }

override string toString() { result = text }
override string toStringImpl() { result = text }

override FormatArgsExpr getParent() { result = Synth::convertFormatArgsExprFromRaw(parent) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Impl {

override Location getLocation() { result = argument.getLocation() }

override string toString() { result = this.getName() }
override string toStringImpl() { result = this.getName() }

/** Gets the name of the variable */
string getName() { result = argument.getName() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ module Impl {
* ```
*/
class Function extends Generated::Function {
override string toString() { result = "fn " + this.getName().getText() }
override string toStringImpl() { result = "fn " + this.getName().getText() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Impl {
* ```
*/
class GenericArgList extends Generated::GenericArgList {
override string toString() { result = this.toAbbreviatedString() }
override string toStringImpl() { result = this.toAbbreviatedString() }

override string toAbbreviatedString() { result = "<...>" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Impl {
* ```
*/
class GenericParamList extends Generated::GenericParamList {
override string toString() { result = this.toAbbreviatedString() }
override string toStringImpl() { result = this.toAbbreviatedString() }

override string toAbbreviatedString() { result = "<...>" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Impl {
* ```
*/
class IdentPat extends Generated::IdentPat {
override string toString() {
override string toStringImpl() {
result = strictconcat(int i | | this.toStringPart(i), " " order by i)
}

Expand Down
4 changes: 3 additions & 1 deletion rust/ql/lib/codeql/rust/elements/internal/IfExprImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module Impl {
* ```
*/
class IfExpr extends Generated::IfExpr {
override string toString() { result = concat(int i | | this.toStringPart(i), " " order by i) }
override string toStringImpl() {
result = concat(int i | | this.toStringPart(i), " " order by i)
}

private string toStringPart(int index) {
index = 0 and result = "if"
Expand Down
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/rust/elements/internal/ImplImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Impl {
* ```
*/
class Impl extends Generated::Impl {
override string toString() {
override string toStringImpl() {
exists(string trait |
(
trait = this.getTrait().toAbbreviatedString() + " for "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Impl {
* ```
*/
class IndexExpr extends Generated::IndexExpr {
override string toString() {
override string toStringImpl() {
result =
this.getBase().toAbbreviatedString() + "[" + this.getIndex().toAbbreviatedString() + "]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Impl {
* ```
*/
class InferTypeRepr extends Generated::InferTypeRepr {
override string toString() { result = this.toAbbreviatedString() }
override string toStringImpl() { result = this.toAbbreviatedString() }

override string toAbbreviatedString() { result = "_" }
}
Expand Down
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/rust/elements/internal/LabelImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Impl {
* ```
*/
class Label extends Generated::Label {
override string toString() { result = this.getText() }
override string toStringImpl() { result = this.getText() }

override string toAbbreviatedString() { result = this.getText() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Impl {
* The base class for expressions that can be labeled (`LoopExpr`, `ForExpr`, `WhileExpr` or `BlockExpr`).
*/
class LabelableExpr extends Generated::LabelableExpr {
final override string toString() {
final override string toStringImpl() {
result = strictconcat(int i | | this.toStringPart(i), " " order by i)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Impl {
* ```
*/
class LetElse extends Generated::LetElse {
override string toString() { result = this.toAbbreviatedString() }
override string toStringImpl() { result = this.toAbbreviatedString() }

override string toAbbreviatedString() { result = "else {...}" }
}
Expand Down
4 changes: 3 additions & 1 deletion rust/ql/lib/codeql/rust/elements/internal/LetExprImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module Impl {
* ```
*/
class LetExpr extends Generated::LetExpr {
override string toString() { result = concat(int i | | this.toStringPart(i), " " order by i) }
override string toStringImpl() {
result = concat(int i | | this.toStringPart(i), " " order by i)
}

private string toStringPart(int index) {
index = 0 and result = "let"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Impl {
* ```
*/
class LetStmt extends Generated::LetStmt {
override string toString() {
override string toStringImpl() {
result = strictconcat(int i | | this.toStringPart(i), " " order by i)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Impl {
* ```
*/
class Lifetime extends Generated::Lifetime {
override string toString() {
override string toStringImpl() {
result = "'" + this.getText()
or
not this.hasText() and result = "'_"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Impl {
* ```
*/
class LiteralExpr extends Generated::LiteralExpr {
override string toString() { result = this.getTrimmedText() }
override string toStringImpl() { result = this.getTrimmedText() }

override string toAbbreviatedString() { result = this.getTrimmedText() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Impl {
* ```
*/
class LiteralPat extends Generated::LiteralPat {
override string toString() { result = this.toAbbreviatedString() }
override string toStringImpl() { result = this.toAbbreviatedString() }

override string toAbbreviatedString() { result = this.getLiteral().getTrimmedText() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ module Impl {
* ```
*/
class MacroCall extends Generated::MacroCall {
override string toString() { result = this.getPath().toAbbreviatedString() + "!..." }
override string toStringImpl() { result = this.getPath().toAbbreviatedString() + "!..." }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ module Impl {
* ```
*/
class MatchArm extends Generated::MatchArm {
override string toString() { result = concat(int i | | this.toStringPart(i), " " order by i) }
override string toStringImpl() {
result = concat(int i | | this.toStringPart(i), " " order by i)
}

private string toStringPart(int index) {
index = 0 and result = this.getPat().toAbbreviatedString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Impl {
* ```
*/
class MatchExpr extends Generated::MatchExpr {
override string toString() {
override string toStringImpl() {
result = "match " + this.getScrutinee().toAbbreviatedString() + " { ... }"
}

Expand Down
Loading