private void CheckGroup( BfsExpGroup group, IBfsDataBlock block )
{
foreach (IBfsExpNode node in group.Members)
{
if (node is BfsNumberExp)
CheckType(group, BfsPrimitiveTypeEnum.Int, block);
else if (node is BfsBooleanExp)
CheckType(group, BfsPrimitiveTypeEnum.Bool, block);
else if (node is BfsCallExp)
CheckType(group, BfsPrimitiveTypeEnum.CallExpression, block);
else if (node is BfsExpressionVariable)
{
BfsExpressionVariable expvar = node as BfsExpressionVariable;
//Check if the type of the variable is a function type (like ascii("Hello"))
if (expvar.LastField is BfsStructField)
if ((expvar.LastField as BfsStructField).FieldType is BfsFunctionType)
BfsCompiler.ReportError(expvar.SourceRange, "Cannot have function types in expressions!");
CheckType(group, expvar.PrimitiveType, block);
//Checking if any part of an expression variable references a variable that is array-extended
foreach( IBfsNamedField field in expvar.NameHierarchy )
if (field is BfsStructField)
{
BfsStructField f = field as BfsStructField;
if (f != null)
{
if (f.FieldType.ArrayExtension != null)
BfsCompiler.ReportError(expvar.SourceRange,
"Cannot use array-extended type in expression: '" + expvar + "'");
if (f.Skip)
BfsCompiler.ReportError(expvar.SourceRange,
"The variable '" + expvar + "' has been marked as skipped data and therefore cannot be used in expressions.");
}
}
}
else if (node is BfsEnumAliasExp)
CheckType(group, BfsPrimitiveTypeEnum.EnumMember, block);
else if (node is BfsOperator)
CheckOperator(group, node as BfsOperator);
else if (node is BfsExpGroup)
{
BfsExpGroup g = node as BfsExpGroup;
CheckGroup(g, block);
//Compare the subgroups type to the parents (this) type.
CheckType(group, g.PrimitiveType, block);
//If the group consists of comparissons then the type of the group must be boolean.
if (g.OperatorPrecedenceLevel == BfsExpGroupOperatorLevel.Comparisson)
group.PrimitiveType = BfsPrimitiveTypeEnum.Bool;
}
}
}