changeset 757:e4b60543c5e8

Revised methods in class Visitor.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Wed, 13 Feb 2008 22:08:58 +0100
parents 804111ec8213
children f4b9680c0e16
files trunk/src/cmd/ASTStats.d trunk/src/cmd/Generate.d trunk/src/dil/ast/Visitor.d
diffstat 3 files changed, 22 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- 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);
   }
 }
--- 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)
--- 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);
   }
 }