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 response Thomas.

I'm trying to do what you say, but I can't get the code with the modifications. You can review the lines 65 - 79 of anexed file?

Many many thanks Thomas!!!



2015-04-23 7:25 GMT+01:00 Corbat Thomas <tcorbat@xxxxxx>:

Hi Gonçalo

 

I guess you are creating the source code in printTree. The problem hereby is, that it is not possible to change the AST itself. In the ASTRewrite (which I guess is the type of r) just the descriptions of the modifications are collected. With that information the traversal path of the visitor is changed. If you afterwards visit the translation unit by yourself you will see it unchanged.

Yet, the source file you created the source code from should be changed if the “change” is valid.

 

Afaik, there is no convenient way of getting the source code in string form directly. This would be the job of the ASTWriter, which internally uses the ChangeGeneratorWriterVisitor, which in turn depends on an ASTModificationStore. The ASTRewrite uses an ASTModificationStore internally too and that’s the part knowing about the modification descriptions, but unfortunately it is not accessible from outside.

 

It’s not a neat solution, but you could go with reflection. Use the ASTRewrite to create the modification store, extract it by reflection. Create an ASTWriter for your AST, insert the extracted modification store into the ASTWriter, call write().

 

I hope this helps.

Regards

Thomas

 

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Gonçalo Pereira
Sent: Montag, 20. April 2015 18:02
To: CDT General developers list.
Subject: 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!

Regards

Thomas

 

 

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

 

Hello,

 

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 ChangeFormatter.java:92:

 

// 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?

 

Cheers

Gonçalo Silva Pereira


_______________________________________________
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

Attachment: ParserExample.java
Description: Binary data


Back to the top