public override void MakeDiscreteTransition(List <Expression> guards, List <Event> events, List <Expression> programBlocks, List <Process> processes, Model model, SymbolicLTS lts) { Expression allCondition = new BoolConstant(false); for (int i = 0; i < Processes.Length; i++) { guards.Add(Expression.AND(Expression.NOT(allCondition), Conditions[i])); events.Add(new Event(Constants.TAU)); programBlocks.Add(null); processes.Add(Processes[i]); if (i == 0) { allCondition = Conditions[0]; } else { allCondition = Expression.OR(allCondition, Conditions[i]); } } guards.Add(Expression.NOT(allCondition)); events.Add(new Event(Constants.TAU)); programBlocks.Add(null); processes.Add(new Skip()); }
private GameObject CreateDefaultValue(ref IValue value, ValueType type) { ActiveLabel variableLabel = CreateActiveLabel(); variableLabel.ValueType = type; switch (variableLabel.ValueType) { case ValueType.Bool: { value = new BoolConstant(); } break; case ValueType.Number: { value = new FloatConstant(); } break; default: Debug.Log("ActiveLabelType is operation but Expression is null!"); break; } variableLabel.Value = value; return(variableLabel.gameObject); }
public void TestBool() { var f = new BoolConstant(true); var res = Util.BoolConstant.Compile(f); HasValue(res, f.Value); }
/// <summary> /// Creates a fully initialized node of given type. If the node requires successors, these successors will also be created and assigned to the node. Successors will be default-value-nodes of required types. /// </summary> /// <param name="type"></param> /// <returns></returns> public static Node createRandomNode(NodeType type, NodeCreationConstrains constrains = null) { Node n; if (type == NodeType.BoolConstant) { n = new BoolConstant(r.NextDouble() < 0.5); return(n); } if (type == NodeType.NumConst) { n = new NumericConstant(r.Next(10)); return(n); } if (type == NodeType.NumInput) { n = new InputNode(r.Next(10)); return(n); } n = createPrototypeNode(type); for (int i = 0; i < n.successors.count; i++) { n.setSuccessor(createDefaultNode(n.successors.GetSlot(i).argumentClass, constrains), i); } return(n); }
/// <summary> /// Return the CUDDNode of the alphabet /// </summary> /// <param name="alphabets"></param> /// <returns></returns> public CUDDNode GetAlphabetInBDD(HashSet <string> alphabets) { Expression result = new BoolConstant(false); foreach (var alphabet in alphabets) { result = Expression.OR(result, GetEventExpression(alphabet)); } return(CUDD.Function.Or(result.TranslateBoolExpToBDD(model).GuardDDs)); }
// // CSC 2 has this behavior, it allows structs to be compared // with the null literal *outside* of a generics context and // inlines that as true or false. // Constant CreateNullConstant(ResolveContext ec, Expression expr) { // FIXME: Handle side effect constants Constant c = new BoolConstant(ec.BuiltinTypes, Oper == Operator.Inequality, loc); if ((Oper & Operator.EqualityMask) != 0) { ec.Report.Warning(472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'", TypeManager.CSharpName(expr.Type), c.GetValueAsLiteral()); } else { ec.Report.Warning(464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'", TypeManager.CSharpName(expr.Type), c.GetValueAsLiteral()); } return(ReducedExpression.Create(c, this)); }
// // CSC 2 has this behavior, it allows structs to be compared // with the null literal *outside* of a generics context and // inlines that as true or false. // Expression CreateNullConstant(ResolveContext ec, Expression expr) { // FIXME: Handle side effect constants Constant c = new BoolConstant(Oper == Operator.Inequality, loc); if ((Oper & Operator.EqualityMask) != 0) { ec.Report.Warning(472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'", expr.GetSignatureForError(), c.AsString()); } else { ec.Report.Warning(464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'", expr.GetSignatureForError(), c.AsString()); } return(ReducedExpression.Create(c, this)); }
/// <summary> /// Return guard, update of channel output /// guard: buffer not full /// update: buffer = sender and update size of message and update length of buffer and update top of buffer /// Does not include update Model.Event_Name /// </summary> /// <param name="channelName"></param> /// <param name="exps"></param> /// <param name="assignmentExp">null if not exist</param> /// <param name="model"></param> /// <returns></returns> private static List <Expression> GetGuardUpdateOfChannelOutput(string channelName, List <Expression> exps, Expression assignmentExp, Model model) { string topChannelVariable = Model.GetTopVarChannel(channelName); string countChannelVariable = Model.GetCountVarChannel(channelName); string sizeElementArray = Model.GetArrayOfSizeElementChannel(channelName); //count_a < L Expression guardOfChannel = new PrimitiveApplication(PrimitiveApplication.LESS, new Variable(countChannelVariable), new IntConstant(model.mapChannelToSize[channelName])); Expression updateOfChannel = new BoolConstant(true); //Update buffer channel //a[top_a] [ i] = exps[i] for (int i = 0; i < exps.Count; i++) { updateOfChannel = new Sequence(updateOfChannel, new PropertyAssignment(new Variable(channelName), new PrimitiveApplication(PrimitiveApplication.PLUS, new PrimitiveApplication(PrimitiveApplication.TIMES, new Variable(topChannelVariable), new IntConstant(Model.MAX_MESSAGE_LENGTH)), new IntConstant(i)), exps[i])); } //Set size of the new element //size_a[top_a] = exps.count updateOfChannel = new Sequence(updateOfChannel, new PropertyAssignment(new Variable(sizeElementArray), new Variable(topChannelVariable), new IntConstant(exps.Count))); //Update size: count_a = count_a + 1 updateOfChannel = new Sequence(updateOfChannel, new Assignment(countChannelVariable, new PrimitiveApplication(PrimitiveApplication.PLUS, new Variable(countChannelVariable), new IntConstant(1)))); //Update top position: top_a = (top_a + 1) %L updateOfChannel = new Sequence(updateOfChannel, new Assignment(topChannelVariable, new PrimitiveApplication(PrimitiveApplication.MOD, new PrimitiveApplication(PrimitiveApplication.PLUS, new Variable(topChannelVariable), new IntConstant(1)), new IntConstant(model.mapChannelToSize[channelName])))); if (assignmentExp != null) { updateOfChannel = new Sequence(updateOfChannel, assignmentExp); } return(new List <Expression>() { guardOfChannel, updateOfChannel }); }
/// <summary> /// P = [] {[guardi] tau -> Pi} /// </summary> /// <param name="encoder"></param> /// <returns></returns> public override AutomataBDD EncodeComposition(BDDEncoder encoder) { List <AutomataBDD> processAutomataBDDs = new List <AutomataBDD>(); Expression previousguardsOR = null; Expression eventUpdateExpression = encoder.GetEventExpression(new Event(Constants.TAU)); for (int i = 0; i < Processes.Length; i++) { Expression guard = null; if (i == 0) { guard = Conditions[i]; } else //if (previousguardsOR != null) { guard = Expression.AND(guard, Expression.NOT(previousguardsOR)); } AutomataBDD processAutomataBDd = Processes[i].Encode(encoder); AutomataBDD guardProcessAutomataBDD = AutomataBDD.EventPrefix(guard, eventUpdateExpression, processAutomataBDd, encoder.model); processAutomataBDDs.Add(guardProcessAutomataBDD); previousguardsOR = Expression.OR(previousguardsOR, guard); } //if all conditions are not satisfied, it becomes Skip Expression allConditions = new BoolConstant(true); foreach (var condition in Conditions) { allConditions = Expression.OR(allConditions, condition); } processAutomataBDDs.Add(AutomataBDD.EventPrefix(Expression.NOT(allConditions), eventUpdateExpression, new Skip().Encode(encoder), encoder.model)); return(AutomataBDD.Choice(processAutomataBDDs, encoder.model)); }
// // CSC 2 has this behavior, it allows structs to be compared // with the null literal *outside* of a generics context and // inlines that as true or false. // Constant CreateNullConstant (ResolveContext ec, Expression expr) { // FIXME: Handle side effect constants Constant c = new BoolConstant (ec.BuiltinTypes, Oper == Operator.Inequality, loc); if ((Oper & Operator.EqualityMask) != 0) { ec.Report.Warning (472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'", TypeManager.CSharpName (expr.Type), c.GetValueAsLiteral ()); } else { ec.Report.Warning (464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'", TypeManager.CSharpName (expr.Type), c.GetValueAsLiteral ()); } return ReducedExpression.Create (c, this); }
public Expression InitializeGlobalVariables(Valuation valuation) { Expression initialVariables = new BoolConstant(true); //continue build inital state //default value of global variables if (valuation.Variables != null) { foreach (StringDictionaryEntryWithKey <ExpressionValue> pair in valuation.Variables._entries) { if (pair != null) { if (!(pair.Value is WildConstant)) { if (pair.Value is RecordValue) { RecordValue array = pair.Value as RecordValue; for (int i = 0; i < array.Associations.Length; i++) { if (!(array.Associations[i] is WildConstant)) { Expression initialVariable = Expression.EQ( new Variable(pair.Key + Model.NAME_SEPERATOR + i), new IntConstant(int.Parse(array.Associations[i].ExpressionID))); initialVariables = Expression.AND(initialVariables, initialVariable); } else { string variableName = pair.Key + Model.NAME_SEPERATOR + i; Expression lowerBound = Expression.GE(new Variable(variableName), new IntConstant(model.GetVarLowerBound(variableName))); Expression upperBound = Expression.LE(new Variable(variableName), new IntConstant(model.GetVarUpperBound(variableName))); initialVariables = Expression.AND(initialVariables, lowerBound); initialVariables = Expression.AND(initialVariables, upperBound); } } } else if (pair.Value is BoolConstant) { int value = (pair.Value as BoolConstant).Value ? 1 : 0; Expression initialVariable = Expression.EQ(new Variable(pair.Key), new IntConstant(value)); initialVariables = Expression.AND(initialVariables, initialVariable); } else { Expression initialVariable = Expression.EQ(new Variable(pair.Key), new IntConstant(int.Parse(pair.Value.ExpressionID))); initialVariables = Expression.AND(initialVariables, initialVariable); } } else { Expression lowerBound = Expression.GE(new Variable(pair.Key), new IntConstant(model.GetVarLowerBound(pair.Key))); Expression upperBound = Expression.LE(new Variable(pair.Key), new IntConstant(model.GetVarUpperBound(pair.Key))); initialVariables = Expression.AND(initialVariables, lowerBound); initialVariables = Expression.AND(initialVariables, upperBound); } } } } if (valuation.Channels != null) { foreach (KeyValuePair <string, ChannelQueue> pair in valuation.Channels) { //initialize the top index of channel is 0 Expression initialVariable = Expression.EQ(new Variable(Model.GetTopVarChannel(pair.Key)), new IntConstant(0)); initialVariables = Expression.AND(initialVariables, initialVariable); //initialize the cound of channel buffer is 0 initialVariable = Expression.EQ(new Variable(Model.GetCountVarChannel(pair.Key)), new IntConstant(0)); initialVariables = Expression.AND(initialVariables, initialVariable); } } return(initialVariables); }
public void SetValueFromDialog(ValueUI valueUI, IValue value) { SetValueDialog setDialog = Instantiate(_resourceProvider.SetValueDialog, _dialogLayer); string inputValue = "0"; bool isNumber = true; INumber number = value as INumber; if (number != null) { inputValue = number.Value.ToString(); } IBoolean boolean = value as IBoolean; if (boolean != null) { inputValue = boolean.IsTrue ? "1" : "0"; isNumber = false; } setDialog.Init("Set Constant", inputValue); setDialog.OnOk.AddListener( (valueString) => { if (isNumber) { if (float.TryParse(valueString, out float floatValue)) { FloatConstant constant = number as FloatConstant; if (constant != null) { number.Value = floatValue; } else { constant = new FloatConstant(); constant.Value = floatValue; _cursorTool.SetLabelTarget.Value = constant; if (_cursorTool.SetLabelTarget.Value.Parent == null) { _cursorTool.SetLabelValueUi.Value = _cursorTool.SetLabelTarget.Value; } } } } else { if (float.TryParse(valueString, out float floatValue)) { BoolConstant constant = boolean as BoolConstant; if (constant != null) { boolean.IsTrue = floatValue != 0; } else { constant = new BoolConstant(); constant.IsTrue = floatValue != 0; _cursorTool.SetLabelTarget.Value = constant; if (_cursorTool.SetLabelTarget.Value.Parent == null) { _cursorTool.SetLabelValueUi.Value = _cursorTool.SetLabelTarget.Value; } } } } valueUI.RebuildAnValue(); }); }
private CUDDNode EncodeBoolConstannt(BoolConstant exp) { return((exp.Value) ? CUDD.Constant(1) : CUDD.Constant(0)); }
// // CSC 2 has this behavior, it allows structs to be compared // with the null literal *outside* of a generics context and // inlines that as true or false. // Expression CreateNullConstant (Expression expr) { // FIXME: Handle side effect constants Constant c = new BoolConstant (Oper == Operator.Inequality, loc); if ((Oper & Operator.EqualityMask) != 0) { Report.Warning (472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'", expr.GetSignatureForError (), c.AsString ()); } else { Report.Warning (464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'", expr.GetSignatureForError (), c.AsString ()); } return ReducedExpression.Create (c, this); }
public void accept(BoolConstant n) { }
public WhileType TypeExpression(BoolConstant boolConst, CompilerContext context) { boolConst.CompilerScope = context.CurrentScope; return(WhileType.BOOL); }
private async Task <Expression> ParsePrimaryTailExpression() { Expression leftMost = null; if (await MaybeToken("statictype", true)) { if (!await MaybeToken("(", false)) { throw new NotImplementedException(); } leftMost = await ParseExpression(); if (leftMost == null) { throw new NotImplementedException(); } if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } leftMost = new StaticTypeExpression { Expression = leftMost }; } else if (await MaybeToken("type", true)) { if (!await MaybeToken("(", false)) { throw new NotImplementedException(); } leftMost = await ParseType(); if (leftMost == null) { throw new NotImplementedException(); } if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } } else if (await MaybeToken("tag", true)) { if (!await MaybeToken("(", false)) { throw new NotImplementedException(); } if (!await MaybeString()) { throw new NotImplementedException(); } string tag = LastString; if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } return(new TagExpression { Tag = new StringConstant { Value = tag } }); } else if (await MaybeToken("(", false)) { // Parse a parenthetical expression leftMost = await ParseExpression(); if (leftMost == null) { throw new NotImplementedException(); } if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } } else { leftMost = ParseUnary(); } if (leftMost != null) { } else if (await MaybeToken("null", true)) { // In theory, null cannot be dotwalked, called, etc. // but that might REALLY mess up our parsing leftMost = new NullExpression { }; } else if (await MaybeToken("true", true)) { leftMost = new BoolConstant { Value = true }; } else if (await MaybeToken("false", true)) { leftMost = new BoolConstant { Value = false }; } else if (await MaybeName()) { leftMost = new NameExpression { Name = LastName }; } else if (await MaybeInt()) { leftMost = new IntConstant { Value = LastInt }; } else if (await MaybeDouble()) { throw new NotImplementedException(); } else if (await MaybeString()) { leftMost = new StringConstant { Value = LastString }; } while (!eof) { if (leftMost is NameExpression ne && await MaybeToken("(", false)) { Expression[] args; if (await MaybeToken(")", false)) { args = new Expression[0]; } else { args = await ParseArgumentList(); if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } } leftMost = new CallExpression { FunctionName = ne, Arguments = args }; }
public TypedValue Evaluate(BoolConstant boolConst, InterpreterContext context) { return(new TypedValue(boolConst.Value)); }