Closed jameysharp closed 9 years ago
It's of course @mainland's call, but Option (1) sounds more attractive to me. As a special case, it should also be possible to emit #line
directives even when the parsed source didn't have any directives — i.e., to emit info about the original source location of the quoted C code.
language-c-quote already parses #line directives and uses them to set source code locations. Is this not working for you?
You can also print out source code with #line pragmas. Check out the prettyPragma* functions in Text.PrettyPrint.Mainland.
I'm going to close this issue. If the line parsing doesn't work, please open a new issue.
It would be nice to be able to manipulate
#line
directives with language-c-quote. I'm particularly interested in setting source locations for statements.I can imagine two approaches to implement this:
#line
directives and setSrcLoc
s accordingly. When pretty-printing, if an element of the AST has aLoc
, use the file and line from its startingPos
to emit a#line
directive. As an optimization, it might be nice to suppress any#line
directive with the same filename as the previous directive, and where the difference in line numbers between the twoLoc
s is the same as the number of lines pretty-printed since the last#line
. If you don't want these directives you can rewrite allSrcLoc
s toNoLoc
before pretty-printing.Line
constructor toStm
, likePragma
.Which would you prefer?