view src/cmd/ASTStats.d @ 820:1d06b4aed7cf

Revised code in the first pass. Added code to handle anonymous unions and structs. Hope the idea will work. Added type to class Aggregate and isAnonymous to some other Symbol classes.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 14 Mar 2008 15:42:08 +0100
parents bcb74c9b895c
children
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[g_classNames.length];
    super.visitN(root);
    return table;
  }

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