public override void CheckStatement()
{
VariableIdentification.CheckExpression();
if (VariableIdentification.Ref is Parameter)
{
Root.AddError("Cannot assign a value to a parameter (" + VariableIdentification + ")");
}
if (VariableIdentification.Ref == null)
{
Root.AddError("Cannot assign a value to " + VariableIdentification);
}
Type targetType = VariableIdentification.GetExpressionType();
if (targetType == null)
{
Root.AddError("Cannot determine type of target " + VariableIdentification);
}
else if (Expression != null)
{
Expression.CheckExpression();
Type type = Expression.GetExpressionType();
if (type != null)
{
if (!targetType.Match(type))
{
UnaryExpression unaryExpression = Expression as UnaryExpression;
if (unaryExpression != null && unaryExpression.Term.LiteralValue != null)
{
Root.AddError("Expression " + Expression + " does not fit in variable " +
VariableIdentification);
}
else
{
Root.AddError("Expression [" + Expression + "] type (" + type.FullName +
") does not match variable [" + VariableIdentification +
"] type (" + targetType.FullName + ")");
}
}
else
{
Range rangeType = targetType as Range;
if (rangeType != null)
{
IValue value = Expression.Ref as IValue;
if (value != null)
{
if (rangeType.convert(value) == null)
{
Root.AddError("Cannot set " + value.LiteralName + " in variable of type " +
rangeType.Name);
}
}
}
}
if (Expression.Ref == EfsSystem.Instance.EmptyValue)
{
if (targetType is Collection)
{
Root.AddError("Assignation of " + Expression.Ref.Name +
" cannot be performed on variables of type collection. Use [] instead.");
}
}
}
else
{
Root.AddError("Cannot determine expression type (3) for " + Expression);
}
}
else
{
Root.AddError("Invalid expression in assignment");
}
// Check that the incoming variables are not modified
if (EnclosingFinder<DataDictionary.Types.NameSpace>.find(Root, true) != null)
{
IVariable variable = VariableIdentification.Ref as IVariable;
if (variable != null && variable.Mode == acceptor.VariableModeEnumType.aIncoming)
{
Root.AddRuleCheckMessage(RuleChecksEnum.Access03, ElementLog.LevelEnum.Error,
"An incoming variable cannot be written");
}
}
}