# Newbie question: source locations

**URL:** <https://discourse.llvm.org/t/newbie-question-source-locations/34219>\
**Category:** Clang Frontend\
**Created:** [October 31, 2014, 9:03pm UTC](https://discourse.llvm.org/t/newbie-question-source-locations/34219 "2014-10-31T21:03:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cconvey](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@cconvey](https://discourse.llvm.org/u/cconvey)\
**Post date:** [October 31, 2014, 9:03pm UTC](https://discourse.llvm.org/t/newbie-question-source-locations/34219/1 "2014-10-31T21:03:35Z")

</div>

I'm dealing with the clang AST for the first time, and I'm having  
trouble understanding from the doxygen docs how the various flavors of  
source locations relate to each other. Can anyone point me to a good  
explanation?

I \*think\* I'm pretty clear on spelling locations. But I'm definitely  
confused about "presumed location" and "getImmediateExpansionRange"

---

<div class="post-metadata">

**Author:** ![r4nt](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@r4nt](https://discourse.llvm.org/u/r4nt)\
**Post date:** [November 3, 2014, 9:04am UTC](https://discourse.llvm.org/t/newbie-question-source-locations/34219/2 "2014-11-03T09:04:07Z")

</div>

> I’m dealing with the clang AST for the first time, and I’m having  
> trouble understanding from the doxygen docs how the various flavors of  
> source locations relate to each other. Can anyone point me to a good  
> explanation?
> 
> I _think_ I’m pretty clear on spelling locations. But I’m definitely  
> confused about “presumed location” and “getImmediateExpansionRange”

Yea, those are tricky - I wanted to write a tutorial there for a while, but never got around to it; I tried to cover some of that in my talk on the clang AST you can view at [http://clang.llvm.org/docs/IntroductionToTheClangAST.html](http://clang.llvm.org/docs/IntroductionToTheClangAST.html) (although it doesn’t cover presumed locations).

I also have a patch that rsmith has bikeshed to death (which means I’ve stopped working on it after a while, perhaps I should revive it) which enables you to get nice output about source locations like this:  
[http://pastebin.com/SzjYDDiu](http://pastebin.com/SzjYDDiu)

If you look at that it gives you a nice example on how expansion and spelling locations work, and why there are different levels. The “immediate” functions always go one level either towards the spelling or the expansion. Note how it is generally a tree and not a single chain.

Presumed locations are simply the expansion locations modified by the #line directives (which you for example find in preprocessed files).

Cheers,  
/Manuel
