diff --git a/tools/genast.py b/tools/genast.py index e4d6bf9..27cc726 100755 --- a/tools/genast.py +++ b/tools/genast.py @@ -53,7 +53,7 @@ def define_visitor(wr: FileWriter, base: str, type_lines: list[str]): for type, members in types: wr.line( - f" fn visit_{type.lower()}_{base.lower()}(&mut self, {base.lower()}: &{type}{base});" + f" fn visit_{type.lower()}_{base.lower()}(&mut self, {base.lower()}: &{type}{base}) -> Result<(), Box>;" ) wr.line("}") wr.line() @@ -69,7 +69,9 @@ def define_ast(wr: FileWriter, base: str, type_lines: list[str]): visitor = f"{base}Visitor" wr.line(f"pub trait {base}: Debug + Any " + "{") - wr.line(f" fn accept(&self, visitor: &mut dyn {visitor});") + wr.line( + f" fn accept(&self, visitor: &mut dyn {visitor}) -> Result<(), Box>;" + ) wr.line(" fn as_any(self: Box) -> Box;") wr.line(" fn as_any_ref(&self) -> &dyn Any;") wr.line("}") @@ -85,8 +87,11 @@ def define_ast(wr: FileWriter, base: str, type_lines: list[str]): wr.line("}") wr.line() wr.line(f"impl {base} for {type}{base} " + "{") - wr.line(f" fn accept(&self, visitor: &mut dyn {visitor})" + "{") - wr.line(f" visitor.visit_{type.lower()}_{base.lower()}(self);") + wr.line( + f" fn accept(&self, visitor: &mut dyn {visitor}) -> Result<(), Box>" + + "{" + ) + wr.line(f" visitor.visit_{type.lower()}_{base.lower()}(self)") wr.line(" }") wr.line() wr.line(" fn as_any(self: Box) -> Box {") @@ -111,10 +116,12 @@ def main(): wr = FileWriter(path) + # File headers wr.line( "// This is an auto-generated file. Any changes made to this file may be overwritten." ) wr.line("// This file was created at: " + time.strftime("%Y-%m-%d %H:%M:%S")) + wr.line("#![allow(dead_code)]") # Imports wr.line("use std::fmt::Debug;")