Rust: rename MatchExpr.expr to scrutinee in all layers

This doesn't require `ql.name` and is simpler while we don't have
to write upgrade scripts. The `ql.name` mechanism might get useful
once we do have to write upgrade scripts, as that doesn't change the
dbscheme.
This commit is contained in:
Paolo Tranquilli
2024-11-26 10:42:13 +01:00
parent 93e7202a69
commit 8a01161d4a
9 changed files with 13 additions and 12 deletions

View File

@@ -28,6 +28,7 @@ fn class_name(type_name: &String) -> String {
fn property_name(type_name: &String, field_name: &String) -> String {
match (type_name.as_str(), field_name.as_str()) {
("Path", "segment") => "part".to_owned(),
("MatchExpr", "expr") => "scrutinee".to_owned(),
(_, "then_branch") => "then".to_owned(),
(_, "else_branch") => "else_".to_owned(),
_ => field_name.to_owned(),

View File

@@ -1,2 +1,2 @@
mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7
top.rs 4504ceb7e13020d5b19a4b938395fa2d5d804a962743985efe8563903448ae0c 4504ceb7e13020d5b19a4b938395fa2d5d804a962743985efe8563903448ae0c
top.rs abab6a736e75f9eabbe31deef4de782fc05f0c053798a01d410fffc859515278 abab6a736e75f9eabbe31deef4de782fc05f0c053798a01d410fffc859515278

View File

@@ -5530,7 +5530,7 @@ impl From<trap::Label<MacroType>> for trap::Label<TypeRef> {
pub struct MatchExpr {
pub id: trap::TrapId<MatchExpr>,
pub attrs: Vec<trap::Label<Attr>>,
pub expr: Option<trap::Label<Expr>>,
pub scrutinee: Option<trap::Label<Expr>>,
pub match_arm_list: Option<trap::Label<MatchArmList>>,
}
@@ -5544,8 +5544,8 @@ impl trap::TrapEntry for MatchExpr {
for (i, v) in self.attrs.into_iter().enumerate() {
out.add_tuple("match_expr_attrs", vec![id.into(), i.into(), v.into()]);
}
if let Some(v) = self.expr {
out.add_tuple("match_expr_exprs", vec![id.into(), v.into()]);
if let Some(v) = self.scrutinee {
out.add_tuple("match_expr_scrutinees", vec![id.into(), v.into()]);
}
if let Some(v) = self.match_arm_list {
out.add_tuple("match_expr_match_arm_lists", vec![id.into(), v.into()]);

View File

@@ -1224,12 +1224,12 @@ impl Translator<'_> {
pub(crate) fn emit_match_expr(&mut self, node: ast::MatchExpr) -> Label<generated::MatchExpr> {
let attrs = node.attrs().map(|x| self.emit_attr(x)).collect();
let expr = node.expr().map(|x| self.emit_expr(x));
let scrutinee = node.expr().map(|x| self.emit_expr(x));
let match_arm_list = node.match_arm_list().map(|x| self.emit_match_arm_list(x));
let label = self.trap.emit(generated::MatchExpr {
id: TrapId::Star,
attrs,
expr,
scrutinee,
match_arm_list,
});
self.emit_location(label, &node);

View File

@@ -525,7 +525,7 @@ lib/codeql/rust/elements/internal/generated/PtrType.qll 40099c5a4041314b66932dfd
lib/codeql/rust/elements/internal/generated/PureSynthConstructors.qll ea294a3ba33fd1bc632046c4fedbcb84dcb961a8e4599969d65893b19d90e590 ea294a3ba33fd1bc632046c4fedbcb84dcb961a8e4599969d65893b19d90e590
lib/codeql/rust/elements/internal/generated/RangeExpr.qll 23cca03bf43535f33b22a38894f70d669787be4e4f5b8fe5c8f7b964d30e9027 18624cef6c6b679eeace2a98737e472432e0ead354cca02192b4d45330f047c9
lib/codeql/rust/elements/internal/generated/RangePat.qll efd93730de217cf50dcba5875595263a5eadf9f7e4e1272401342a094d158614 229b251b3d118932e31e78ac4dfb75f48b766f240f20d436062785606d44467b
lib/codeql/rust/elements/internal/generated/Raw.qll b342060fd7fe2214eea191859f559334a8a64cf6785048f784ed641ea1e616fd 4737f09bbd2e190eee9bb83476a0045887ff2982dd06cd4e6538fc31637ab521
lib/codeql/rust/elements/internal/generated/Raw.qll 9476dd5a6607f722de107b51713c1f529e95429416c7e0d102b78779cf826fe6 b3a4d58fb560c89344ac734cfda3df7f4dcb627c2db79dbe26babd6a67e69dce
lib/codeql/rust/elements/internal/generated/RecordExpr.qll eb6cb662e463f9260efae1a6ce874fa781172063b916ef1963f861e9942d308d 1a21cbccc8f3799ff13281e822818ebfb21d81591720a427cac3625512cb9d40
lib/codeql/rust/elements/internal/generated/RecordExprField.qll 7e9f8663d3b74ebbc9603b10c9912f082febba6bd73d344b100bbd3edf837802 fbe6b578e7fd5d5a6f21bbb8c388957ab7210a6a249ec71510a50fb35b319ea1
lib/codeql/rust/elements/internal/generated/RecordExprFieldList.qll 179a97211fe7aa6265085d4d54115cdbc0e1cd7c9b2135591e8f36d6432f13d3 dd44bbbc1e83a1ed3a587afb729d7debf7aeb7b63245de181726af13090e50c0

View File

@@ -2172,7 +2172,7 @@ module Raw {
/**
* Gets the scrutinee (the expression being matched) of this match expression, if it exists.
*/
Expr getScrutinee() { match_expr_exprs(this, result) }
Expr getScrutinee() { match_expr_scrutinees(this, result) }
/**
* Gets the match arm list of this match expression, if it exists.

View File

@@ -1896,9 +1896,9 @@ match_expr_attrs(
);
#keyset[id]
match_expr_exprs(
match_expr_scrutinees(
int id: @match_expr ref,
int expr: @expr ref
int scrutinee: @expr ref
);
#keyset[id]

View File

@@ -289,7 +289,7 @@ class _:
}
```
"""
expr: _ | ql.name("scrutinee") | doc("scrutinee (the expression being matched) of this match expression")
scrutinee: _ | doc("scrutinee (the expression being matched) of this match expression")
@annotate(ContinueExpr, cfg = True)

2
rust/schema/ast.py generated
View File

@@ -364,7 +364,7 @@ class MatchArmList(AstNode):
class MatchExpr(Expr):
attrs: list["Attr"] | child
expr: optional["Expr"] | child
scrutinee: optional["Expr"] | child
match_arm_list: optional["MatchArmList"] | child
class MatchGuard(AstNode):