file handling

Hi all,
Can any one tell me how to handle files in clang. I want to open the file in write mode and write some data in file. Can i use iostream ios:: file handling in clang plugin.
Thanks,
akshay

Do you mean Translation unit means compilation unit ? If you are compiling more than one c or cxx files using clang then
when single .c or .cxx is compiled , all function calls and function protos and function definations within that file are obtained.

To get all function calls there is virtual function VisitCallExpr ( you can all function calls within that single c file ) and
another function is VisitFunctionDecl ( all functions i,e function body ( defination) and function prototypes handle by FunctionDecl Object)
I got hint from following and then i modified some code according to my need ( I googled it for sample code and found
https://github.com/mozilla/dxr/blob/master/xref-tools/cxx-clang/dxr-index.cpp. There are some very useful functions there
)

Suhas Limaye.
Pune.

Hi all,
Can any one tell me how to handle files in clang. I want to open the
file in write mode and write some data in file. Can i use iostream ios::
file handling in clang plugin.

LLVM has its own ostream (in your case: llvm::raw_fd_ostream):
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?revision=124771&view=markup

Cheers,
/Manuel

Yes! But if you try to edit existing file with raw_fd_ostream , it modifies
and create in MAC file format. ( If file mode is not set to binary ) on
windows....

For answers to questions like this, it helps to keep the list cc'ed :slight_smile:

Cheers,
/Manuel