Function Lookup in SemaExpr

Dear Clang Developers:

Inside of SemaExpr.cpp when handling BinOps, I want to lookup the (Expr *) and (NamedDecl) of a function by its name. How can I do this?

Create LookupResult and call LookupName on it passing appropriate DeclarationContext into which you’re performing the lookup (can be a scope or record decl).

Dear Nikola:

Thanks for the introduction to LookupName() and LookupResult. I think this is exactly what I want, especially LookupSingleName(). However, I seem to require a DeclarationName, which I don’t have yet. I’m not sure how to get one. I just have a string which is the name of the function I wish to lookup (this is in C), and I don’t know how to get from there to a DeclarationName and the other information I need.

Where is this function name coming from? Is it some kind of built-in?

You should be able to construct DeclarationName from IdentifierInfo. Call PP.getIdentiferInfo inside Sema to get the identifier.

Dear Nikola:

Thanks a bunch for the help, this is what I was looking for. I was trying to do it with Context.Idents. Basically, at the moment it’s sort of like a built-in function, but the reason I need to lookup the function is because I’m rewriting parts of the AST to be calls into these built-ins instead of what they would be originally.