Made CalculateMaxLocalCount a property.
This commit is contained in:
parent
9ace3833cb
commit
8e4d9acb31
2 changed files with 30 additions and 27 deletions
|
@ -37,6 +37,35 @@ namespace arookas
|
||||||
public bool IsBranch { get { return Count > 0; } }
|
public bool IsBranch { get { return Count > 0; } }
|
||||||
public bool IsLeaf { get { return Count < 1; } }
|
public bool IsLeaf { get { return Count < 1; } }
|
||||||
|
|
||||||
|
public int MaxLocalCount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int locals = 0;
|
||||||
|
int maxChildLocals = 0;
|
||||||
|
foreach (var child in this)
|
||||||
|
{
|
||||||
|
if (child is sunVariableDeclaration || child is sunVariableDefinition)
|
||||||
|
{
|
||||||
|
++locals;
|
||||||
|
}
|
||||||
|
else if (child is sunCompoundStatement)
|
||||||
|
{
|
||||||
|
locals += child.MaxLocalCount; // HACK: compound statements aren't their own scope
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int childLocals = child.MaxLocalCount;
|
||||||
|
if (childLocals > maxChildLocals)
|
||||||
|
{
|
||||||
|
maxChildLocals = childLocals;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return locals + maxChildLocals;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public sunNode(sunSourceLocation location)
|
public sunNode(sunSourceLocation location)
|
||||||
{
|
{
|
||||||
children = new List<sunNode>(5);
|
children = new List<sunNode>(5);
|
||||||
|
|
|
@ -135,7 +135,7 @@ namespace arookas
|
||||||
context.DeclareParameter(parameter);
|
context.DeclareParameter(parameter);
|
||||||
}
|
}
|
||||||
context.Text.StoreDisplay(1);
|
context.Text.StoreDisplay(1);
|
||||||
context.Text.DeclareLocal(CalculateMaxLocalCount(Body));
|
context.Text.DeclareLocal(Body.MaxLocalCount);
|
||||||
Body.Compile(context);
|
Body.Compile(context);
|
||||||
context.Text.ReturnVoid();
|
context.Text.ReturnVoid();
|
||||||
context.Scopes.Pop();
|
context.Scopes.Pop();
|
||||||
|
@ -152,32 +152,6 @@ namespace arookas
|
||||||
context.Text.ClosePoint(callSite, Offset);
|
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>
|
class sunParameterInfo : IEnumerable<string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue