/// <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); } }
public override void visit(Generated.Type obj, bool visitSubNodes) { Types.Type type = obj as Types.Type; if (type != null) { if (type is Types.StateMachine) { // Ignore state machines } else { if (!(type is Types.Structure) && !(type is Functions.Function)) { if (Utils.Utils.isEmpty(type.getDefault())) { type.AddError("Types should define their default value"); } else { if (type.DefaultValue == null) { type.AddError("Invalid default value"); } } if (type is Types.Range) { Types.Range range = type as Types.Range; if (range.getPrecision() == Generated.acceptor.PrecisionEnum.aIntegerPrecision && range.Default.IndexOf('.') > 0 || range.getPrecision() == Generated.acceptor.PrecisionEnum.aDoublePrecision && range.Default.IndexOf('.') <= 0) { type.AddError("Default value's precision does not correspond to the type's precision"); } foreach (Constants.EnumValue specValue in range.SpecialValues) { String value = specValue.getValue(); if (range.getPrecision() == Generated.acceptor.PrecisionEnum.aDoublePrecision && value.IndexOf('.') <= 0 || range.getPrecision() == Generated.acceptor.PrecisionEnum.aIntegerPrecision && value.IndexOf('.') > 0) { type.AddError("Precision of the special value + " + specValue.Name + " does not correspond to the type's precision"); } } } } if (declaredTypes.ContainsKey(type.FullName)) { declaredTypes[type.Name].AddError(TYPE_DECLARED_SEVERAL_TIMES); type.AddError(TYPE_DECLARED_SEVERAL_TIMES); } else { declaredTypes[type.Name] = type; } } } base.visit(obj, visitSubNodes); }
public override Range createRange() { Range retVal = new Types.Range(); _defaultValueSetter.SetDefaultValue(retVal); return(retVal); }
/// <summary> /// Constructor /// </summary> /// <param name="panel"></param> /// <param name="model"></param> public RangeModelControl(ModelDiagramPanel panel, Range model) : base(panel, model) { }
public override Range createRange() { Range retVal = new Types.Range(); _defaultValueSetter.SetDefaultValue(retVal); return retVal; }
/// <summary> /// Fills the given structure with the values provided from the database /// </summary> /// <param name="aNameSpace">Namespace of the structure</param> /// <param name="fields">Fields to be copied into the structure</param> /// <param name="index">Index (of fields list) from which we have to start copying</param> /// <param name="aStructure">The structure to be filled</param> private static void FillStructure(NameSpace aNameSpace, ArrayList fields, ref int currentIndex, StructureValue aStructure) { EfsSystem system = EfsSystem.Instance; int j = 0; while (currentIndex < fields.Count) { DBField field = fields[currentIndex] as DBField; KeyValuePair <string, IVariable> pair = aStructure.SubVariables.ElementAt(j); IVariable variable = pair.Value; // conditional variables can be missing in the database fields, but present in our structure => skip them while (!variable.Name.StartsWith(field.Variable) && j < aStructure.SubVariables.Count - 1) { j++; pair = aStructure.SubVariables.ElementAt(j); variable = pair.Value; } // We use StartsWith and not Equals because we can have N_ITER_1 and N_ITER if (variable.Name.StartsWith(field.Variable)) { if (variable.Type is Enum) { Enum type = variable.Type as Enum; foreach (EnumValue enumValue in type.Values) { int value = int.Parse(enumValue.getValue()); int other = int.Parse(field.Value); if (value == other) { variable.Value = enumValue; j++; break; } } } else if (variable.Type is Range) { Range type = variable.Type as Range; object v = VariableConverter.INSTANCE.Convert(variable.Name, field.Value); string stringValue = v as string; if (stringValue != null) { int intValue; if (int.TryParse(stringValue, out intValue)) { v = intValue; } } variable.Value = new IntValue(type, (int)v); j++; } else if (variable.Type is StringType) { StringType type = variable.Type as StringType; variable.Value = new StringValue(type, field.Value); j++; } else { throw new Exception("Unhandled variable type"); } if (variable.Name.StartsWith("N_ITER")) // we have to create a sequence { KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j); IVariable sequenceVariable = sequencePair.Value; Collection collectionType = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName); ListValue sequence = new ListValue(collectionType, new List <IValue>()); int value = int.Parse(field.Value); for (int k = 0; k < value; k++) { currentIndex++; Structure structureType = (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName); StructureValue structureValue = new StructureValue(structureType); FillStructure(aNameSpace, fields, ref currentIndex, structureValue); sequence.Val.Add(structureValue); } sequenceVariable.Value = sequence; j++; } } // Special case for X_TEXT if ("Sequence1".Equals(variable.Name) && "X_TEXT".Equals(field.Variable)) { KeyValuePair <string, IVariable> sequencePair = aStructure.SubVariables.ElementAt(j); IVariable sequenceVariable = sequencePair.Value; Collection collectionType = (Collection)system.FindType(aNameSpace, sequenceVariable.TypeName); ListValue sequence = new ListValue(collectionType, new List <IValue>()); while (field != null && "X_TEXT".Equals(field.Variable)) { if (string.IsNullOrEmpty(field.Value)) { field.Value = " "; } Structure structureType = (Structure)system.FindType(aNameSpace, sequence.CollectionType.Type.FullName); StructureValue structureValue = new StructureValue(structureType); FillStructure(aNameSpace, fields, ref currentIndex, structureValue); sequence.Val.Add(structureValue); currentIndex += 1; if (currentIndex < fields.Count) { field = fields[currentIndex] as DBField; } else { field = null; } } sequenceVariable.Value = sequence; j++; } // if all the fields of the structue are filled, we terminated if (j == aStructure.SubVariables.Count) { break; } else { currentIndex += 1; } } }
/// <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"); } } }