Skip to content

Commit 4d04c5a

Browse files
author
Paolo Tranquilli
committed
Rust: fix non-existent string representations
1 parent 57973df commit 4d04c5a

19 files changed

+809
-767
lines changed

rust/ql/.generated.list

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 0 additions & 2 deletions
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/BreakExprImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ module Impl {
106106
override string toString() {
107107
exists(string label, string expr |
108108
(
109-
result = " " + this.getLifetime().toString()
109+
label = " " + this.getLifetime().toString()
110110
or
111-
not this.hasLifetime() and result = ""
111+
not this.hasLifetime() and label = ""
112112
) and
113113
(if this.hasExpr() then expr = " ..." else expr = "") and
114114
result = "break" + label + expr

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,30 @@ module Impl {
2020
* ```
2121
*/
2222
class Comment extends Generated::Comment {
23-
override string getText() { result = this.getCommentMarker() + " ..." }
23+
override string toString() {
24+
result = this.getCommentMarker() + "..." + this.getCommentEndMarker()
25+
}
2426

2527
/**
26-
* Gets the text of this comment, excluding the comment marker.
28+
* Gets the text of this comment, excluding the comment markers.
2729
*/
2830
string getCommentText() {
29-
exists(string s | s = this.getText() | result = s.regexpCapture("///?\\s*(.*)", 1))
31+
exists(string s | s = this.getText() |
32+
result =
33+
[
34+
s.regexpCapture("///?\\s*(.*)", 1),
35+
s.regexpCapture("(?s)/\\*\\*?\\s*(.*?)\\s*\\*/", 1)
36+
]
37+
)
3038
}
3139

3240
/**
33-
* Gets the marker of this comment, that is `//` or `///`.
41+
* Gets the marker of this comment, that is `"//"`, `"///"`, `"/*"` or `"/**"`.
3442
*/
35-
string getCommentMarker() {
36-
exists(string s | s = this.getText() | result = s.regexpCapture("(///?).*", 1))
43+
string getCommentMarker() { result = this.getText().regexpCapture("(?s)(///?|/\\*\\*?).*", 1) }
44+
45+
private string getCommentEndMarker() {
46+
if this.getCommentMarker() = ["//", "///"] then result = "" else result = "*/"
3747
}
3848
}
3949
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `ForExpr`.
43
*
@@ -12,11 +11,14 @@ private import codeql.rust.elements.internal.generated.ForExpr
1211
* be referenced directly.
1312
*/
1413
module Impl {
14+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1515
/**
1616
* A ForExpr. For example:
1717
* ```rust
1818
* todo!()
1919
* ```
2020
*/
21-
class ForExpr extends Generated::ForExpr { }
21+
class ForExpr extends Generated::ForExpr {
22+
override string toString() { result = "for " + this.getPat().toString() + " in ... { ... }" }
23+
}
2224
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ module Impl {
1919
* ```
2020
*/
2121
class Lifetime extends Generated::Lifetime {
22-
override string toString() { result = "'" + this.getText() }
22+
override string toString() {
23+
result = "'" + this.getText()
24+
or
25+
not this.hasText() and result = "'_"
26+
}
2327
}
2428
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ module Impl {
2020
*/
2121
class Param extends Generated::Param {
2222
override string toString() {
23-
result = this.getPat().toString() + ": " + this.getTy().toString()
23+
exists(string ty |
24+
(
25+
ty = ": " + this.getTy().toString()
26+
or
27+
not this.hasTy() and ty = ""
28+
) and
29+
result = this.getPat().toString() + ty
30+
)
2431
}
2532
}
2633
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `Union`.
43
*
@@ -12,11 +11,14 @@ private import codeql.rust.elements.internal.generated.Union
1211
* be referenced directly.
1312
*/
1413
module Impl {
14+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1515
/**
1616
* A Union. For example:
1717
* ```rust
1818
* todo!()
1919
* ```
2020
*/
21-
class Union extends Generated::Union { }
21+
class Union extends Generated::Union {
22+
override string toString() { result = "union " + this.getName().toString() }
23+
}
2224
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| gen_break_expr.rs:7:13:7:17 | (no string representation) | getNumberOfAttrs: | 0 | hasExpr: | no | hasLifetime: | no |
2-
| gen_break_expr.rs:12:13:12:27 | (no string representation) | getNumberOfAttrs: | 0 | hasExpr: | yes | hasLifetime: | yes |
3-
| gen_break_expr.rs:17:13:17:27 | (no string representation) | getNumberOfAttrs: | 0 | hasExpr: | yes | hasLifetime: | yes |
1+
| gen_break_expr.rs:7:13:7:17 | break | getNumberOfAttrs: | 0 | hasExpr: | no | hasLifetime: | no |
2+
| gen_break_expr.rs:12:13:12:27 | break ''label ... | getNumberOfAttrs: | 0 | hasExpr: | yes | hasLifetime: | yes |
3+
| gen_break_expr.rs:17:13:17:27 | break ''label ... | getNumberOfAttrs: | 0 | hasExpr: | yes | hasLifetime: | yes |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| gen_break_expr.rs:12:13:12:27 | (no string representation) | gen_break_expr.rs:12:26:12:27 | 42 |
2-
| gen_break_expr.rs:17:13:17:27 | (no string representation) | gen_break_expr.rs:17:26:17:27 | 42 |
1+
| gen_break_expr.rs:12:13:12:27 | break ''label ... | gen_break_expr.rs:12:26:12:27 | 42 |
2+
| gen_break_expr.rs:17:13:17:27 | break ''label ... | gen_break_expr.rs:17:26:17:27 | 42 |

0 commit comments

Comments
 (0)