Interesting problem trying to obtain UsingShadowDecl from DeclRefExpr

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Interesting problem trying to obtain UsingShadowDecl from DeclRefExpr

Abramo Bagnara-2
namespace ns {
int a;
}

int main() {
  using ns::a;
  return a;
}

I need to relate DeclRefExpr for 'a' to the used UsingShadowDecl, but
DeclRefExpr::getDecl() is designed to give me the target VarDecl instead
of the "bridge".

Is this intentional?

Do I have another way to get this info?

A similar problem is present trying to obtain target UsingShadowDecl
from another UsingShadowDecl.

This is fundamental to build a dependency graph and to detect unused
UsingDecl.

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interesting problem trying to obtain UsingShadowDecl from DeclRefExpr

Douglas Gregor

On Mar 29, 2011, at 7:37 AM, Abramo Bagnara wrote:

> namespace ns {
> int a;
> }
>
> int main() {
>  using ns::a;
>  return a;
> }
>
> I need to relate DeclRefExpr for 'a' to the used UsingShadowDecl, but
> DeclRefExpr::getDecl() is designed to give me the target VarDecl instead
> of the "bridge".
>
> Is this intentional?

It probably was, since DeclRefExpr tends to refer to the declaration as resolved. That said, it doesn't seem like there is any reason to require this behavior.

> Do I have another way to get this info?

I don't think so.

> A similar problem is present trying to obtain target UsingShadowDecl
> from another UsingShadowDecl.
>
> This is fundamental to build a dependency graph and to detect unused
> UsingDecl.


Agreed. I think it would be perfectly reasonable to store the UsingShadowDecl within the DeclRefExpr. It might make sense, however, for the normal accessor (DeclRefExpr::getDecl()) to return the underlying declaration, and add a different accessor (say, DeclRefExpr::getReferencedDecl()) to get the result as found by name lookup.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev