diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index a0a1bf7..628832a 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -8,27 +8,17 @@ use crate::ast::walker; //TODO default implmentations should call walk methods - then I can test printing pub trait ASTVisitor: Sized { - fn visit(&mut self, ast: &AST) { - println!("FUCK"); - walker::ast(self, ast); + fn ast(&mut self, ast: &AST) { } - fn block(&mut self, statements: &Vec) { - println!("oi"); - walker::block(self, statements); - } + fn block(&mut self, statements: &Vec) {} - fn statement(&mut self, statement: &Statement) { - println!("stmt"); - walker::statement(self, statement); - } + fn statement(&mut self, statement: &Statement) {} fn declaration(&mut self, declaration: &Declaration) { - walker::declaration(self, declaration); } fn signature(&mut self, signature: &Signature) { - walker::signature(self, signature); } fn type_declaration(&mut self, name: &TypeSingletonName, body: &TypeBody, mutable: bool) { @@ -38,8 +28,6 @@ pub trait ASTVisitor: Sized { } fn binding(&mut self, name: &Rc, constant: bool, type_anno: Option<&TypeIdentifier>, expr: &Expression) { - walker::maybe_type_identifier(self, type_anno); - walker::expression(self, expr); } fn implemention(&mut self, type_name: &TypeIdentifier, interface_name: Option<&TypeSingletonName>, block: &Vec) { @@ -49,7 +37,6 @@ pub trait ASTVisitor: Sized { } fn expression(&mut self, expression: &Expression) { - walker::expression(self, expression); } fn expression_kind(&mut self, kind: &ExpressionKind) { diff --git a/schala-lang/language/src/ast/visitor_test.rs b/schala-lang/language/src/ast/visitor_test.rs index ed33edf..f835f1f 100644 --- a/schala-lang/language/src/ast/visitor_test.rs +++ b/schala-lang/language/src/ast/visitor_test.rs @@ -27,11 +27,15 @@ import gragh let a = 20 + 84 let b = 28 + 1 + 2 + 2.0 +fn heh() { + let m = 9 + +} "#); - tester.visit(&ast); + walker::ast(&mut tester, &ast); - assert_eq!(tester.count, 5); + assert_eq!(tester.count, 6); assert_eq!(tester.float_count, 1); } diff --git a/schala-lang/language/src/ast/walker.rs b/schala-lang/language/src/ast/walker.rs index e884a7d..527736c 100644 --- a/schala-lang/language/src/ast/walker.rs +++ b/schala-lang/language/src/ast/walker.rs @@ -4,20 +4,28 @@ use crate::ast::visitor::ASTVisitor; use std::ops::Deref; pub fn ast(v: &mut V, ast: &AST) { - v.block(&ast.statements); + v.ast(ast); + walk_block(v, &ast.statements); } -pub fn block(v: &mut V, block: &Vec) { - for statement in block { - v.statement(statement); +pub fn walk_block(v: &mut V, block: &Vec) { + for s in block { + v.statement(s); + statement(v, s); } } pub fn statement(v: &mut V, statement: &Statement) { use StatementKind::*; match statement.kind { - Expression(ref expr) => v.expression(expr), - Declaration(ref decl) => v.declaration(decl), + Expression(ref expr) => { + v.expression(expr); + expression(v, expr); + }, + Declaration(ref decl) => { + v.declaration(decl); + declaration(v, decl); + }, Import(ref import_spec) => v.import(import_spec), } } @@ -27,15 +35,19 @@ pub fn declaration(v: &mut V, decl: &Declaration) { match decl { FuncSig(sig) => { v.signature(&sig); + signature(v, &sig); }, FuncDecl(sig, block) => { v.signature(&sig); v.block(&block); + walk_block(v, block); }, TypeDecl { name, body, mutable } => v.type_declaration(name, body, *mutable), TypeAlias(n, a) => v.type_alias(n, a), Binding { name, constant, type_anno, expr } => { v.binding(name, *constant, type_anno.as_ref(), expr); + maybe_type_identifier(v, type_anno.as_ref()); + expression(v, &expr); }, Impl { type_name, interface_name, block } => { v.implemention(type_name, interface_name.as_ref(), block);