Let suppose, I have a object “startLoc” of class “SourceLocation”. The object contains line and column number information. How can I modify the line number in startLoc object? I was expecting “set()” kind of methods for class SourceLocation, but I could not find any. I would be thankful for your help.
a SourceLocation object points to a specific location inside a buffer. The line and column information is derived from that via the SourceManager. The locations are immutable, but you can create a modified copy with SourceLocation::getLocWithOffset.
I’m not familiar with a direct way to change the line number, but maybe you can figure out an appropriate method for your use-case with the helpers in the Preprocessor or Lexer classes (e.g. advance to next token).