Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Standalone Software Fault Injector

Thanks for the responde Thomas.

I have done it with one project, But I have problems with remove nodes from AST.

I do this:

r.remove(node, null);
Change change = r.rewriteAST();
change = change.perform(new NullProgressMonitor());
printTree(translationUnit, 1);

But when I Print the translationUnit, I have the same code that I have in begining.

What I'm doing wrong? Who I extract the code from rewriteAST?

Thanks in advance.
Gonçalo Silva Pereira

2015-04-20 8:01 GMT+01:00 Corbat Thomas <tcorbat@xxxxxx>:

Hi Gonçalo


At a glance I would say yes you have to create a project. The exception actually happens because you don’t have an originating translation unit for your AST, which you could set manually. But faking a translation unit might not be that simple. The ChangeFormatter will furthermore try to query the project of the translation unit for its formatter options.


In principle I see three options:

1.       Work with a project.

2.       Derive the ChangeGenerator and ASTWriting infrastructure (with your own implementation) to avoid the formatting or do it with default options.

3.       Try to create your own translation unit and cproject classes which just satisfy the required operations, which you could set as originating translation unit for your AST.

If possible I would follow the first option and I would really try to avoid the last two options.


I hope this helps!





From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Gonçalo Pereira
Sent: Freitag, 17. April 2015 15:28
To: CDT General developers list.
Subject: [cdt-dev] Standalone Software Fault Injector




I'm trying to do an software to inject software faults in C programs, using CDT.


I have some .c files and read them with:


translationUnit = GPPLanguage.getDefault().getASTTranslationUnit(fileContent, info, emptyIncludes, null, opts, log);


But, when I try rewrite the AST Tree I get a NullPointException in


// Calculate formatting changes for the regions after the refactoring changes.

                                   ICProject project = tu.getCProject();


What is my problem? 

What I'm doing wrong? 

I need to have a project with C files? Is mandatory?



Gonçalo Silva Pereira

cdt-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top