示例#1
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            NodeIf node = source as NodeIf;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (NodeValidation n) => {
                var action    = new EqualityCompare();
                action.target = new MultipurposeMember(node.condition);
                action.value  = new MemberData(true);
                n.Validation.AddBlock(action, EventActionData.EventType.Event);
                n.onTrue     = node.onTrue;
                n.onFalse    = node.onFalse;
                n.onFinished = node.onFinished;
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
示例#2
0
        internal void Accept(NodeIf expr)
        {
            var condition = expr.condition;

            expr.pass.isResultRequired = expr.isResultRequired;
            expr.pass.inTailPosition = expr.inTailPosition;
            if (expr.fail != null)
            {
                expr.fail.isResultRequired = expr.isResultRequired;
                expr.fail.inTailPosition = expr.inTailPosition;
            }

            // Disable scopes, we'll do them ourselves
            if (expr.pass is NodeBlock)
                (expr.pass as NodeBlock).createScope = false;
            if (expr.fail != null && expr.fail is NodeBlock)
                (expr.fail as NodeBlock).createScope = false;

            builder.StartScope();
            uint failLoc;
            /*
            if (condition is NodeInfix && (condition as NodeInfix).op == "==")
            {

            }
            else if (condition is NodeInfix && (condition as NodeInfix).op == "!=")
            {

            }
            else // */
            {
                condition.Visit(this);
                failLoc = builder.InsnCount;
                if (expr.not)
                    builder.OpJumpT(0);
                else builder.OpJumpF(0);
            }

            expr.pass.Visit(this);
            builder.EndScope();

            if (expr.fail != null)
            {
                uint passLoc = builder.OpJump(0);
                builder.SetOpC(failLoc, builder.InsnCount);
                builder.StartScope();
                expr.fail.Visit(this);
                builder.EndScope();
                builder.SetOpC(passLoc, builder.InsnCount);
            }
            else
            {
                builder.SetOpC(failLoc, builder.InsnCount);
                if (expr.isResultRequired)
                    builder.OpNull();
            }
        }
示例#3
0
 void ASTVisitor.Accept(NodeIf value)
 {
     Accept(value);
 }
示例#4
0
文件: Parser.cs 项目: LayeLang/Laye
        private Node ParseIf()
        {
            var expr = new NodeIf(Location);
            Advance();

            // if not (condition) is allowed and handled specially.
            if (Check(NOT))
            {
                expr.not = true;
                Advance();
            }

            // Conditions must be in braces ()
            Expect(OPEN_BRACE, "An open brace ('(') is expected to start the condition of an 'if' expression.");
            if (!TokensRemain)
            {
                log.Error(expr.location, "Expected expression for 'if' condition, but the end of the file was reached.");
                return expr;
            }
            expr.condition = Expression();
            Expect(CLOSE_BRACE, "A close brace (')') is expected to end the condition of an 'if' expression.");

            // Get the body:
            if (!TokensRemain)
            {
                log.Error(expr.location, "Expected expression for 'if' body, but the end of the file was reached.");
                return expr;
            }
            expr.pass = Expression();

            // Check for an 'el' (fail) condition
            if (Check(EL))
            {
                Advance();
                if (!TokensRemain)
                {
                    log.Error(expr.location, "Expected expression for 'el' body, but the end of the file was reached.");
                    return expr;
                }
                expr.fail = Expression();
            }

            return expr;
        }