Getting a DeclarationName with name "default"

Hi!

I just encountered this problem when implementing a new feature in OpenMP 5.0, which is called user defined mapper (the details of this feature are irrelevant to this question).

I need to build a NamedDecl. In some cases, programs will provide a name. In these cases, I will use the token of the name to get the corresponding DeclarationName from ASTContect::DeclarationNames, which will be used to initiate the NamedDecl I want.

The code is like:

DeclarationName ID = Actions.getASTContext().DeclarationNames.getIdentifier(Tok.getIdentifierInfo());

In other cases, programs do not provide a name, and the name should be the keyword “default” in these cases. No “default” token is available from the preprocessor in these cases so the previous method does not work.

My question is, in the later cases, how do I create a DeclarationName with the name “default”, so that I can create the NamedDecl later? Any feedback will be much appreciated!

Thanks a lot,

Lingda Li

Hi,

you should be able to get an IndentifierInfo for "default" using
IdentifierTable::get(StringRef). You get an IdentifierTable object
from ASTContext::Idents (public field).

Michael

That works as a charm. Thanks a lot Michael!