IEnumerator OnUpdate() { while (condition.Validate(owner)) { JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (!nodeToExecute.IsFinished()) { yield return(nodeToExecute.WaitUntilFinish()); } if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } Finish(); }
IEnumerator Do() { if (!targetNode.isAssigned) { Debug.LogError("Unassigned target node", this); Finish(); yield break; } Node n; WaitUntil w; if (!targetNode.ActivateFlowNode(out n, out w)) { yield return(w); } if (n == null) { throw new System.Exception("targetNode must be FlowNode"); } JumpStatement js = n.GetJumpState(); if (js != null) { jumpState = js; } state = StateType.Failure; Finish(); }
public override void OnExecute() { if (IsCoroutine()) { owner.StartCoroutine(OnUpdate(), this); } else { while (condition.Validate(owner)) { JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } Finish(); } }
IEnumerator OnUpdate() { for (int i = 0; i < targetNodes.Count; i++) { var t = targetNodes[i]; if (!t.isAssigned) { continue; } Node n; WaitUntil w; if (!t.ActivateFlowNode(out n, out w)) { yield return(w); } if (n == null) { throw new System.Exception("targetNode must be FlowNode"); } JumpStatement js = n.GetJumpState(); if (js != null) { jumpState = js; Finish(); yield break; } if (n.currentState == StateType.Failure) { state = StateType.Failure; Finish(); yield break; } } Finish(); }
static Statement() { Declaration = new DeclarationStatement(); Jump = new JumpStatement(); Selection = new SelectionStatement(); Iteration = new IterationStatement(); Expression = new ExpressionStatement(); }
public IEnumerator OnUpdate() { while (state == StateType.Running) { if (!targetNode.isAssigned) { Debug.LogError("Unassigned target node", this); Finish(); yield break; } Node n; if (canExecuteEvent && (RepeatForever || RepeatCount > repeatNumber)) { WaitUntil w; if (!targetNode.ActivateFlowNode(out n, out w)) { yield return(w); } repeatNumber++; canExecuteEvent = false; } else { n = targetNode.GetTargetNode(); } if (n.IsFinished()) { JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else if (js.jumpType == JumpStatementType.Break) { Finish(); yield break; } jumpState = js; Finish(); yield break; } if (StopEventOnFailure && n.currentState == StateType.Failure) { Finish(); yield break; } if (!RepeatForever && RepeatCount <= repeatNumber) { Finish(); } canExecuteEvent = true; } yield return(null); } }
protected override object Value() { System.Type type = returnType.Get <System.Type>(); if (type != null) { if (type == typeof(void)) { return(CustomDelegate.CreateActionDelegate((obj) => { if (owner == null) { return; } for (int i = 0; i < parameterValues.Count; i++) { parameterValues[i] = obj[i]; } body.InvokeFlow(); }, parameterTypes.Select((item) => item.Get <System.Type>()).ToArray())); } else { System.Type[] types = new System.Type[parameterTypes.Count + 1]; for (int x = 0; x < parameterTypes.Count; x++) { types[x] = parameterTypes[x].Get <System.Type>(); } types[types.Length - 1] = type; return(CustomDelegate.CreateFuncDelegate((obj) => { if (owner == null) { return null; } for (int i = 0; i < parameterValues.Count; i++) { parameterValues[i] = obj[i]; } Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { throw new System.Exception("Coroutine aren't supported by anonymous function in runtime."); } if (n == null) { throw new System.Exception("No return value"); } JumpStatement js = n.GetJumpState(); if (js == null || js.jumpType != JumpStatementType.Return || !(js.from is NodeReturn)) { throw new System.Exception("No return value"); } return (js.from as NodeReturn).GetReturnValue(); }, types)); } } return(null); }
public override void OnExecute() { if (!HasCoroutineInFlow(body)) { IEnumerable lObj = target.Get() as IEnumerable; if (lObj != null) { foreach (object obj in lObj) { if (body == null || !body.isAssigned) { continue; } loopObject = obj; Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { throw new System.Exception("body is not coroutine but body is not finished."); } if (n == null) //Skip on executing flow input pin. { continue; } JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } } else { Debug.LogError("The target must be IEnumerable"); } Finish(onFinished); } else { owner.StartCoroutine(OnUpdate(), this); } }
public override void OnExecute() { if (!hasInitialize) { if (targetArray.type.IsArray) { Item.Type = targetArray.type.GetElementType(); } else { Item.Type = targetArray.type.GetGenericArguments()[0]; } hasInitialize = true; } if (IsCoroutine()) { owner.StartCoroutine(OnUpdate(), this); } else { object tObj = targetArray.Get(); if (targetArray.type.IsGenericType || targetArray.type.IsArray) { IEnumerable lObj = tObj as IEnumerable; foreach (object obj in lObj) { Item.Set(obj); JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } } else { throw new System.Exception("The target array must be array list or generic list"); } Finish(); } }
public override IAstNode Visit(JumpStatement node) { IAstNode n; if (AcceptJump(node)) { n = new GoToStatement(CreateLabel(node)){ StartOffset = node.StartOffset, EndOffset = node.EndOffset }; } else { n = node; } return n; }
IEnumerator OnUpdate() { List <int> eventIndex = new List <int>(); for (int i = 0; i < targetNodes.Count; ++i) { eventIndex.Add(i); } List <int> randomOrder = new List <int>(); for (int i = targetNodes.Count; i > 0; --i) { int index = Random.Range(0, i); randomOrder.Add(eventIndex[index]); eventIndex.RemoveAt(index); } for (int i = 0; i < targetNodes.Count; i++) { var t = targetNodes[randomOrder[i]]; if (!t.isAssigned) { continue; } Node n; WaitUntil w; if (!t.ActivateFlowNode(out n, out w)) { yield return(w); } if (n == null) { throw new System.Exception("targetNode must be FlowNode"); } JumpStatement js = n.GetJumpState(); if (js != null) { jumpState = js; Finish(); yield break; } if (n.currentState == StateType.Success) { state = StateType.Success; Finish(); yield break; } } state = StateType.Failure; Finish(); }
IEnumerator OnUpdate() { JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (!nodeToExecute.IsFinished()) { yield return(nodeToExecute.WaitUntilFinish()); } if (js != null) { jumpState = js; } Finish(onFinished); }
static BlockStatement ReplaceJump(JumpStatement jump, BlockStatement block) { if (jump.StartOffset < block.StartOffset) throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); if (jump.JumpOffset > block.EndOffset) throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); var newBlock = new BlockStatement(); var ifStatement = new IfStatement(Not(jump.Condition), new BlockStatement()){ StartOffset = jump.StartOffset, EndOffset = jump.JumpOffset }; var inside = false; foreach (var statement in block) { if (statement is IfStatement && statement.Contains(jump.StartOffset.Value) && statement.EndOffset >= jump.JumpOffset) { var ifStatement2 = (IfStatement)statement; var b2 = ReplaceJump(jump, (BlockStatement)ifStatement2.TrueStatement); var newIfStatement2 = new IfStatement(ifStatement2.Condition, new BlockStatement()){ StartOffset = ifStatement2.StartOffset, EndOffset = ifStatement2.EndOffset }; ((BlockStatement)newIfStatement2.TrueStatement).AddStatements((IEnumerable<Statement>)b2); newBlock.AddStatement(newIfStatement2); } else if (statement.StartOffset == jump.StartOffset) { inside = true; } else if (statement.StartOffset == jump.JumpOffset) { if (ifStatement == null) throw new InvalidOperationException("ifStatement can't be null"); newBlock.AddStatement(ifStatement); newBlock.AddStatement(statement); ifStatement = null; inside = false; } else if (inside) { ((BlockStatement)ifStatement.TrueStatement).AddStatement(statement); } else { var lastStatement = newBlock.LastOrDefault(); if (lastStatement != null && lastStatement.EndOffset > statement.StartOffset) { throw new NotSupportedException("invalid Statement"); } newBlock.AddStatement(statement); } } return newBlock; }
public static void ResolveJumpStatement(JumpStatement jumpStatement, Table.Table table) { if (jumpStatement.IsContinue() | jumpStatement.IsBreak()) { if (!jumpStatement.IsSituatedInLoop()) { ReportError(new OperatorMustBeSituatedInLoop(jumpStatement.IsContinue() ? "сontinue" : "break", jumpStatement.SourceContext)); } } else if (((ReturnStatement)jumpStatement).ReturnBody != null) { ResolveExpression(((ReturnStatement)jumpStatement).ReturnBody, table); } }
public override void OnExecute() { if (!body.isAssigned) { throw new System.Exception("body is unassigned"); } if (HasCoroutineInFlow(body)) { owner.StartCoroutine(OnUpdate(), this); } else { do { if (body == null || !body.isAssigned) { continue; } Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { throw new System.Exception("body is not coroutine but body is not finished."); } if (n == null) //Skip on executing flow input pin. { continue; } JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } while(condition.GetValue <bool>()); Finish(onFinished); } }
IEnumerator OnUpdate() { IEnumerable lObj = target.Get() as IEnumerable; if (lObj != null) { foreach (object obj in lObj) { if (body == null || !body.isAssigned) { continue; } loopObject = obj; Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { yield return(w); } if (n == null) //Skip on executing flow input pin. { continue; } JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } } else { Debug.LogError("The target must be IEnumerable"); } Finish(onFinished); }
public override void OnExecute() { if (!HasCoroutineInFlow(body)) { for (index = startIndex.Get(); uNodeHelper.OperatorComparison(index, compareNumber.Get(), compareType); uNodeHelper.SetObject(ref index, iteratorSetValue.Get(), iteratorSetType)) { if (!body.isAssigned) { continue; } Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { throw new System.Exception("body is not coroutine but body is not finished."); } if (n == null) //Skip on executing flow input pin. { continue; } JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } Finish(onFinished); } else { owner.StartCoroutine(OnUpdate(), this); } }
public IEnumerator OnUpdate() { while (state == StateType.Running) { if (!targetNode.isAssigned) { Debug.LogError("No Target Event", this); Finish(); yield break; } Node n; WaitUntil w; if (!targetNode.ActivateFlowNode(out n, out w)) { yield return(w); } if (n == null) { throw new System.Exception("targetNode must be FlowNode"); } JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else if (js.jumpType == JumpStatementType.Break) { Finish(); yield break; } jumpState = js; Finish(); yield break; } if (n.currentState == StateType.Failure) { Finish(); yield break; } yield return(null); } }
static BlockStatement ReplaceJump(JumpStatement jump, BlockStatement block) { if (jump.StartOffset < block.StartOffset) throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); if (jump.JumpOffset > block.EndOffset) throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block"); var newBlock = new BlockStatement(); var doWhileStatement = new DoWhileStatement(jump.Condition, new BlockStatement()){ StartOffset = jump.StartOffset, EndOffset = jump.JumpOffset }; var inside = false; foreach (var statement in block) { if (statement.StartOffset == jump.JumpOffset) { ((BlockStatement)doWhileStatement.Statement).AddStatement(statement); inside = true; } else if (statement.StartOffset == jump.StartOffset) { if (doWhileStatement == null) throw new InvalidOperationException("DoWhileStatement can't be null"); newBlock.AddStatement(doWhileStatement); doWhileStatement = null; inside = false; } else if (inside) { ((BlockStatement)doWhileStatement.Statement).AddStatement(statement); } else { var lastStatement = newBlock.LastOrDefault(); if (lastStatement != null && lastStatement.EndOffset > statement.StartOffset) { throw new NotSupportedException("invalid Statement"); } newBlock.AddStatement(statement); } } return newBlock; }
public override void OnExecute() { InitializeVariable(); if (IsCoroutine()) { owner.StartCoroutine(OnUpdate(), this); } else { JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (!nodeToExecute.IsFinished()) { throw new System.Exception($"Start node in group: {GetNodeName()} is not coroutine but it is not finished."); } if (js != null) { jumpState = js; } Finish(onFinished); } }
public override void OnExecute() { if (IsCoroutine()) { owner.StartCoroutine(OnUpdate(), this); } else { if (startIndex.isAssigned && compareNumber.isAssigned) { for (var index = startIndex.Get(); uNodeHelper.OperatorComparison(index, compareNumber.Get(), compareType); uNodeHelper.SetObject(ref index, iteratorSetValue.Get(), iteratorSetType)) { Item.Set(index); JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } } else { throw new System.Exception("The target array must be array list or generic list"); } Finish(); } }
IEnumerator OnUpdate() { for (index = startIndex.Get(); uNodeHelper.OperatorComparison(index, compareNumber.Get(), compareType); uNodeHelper.SetObject(ref index, iteratorSetValue.Get(), iteratorSetType)) { if (!body.isAssigned) { continue; } Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { yield return(w); } if (n == null) //Skip on executing flow input pin. { continue; } JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } Finish(onFinished); }
IEnumerator OnUpdate() { object tObj = targetArray.Get(); if (targetArray.type.IsGenericType || targetArray.type.IsArray) { IEnumerable lObj = tObj as IEnumerable; foreach (object obj in lObj) { Item.Set(obj); JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (!nodeToExecute.IsFinished()) { yield return(nodeToExecute.WaitUntilFinish()); } if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } } else { throw new System.Exception("The target array must be array list or generic list"); } Finish(); }
IEnumerator OnUpdate() { if (startIndex.isAssigned && compareNumber.isAssigned) { for (var index = startIndex.Get(); uNodeHelper.OperatorComparison(index, compareNumber.Get(), compareType); uNodeHelper.SetObject(ref index, iteratorSetValue.Get(), iteratorSetType)) { Item.Set(index); JumpStatement js = nodeToExecute.ActivateAndFindJumpState(); if (!nodeToExecute.IsFinished()) { yield return(nodeToExecute.WaitUntilFinish()); } if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } } else { throw new System.Exception("The target array must be array list or generic list"); } Finish(); }
IEnumerator OnUpdate() { do { if (body == null || !body.isAssigned) { continue; } Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { yield return(w); } if (n == null) //Skip on executing flow input pin. { continue; } JumpStatement js = n.GetJumpState(); if (js != null) { if (js.jumpType == JumpStatementType.Continue) { continue; } else { if (js.jumpType == JumpStatementType.Return) { jumpState = js; } break; } } } while(condition.GetValue <bool>()); Finish(onFinished); }
// [41] JumpStatement = 'continue' ';' | 'break' ';' | 'return' [Expression] ';'. private bool IsJumpStatement(out JumpStatement jumpStatement) { jumpStatement = new JumpStatement(); if (CheckToken(SyntaxKind.ContinueKeyword)) { if (!CheckToken(SyntaxKind.SemiColonToken)) { return(false); } return(true); } else if (CheckToken(SyntaxKind.BreakKeyword)) { if (!CheckToken(SyntaxKind.SemiColonToken)) { return(false); } return(true); } else if (CheckToken(SyntaxKind.ReturnKeyword)) { if (IsExpression(out var expression)) { ; } if (!CheckToken(SyntaxKind.SemiColonToken)) { return(false); } return(true); } return(false); }
/// <summary> /// Generates the code for a JumpStatement node. /// </summary> /// <param name="js">The JumpStatement node.</param> /// <returns>String containing C# code for JumpStatement js.</returns> private string GenerateJumpStatement(JumpStatement js) { return Generate(String.Format("goto {0}", CheckName(js.TargetName)), js); }
/// <summary> /// Generates the code for a JumpStatement node. /// </summary> /// <param name="js">The JumpStatement node.</param> /// <returns>String containing C# code for JumpStatement js.</returns> private string GenerateJumpStatement(JumpStatement js) { return(Generate(String.Format("goto {0}", CheckName(js.TargetName)), js)); }
public override void OnExecute() { jumpState = new JumpStatement(JumpStatementType.Return, this); Finish(); }
public void SetUp() { @return = new JumpStatement(); }
/// <summary> /// Generates the code for a JumpStatement node. /// </summary> /// <param name="js">The JumpStatement node.</param> /// <returns>String containing C# code for JumpStatement js.</returns> private void GenerateJumpStatement(JumpStatement js, StringBuilder sb) { Generate(String.Format("goto {0}", CheckName(js.TargetName)), js, sb); }
public override void RegisterPort() { register.onExecute = () => { if (target.isAssigned) { object val = target.Get(); if (val == null) { val = new MemberData.Event(target.CreateRuntimeEvent(), null); } if (val is MemberData.Event) { MemberData.Event e = val as MemberData.Event; if (e.eventInfo != null) { if (m_Delegate == null) { if (e.eventInfo is RuntimeEvent) { var returnType = target.type.GetMethod("Invoke").ReturnType; m_Delegate = new MemberData.EventCallback((obj => { if (owner == null) { return(null); } if (obj != null && parameters.Count == obj.Length) { for (int i = 0; i < obj.Length; i++) { parameters[i] = obj[i]; } } if (returnType == typeof(void)) { body.InvokeFlow(); return(null); } else { Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { throw new uNodeException("Coroutine aren't supported by EventHook node in runtime.", this); } if (n == null) { throw new uNodeException("No return value", this); } JumpStatement js = n.GetJumpState(); if (js == null || js.jumpType != JumpStatementType.Return || !(js.from is NodeReturn)) { throw new uNodeException("No return value", this); } return((js.from as NodeReturn).GetReturnValue()); } })); } else { var method = e.eventInfo.EventHandlerType.GetMethod("Invoke"); var type = method.ReturnType; if (type == typeof(void)) { m_Delegate = CustomDelegate.CreateActionDelegate((obj) => { if (owner == null) { return; } if (obj != null && parameters.Count == obj.Length) { for (int i = 0; i < obj.Length; i++) { parameters[i] = obj[i]; } } body.InvokeFlow(); }, method.GetParameters().Select(i => i.ParameterType).ToArray()); } else { var types = method.GetParameters().Select(i => i.ParameterType).ToList(); types.Add(type); m_Delegate = CustomDelegate.CreateFuncDelegate((obj) => { if (owner == null) { return(null); } if (obj != null && parameters.Count == obj.Length) { for (int i = 0; i < obj.Length; i++) { parameters[i] = obj[i]; } } Node n; WaitUntil w; if (!body.ActivateFlowNode(out n, out w)) { throw new uNodeException("Coroutine aren't supported by EventHook node in runtime.", this); } if (n == null) { throw new uNodeException("No return value", this); } JumpStatement js = n.GetJumpState(); if (js == null || js.jumpType != JumpStatementType.Return || !(js.from is NodeReturn)) { throw new uNodeException("No return value", this); } return((js.from as NodeReturn).GetReturnValue()); }, types.ToArray()); } m_Delegate = ReflectionUtils.ConvertDelegate(m_Delegate, e.eventInfo.EventHandlerType); } } e.eventInfo.AddEventHandler(e.instance, m_Delegate); } } else if (val is UnityEventBase) { var method = val.GetType().GetMethod("AddListener"); if (m_Delegate == null) { var param = method.GetParameters()[0].ParameterType; var gType = param.GetGenericArguments(); m_Delegate = CustomDelegate.CreateActionDelegate((obj) => { if (owner == null) { return; } if (obj != null && parameters.Count == obj.Length) { for (int i = 0; i < obj.Length; i++) { parameters[i] = obj[i]; } } body.InvokeFlow(); }, gType); m_Delegate = System.Delegate.CreateDelegate(param, m_Delegate.Target, m_Delegate.Method); } method.InvokeOptimized(val, new object[] { m_Delegate }); } else { if (val == null) { throw new uNodeException("The target event is null", this); } throw new uNodeException("Invalid target value: " + val, this); } } }; unregister.onExecute = () => { if (m_Delegate != null && target.isAssigned) { object val = target.Get(); if (val is MemberData.Event) { MemberData.Event e = val as MemberData.Event; if (e.eventInfo != null) { e.eventInfo.RemoveEventHandler(e.instance, m_Delegate); } } else if (val is UnityEventBase) { var method = val.GetType().GetMethod("RemoveListener"); method.InvokeOptimized(val, new object[] { m_Delegate }); } } }; if (CodeGenerator.isGenerating) { CodeGenerator.RegisterFlowNode(this); register.codeGeneration = () => { if (target.type.IsCastableTo(typeof(UnityEventBase))) { return(target.ParseValue().AddFunction("AddListener", GenerateEventCodes()).AddSemicolon()); } return(CodeGenerator.GenerateSetCode(target, GenerateEventCodes(), SetType.Add, target.type)); }; unregister.codeGeneration = () => { if (target.type.IsCastableTo(typeof(UnityEventBase))) { return(target.ParseValue().AddFunction("RemoveListener", GenerateEventCodes()).AddSemicolon()); } return(CodeGenerator.GenerateSetCode(target, GenerateEventCodes(), SetType.Subtract, target.type)); }; } }
public override void Visit(JumpStatement node) { Jumps.Add(node); }
public virtual void Visit(JumpStatement node) { DefaultVisit(node); }
static bool AcceptJump(JumpStatement node) { var condition = node.Condition as BooleanLiteralExpression; return (condition != null && condition.Value); }
static string CreateLabel(JumpStatement node) { return string.Format("label_{0}", node.JumpOffset); }