mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: add MacroStmts and MacroItems
This commit is contained in:
@@ -538,9 +538,6 @@ fn main() -> std::io::Result<()> {
|
||||
.parse()
|
||||
.unwrap();
|
||||
let mut grammar = codegen::grammar::lower(&grammar);
|
||||
grammar
|
||||
.nodes
|
||||
.retain(|x| x.name != "MacroStmts" && x.name != "MacroItems");
|
||||
|
||||
grammar.enums.retain(|x| x.name != "Adt");
|
||||
|
||||
|
||||
24
rust/extractor/src/translate/generated.rs
generated
24
rust/extractor/src/translate/generated.rs
generated
@@ -1004,6 +1004,17 @@ impl Translator {
|
||||
label
|
||||
}
|
||||
|
||||
pub(crate) fn emit_macro_items(&mut self, node: ast::MacroItems) -> Label<generated::MacroItems> {
|
||||
let items = node.items().map(|x| self.emit_item(x)).collect();
|
||||
let label = self.trap.emit(generated::MacroItems {
|
||||
id: TrapId::Star,
|
||||
items,
|
||||
});
|
||||
self.emit_location(label, &node);
|
||||
self.emit_tokens(label.into(), node.syntax().children_with_tokens());
|
||||
label
|
||||
}
|
||||
|
||||
pub(crate) fn emit_macro_pat(&mut self, node: ast::MacroPat) -> Label<generated::MacroPat> {
|
||||
let macro_call = node.macro_call().map(|x| self.emit_macro_call(x));
|
||||
let label = self.trap.emit(generated::MacroPat {
|
||||
@@ -1032,6 +1043,19 @@ impl Translator {
|
||||
label
|
||||
}
|
||||
|
||||
pub(crate) fn emit_macro_stmts(&mut self, node: ast::MacroStmts) -> Label<generated::MacroStmts> {
|
||||
let expr = node.expr().map(|x| self.emit_expr(x));
|
||||
let statements = node.statements().map(|x| self.emit_stmt(x)).collect();
|
||||
let label = self.trap.emit(generated::MacroStmts {
|
||||
id: TrapId::Star,
|
||||
expr,
|
||||
statements,
|
||||
});
|
||||
self.emit_location(label, &node);
|
||||
self.emit_tokens(label.into(), node.syntax().children_with_tokens());
|
||||
label
|
||||
}
|
||||
|
||||
pub(crate) fn emit_macro_type(&mut self, node: ast::MacroType) -> Label<generated::MacroType> {
|
||||
let macro_call = node.macro_call().map(|x| self.emit_macro_call(x));
|
||||
let label = self.trap.emit(generated::MacroType {
|
||||
|
||||
7
rust/schema/ast.py
generated
7
rust/schema/ast.py
generated
@@ -304,6 +304,9 @@ class MacroDef(Item):
|
||||
class MacroExpr(Expr):
|
||||
macro_call: optional["MacroCall"] | child
|
||||
|
||||
class MacroItems(AstNode):
|
||||
items: list["Item"] | child
|
||||
|
||||
class MacroPat(Pat):
|
||||
macro_call: optional["MacroCall"] | child
|
||||
|
||||
@@ -313,6 +316,10 @@ class MacroRules(Item):
|
||||
token_tree: optional["TokenTree"] | child
|
||||
visibility: optional["Visibility"] | child
|
||||
|
||||
class MacroStmts(AstNode):
|
||||
expr: optional["Expr"] | child
|
||||
statements: list["Stmt"] | child
|
||||
|
||||
class MacroType(TypeRef):
|
||||
macro_call: optional["MacroCall"] | child
|
||||
|
||||
|
||||
Reference in New Issue
Block a user