Skip to content

Commit

Permalink
Merge pull request #18071 from github/redsun82/rust-format-parent-child
Browse files Browse the repository at this point in the history
Rust: fix parent/child relationship for format entities
  • Loading branch information
redsun82 authored Nov 22, 2024
2 parents faabc99 + 2e90c80 commit 626b1ce
Show file tree
Hide file tree
Showing 52 changed files with 332 additions and 74 deletions.
32 changes: 19 additions & 13 deletions rust/ql/.generated.list

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

12 changes: 9 additions & 3 deletions rust/ql/.gitattributes

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

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

1 change: 1 addition & 0 deletions rust/ql/lib/codeql/rust/elements/Format.qll

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

7 changes: 6 additions & 1 deletion rust/ql/lib/codeql/rust/elements/FormatArgsExpr.qll

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

1 change: 1 addition & 0 deletions rust/ql/lib/codeql/rust/elements/FormatArgument.qll

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

14 changes: 7 additions & 7 deletions rust/ql/lib/codeql/rust/elements/internal/FormatArgsExprImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ module Impl {
/**
* A FormatArgsExpr. For example:
* ```rust
* todo!()
* format_args!("no args");
* format_args!("{} foo {:?}", 1, 2);
* format_args!("{b} foo {a:?}", a=1, b=2);
* let (x, y) = (1, 42);
* format_args!("{x}, {y}");
* ```
*/
class FormatArgsExpr extends Generated::FormatArgsExpr {
/**
* Gets the `index`th format of this `FormatArgsExpr`'s formatting template (0-based).
*/
Format getFormat(int index) {
result =
rank[index + 1](Format f, int i | f.getParent() = this and f.getIndex() = i | f order by i)
override Format getFormat(int index) {
result.getParent() = this and result.getIndex() = index + 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module Impl {
override string toString() { result = name }

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

override FormatTemplateVariableAccess getVariable() { result.getArgument() = this }
}

private class FormatSynthLocationImpl extends FormatArgument, LocatableImpl::SynthLocatable {
Expand Down
2 changes: 2 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module Impl {

override int getIndex() { result = index }

override FormatArgument getArgument() { result.getParent() = this }

/**
* Gets the name or position reference of this format, if any. For example `name` and `0` in:
* ```rust
Expand Down
11 changes: 11 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/generated/Format.qll

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

Loading

0 comments on commit 626b1ce

Please sign in to comment.