Rust: make MacroStmts a CFG Expr

This commit is contained in:
Arthur Baars
2025-04-17 18:57:26 +02:00
parent 4ca98ba816
commit 9ca6706550
16 changed files with 267 additions and 190 deletions

View File

@@ -1,2 +1,2 @@
mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7
top.rs 060225ccbae440eef117e2ef0a82f3deba29e6ba2d35f00281f9c0e6a945e692 060225ccbae440eef117e2ef0a82f3deba29e6ba2d35f00281f9c0e6a945e692
top.rs f7c07bc5a6ad3e1a3af05d16b5b448509f9f8403a510bfca1db42348d3c7038b f7c07bc5a6ad3e1a3af05d16b5b448509f9f8403a510bfca1db42348d3c7038b

View File

@@ -1515,60 +1515,6 @@ impl From<trap::Label<MacroItems>> for trap::Label<Element> {
}
}
#[derive(Debug)]
pub struct MacroStmts {
pub id: trap::TrapId<MacroStmts>,
pub expr: Option<trap::Label<Expr>>,
pub statements: Vec<trap::Label<Stmt>>,
}
impl trap::TrapEntry for MacroStmts {
fn extract_id(&mut self) -> trap::TrapId<Self> {
std::mem::replace(&mut self.id, trap::TrapId::Star)
}
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
out.add_tuple("macro_stmts", vec![id.into()]);
if let Some(v) = self.expr {
out.add_tuple("macro_stmts_exprs", vec![id.into(), v.into()]);
}
for (i, v) in self.statements.into_iter().enumerate() {
out.add_tuple("macro_stmts_statements", vec![id.into(), i.into(), v.into()]);
}
}
}
impl trap::TrapClass for MacroStmts {
fn class_name() -> &'static str { "MacroStmts" }
}
impl From<trap::Label<MacroStmts>> for trap::Label<AstNode> {
fn from(value: trap::Label<MacroStmts>) -> Self {
// SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of AstNode
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<MacroStmts>> for trap::Label<Locatable> {
fn from(value: trap::Label<MacroStmts>) -> Self {
// SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Locatable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<MacroStmts>> for trap::Label<Element> {
fn from(value: trap::Label<MacroStmts>) -> Self {
// SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Element
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
#[derive(Debug)]
pub struct MatchArm {
pub id: trap::TrapId<MatchArm>,
@@ -6479,6 +6425,69 @@ impl From<trap::Label<MacroPat>> for trap::Label<Element> {
}
}
#[derive(Debug)]
pub struct MacroStmts {
pub id: trap::TrapId<MacroStmts>,
pub expr: Option<trap::Label<Expr>>,
pub statements: Vec<trap::Label<Stmt>>,
}
impl trap::TrapEntry for MacroStmts {
fn extract_id(&mut self) -> trap::TrapId<Self> {
std::mem::replace(&mut self.id, trap::TrapId::Star)
}
fn emit(self, id: trap::Label<Self>, out: &mut trap::Writer) {
out.add_tuple("macro_stmts", vec![id.into()]);
if let Some(v) = self.expr {
out.add_tuple("macro_stmts_exprs", vec![id.into(), v.into()]);
}
for (i, v) in self.statements.into_iter().enumerate() {
out.add_tuple("macro_stmts_statements", vec![id.into(), i.into(), v.into()]);
}
}
}
impl trap::TrapClass for MacroStmts {
fn class_name() -> &'static str { "MacroStmts" }
}
impl From<trap::Label<MacroStmts>> for trap::Label<Expr> {
fn from(value: trap::Label<MacroStmts>) -> Self {
// SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Expr
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<MacroStmts>> for trap::Label<AstNode> {
fn from(value: trap::Label<MacroStmts>) -> Self {
// SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of AstNode
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<MacroStmts>> for trap::Label<Locatable> {
fn from(value: trap::Label<MacroStmts>) -> Self {
// SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Locatable
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
impl From<trap::Label<MacroStmts>> for trap::Label<Element> {
fn from(value: trap::Label<MacroStmts>) -> Self {
// SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Element
unsafe {
Self::from_untyped(value.as_untyped())
}
}
}
#[derive(Debug)]
pub struct MacroTypeRepr {
pub id: trap::TrapId<MacroTypeRepr>,