Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] setName frozen ast node exception

Thanks for the information and your help.  We hadn't looked into CDT's rewrite API and it seems like this is a step in the right direction.

The rename refactoring would not suit our needs because in the end, our plugin intends to replace certain function calls with other function calls of differing parameter length.  For example, calls to C's strcat would be replaced with strncat, or something of the like.

I think we'll take a look at ASTRewrite and specifically, the replace function, unless you'd recommend us in a different direction.

Thanks,
Justin


On Mon, Oct 5, 2009 at 4:31 PM, Mike Kucera <mkucera@xxxxxxxxxx> wrote:

Its not valid to call set() methods on an AST returned by the parser. The set() methods are part of the AST node interfaces for historical reasons, but they really shouldn't be there. The problem is that when you resolve bindings a bunch of information gets cached in various AST nodes, and there are other data-structures like the C model that are built from the AST. If you start changing things in the AST then all that cached/derived info gets invalidated. Its much simpler and more robust for the AST to just be immutable.

CDT has a rewrite API for refactoring purposes, you might what to try using that instead. Although CDT already supports the rename refactoring, does that not suit your needs?

Mike Kucera
Software Developer
IBM Eclipse CDT/PTP Team
mkucera@xxxxxxxxxx

Inactive hide details for Justin Moy ---10/05/2009 05:03:52 PM---Hello all,Justin Moy ---10/05/2009 05:03:52 PM---Hello all,


From:

Justin Moy <jcmoy2@xxxxxxxxxxxx>

To:

cdt-dev@xxxxxxxxxxx

Date:

10/05/2009 05:03 PM

Subject:

[cdt-dev] setName frozen ast node exception




Hello all,

We are working on a simple Eclipse plugin to change function calls of one name to another.

We are first working on the trivial case of changing the function call to the same function call, but we are receiving an exception.  The exception is: "attempt to modify frozen ast node".

Below is our visitor code:
public int visit(IASTExpression _expression_) {
   if (_expression_.getRawSignature().equals("printf"))

   {
      ((IASTIdExpression) _expression_).setName(((IASTIdExpression) _expression_).getName());
   }
   return PROCESS_CONTINUE;
}

Through debugging, we have learned _expression_ is of type CASTIdExpression, so I believe it is valid to cast it as an IASTIdExpression and we are not doing any specific freezing of AST nodes, so I'm not sure why we're receiving this exception.

Any help is much appreciated.


Justin
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev



Back to the top