[cfe-dev] Return Type Location

Nikola Smiljanic popizdeh at gmail.com
Tue Jul 1 17:18:42 PDT 2014


So in case of say

namespace MyNS
{
  class MyClass {};
}

MyNs::MyClass foo();

You'd like to get the location pointing to MyClass?

TypeLoc TL = FunctionDecl->getTypeSourceInfo()->getTypeLoc();
FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>();
ElaboratedTypeLoc ETL = FTL.getReturnLoc().getAs<ElaboratedTypeLoc>();
ETL.getNamedTypeLoc().getBeginLoc();


Nikola


On Wed, Jul 2, 2014 at 8:26 AM, Daniel Dilts <diltsman at gmail.com> wrote:

> That seems to work for the simple case but not for the case with namespace
> qualifiers.  How would that be modified to handle a qualified name?
>
>
> On Tue, Jul 1, 2014 at 3:19 PM, Nikola Smiljanic <popizdeh at gmail.com>
> wrote:
>
>> What about getTypeSpecStartLoc? FunctionDecl is derived from a number of
>> classes, the method is likely to be in one of them.
>>
>>
>> On Wed, Jul 2, 2014 at 6:11 AM, Daniel Dilts <diltsman at gmail.com> wrote:
>>
>>> How do I get a SourceLocation for a FunctionDecl return type?
>>> FunctionDecl::getReturnType() returns QualType, and I don't think that I
>>> can get source locations from there.
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140702/ee25b3f8/attachment.html>


More information about the cfe-dev mailing list