/// <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); }
/// <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); }
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); } }
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; }