/// <summary> /// Checks the expression and appends errors to the root tree node when inconsistencies are found /// </summary> public override void CheckExpression() { base.CheckExpression(); Type initialValueType = InitialValue.GetExpressionType(); if (initialValueType != null) { Collection listExpressionType = ListExpression.GetExpressionType() as Collection; if (listExpressionType != null) { IteratorExpression.CheckExpression(); } } else { AddError("Cannot determine initial value expression type for " + ToString(), RuleChecksEnum.SemanticAnalysisError); } bool refToResultFound = false; foreach (Usage usage in IteratorExpression.StaticUsage.AllUsages) { if (usage.Referenced == AccumulatorVariable && usage.Mode == Usage.ModeEnum.Read) { refToResultFound = true; break; } } if (!refToResultFound) { AddError("REDUCE expressions should reference RESULT variable", RuleChecksEnum.SyntaxError); } }
/// <summary> /// Performs the semantic analysis of the expression /// </summary> /// <param name="instance">the reference instance on which this element should analysed</param> /// <param name="expectation">Indicates the kind of element we are looking for</param> /// <returns>True if semantic analysis should be continued</returns> public override bool SemanticAnalysis(INamable instance, BaseFilter expectation) { bool retVal = base.SemanticAnalysis(instance, expectation); if (retVal) { // ListExpression if (ListExpression != null) { ListExpression.SemanticAnalysis(instance, IsRightSide.INSTANCE); StaticUsage.AddUsages(ListExpression.StaticUsage, Usage.ModeEnum.Read); Collection collectionType = ListExpression.GetExpressionType() as Collection; if (collectionType != null) { StaticUsage.AddUsage(collectionType, Root, Usage.ModeEnum.Type); IteratorVariable.Type = collectionType.Type; PreviousIteratorVariable.Type = collectionType.Type; } else { AddError("Cannot determine collection type on list expression " + ToString(), RuleChecksEnum.SemanticAnalysisError); } } else { AddError("List expression not provided", RuleChecksEnum.SemanticAnalysisError); } } return(retVal); }
/// <summary> /// Provides the value of the function /// </summary> /// <param name="context"></param> /// <param name="actuals">the actual parameters values</param> /// <param name="explain"></param> /// <returns>The value for the function application</returns> public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals, ExplanationPart explain) { IValue retVal = null; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); ListValue value = context.FindOnStack(Collection) as ListValue; if (value != null) { Collection collectionType = value.Type as Collection; if (collectionType != null && collectionType.Type != null) { Type elementType = collectionType.Type; if (value.Val.Count >= collectionType.getMaxSize()) { AddError("Cannot allocate element in list : list full"); } else { retVal = elementType.DefaultValue; value.Val.Add(retVal); } } } context.LocalScope.PopContext(token); return(retVal); }
/// <summary> /// Provides the value of the function /// </summary> /// <param name="context"></param> /// <param name="actuals">the actual parameters values</param> /// <param name="explain"></param> /// <returns>The value for the function application</returns> public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals, ExplanationPart explain) { IValue retVal = null; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); Collection collectionType = (Collection) EFSSystem.FindType( OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default"), "TargetsCol"); ListValue collection = new ListValue(collectionType, new List <IValue>()); Function function = context.FindOnStack(Targets).Value as Function; if (function != null && !function.Name.Equals("EMPTY")) { Graph graph1 = createGraphForValue(context, function, explain); ComputeTargets(graph1.Function, collection); } context.LocalScope.PopContext(token); retVal = collection; return(retVal); }
/// <summary> /// Executes the action requested by this tool strip button /// </summary> protected override void OnClick(EventArgs e) { Collection collectionType = (Collection)Variable.Type; Structure structureType = (Structure)collectionType.Type; StructureValue element = new StructureValue(structureType, false); if (structureType.Elements.Count == 1) { StructureElement subElement = (StructureElement)structureType.Elements[0]; Structure subElementStructureType = subElement.Type as Structure; if (subElementStructureType != null) { element.CreateField(subElement, structureType); } } ListValue value = Variable.Value.RightSide(Variable, false, true) as ListValue; Variable.Value = value; if (value != null) { value.Val.Add(element); element.Enclosing = value; } base.OnClick(e); }
/// <summary> /// Provides the type of this expression /// </summary> /// <returns></returns> public override Type GetExpressionType() { Type retVal = null; Type iteratorType = IteratorExpression.GetExpressionType(); if (iteratorType != null) { Collection collection = (Collection)acceptor.getFactory().createCollection(); collection.Enclosing = EfsSystem.Instance; collection.Type = iteratorType; Collection originalListType = ListExpression.GetExpressionType() as Collection; if (originalListType != null) { collection.setMaxSize(originalListType.getMaxSize()); } retVal = collection; } else { AddError("Cannot evaluate iterator type for " + ToString(), RuleChecksEnum.SemanticAnalysisError); } return(retVal); }
private void displayType(int indent, Type type) { Structure structureType = type as Structure; if (structureType != null) { foreach (StructureElement element in structureType.Elements) { displayIndent(indent); Type subType = element.Type; Writer.WriteLine(element.Name + " : " + subType.FullName); displayType(indent + 1, subType); } } Range rangeType = type as Range; if (rangeType != null) { displayIndent(indent); Writer.WriteLine("RANGE " + rangeType.MinValueAsDouble + ".." + rangeType.MaxValueAsDouble + " DEFAULT VALUE = " + rangeType.DefaultValue.LiteralName); } Collection collectionType = type as Collection; if (collectionType != null) { displayIndent(indent); Type subType = collectionType.Type; Writer.WriteLine("COLLECTION [" + collectionType.getMaxSize() + "] OF " + subType.FullName); displayType(indent + 1, subType); } }
/// <summary> /// Accepts drop of a tree node, in a drag & drop operation /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { base.AcceptDrop(SourceNode); if (SourceNode is CollectionTreeNode) { CollectionTreeNode collectionTreeNode = SourceNode as CollectionTreeNode; DataDictionary.Types.Collection collection = collectionTreeNode.Item; collectionTreeNode.Delete(); AddCollection(collection); } else if (SourceNode is SpecificationView.ParagraphTreeNode) { SpecificationView.ParagraphTreeNode node = SourceNode as SpecificationView.ParagraphTreeNode; DataDictionary.Specification.Paragraph paragaph = node.Item; DataDictionary.Types.Collection collection = (DataDictionary.Types.Collection)DataDictionary.Generated.acceptor.getFactory().createCollection(); collection.Name = paragaph.Name; DataDictionary.ReqRef reqRef = (DataDictionary.ReqRef)DataDictionary.Generated.acceptor.getFactory().createReqRef(); reqRef.Name = paragaph.FullId; collection.appendRequirements(reqRef); AddCollection(collection); } }
public void AddHandler(object sender, EventArgs args) { DataDictionaryTreeView treeView = BaseTreeView as DataDictionaryTreeView; if (treeView != null) { DataDictionary.Types.Collection collection = (DataDictionary.Types.Collection)DataDictionary.Generated.acceptor.getFactory().createCollection(); collection.Name = "<Collection" + (GetNodeCount(false) + 1) + ">"; AddCollection(collection); } }
/// <summary> /// Creates a colleciton in the namespace provided /// </summary> /// <param name="enclosing"></param> /// <param name="name">The name of the collection</param> /// <param name="typeName">The name of the type of the elements in the collection</param> /// <param name="maxSize">The maximum collection size</param> /// <returns></returns> protected Collection CreateCollection(NameSpace enclosing, string name, string typeName, int maxSize) { Collection retVal = (Collection)Factory.createCollection(); enclosing.appendCollections(retVal); retVal.Name = name; retVal.TypeName = typeName; retVal.setMaxSize(maxSize); return(retVal); }
/// <summary> /// Checks the expression and appends errors to the root tree node when inconsistencies are found /// </summary> public override void CheckExpression() { base.CheckExpression(); Collection listExpressionType = ListExpression.GetExpressionType() as Collection; if (listExpressionType != null) { IteratorExpression.CheckExpression(); } Accumulator.CheckExpression(); if (!(DefinedAccumulator.GetExpressionType() is Range)) { AddError("Accumulator expression should be a range", RuleChecksEnum.SyntaxError); } }
public void TestCollectionConcatenation() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "NameSpace"); Structure structure = CreateStructure(nameSpace, "ModelElement"); StructureElement structElem = CreateStructureElement(structure, "Value", "Boolean"); structElem.setDefault("True"); Collection collection = CreateCollection(nameSpace, "Coll", "ModelElement", 10); collection.Type = structure; collection.setMaxSize(3); collection.Default = "[]"; Variable variable = CreateVariable(nameSpace, "V", "Coll"); RuleCondition ruleCondition = CreateRuleAndCondition(nameSpace, "Test"); Action action = CreateAction(ruleCondition, "V <- V + [ModelElement{Value => True}] "); RuleCheckerVisitor visitor = new RuleCheckerVisitor(dictionary); visitor.visit(nameSpace); Util.IsThereAnyError isThereAnyError = new Util.IsThereAnyError(); Assert.AreEqual(0, isThereAnyError.ErrorsFound.Count); Assert.AreEqual("[]", variable.Value.LiteralName); Runner runner = new Runner(false); runner.Cycle(); Assert.AreEqual("[" + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName); runner.Cycle(); Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName); runner.Cycle(); Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName); // In this case, the new collection cannot be placed in the variable runner.Cycle(); Assert.AreEqual(1, action.Messages.Count); Assert.AreEqual(ElementLog.LevelEnum.Error, action.Messages[0].Level); }
public static void HandleCellEditStarting(object sender, CellEditEventArgs e) { IVariable variable = e.RowObject as IVariable; if (variable != null) { Enum enumType = variable.Type as Enum; if (enumType != null) { ComboBox control = new ComboBox { Bounds = e.CellBounds, Font = ((ObjectListView)sender).Font, DropDownStyle = ComboBoxStyle.DropDownList, Text = (string)e.Value, DrawMode = DrawMode.OwnerDrawFixed }; foreach (EnumValue enumValue in enumType.Values) { control.Items.Add(enumValue.Name); } control.Items.Add(DefaultConst); control.Text = variable.Value.Name; control.DrawItem += cbb_DrawItem; e.Control = control; } Range rangeType = variable.Type as Range; if (rangeType != null) { ComboBox control = new ComboBox { Bounds = e.CellBounds, Font = ((ObjectListView)sender).Font, DropDownStyle = ComboBoxStyle.DropDown, Text = (string)e.Value, DrawMode = DrawMode.OwnerDrawFixed }; foreach (EnumValue enumValue in rangeType.SpecialValues) { control.Items.Add(enumValue.Name); } control.Items.Add(DefaultConst); control.Text = variable.Value.Name; control.DrawItem += cbb_DrawItem; e.Control = control; } Structure structure = variable.Type as Structure; if (structure != null) { e.Cancel = true; } Collection collection = variable.Type as Collection; if (collection != null) { e.Cancel = true; } } else { e.Cancel = true; } }
public static void CreateContextualMenu(object obj, CellRightClickEventArgs args) { ContextMenuStrip menuStrip = new ContextMenuStrip(); List <BaseToolStripButton> items = new List <BaseToolStripButton>(); IVariable enclosingVariable = args.Model as IVariable; IValue value = DerefVariable(args.Model); StructureValue structureValue = value as StructureValue; if (structureValue != null) { Structure structureType = (Structure)structureValue.Type; foreach (StructureElement element in structureType.Elements) { if (element.Type is Structure) { IVariable subVariable = null; INamable tmp; if (structureValue.Val.TryGetValue(element.Name, out tmp)) { subVariable = tmp as IVariable; } if (subVariable == null || subVariable.Value == EfsSystem.Instance.EmptyValue || subVariable.Value is DefaultValue) { items.Add(new ToolStripAddStructureMember(args, structureValue, element)); } } } if (enclosingVariable != null) { StructureValue enclosingStructureValue = enclosingVariable.Enclosing as StructureValue; if (enclosingStructureValue != null) { items.Add(new ToolStripRemoveStructureMember(args, enclosingVariable)); } } TreeListView treeListView = (TreeListView)obj; object parent = treeListView.GetParent(args.Model); ListValue enclosingListValue = DerefVariable(parent) as ListValue; if (enclosingListValue != null) { items.Add(new ToolStripRemoveListEntry(args, enclosingListValue, structureValue)); } } ListValue listValue = value as ListValue; if (listValue != null) { if (enclosingVariable != null) { Collection collection = (Collection)enclosingVariable.Type; if (listValue.Val.Count < collection.getMaxSize()) { items.Add(new ToolStripAddValueInList(args, enclosingVariable)); } } } items.Sort((b1, b2) => String.Compare(b1.Text, b2.Text, StringComparison.Ordinal)); foreach (BaseToolStripButton menuItem in items) { menuStrip.Items.Add(menuItem); } args.MenuStrip = menuStrip; }
/// <summary> /// Appends the corresponding field in the structure, according to its type /// </summary> /// <param name="obj">The object which represents the field</param> /// <param name="structure">The structure which should contain the field</param> private void AppendField(object obj, DataDictionary.Types.Structure structure, string defaultValue) { if (obj is Field) { Field field = obj as Field; DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = field.name; element.TypeName = EFSType(field.type_definition); if (element.TypeName == null) { element.TypeName = getTypeName(field.type); } element.setMode(DataDictionary.Generated.acceptor.VariableModeEnumType.aInOut); if (field.name.Equals("NID_PACKET")) { element.Default = defaultValue; } else { element.Default = DefaultValue(field.type_definition); } structure.appendElements(element); } else if (obj is LoopFieldSequence) { LoopFieldSequence loopFieldSequence = obj as LoopFieldSequence; // Create a structure for the elements enclosed in the loop field DataDictionary.Types.Structure subStructure = (DataDictionary.Types.Structure)DataDictionary.Generated.acceptor.getFactory().createStructure(); subStructure.Name = "SubStructure" + numberOfSubStructures; numberOfSubStructures += 1; structure.NameSpace.appendStructures(subStructure); RenameDuplicates(loopFieldSequence.Items); foreach (object obj2 in loopFieldSequence.Items) { AppendField(obj2, subStructure, ""); } // Create the collection type for the sequence DataDictionary.Types.Collection collection = (DataDictionary.Types.Collection)DataDictionary.Generated.acceptor.getFactory().createCollection(); collection.Name = "Collection" + numberOfCollections; collection.setTypeName(subStructure.Name); collection.setDefault("[]"); structure.NameSpace.appendCollections(collection); // Create the field in the strcuture which shall hold the collection DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = "Sequence" + numberOfCollections; element.TypeName = collection.Name; element.setMode(DataDictionary.Generated.acceptor.VariableModeEnumType.aInOut); structure.appendElements(element); numberOfCollections += 1; } else if (obj is ConditionalFieldSequence) { ConditionalFieldSequence conditionalFieldSequence = obj as ConditionalFieldSequence; RenameDuplicates(conditionalFieldSequence.content); foreach (object obj2 in conditionalFieldSequence.content) { AppendField(obj2, structure, ""); } } else if (obj is FieldGroupReference) { FieldGroupReference fieldGroupReference = obj as FieldGroupReference; DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = fieldGroupReference.name; if (Utils.Utils.isEmpty(element.Name)) { string[] names = [email protected]('/'); element.Name = names[names.Length - 1]; } element.setMode(DataDictionary.Generated.acceptor.VariableModeEnumType.aInOut); element.TypeName = getTypeName(fieldGroupReference.@ref) + ".Message"; element.Default = "EMPTY"; structure.appendElements(element); } else if (obj is Choice) { Choice choice = obj as Choice; RenameDuplicates(choice.field_group_reference); foreach (FieldGroupReference obj2 in choice.field_group_reference) { AppendField(obj2, structure, ""); } } }
/// <summary> /// Evaluates the rules associated to a single variable /// </summary> /// <param name="priority">The priority in which this variable is evaluated</param> /// <param name="activations">The activation list result of this evaluation</param> /// <param name="variable">The variable to evaluate</param> /// <param name="explanation">The explanation part to be filled</param> private void EvaluateVariable(acceptor.RulePriority priority, HashSet <Activation> activations, IVariable variable, ExplanationPart explanation) { if (variable != null && variable.Value != EfsSystem.Instance.EmptyValue) { if (variable.Type != null && variable.Type.ApplicableRule(priority)) { if (variable.Type is Structure) { Structure structure = variable.Type as Structure; foreach (Rules.Rule rule in structure.Rules) { rule.Evaluate(this, priority, variable, activations, explanation); } StructureValue value = variable.Value as StructureValue; if (value != null) { foreach (IVariable subVariable in value.SubVariables.Values) { EvaluateVariable(priority, activations, subVariable, explanation); } } } else if (variable.Type is StateMachine) { EvaluateStateMachine(activations, priority, variable, explanation); } else if (variable.Type is Collection) { Collection collectionType = variable.Type as Collection; if (variable.Value != EfsSystem.Instance.EmptyValue) { ListValue val = variable.Value as ListValue; if (val != null) { foreach (IValue subVal in val.Val) { Variables.Variable tmp = new Variables.Variable { Name = "list_entry", Type = collectionType.Type, Value = subVal }; EvaluateVariable(priority, activations, tmp, explanation); } } else { ModelElement element = variable as ModelElement; if (element != null) { element.AddError("Variable " + variable.Name + " does not hold a collection but " + variable.Value); } else { throw new Exception("Variable " + variable.Name + " does not hold a collection but " + variable.Value); } } } } } } }
/// <summary> /// Adds a new collection /// </summary> /// <param name="collection"></param> public void AddCollection(DataDictionary.Types.Collection collection) { Item.appendCollections(collection); Nodes.Add(new CollectionTreeNode(collection)); SortSubNodes(); }
/// <summary> /// Adds a new collection type /// </summary> /// <param name="collection"></param> public void AddCollection(DataDictionary.Types.Collection collection) { collections.AddCollection(collection); }