Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse and print '#line' directives #46

Closed
jameysharp opened this issue Feb 18, 2015 · 2 comments
Closed

Parse and print '#line' directives #46

jameysharp opened this issue Feb 18, 2015 · 2 comments

Comments

@jameysharp
Copy link

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:

  1. Parse #line directives and set SrcLocs accordingly. When pretty-printing, if an element of the AST has a Loc, use the file and line from its starting Pos 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 two Locs is the same as the number of lines pretty-printed since the last #line. If you don't want these directives you can rewrite all SrcLocs to NoLoc before pretty-printing.
  2. Add a Line constructor to Stm, like Pragma.

Which would you prefer?

@mchakravarty
Copy link
Contributor

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.

@mainland
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants