   finding variables of a certain type
  I'm currently working on some code (in C) that uses a tree structure.  In many places throughout the code, pointers to nodes of the tree are checked to see if they're null:if(node == NULL) ...but because of design changes, I want to replace all of those checks with:if(is_leaf(node))Is there a way to write a script to do this?  I was thinking that I could search through the source code for all the places where pointers to nodes are declared:tree_node *node;Then store a list of all those variable names and check search through the code for places where variables of those names are equated to null, and replace them with the is_leaf function.  There're two problems with this:1) Even if I find a line with the string "tree_node" it isn't trivial to extract all the variable names that it defines.2) Throughout the code there could be local variables that have the same name as tree_nodes in a different scope.Does anyone have any ideas to solve this problem?Thanks.   
  Any ideas?Thanks.   ;  When would this table be built? On runtime? If so you'd have to distribute your code with your executable in a reliable location and can't be moved around.   ;  You could carry a type-field in your nodes:struct X {    uint32_t flags;};int isLeafNode (const X *x) {    return x->flags & 1;}int setLeafNode (X *x, int value) {    x->flags = (x->flags & ~1) | !!value;}Not sure if that was what you need. If it is only about the global-search-and-replace: That is a difficult one when you don't know all the names. It goes into the direction of writing a compiler, maybe there is a refactoring tool available for that.Anyways, personally, I would just search for every occurence of your node type (maybe "Node") and see what it says. If you have global variables, search for all references to that global variable.Or you know that you always name your nodes "node", and all variable that carry the name "node" are of type "Node" (or so). Then, a regex-search+replace could do the job ("node[ \n\t]*==[ \n\t]*NULL" -> "is_leaf(node)"). You could tweak the regex so that it would replace all "XXX == NULL", but that is probably not what you need.   ;  I don't know of a truly automated method, but you can find all the places where your class is being used by changing its name in the header file (to `NodeChecked' or something like that). The compiler will then find the variables for you. After you analyze each one, give it the new name. At the end, replace `NodeChecked' back to `Node'.This method might be tedious, but at least it is exhaustive.   