Added CalculateMaxLocalCount.
This commit is contained in:
parent
5a3a01ac8b
commit
7c7ab8790e
1 changed files with 26 additions and 0 deletions
|
@ -151,6 +151,32 @@ namespace arookas
|
|||
context.Text.ClosePoint(callSite, Offset);
|
||||
}
|
||||
}
|
||||
|
||||
static int CalculateMaxLocalCount(sunNode node)
|
||||
{
|
||||
int locals = 0;
|
||||
int maxChildLocals = 0;
|
||||
foreach (var child in node)
|
||||
{
|
||||
if (child is sunVariableDeclaration || child is sunVariableDefinition)
|
||||
{
|
||||
++locals;
|
||||
}
|
||||
else if (child is sunCompoundStatement)
|
||||
{
|
||||
locals += CalculateMaxLocalCount(child); // HACK: compound statements aren't their own scope
|
||||
}
|
||||
else
|
||||
{
|
||||
int childLocals = CalculateMaxLocalCount(child);
|
||||
if (childLocals > maxChildLocals)
|
||||
{
|
||||
maxChildLocals = childLocals;
|
||||
}
|
||||
}
|
||||
}
|
||||
return locals + maxChildLocals;
|
||||
}
|
||||
}
|
||||
|
||||
class sunParameterInfo : IEnumerable<string>
|
||||
|
|
Loading…
Reference in a new issue