[cfe-dev] Generating printf format specifiers

Dave Keck davekeck at gmail.com
Sun Jan 24 02:06:47 CST 2010


> Well, I'm not really asking about language, I'm asking about semantics.  It looks like you want this to work in all cases as if the user had typed a string literal instead of __fmt__(foo).  That's going to complicate the implementation, because the parser has to be prepared to accept __fmt__ everywhere it would accept a string literal.  That might be very straightforward, it might not be.

Indeed - to make it truly useful, __fmt__ would have to be allowed
wherever string literals are (the most common case I imagine being
string literal concatenation.)

> If you just want it in private code, of course that's fine.  You'll need to recognize __fmt__ as a new type of token, parse the following tokens appropriately (presumably as an arbitrary expression), and add an API call to Sema to turn the expression into a string literal (by looking at its type).  If you do this in ParseStringLiteralExpression and fake up a string-literal token appropriately, most everything else should fall out.

Exactly what I was looking for to get me started, thanks very much!

David



More information about the cfe-dev mailing list