I have a data structure that represents C# code like this:
class Namespace:
string Name;
List<Class> Classes;
class Class:
string Name;
List<Property> Properties;
List<Method> Methods;
List<Method> Constructors;
List<Field> Fields;
List<Class> InnerClasses;
Class Parent;
List<Interface> Implements;
... which I'm building using a simple lexer/parser combination. I need to traverse the tree and apply a large set of rules (more than 3000). Rules run when encountering different (and quite complex) patterns in the tree. For example, there's a rule that runs when a class only implements interfaces in the same assembly.
My original naïve implementation iterates over each rule and then each rule traverses the tree looking for its specific pattern. Of course, this takes quite a lot of time, even with a small amount of source code.
I suppose this could be likened to how antivirus software works, recognizing complex patterns on a large body of binary code.
How would you suggest one implement this kind of software?
EDT: Just like to add: No, I'm not re-implementing FxCop.
Thanks