using raw_ostream in ASTConsumers

Hi!
Are you planning to modify current ast consumers to print its output via raw_ostream ?
And a second idea: It would be great to move ast consumers to libDriver to provide some reusability.

Cheers,
Csaba

Hi Csaba,

Are you planning to modify current ast consumers to print its output via raw_ostream ?
And a second idea: It would be great to move ast consumers to libDriver to provide some reusability.

moving stuff from Driver to lib/Driver and making it more reusable is generally a good idea. The fastest way to get a change you want is probably to submit a patch that does your change. Just make sure that `make test` doesn't fail with your changes, and that you do not move and command line parameter stuff to libDriver. And submit several small, focussed patches instead of few big ones.

Nico

I hadn't planned on switching them over myself, but I think this is something we want to do. If you have time, it would be a great project.

-Chris

I've started porting to raw_ostream.

Ok, if there are pieces that can be moved over without any roadblocks, it would be useful to move those over in pieces, instead of doing one "big bang" patch.

I've found these problems:
- raw_stream is currently not supports pointer printing. << (void*)X

This should be easy to add, just add a method to raw_stream?

- not supports field width like: << std::setw(3) << ... (this is in file: CFG.cpp line 1485)
- not supports hexa printing like: <<std::hex << value (this is in file: StmtPrinter.cpp line 550)

Adding a full set of formatting is a non-trival job, and we don't want to follow the lead of iostreams. I'll see if I can hack something in quickly.

One more thing: In many cases ostringstream is used. Should we always wrap this ostream with raw_os_ostream or is there a better solution ?

It is probably best to add a raw_string_stream that directly concatenates the output into a string.

-Chris

I've found these problems:
- raw_stream is currently not supports pointer printing. << (void*)X

This should be easy to add, just add a method to raw_stream?

I didn't add this, can you add it?

- not supports field width like: << std::setw(3) << ... (this is in
file: CFG.cpp line 1485)
- not supports hexa printing like: <<std::hex << value (this is in
file: StmtPrinter.cpp line 550)

Adding a full set of formatting is a non-trival job, and we don't want
to follow the lead of iostreams. I'll see if I can hack something in
quickly.

Okay, you can now do stuff like this:

OS << "whatever" << format("%4.3f some hex thing 0x%X", mydouble, 255) << " blah";

This is efficient (no temporary strings etc), and you can use any (portable) printf formatting without penalty.

-Chris

Hi!
I’ve sent a patch what replaces std::ostream with llvm::raw_ostream. What’s the status of its review ? I know it is not an important patch but i would like to finish porting because i’d like to finish existing distcc clang code to be ready for merge sooner then later.

Cheers,
Csaba

2008/8/23 Chris Lattner <clattner@apple.com>