Accessing scope/symbol table information at any statement

I have a RecursiveASTVisitor, and, during the visit, I want to inspect which variables are currently in scope at a particular (random) statement.

For example, in the following code:

int a = 1, b = 2;
  int c;
  c = a + b; // statement 1
    char a = 'a';
    c = a + b; // statement 2

At statement 1, I want to know that a, b, c are visible and have type ‘int'.
At statement 2, I want to know that a, b, c are visible, and that b, c have type ‘int' but a has type ‘char’.

In my visitor class I have the following, amongst other code:

ASTContext &Context;
bool VisitStmt(Stmt *s) {
  // Scope code goes here
  return true;

I have looked through several classes defined in Clang, e.g., Scope, IdentifierTable and DeclContext, and I think a Scope object will serve my needs. But, even assuming that is correct, I have no idea how to retrieve a Scope object at a Stmt object.

Help very much appreciated.

We do not provide any way to do that; the Scope objects used while parsing
are transient and short-lived. You can in principle rebuild them by walking
the lexically-enclosing function(s). We would happily accept a patch to add
such functionality; this is a commonly-requested feature.