Here is the related code. It is on my branch and not upstreamed. You can find related tree-structure extraction code.