[cfe-dev] Distinguish between reference expressions to enum constants and other reference expressions.

Douglas Gregor dgregor at apple.com
Mon Feb 16 08:19:25 PST 2009


On Feb 16, 2009, at 1:51 AM, Paolo Bolzoni wrote:

> Here a simple source code:
> --->
> enum colors { OCHRE, BURNT_SIENNA, BLUE };
> int my_global_int;
>
> int main() {
>  my_global_int = OCHRE;
> }
> ---<
>
> the ast vertices relative to `my_global_int' and `OCHRE' are both of  
> type
> clang::DeclRefExpr.
> I need to distinguish between references to enum constants and  
> references to
> other entities.
>
> Being `node' a pointer to a DeclRefExpr, at the moment I use
> clang:: EnumConstantDecl:: classof(node-> getDecl());
> if it does return true the reference is to a enum constant decl, if  
> it return
> false it is not.


classof is an implementation detail. You should use:

	isa<EnumConstantDecl>(node->getDecl())

to determine whether node->getDecl() is an EnumConstantDecl. There's  
more documentation for the type casting/query functionality of LLVM  
here:

	http://llvm.org/docs/ProgrammersManual.html#isa

	- Doug



More information about the cfe-dev mailing list