[cfe-dev] Multiple Clang Frontend Actions

Murat B murat8307 at yahoo.com
Tue Jan 11 14:01:58 PST 2011


Hi all,

I am implementing two clang actions derived from the class clang::PluginASTAction.
First tool analyzes the translation unit and modifies it.
Second tool extracts from the modified translation unit.

The second tool is able to extract the function declarations onto separate files, but I cannot get the modified translation unit from the first tool. It extracts from the original translation unit.

First tool creates
* class FirstConsumer : public clang::ASTConsumer
and second tool creates
* class SecondConsumer : public clang::ASTConsumer

First consumer class modifies function attributes:
* void FirstConsumer::HandleFunctionDecl(FunctionDecl *FD)
* {
*     ......
*     FD->addAttr(::new (*context) PureAttr(FD->getLocation(), *context));
*     ......
* }

Second consumer class checks function attributes:
* void SecondConsumer::HandleFunctionDecl(const FunctionDecl *FD)
* {
*    .....
*    for (Decl::attr_iterator AI = FD->attr_begin(),
*           AE = FD->attr_end(); AI != AE; AI++) {
*         if (PureAttr::classof(*AI))
*             llvm::errs() << "Pure Function\n";
*     }
*    .....
* }

The second tool does not see the modified version of the FunctionDecl. If I include the attribute check into the first tool, the tool gets new attribute information, but I would like to have two tools where one modifies the function and second one checks it.

Can anyone tell me if there is a way to do that?

I create the actions in this way in the driver:
* ....
* llvm::OwningPtr<FirstAction> firstact(new FirstAction);
* Clang.ExecuteAction(*firstact);
* llvm::OwningPtr<SecondAction> secondact(new SecondAction);
* Clang.ExecuteAction(*secondact);
* .....

Thanks for your help in advance!
Murat



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110111/24553b57/attachment.html>


More information about the cfe-dev mailing list