From f06b5922de5ba276b8b5b6f8cfc88fd8e935ef57 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 28 Sep 2019 02:37:36 -0700 Subject: [PATCH] Visitor cleanup --- schala-lang/language/src/ast/visitor.rs | 65 ++++++++++++------------- schala-lang/language/src/ast/walker.rs | 3 +- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/schala-lang/language/src/ast/visitor.rs b/schala-lang/language/src/ast/visitor.rs index c1dc9f2..2e8692e 100644 --- a/schala-lang/language/src/ast/visitor.rs +++ b/schala-lang/language/src/ast/visitor.rs @@ -1,43 +1,38 @@ use std::rc::Rc; -use std::error::Error; use crate::ast::*; -use crate::ast::walker; //TODO maybe these functions should take closures that return a KeepRecursing | StopHere type, //or a tuple of (T, ) -//TODO default implmentations should call walk methods - then I can test printing pub trait ASTVisitor: Sized { - fn ast(&mut self, ast: &AST) {} - fn block(&mut self, statements: &Vec) {} - fn statement(&mut self, statement: &Statement) {} - fn declaration(&mut self, declaration: &Declaration) {} - fn signature(&mut self, signature: &Signature) {} - fn type_declaration(&mut self, name: &TypeSingletonName, body: &TypeBody, mutable: bool) {} - fn type_alias(&mut self, old_name: &Rc, new_name: &Rc) {} - fn binding(&mut self, name: &Rc, constant: bool, type_anno: Option<&TypeIdentifier>, expr: &Expression) {} - fn implemention(&mut self, type_name: &TypeIdentifier, interface_name: Option<&TypeSingletonName>, block: &Vec) {} - fn interface(&mut self, name: &Rc, signatures: &Vec) {} - fn expression(&mut self, expression: &Expression) {} - fn expression_kind(&mut self, kind: &ExpressionKind) {} - fn type_annotation(&mut self, type_anno: Option<&TypeIdentifier>) {} - fn named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc, Expression)>) {} - fn call(&mut self, f: &Expression, arguments: &Vec) {} - fn index(&mut self, indexee: &Expression, indexers: &Vec) {} - fn if_expression(&mut self, discrim: &Discriminator, body: &IfExpressionBody) {} - fn while_expression(&mut self, condition: Option<&Expression>, body: &Block) {} - fn for_expression(&mut self, enumerators: &Vec, body: &ForBody) {} - fn lambda(&mut self, params: &Vec, type_anno: Option<&TypeIdentifier>, body: &Block) {} - fn invocation_argument(&mut self, arg: &InvocationArgument) {} - fn formal_param(&mut self, param: &FormalParam) {} - fn import(&mut self, import: &ImportSpecifier) {} - fn qualified_name(&mut self, name: &QualifiedName) {} - fn nat_literal(&mut self, n: u64) {} - fn float_literal(&mut self, f: f64) {} - fn string_literal(&mut self, s: &Rc) {} - fn bool_literal(&mut self, b: bool) {} - fn binexp(&mut self, op: &BinOp, lhs: &Expression, rhs: &Expression) {} - fn prefix_exp(&mut self, op: &PrefixOp, arg: &Expression) {} + fn ast(&mut self, _ast: &AST) {} + fn block(&mut self, _statements: &Vec) {} + fn statement(&mut self, _statement: &Statement) {} + fn declaration(&mut self, _declaration: &Declaration) {} + fn signature(&mut self, _signature: &Signature) {} + fn type_declaration(&mut self, _name: &TypeSingletonName, _body: &TypeBody, _mutable: bool) {} + fn type_alias(&mut self, _old_name: &Rc, _new_name: &Rc) {} + fn binding(&mut self, _name: &Rc, _constant: bool, _type_anno: Option<&TypeIdentifier>, _expr: &Expression) {} + fn implemention(&mut self, _type_name: &TypeIdentifier, _interface_name: Option<&TypeSingletonName>, _block: &Vec) {} + fn interface(&mut self, _name: &Rc, _signatures: &Vec) {} + fn expression(&mut self, _expression: &Expression) {} + fn expression_kind(&mut self, _kind: &ExpressionKind) {} + fn type_annotation(&mut self, _type_anno: Option<&TypeIdentifier>) {} + fn named_struct(&mut self, _name: &QualifiedName, _fields: &Vec<(Rc, Expression)>) {} + fn call(&mut self, _f: &Expression, _arguments: &Vec) {} + fn index(&mut self, _indexee: &Expression, _indexers: &Vec) {} + fn if_expression(&mut self, _discrim: &Discriminator, _body: &IfExpressionBody) {} + fn while_expression(&mut self, _condition: Option<&Expression>, _body: &Block) {} + fn for_expression(&mut self, _enumerators: &Vec, _body: &ForBody) {} + fn lambda(&mut self, _params: &Vec, _type_anno: Option<&TypeIdentifier>, _body: &Block) {} + fn invocation_argument(&mut self, _arg: &InvocationArgument) {} + fn formal_param(&mut self, _param: &FormalParam) {} + fn import(&mut self, _import: &ImportSpecifier) {} + fn qualified_name(&mut self, _name: &QualifiedName) {} + fn nat_literal(&mut self, _n: u64) {} + fn float_literal(&mut self, _f: f64) {} + fn string_literal(&mut self, _s: &Rc) {} + fn bool_literal(&mut self, _b: bool) {} + fn binexp(&mut self, _op: &BinOp, _lhs: &Expression, _rhs: &Expression) {} + fn prefix_exp(&mut self, _op: &PrefixOp, _arg: &Expression) {} } - - diff --git a/schala-lang/language/src/ast/walker.rs b/schala-lang/language/src/ast/walker.rs index 7aef9f3..9d8fe20 100644 --- a/schala-lang/language/src/ast/walker.rs +++ b/schala-lang/language/src/ast/walker.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use std::rc::Rc; use crate::ast::*; use crate::ast::visitor::ASTVisitor; @@ -8,7 +9,7 @@ pub fn ast(v: &mut V, ast: &AST) { walk_block(v, &ast.statements); } -pub fn walk_block(v: &mut V, block: &Vec) { +fn walk_block(v: &mut V, block: &Vec) { for s in block { v.statement(s); statement(v, s);