view trunk/src/cmd/ASTStats.d @ 795:069317bb84cf

Improved CSS document.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 29 Feb 2008 03:04:15 +0100
parents 8380fb2c765f
children cf2ad5df025c
line wrap: on
line source

/++
  Author: Aziz Köksal
  License: GPL3
+/
module cmd.ASTStats;

import dil.ast.DefaultVisitor;
import dil.ast.Node,
       dil.ast.Declaration,
       dil.ast.Statement,
       dil.ast.Expression,
       dil.ast.Types;

/// Counts the nodes in a syntax tree.
class ASTStats : DefaultVisitor
{
  uint[] table; /// Table for counting nodes.

  /// Starts counting.
  uint[] count(Node root)
  {
    table = new uint[classNames.length];
    super.visitN(root);
    return table;
  }

  // Override dispatch function.
  override Node dispatch(Node n)
  {
    table[n.kind]++;
    return super.dispatch(n);
  }
}