I’ve tried using SourceMgr in a parser to get the nice error reporting with automatic line/column tracking, and it works well.
I’m thinking about extending that to try to get the nice error reporting in subsequent type checking, and that leads to a question.
As I understand it, SourceMgr owns the memory buffers (be they allocated chunks of memory, or memory mapped files) containing the source, the idea being that when you finish parsing and return, the SourceMgr destructor automatically frees the memory buffers, which makes sense. It doesn’t seem to have anything like a .clear function, presumably because the whole idea is you are supposed to let the destructor automatically do it?
But that would seem to indicate that the memory buffers are not going to be available once parsing is finished and you’ve moved on to things like type checking; the SourceMgr object will be out of scope and destructed. What’s the intended way to deal with this? I suppose you could allocate SourceMgr on the heap and manually destruct it once type checking is finished, but that doesn’t seem to be how the example code I’ve looked at does things?