# HG changeset patch # User Aziz K?ksal # Date 1202936938 -3600 # Node ID e4b60543c5e81451700d220f56768973e05e60c7 # Parent 804111ec8213de17b1a85b7c41b665c07420c059 Revised methods in class Visitor. diff -r 804111ec8213 -r e4b60543c5e8 trunk/src/cmd/ASTStats.d --- a/trunk/src/cmd/ASTStats.d Wed Feb 13 21:46:24 2008 +0100 +++ b/trunk/src/cmd/ASTStats.d Wed Feb 13 22:08:58 2008 +0100 @@ -22,35 +22,10 @@ return table; } - // Override dispatch functions. -override: - Declaration visitD(Declaration n) - { - table[n.kind]++; - return super.visitD(n); - } - - Statement visitS(Statement n) + // Override dispatch function. + override Node dispatch(Node n) { table[n.kind]++; - return super.visitS(n); - } - - Expression visitE(Expression n) - { - table[n.kind]++; - return super.visitE(n); - } - - TypeNode visitT(TypeNode n) - { - table[n.kind]++; - return super.visitT(n); - } - - Node visitN(Node n) - { - table[n.kind]++; - return super.visitN(n); + return super.dispatch(n); } } diff -r 804111ec8213 -r e4b60543c5e8 trunk/src/cmd/Generate.d --- a/trunk/src/cmd/Generate.d Wed Feb 13 21:46:24 2008 +0100 +++ b/trunk/src/cmd/Generate.d Wed Feb 13 22:08:58 2008 +0100 @@ -356,18 +356,12 @@ } } - // Override dispatch functions. -override: - Declaration visitD(Declaration n) - { return push(n), super.visitD(n); } - Statement visitS(Statement n) - { return push(n), super.visitS(n); } - Expression visitE(Expression n) - { return push(n), super.visitE(n); } - TypeNode visitT(TypeNode n) - { return push(n), super.visitT(n); } - Node visitN(Node n) - { return push(n), super.visitN(n); } + // Override dispatch function. + override Node dispatch(Node n) + { + push(n); + return super.dispatch(n); + } } char getTag(NodeCategory nc) diff -r 804111ec8213 -r e4b60543c5e8 trunk/src/dil/ast/Visitor.d --- a/trunk/src/dil/ast/Visitor.d Wed Feb 13 21:46:24 2008 +0100 +++ b/trunk/src/dil/ast/Visitor.d Wed Feb 13 22:08:58 2008 +0100 @@ -94,11 +94,17 @@ static assert(dispatch_vtable.length == classNames.length, "vtable length doesn't match number of classes"); // Returns the dispatch function for n. - final T function(Visitor,T) getDispatchFunction(T)(T n) + Node function(Visitor, Node) getDispatchFunction()(Node n) { - return cast(T function(Visitor,T))dispatch_vtable[n.kind]; + return cast(Node function(Visitor, Node))dispatch_vtable[n.kind]; } + Node dispatch(Node n) + { // Do first dispatch. Second dispatch is done in the called function. + return getDispatchFunction(n)(this, n); + } + +final: Declaration visit(Declaration n) { return visitD(n); } Statement visit(Statement n) @@ -112,27 +118,26 @@ Declaration visitD(Declaration n) { - // Do first dispatch. Second dispatch is done in the called function. - return getDispatchFunction(n)(this, n); + return cast(Declaration)cast(void*)dispatch(n); } Statement visitS(Statement n) { - return getDispatchFunction(n)(this, n); + return cast(Statement)cast(void*)dispatch(n); } Expression visitE(Expression n) { - return getDispatchFunction(n)(this, n); + return cast(Expression)cast(void*)dispatch(n); } TypeNode visitT(TypeNode n) { - return getDispatchFunction(n)(this, n); + return cast(TypeNode)cast(void*)dispatch(n); } Node visitN(Node n) { - return getDispatchFunction(n)(this, n); + return dispatch(n); } }