Skip to content

Commit

Permalink
refactor: Rewrite Graphviz label group
Browse files Browse the repository at this point in the history
  • Loading branch information
sbwtw committed Nov 23, 2024
1 parent e1805ae commit 5d36bad
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 166 deletions.
5 changes: 4 additions & 1 deletion lib/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ impl Statement {
) -> Self {
Self {
kind: StmtKind::Expr(expr),
info: StmtInfo::default(),
info: StmtInfo {
start_pos: start,
end_pos: end,
},
}
}

Expand Down
14 changes: 5 additions & 9 deletions lib/src/ast/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ pub trait AstVisitor<'ast>: Sized {
}

#[inline]
fn visit_expr_statement(&mut self, stmt: &'ast Statement, expr: &'ast ExprStatement) {
walk_expr_statement(self, stmt, expr)
fn visit_expr_statement(&mut self, info: &'ast StmtInfo, expr: &'ast ExprStatement) {
walk_expr_statement(self, info, expr)
}

#[inline]
Expand Down Expand Up @@ -374,7 +374,7 @@ fn walk_expression<'a, V: AstVisitor<'a>>(vis: &mut V, expr: &'a Expression) {
#[inline]
fn walk_statement<'a, V: AstVisitor<'a>>(vis: &mut V, stmt: &'a Statement) {
match stmt.kind {
StmtKind::Expr(ref expr) => vis.visit_expr_statement(stmt, expr),
StmtKind::Expr(ref expr) => vis.visit_expr_statement(&stmt.info, expr),
StmtKind::If(ref ifst) => vis.visit_if_statement(&stmt.info, ifst),
StmtKind::Stmts(ref v) => vis.visit_statement_list(v),
}
Expand All @@ -390,17 +390,13 @@ fn walk_statement_list<'a, V: AstVisitor<'a>>(vis: &mut V, stmts: &'a Vec<Statem
#[inline]
fn walk_expr_statement<'a, V: AstVisitor<'a>>(
vis: &mut V,
stmt: &'a Statement,
_: &'a StmtInfo,
expr: &'a ExprStatement,
) {
vis.visit_expression(expr.expr())
}

fn walk_if_statement<'a, V: AstVisitor<'a>>(
vis: &mut V,
info: &'a StmtInfo,
ifst: &'a IfStatement,
) {
fn walk_if_statement<'a, V: AstVisitor<'a>>(vis: &mut V, _: &'a StmtInfo, ifst: &'a IfStatement) {
vis.visit_expression(ifst.condition());
if let Some(ctrl) = ifst.then_controlled() {
vis.visit_statement(ctrl);
Expand Down
Loading

0 comments on commit 5d36bad

Please sign in to comment.