digitalmars.D.learn - Hacking the compiler: Get Scope after some line of function
Hello! I'm trying to do some strange thing: compile some Statement (do semantic3 phase) in the scope of other function. Other function is for example: auto megafunction() { B b; uint a = 25; return b; } AST of this code looks like: FuncDeclaration { fbody = CompoundStatement { ExpStatement { exp = DeclarationExp } ExpStatement { exp = DeclarationExp } ReturnStatement; } } So if I'm trying to take fbody._scope, all works correctly (other functions and templates from this module are declared), but neither a nor b are declared in this scope. But exp.declaration._scope is null. So how to get scope e.g. after line "B b;"?
Jul 27 2017
On Thursday, 27 July 2017 at 11:59:51 UTC, unDEFER wrote:So how to get scope e.g. after line "B b;"?I have found. That in scopes was found symbols from declarations, you must iterate by declarations (DeclarationExp) and add symbols by sc.insert(decexp.declaration);
Jul 27 2017