Skip to content

Commit cc4926a

Browse files
authored
Merge pull request #21148 from hvitved/rust/remove-macro-block-expr
Rust: Remove `MacroBlockExpr` class
2 parents 519f0d2 + 31b4f88 commit cc4926a

File tree

40 files changed

+16874
-2373
lines changed

40 files changed

+16874
-2373
lines changed

rust/ast-generator/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ fn class_name(type_name: &str) -> String {
2222
"Literal" => "LiteralExpr".to_owned(),
2323
"ArrayExpr" => "ArrayExprInternal".to_owned(),
2424
"AsmOptions" => "AsmOptionsList".to_owned(),
25-
"MacroStmts" => "MacroBlockExpr".to_owned(),
2625
_ if type_name.starts_with("Record") => type_name.replacen("Record", "Struct", 1),
2726
_ if type_name.ends_with("Type") => format!("{type_name}Repr"),
2827
_ => type_name.to_owned(),
@@ -36,7 +35,6 @@ fn property_name(type_name: &str, field_name: &str) -> String {
3635
("MatchExpr", "expr") => "scrutinee",
3736
("Variant", "expr") => "discriminant",
3837
("FieldExpr", "expr") => "container",
39-
("MacroBlockExpr", "expr") => "tail_expr",
4038
(_, "name_ref") => "identifier",
4139
(_, "then_branch") => "then",
4240
(_, "else_branch") => "else_",
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
class Element extends @element {
2+
string toString() { none() }
3+
}
4+
5+
newtype TAddedElement =
6+
TMacroBlockExpr(Element block) {
7+
block_exprs(block) and macro_call_macro_call_expansions(_, block)
8+
}
9+
10+
module Fresh = QlBuiltins::NewEntity<TAddedElement>;
11+
12+
class TNewElement = @element or Fresh::EntityId;
13+
14+
class NewElement extends TNewElement {
15+
string toString() { none() }
16+
}
17+
18+
query predicate new_macro_block_exprs(NewElement id) { id = Fresh::map(TMacroBlockExpr(_)) }
19+
20+
query predicate new_macro_block_expr_statements(NewElement id, int index, Element stmt) {
21+
exists(Element block, Element list |
22+
id = Fresh::map(TMacroBlockExpr(block)) and
23+
block_expr_stmt_lists(block, list) and
24+
stmt_list_statements(list, index, stmt)
25+
)
26+
}
27+
28+
query predicate new_macro_block_expr_tail_exprs(NewElement id, Element expr) {
29+
exists(Element block, Element list |
30+
id = Fresh::map(TMacroBlockExpr(block)) and
31+
block_expr_stmt_lists(block, list) and
32+
stmt_list_tail_exprs(list, expr)
33+
)
34+
}
35+
36+
query predicate new_block_exprs(Element id) {
37+
block_exprs(id) and
38+
not macro_call_macro_call_expansions(_, id)
39+
}
40+
41+
query predicate new_stmt_lists(Element id) {
42+
stmt_lists(id) and
43+
not exists(Element block |
44+
macro_call_macro_call_expansions(_, block) and
45+
block_expr_stmt_lists(block, id)
46+
)
47+
}
48+
49+
query predicate new_block_expr_stmt_lists(Element id, Element list) {
50+
block_expr_stmt_lists(id, list) and
51+
not macro_call_macro_call_expansions(_, id)
52+
}
53+
54+
query predicate new_stmt_list_statements(Element id, int index, Element stmt) {
55+
stmt_list_statements(id, index, stmt) and
56+
not exists(Element block |
57+
macro_call_macro_call_expansions(_, block) and
58+
block_expr_stmt_lists(block, id)
59+
)
60+
}
61+
62+
query predicate new_stmt_list_tail_exprs(Element id, Element expr) {
63+
stmt_list_tail_exprs(id, expr) and
64+
not exists(Element block |
65+
macro_call_macro_call_expansions(_, block) and
66+
block_expr_stmt_lists(block, id)
67+
)
68+
}
69+
70+
query predicate new_macro_call_macro_call_expansions(NewElement id, NewElement expansion) {
71+
macro_call_macro_call_expansions(id, expansion) and
72+
not block_exprs(expansion)
73+
or
74+
exists(Element block |
75+
expansion = Fresh::map(TMacroBlockExpr(block)) and
76+
macro_call_macro_call_expansions(id, block)
77+
)
78+
}

0 commit comments

Comments
 (0)