Questions on Accessing Fully Qualified Names

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

Questions on Accessing Fully Qualified Names

Oleg Smolsky via cfe-dev
Hello,

I'm working on a check for fully qualifying names in using declarations. 

When creating an alias for an object outside the file, this just involves prepending the global specifier, so that " using foo::f; " becomes " using ::foo::f; ". 

However, this shouldn't work in general for objects declaring in the existing file. 

For example, for code like

namespace example { 
namespace util { 
 
namespace internal {  
enum Color {Red, Green, Blue}; 
}  
using internal::Color; 
  

I'd like to replace "internal::Color" with "::example::util::internal::Color" instead of "::internal::Color". 

Given this motivation, I have two questions:
  1. Given a name inside a using declaration, what's the best way to check if that name is declared in the current file?
  2. Given an object declaration, what is the recommended way of finding it's full nested-name-specifier? (I think getUnderlyingDecl() probably works here)
Thank you,
Shyan

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Questions on Accessing Fully Qualified Names

Oleg Smolsky via cfe-dev
On Tue, Nov 13, 2018 at 3:25 AM Shyan Akmal <[hidden email]> wrote:
Hello,

I'm working on a check for fully qualifying names in using declarations. 

When creating an alias for an object outside the file, this just involves prepending the global specifier, so that " using foo::f; " becomes " using ::foo::f; ". 

However, this shouldn't work in general for objects declaring in the existing file. 

For example, for code like

namespace example { 
namespace util { 
 
namespace internal {  
enum Color {Red, Green, Blue}; 
}  
using internal::Color; 
  

I'd like to replace "internal::Color" with "::example::util::internal::Color" instead of "::internal::Color". 

Given this motivation, I have two questions:
  1. Given a name inside a using declaration, what's the best way to check if that name is declared in the current file?

Why does that matter? Can't the same happen across files? 
  1. Given an object declaration, what is the recommended way of finding it's full nested-name-specifier? (I think getUnderlyingDecl() probably works here)
I think printQualifiedName on the namedDecl is your best bet; I don't know how getUnderlyingDecl() would help?

Cheers,
/Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Questions on Accessing Fully Qualified Names

Oleg Smolsky via cfe-dev
Thanks for your response. 

I worded my question very poorly, sorry about that. In 1, I meant to ask how one can find the location of a name being declared (in the file overall - included the expanded headers). This is because plan was to find the declaration location, and then try to use getUnderlyingDecl() at that node to figure out the full nested-name-specifier required for a fully qualified name.

There could definitely be an alternate, better approach that I'm not seeing though. 

Thanks for the suggestion - I'll look into printQualifiedName. 

- Shyan

On Tue, Nov 13, 2018 at 1:00 AM Manuel Klimek <[hidden email]> wrote:
On Tue, Nov 13, 2018 at 3:25 AM Shyan Akmal <[hidden email]> wrote:
Hello,

I'm working on a check for fully qualifying names in using declarations. 

When creating an alias for an object outside the file, this just involves prepending the global specifier, so that " using foo::f; " becomes " using ::foo::f; ". 

However, this shouldn't work in general for objects declaring in the existing file. 

For example, for code like

namespace example { 
namespace util { 
 
namespace internal {  
enum Color {Red, Green, Blue}; 
}  
using internal::Color; 
  

I'd like to replace "internal::Color" with "::example::util::internal::Color" instead of "::internal::Color". 

Given this motivation, I have two questions:
  1. Given a name inside a using declaration, what's the best way to check if that name is declared in the current file?

Why does that matter? Can't the same happen across files? 
  1. Given an object declaration, what is the recommended way of finding it's full nested-name-specifier? (I think getUnderlyingDecl() probably works here)
I think printQualifiedName on the namedDecl is your best bet; I don't know how getUnderlyingDecl() would help?

Cheers,
/Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Questions on Accessing Fully Qualified Names

Oleg Smolsky via cfe-dev


On Thu, 15 Nov 2018, 01:56 Shyan Akmal <[hidden email] wrote:
Thanks for your response. 

I worded my question very poorly, sorry about that. In 1, I meant to ask how one can find the location of a name being declared (in the file overall - included the expanded headers). This is because plan was to find the declaration location, and then try to use getUnderlyingDecl() at that node to figure out the full nested-name-specifier required for a fully qualified name.

I'm a bit confused by this - there might not be a fqn ever spelled out. Perhaps if you give an example that would help :)


There could definitely be an alternate, better approach that I'm not seeing though. 

Thanks for the suggestion - I'll look into printQualifiedName. 

- Shyan

On Tue, Nov 13, 2018 at 1:00 AM Manuel Klimek <[hidden email]> wrote:
On Tue, Nov 13, 2018 at 3:25 AM Shyan Akmal <[hidden email]> wrote:
Hello,

I'm working on a check for fully qualifying names in using declarations. 

When creating an alias for an object outside the file, this just involves prepending the global specifier, so that " using foo::f; " becomes " using ::foo::f; ". 

However, this shouldn't work in general for objects declaring in the existing file. 

For example, for code like

namespace example { 
namespace util { 
 
namespace internal {  
enum Color {Red, Green, Blue}; 
}  
using internal::Color; 
  

I'd like to replace "internal::Color" with "::example::util::internal::Color" instead of "::internal::Color". 

Given this motivation, I have two questions:
  1. Given a name inside a using declaration, what's the best way to check if that name is declared in the current file?

Why does that matter? Can't the same happen across files? 
  1. Given an object declaration, what is the recommended way of finding it's full nested-name-specifier? (I think getUnderlyingDecl() probably works here)
I think printQualifiedName on the namedDecl is your best bet; I don't know how getUnderlyingDecl() would help?

Cheers,
/Manuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev