How to create a SourceLocation from line number?

For a rewriting project, I need to replace one line text with another text. How do I create a SourceLocation or SourceRange for a given line number?

Thanks,

Does SourceManager::translateFileLineCol work for you?

http://clang.llvm.org/doxygen/classclang_1_1SourceManager.html#a5573aab1578a194e43c7934e6902aeec

– Sean Silva

Cool! It works!

Thanks,
Welson

Which says:
"
If the source file is included multiple times, the source location
will be based upon the first inclusion.
If the source file is included multiple times, the source location
will be based upon an arbitrary inclusion.
"

These two sentences contradict each other.

Csaba

> Does SourceManager::translateFileLineCol work for you?
>
>
http://clang.llvm.org/doxygen/classclang_1_1SourceManager.html#a5573aab1578a194e43c7934e6902aeec

Which says:
"
If the source file is included multiple times, the source location
will be based upon the first inclusion.
If the source file is included multiple times, the source location
will be based upon an arbitrary inclusion.
"

These two sentences contradict each other.

Indeed. Which one is it?

-- Sean Silva

... and that's why you don't duplicate function comments between header and
source file. =)

A related question: how do you get the line number from a SourceLocation. There is something in FullSourceLocation, but you can only get the SourceLocation from a Stmt.

-Welson

Ah, SourceManager has it: http://clang.llvm.org/doxygen/classclang_1_1SourceManager.html#a49b472113f3678f52fb1ed54247cada3