/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> /// <param name="runner"></param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply, Runner runner) { IVariable var = VariableIdentification.GetVariable(context); if (var != null) { IValue value = Expression.GetExpressionValue(context, explanation); if (value != null) { value = value.RightSide(var, true, true); } Range range = var.Type as Range; Collection collection = var.Type as Collection; if (range != null && range.convert(value) == null) { AddError("Value " + value + " is outside range", RuleChecksEnum.ExecutionFailed); } else if (collection != null && collection.convert(value) == null) { AddError("Value " + value + " cannot be assigned to variable", RuleChecksEnum.ExecutionFailed); } else { Change change = new Change(var, var.Value, value); changes.Add(change, apply, runner); ExplanationPart.CreateSubExplanation(explanation, Root, change); } } else { AddError("Cannot find variable " + VariableIdentification, RuleChecksEnum.ExecutionFailed); } }
/// <summary> /// Performs the semantic analysis of the statement /// </summary> /// <param name="instance">the reference instance on which this element should analysed</param> /// <returns>True if semantic analysis should be continued</returns> public override bool SemanticAnalysis(Utils.INamable instance) { bool retVal = base.SemanticAnalysis(instance); if (retVal) { VariableIdentification.SemanticAnalysis(instance, Filter.IsLeftSide); Expression.SemanticAnalysis(instance, Filter.IsRightSide); } return(retVal); }
/// <summary> /// Provides a real short description of this statement /// </summary> /// <returns></returns> public override string ShortShortDescription() { string retVal; if (VariableIdentification.ToString().Trim() == "THIS") { retVal = Expression.ToString(); } else { retVal = VariableIdentification.Name; } return(retVal); }
/// <summary> /// Checks the statement for semantical errors /// </summary> public override void CheckStatement() { Types.Type targetType = VariableIdentification.GetExpressionType(); if (targetType == null) { Root.AddError("Cannot determine type of target " + VariableIdentification.ToString()); } else if (Expression != null) { Expression.checkExpression(); Types.Type type = Expression.GetExpressionType(); if (type != null) { if (targetType != null) { if (!targetType.Match(type)) { UnaryExpression unaryExpression = Expression as UnaryExpression; if (unaryExpression != null && unaryExpression.Term.LiteralValue != null) { if (targetType.getValue(unaryExpression.ToString()) == null) { Root.AddError("Expression " + Expression.ToString() + " does not fit in variable " + VariableIdentification.ToString()); } } else { Root.AddError("Expression [" + Expression.ToString() + "] type (" + type.FullName + ") does not match variable [" + VariableIdentification.ToString() + "] type (" + targetType.FullName + ")"); } } } else { Root.AddError("Cannot determine variable type"); } } else { Root.AddError("Cannot determine expression type (3) for " + Expression.ToString()); } } else { Root.AddError("Invalid expression in assignment"); } }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply) { Variables.IVariable var = VariableIdentification.GetVariable(context); if (var != null) { string tmp = var.FullName; Values.IValue value = Expression.GetValue(context); if (value != null) { value = value.RightSide(var, true); } Rules.Change change = new Rules.Change(var, var.Value, value); changes.Add(change, apply); explanation.SubExplanations.Add(new ExplanationPart(Root, change)); } else { AddError("Cannot find variable " + VariableIdentification.ToString()); } }
/// <summary> /// Performs the semantic analysis of the statement /// </summary> /// <param name="instance">the reference instance on which this element should analysed</param> /// <returns>True if semantic analysis should be continued</returns> public override bool SemanticAnalysis(INamable instance = null) { bool retVal = base.SemanticAnalysis(instance); if (retVal) { // VariableIdentification if (VariableIdentification != null) { VariableIdentification.SemanticAnalysis(instance, IsLeftSide.INSTANCE); StaticUsage.AddUsages(VariableIdentification.StaticUsage, Usage.ModeEnum.Write); } else { AddError("Altered variable not specified", RuleChecksEnum.SemanticAnalysisError); } // Expression Expression.SemanticAnalysis(instance, IsRightSide.INSTANCE); StaticUsage.AddUsages(Expression.StaticUsage, Usage.ModeEnum.Read); } return(retVal); }
public override string ToString() { return(VariableIdentification.ToString() + " <- " + Expression.ToString()); }
/// <summary> /// Checks the statement for semantical errors /// </summary> 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.AddError("An incoming variable cannot be written"); } } }