[cfe-dev] How can I foint out if a ValueDecl is an array?
Eli Friedman
eli.friedman at gmail.com
Tue Dec 18 19:15:30 PST 2012
On Tue, Dec 18, 2012 at 6:57 PM, Peeter Joot <peeter.joot at gmail.com> wrote:
> I use some code like so:
>
> inline QualType getQualTypeForDecl( DeclaratorDecl * f )
> {
> TypeSourceInfo * pThisFieldSourceInfo = f->getTypeSourceInfo() ;
>
> TypeLoc thisFieldTypeLoc = pThisFieldSourceInfo->getTypeLoc() ;
>
> // don't care if it's an array, just want the basic underlying type of
> the array.
> if ( const ArrayTypeLoc * pTypeLocIfArray = dyn_cast<ArrayTypeLoc>(
> &thisFieldTypeLoc ) )
> {
> thisFieldTypeLoc = pTypeLocIfArray->getElementLoc() ;
> }
>
> return thisFieldTypeLoc.getType() ;
> }
>
> to strip off one level of array from a field declaration. Can you use
> something like that?
Hmm... that isn't actually checking whether the type of the decl is an
array type; it's checking whether the outermost declarator is an array
declarator. (This makes a difference for e.g. "typedef int T[2]; T
x;", where x is an array but does not have an array declarator.) My
first reaction to "is this decl an array" would be
"VD->getType()->isArrayType()", which checks the actual type. But I
guess both are useful, depending on what you're doing.
-Eli
More information about the cfe-dev
mailing list