Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Using ASTRewriter to reflect intermediate changes to the AST and perform further rewrites

Mm. It makes the challenges clear. But are there simple steps i could follow to make sure every rewrite operation updates the existinf rewrite with the new rewrite?

For example

Astrewrite rewrite = getrewrterfor ast ()

rewrite = rewrite.insertbefore...

rewrite = rewrite.replace....

Wont work as it returns the rewrite of the subtree and not the main tree. Any way to work around this?

On Jun 8, 2016 8:01 AM, "Corbat Thomas" <thomas.corbat@xxxxxx> wrote:

The capabilities of the ASTRewrite basically work as follows: You can remove, replace and insert nodes. The methods for replacing and inserting nodes return a new ASTRewrite object specifically for the subtree that has been inserted (or that is the replacement for another node respectively). This API is required as the arguments of those methods can either be new AST nodes or nodes that already exist in the same AST. In order to avoid modifications of an inserted subtree in two locations you get an ASTRewrite for every occurrence of the subtree.


An example to make it more clear:

- You have a function definition, known by its AST node...


ICPPASTFunctionDefinition fun = ...;


- ...and you want to create a clone of this function with a different name, ...


ASTRewrite rewrite = ...;

ASTRewrite insertionRewrite = rewrite.insertBefore(fun.getParent(), fun, fun);


- ... the insertBefore method call duplicates the function definition (inserts it again before the already existing definition). Now if you would like to make a change to that newly inserted function definition (and only to that definition) you need to use the insertionRewrite object to make these changes. Othwerwise, if there was only one rewrite object it would either affect both definitions of the function or only the original definition.


However, the infrastructure provided by CDT does not support working on a modification, description represented by an ASTRewrite, in the same way as if it was parsed from a source file. It lacks information about name bindings.


I hope this helps.

Regards

Thomas





Von: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> im Auftrag von Krishna Narasimhan <krishna.nm86@xxxxxxxxx>
Gesendet: Dienstag, 7. Juni 2016 00:02
An: CDT General developers list.
Betreff: Re: [cdt-dev] Using ASTRewriter to reflect intermediate changes to the AST and perform further rewrites
 

Would be really nice if you could send an example if u bump into it.

Not obligatory. But thanks a lot anyway

On Jun 6, 2016 11:55 PM, "Sergey Prigogin" <eclipse.sprigogin@xxxxxxxxx> wrote:
This is done by creating hew rewriters based on the previously created rewriters. Don't remember examples from the top of my head, but should be able to find a few in the refactoring code.

-sergey

On Mon, Jun 6, 2016 at 2:11 PM, Krishna Narasimhan <krishna.nm86@xxxxxxxxx> wrote:
Hi,
   Is there a possibility for me to incrementally transform an AST in Eclipse CDT. It seems like ASTRewriter functions donot reflect the actual changes till the complete refactoring is done. Can I change the AST in the between, so that the following changes happen on the changed AST and not on the original AST,

Regards
Krishna

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Back to the top