Go generate and #line pragma

I used to generate C programs with ctangle or other tools. Such C code generators use the #line pragma to allow the compiler to keep track of the original source file, that generated the source file.

#line 14 "./sham.w"

The go tool generate is a first approach generating go code on the fly. But is it possible to have the go build tool to report the original line numbers of the master input file, that produced the code?

Are there existing experiments to implement that stuff or did I just missed it from the main line?

As the CPP pre processor uses these #line statements to tell the compiler about include files, this information is used in the original build chain for C code.
I understand that the go compiler works a bit different, but it should not be hard to add and process such “virtual text file offset statements” to the compiler, as only error reporting is affected (possibly also true for godoc?)

Ok, sorry for the noise, but actually I just should have looked at https://golang.org/cmd/compile/ (go doc cmd/compile)

The //line compiler directive supports everything I need. So RTFM.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.