[cfe-dev] Getting the SourceLocation of the qualifier of a parameter

Magnus Reftel magnus.reftel at gmail.com
Thu Apr 15 09:16:09 PDT 2010


Hi all,

I'm trying to find the start of a parameter declaration, but only have
limited success. The function I'm looking at is defined similar to

void foo(const int* p)
{
}

and I'm using ASTConsumer::HandleTranslationUnit to trawl though the
AST looking for function definitions. When I find one I'm interested
in, I do

FunctionDecl* function=static_cast<FunctionDecl*>(decl);
VarDecl* parm=function->getParamDecl(0);
SourceLocation pos;
pos=parm->getSourceRange().getBegin();  // Nope, didn't work
cout << "Parameter declaration starts at column " <<
source_manager->getSpellingColumnNumber(pos) << endl;
pos=parm->getTypeSpecStartLoc();  // Nope, didn't work wither
cout << "Parameter declaration starts at column " <<
source_manager->getSpellingColumnNumber(pos) << endl;
pos=parm->getTypeSourceInfo()->getTypeLoc().getFullSourceRange().getBegin();
// What about this one?
cout << "Parameter declaration starts at column " <<
source_manager->getSpellingColumnNumber(pos) << endl;

In all cases I've tried, I get the position of the "int", not the
position of the "const". Is there a way of doing it that I have
missed, or is this an omission?

A simple test case showing this problem is attached.

Best Regards
Magnus Reftel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: const_pos-1.zip
Type: application/zip
Size: 1812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100415/bac03afd/attachment.zip>


More information about the cfe-dev mailing list