Scope differentiate.

Hi All ,

We added the below code to differentiate Local and Global Variable in
the "NamedDecl *Sema::HandleDeclarator" function.

if(S->getFlags() == Scope::DeclScope)
its global
its local

Where S is a pointer parameter to the HandleDeclarator of type Scope.

At first place ,we decided to use
"D.getDeclSpec().getStorageClassSpec()" ,but has no luck ,since its
always "SCS_unspecified " .

Question is that , do using the "Scope::DeclScope" to differentiate
the variable scope is the right approach, if so

we have a problem for some instance like a nested local declaration,
we are not able to differentiate.

if the "Scope::DeclScope" is not the right approach, then please
anybody here , help us with the right approach and would like to
inform you all that, we need this info before any Act call like

Thank you

HandleDeclarator computes the DeclContext for the declarator; you can check
DC->getRedeclContext()->isFileContext() to find if that's global scope
(translation unit or namespace scope, or extern "C" context within them,
that kind of thing).

But that just tells you where the variable was declared, which is not the
same as whether it's local or global. You'll also need to check for
SCS_extern to handle local extern declarations, and possibly also for
SCS_static if you want to treat static local variables as global rather
than local. If you also care about C++, you'd also need to decide how you
want to handle static class members (for which DC would be a CXXRecordDecl).