title: Visitor's nodes not suitable to be replaced by visitor?
body: <p>In my small compiler I currently have a hand-made AST.</p>
  
  <p>I was considering the idea of having a visitor that would look after nodes of a certain type <code>X</code> and would replace them by nodes of type <code>X'</code>. The trouble is that it seems that it isn't something easy to implement with the visitor pattern. </p>
  
  <p>The only way I can see to make this work would be to have visit() methods to all kinds of nodes that could possibility have a node of type <code>X</code> as child and put my node replacing logic there, but there may be lots of those nodes. Plus, if I later decide to add a new kind of node, I incur the risk of not remembering to check for that new special case in this visitor.</p>
  
  <h2>What's the problem I'm trying to solve:</h2>
  
  <p>For the current case I have in my tree nodes of type <code>FunctionCall</code> that convey only the name of a operation as well as its parameters.</p>
  
  <p>I'd like to substitute those with a <code>MethodInvocation</code>, with the appropriate OOish transformation:</p>
  
  <pre><code>m(A, B) -&gt; A.m(B)
  m(n(A, B), C) -&gt; (A.n(B)).m(C)
  </code></pre>
  
  <p>Of course this can be done in a thousand of different ways, being the easiest one to simply try to consider only a <code>Call</code> class in which there may or may not exist a target, but I'd like to be as explicit as possible (that is, using different kinds of nodes), to express different things, if possible.</p>