Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Inserting Statement/ Setting Statements in a CompoundStatementNode

Hi,

      Before I go ahead , I know a question that is looming  "But Why? Why not just use the ASTRewrite.insertBefore()

Because ASTRewrite doesnt work on non project ASTs. That may happen with a few hacks as suggested in another thread. But even if it does, ASTRewrite doesnt provide intermediate ASTs. I cant use the same rewrite to work on an AST that I previously modified. 

So, I went ahead with a solution Corbat Thomas once suggested which is to have knowledge of the parent node to which I like to make the modification and modify it accordingly.

And I ran into this issue. I am trying to insert a statement into a CompoundStatement. And the method I currently have is tedious. Since there is no insertStatementBefore or even setStatements

I have a non frozen AST which I created myself. And based on some conditions, I need to insert some statements to a CompoundStatement .

Right now , I do this :

1) Identify the insertionPoint
2) Get the Parent Compound Statement and the GrandParent(Parent of CompoundStatement)
3) Create a new CompoundStatement with the children from the parent and the node to be inserted at the insertionpoint,
4) Replace the parent with the new parent in the grand parent.

Sounds tedious, But I have no way around this. 



Regards
       Krishna

Back to the top