fix a stack overflow issue in the analyzer

@umop

Change a recursive method to an iterative one - this avoids a stack overflow issue when analyzing large projects.