private void CleanConditionBehaviorReferences()
 {
     this.ClearConditionList();
     this.conditions = (ISceneNodeCollection <SceneNode>)null;
     this.conditionalExpressionNode = (ConditionalExpressionNode)null;
     this.conditionBehaviorNode     = (ConditionBehaviorNode)null;
 }
Exemplo n.º 2
0
 protected override Void handleConditional(ConditionalExpressionNode conditional, Set <TypeInfo> dependencies, bool nested)
 {
     handleExpression(conditional.Condition, dependencies, true);
     handleExpression(conditional.IfTrue, dependencies, true);
     handleExpression(conditional.IfFalse, dependencies, true);
     return(null);
 }
Exemplo n.º 3
0
            public bool VisitConditionalExpressionNode(ConditionalExpressionNode node, CompilationState state)
            {
                EncapsulateOrNot(state, node.Condition);
                state.Write(" and ");
                EncapsulateOrNot(state, node.IfYes);
                state.Write(" or ");
                EncapsulateOrNot(state, node.IfNo);

                return(true);
            }
        internal void AddConditionNode()
        {
            if (!this.EnsureInteractionsAssemblyReferenced() || this.behaviorTriggerBaseNode == null)
            {
                return;
            }
            BehaviorTriggerBaseNode newTriggerParent = this.CloneCurrentTrigger();

            using (SceneEditTransaction editTransaction = this.sceneViewModel.CreateEditTransaction(StringTable.AddConditionUndo))
            {
                ISceneNodeCollection <SceneNode> collectionForProperty = newTriggerParent.GetCollectionForProperty(BehaviorHelper.BehaviorsProperty);
                this.conditionalExpressionNode = (ConditionalExpressionNode)null;
                this.conditionBehaviorNode     = (ConditionBehaviorNode)null;
                foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)collectionForProperty)
                {
                    if (ProjectNeutralTypes.ConditionBehavior.IsAssignableFrom((ITypeId)sceneNode.TrueTargetTypeId))
                    {
                        ConditionBehaviorNode     conditionBehaviorNode     = (ConditionBehaviorNode)sceneNode;
                        ConditionalExpressionNode conditionalExpressionNode = conditionBehaviorNode.ConditionAsConditionalExpressionNode;
                        if (conditionalExpressionNode != null)
                        {
                            this.conditionBehaviorNode     = conditionBehaviorNode;
                            this.conditionalExpressionNode = conditionalExpressionNode;
                            break;
                        }
                    }
                }
                if (this.conditionBehaviorNode == null)
                {
                    this.conditionBehaviorNode = (ConditionBehaviorNode)this.sceneViewModel.CreateSceneNode(ProjectNeutralTypes.ConditionBehavior);
                    collectionForProperty.Add((SceneNode)this.conditionBehaviorNode);
                    this.conditionalExpressionNode = (ConditionalExpressionNode)this.sceneViewModel.CreateSceneNode(ProjectNeutralTypes.ConditionalExpression);
                    this.conditionBehaviorNode.ConditionAsConditionalExpressionNode = this.conditionalExpressionNode;
                }
                this.conditions = this.conditionalExpressionNode.Conditions;
                if (this.conditions != null)
                {
                    this.conditions.Add(this.sceneViewModel.CreateSceneNode(ProjectNeutralTypes.ComparisonCondition));
                }
                if (this.behaviorTriggerBaseNode.Actions.Count > 1)
                {
                    this.objectSet.ReparentActionAndCopyBehaviors(newTriggerParent);
                    this.behaviorTriggerBaseNode = newTriggerParent;
                }
                else
                {
                    SceneNode valueAsSceneNode = newTriggerParent.GetLocalValueAsSceneNode(BehaviorHelper.BehaviorsProperty);
                    valueAsSceneNode.Remove();
                    this.behaviorTriggerBaseNode.SetValueAsSceneNode(BehaviorHelper.BehaviorsProperty, valueAsSceneNode);
                }
                editTransaction.Commit();
            }
            this.Rebuild();
            this.Expanded = true;
        }
            protected override AssignmentState handleConditional(ConditionalExpressionNode conditional, HashSet <StatementNode> visited,
                                                                 bool nested)
            {
                switch (handleExpression(conditional.Condition, visited, true))
                {
                case Assigned:
                    return(AssignmentState.Assigned);

                case AssignedAfterTrue:
                    if (handleExpression(conditional.IfFalse, visited, true) == AssignmentState.Assigned)
                    {
                        return(AssignmentState.Assigned);
                    }
                    break;

                case AssignedAfterFalse:
                    if (handleExpression(conditional.IfTrue, visited, true) == AssignmentState.Assigned)
                    {
                        return(AssignmentState.Assigned);
                    }
                    break;

                default:
                    var cinfo = conditional.Condition.getUserData(typeof(ExpressionInfo));
                    if (cinfo.IsConstant)
                    {
                        if ((Boolean)cinfo.Value)
                        {
                            return(handleExpression(conditional.IfTrue, visited, true));
                        }
                        else
                        {
                            return(handleExpression(conditional.IfFalse, visited, true));
                        }
                    }
                    var ts = handleExpression(conditional.IfTrue, visited, true);
                    var fs = handleExpression(conditional.IfFalse, visited, true);
                    if (ts == AssignmentState.Assigned && fs == AssignmentState.Assigned)
                    {
                        return(AssignmentState.Assigned);
                    }
                    break;
                }
                return(AssignmentState.NotAssigned);
            }
 private void Rebuild()
 {
     if (this.behaviorTriggerBaseNode == null)
     {
         return;
     }
     this.CleanConditionBehaviorReferences();
     if (this.behaviorTriggerBaseNode.IsSet(BehaviorHelper.BehaviorsProperty) == PropertyState.Set)
     {
         foreach (SceneNode sceneNode in (IEnumerable <SceneNode>) this.behaviorTriggerBaseNode.GetCollectionForProperty(BehaviorHelper.BehaviorsProperty))
         {
             if (ProjectNeutralTypes.ConditionBehavior.IsAssignableFrom((ITypeId)sceneNode.Type))
             {
                 this.conditionBehaviorNode = (ConditionBehaviorNode)sceneNode;
                 ConditionalExpressionNode conditionalExpressionNode = this.conditionBehaviorNode.ConditionAsConditionalExpressionNode;
                 if (conditionalExpressionNode != null)
                 {
                     this.conditionalExpressionNode = conditionalExpressionNode;
                     this.conditions = this.conditionalExpressionNode.Conditions;
                     break;
                 }
             }
         }
     }
     this.ConditionUIAvailable = true;
     if (this.ConditionsNodeView != null && this.conditions != null)
     {
         foreach (SceneNode condition in (IEnumerable <SceneNode>) this.conditions)
         {
             PropertyEntry entryForCondition = this.CreatePropertyEntryForCondition(condition);
             this.ConditionNodes.Add(entryForCondition);
             if (entryForCondition.PropertyValue.SubProperties.Count == 0)
             {
                 this.ConditionUIAvailable = false;
                 this.CleanConditionBehaviorReferences();
                 break;
             }
         }
     }
     this.ConditionsNodeView.MoveCurrentToLast();
     this.OnPropertyChanged("ConditionsNodeView");
     this.OnPropertyChanged("ForwardChainingSetToOr");
     this.OnPropertyChanged("ForwardChainingSetToOrEnabled");
     this.OnPropertyChanged("ConditionUIAvailable");
 }
Exemplo n.º 7
0
        private object EvaluateNode(ConditionalExpressionNode expression, Context context)
        {
            var condition = EvaluateNode(expression.cond, context);

            if (expression.no != null && expression.yes != null)
            {
                if ((bool)condition)
                {
                    return(EvaluateNode(expression.yes, context));
                }
                else
                {
                    return(EvaluateNode(expression.no, context));
                }
            }
            else
            {
                return(condition);
            }
        }
 public virtual Value evaluate(Context cx, ConditionalExpressionNode node)
 {
     output("<ConditionalExpressionNode position=\"" + node.pos() + "\">");
     indent_Renamed_Field++;
     if (node.condition != null)
     {
         node.condition.evaluate(cx, this);
     }
     if (node.thenexpr != null)
     {
         node.thenexpr.evaluate(cx, this);
     }
     if (node.elseexpr != null)
     {
         node.elseexpr.evaluate(cx, this);
     }
     indent_Renamed_Field--;
     output("</ConditionalExpressionNode>");
     return(null);
 }
Exemplo n.º 9
0
        private static void ParseNodeIf(ScriptProgram program, Node root, TokenStream stream)
        {
            var node = new ConditionalExpressionNode();

            root.AddChildNode(node);

            while (stream.GetCurrent().TokenType == SemanticTokenType.NodeParameter)
            {
                var parameter = stream.Pop();
                if (parameter.TokenValue == "expr:")
                {
                    node.Expression = ParseExpression(program.GlobalVariables, stream);
                }
                else
                {
                    throw new Exception("Invalid token parameter value");
                }
            }

            ParseNodeChildren(program, node, stream);
        }
Exemplo n.º 10
0
        private static PythonNode Wrap(ConditionalExpression exp, PythonNode parent)
        {
            var result = new ConditionalExpressionNode(exp)
            {
                Parent = parent
            };

            if (exp.Test != null)
            {
                result.AddChild(Wrap(exp.Test, result));
            }
            if (exp.FalseExpression != null)
            {
                result.AddChild(Wrap(exp.FalseExpression, result));
            }
            if (exp.TrueExpression != null)
            {
                result.AddChild(Wrap(exp.TrueExpression, result));
            }
            return(result);
        }
Exemplo n.º 11
0
 public virtual XzaarExpression Visit(ConditionalExpressionNode node)
 {
     return(null);
 }
Exemplo n.º 12
0
        public override object VisitExpr(Z80AsmParser.ExprContext context)
        {
            if (context == null)
            {
                return(null);
            }

            // --- Extract the expression text
            var sb = new StringBuilder(400);

            for (var i = 0; i < context.ChildCount; i++)
            {
                var token = context.GetChild(i).GetText();
                sb.Append(token);
            }

            ExpressionNode expr = null;

            switch (context)
            {
            // --- Primary operators
            case Z80AsmParser.BuiltInFunctionExprContext ctx:
                expr = (ExpressionNode)VisitBuiltinFunctionInvocation(ctx.builtinFunctionInvocation());
                break;

            case Z80AsmParser.FunctionInvocationExprContext ctx:
                expr = new FunctionInvocationNode(ctx.functionInvocation(), this);
                break;

            case Z80AsmParser.MacroParamExprContext ctx:
                expr = new MacroParamNode(ctx.macroParam(), this);
                break;

            // --- Unary operators
            case Z80AsmParser.UnaryPlusExprContext ctx:
                expr = new UnaryPlusNode(ctx, this);
                break;

            case Z80AsmParser.UnaryMinusExprContext ctx:
                expr = new UnaryMinusNode(ctx, this);
                break;

            case Z80AsmParser.BinaryNotExprContext ctx:
                expr = new UnaryBitwiseNotNode(ctx, this);
                break;

            case Z80AsmParser.LogicalNotExprContext ctx:
                expr = new UnaryLogicalNotNode(ctx, this);
                break;

            // --- Bracketed/Parenthesized expressions
            case Z80AsmParser.BracketedExprContext ctx:
                expr = (ExpressionNode)VisitExpr(ctx.expr());
                break;

            case Z80AsmParser.ParenthesizedExprContext ctx:
                expr = (ExpressionNode)VisitExpr(ctx.expr());
                break;

            // --- Literals
            case Z80AsmParser.LiteralExprContext ctx:
                expr = (ExpressionNode)VisitLiteral(ctx.literal());
                break;

            case Z80AsmParser.SymbolExprContext ctx:
                if (ctx.ChildCount != 0 && ctx.symbol()?.IDENTIFIER() != null)
                {
                    AddIdentifier(ctx);
                    expr = new IdentifierNode(ctx.symbol());
                }
                break;

            // --- Min/Max operators
            case Z80AsmParser.MinMaxExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<?":
                    expr = new MinOperationNode(ctx, this);
                    break;

                default:
                    expr = new MaxOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Multiplication operators
            case Z80AsmParser.MultExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "*":
                    expr = new MultiplyOperationNode(ctx, this);
                    break;

                case "/":
                    expr = new DivideOperationNode(ctx, this);
                    break;

                default:
                    expr = new ModuloOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Addition operators
            case Z80AsmParser.AddExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "+":
                    expr = new AddOperationNode(ctx, this);
                    break;

                default:
                    expr = new SubtractOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Shift operators
            case Z80AsmParser.ShiftExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<<":
                    expr = new ShiftLeftOperationNode(ctx, this);
                    break;

                default:
                    expr = new ShiftRightOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Relational operators
            case Z80AsmParser.RelExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "<":
                    expr = new LessThanOperationNode(ctx, this);
                    break;

                case "<=":
                    expr = new LessThanOrEqualOperationNode(ctx, this);
                    break;

                case ">":
                    expr = new GreaterThanOperationNode(ctx, this);
                    break;

                default:
                    expr = new GreaterThanOrEqualOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Equality operators
            case Z80AsmParser.EquExprContext ctx:
                switch (ctx.op?.Text)
                {
                case "==":
                    expr = new EqualOperationNode(ctx, this);
                    break;

                case "===":
                    expr = new CaseInsensitiveEqualOperationNode(ctx, this);
                    break;

                case "!=":
                    expr = new NotEqualOperationNode(ctx, this);
                    break;

                default:
                    expr = new CaseInsensitiveNotEqualOperationNode(ctx, this);
                    break;
                }
                break;

            // --- Bitwise operators
            case Z80AsmParser.AndExprContext ctx:
                expr = new BitwiseAndOperationNode(ctx, this);
                break;

            case Z80AsmParser.XorExprContext ctx:
                expr = new BitwiseXorOperationNode(ctx, this);
                break;

            case Z80AsmParser.OrExprContext ctx:
                expr = new BitwiseOrOperationNode(ctx, this);
                break;

            // --- Ternary operator
            case Z80AsmParser.TernaryExprContext ctx:
                expr = new ConditionalExpressionNode(ctx, this);
                break;
            }

            if (expr != null)
            {
                expr.SourceText = sb.ToString();
            }
            return(expr);
        }
Exemplo n.º 13
0
 private ExpressionNode parseConditionalExpression() {
     var filename = scanner.Filename;
     var line = scanner.StartLine;
     var column = scanner.StartColumn;
     var disabledWarnings = scanner.CodeErrorManager.DisabledWarnings;
     var startPosition = scanner.StartPosition;
     
     var result = parseBinaryExpression();
     if (lexicalUnit == LexicalUnit.QuestionMark) {
         nextLexicalUnit(true);
         var ifTrue = parseExpression();
         if (lexicalUnit != LexicalUnit.Colon) {
             throw error(ParseErrorId.ColonExpected);
         }
         nextLexicalUnit(true);
         var expr = new ConditionalExpressionNode { Filename = filename, Line = line, Column = column, DisabledWarnings = disabledWarnings,
                 StartPosition = startPosition, Condition = result, IfTrue = ifTrue, IfFalse = parseExpression() };
         expr.EndPosition = expr.IfFalse.EndPosition;
         result = expr;
     }
     return result;
 }
		public virtual Value evaluate(Context cx, ConditionalExpressionNode node)
		{
			output("<ConditionalExpressionNode position=\"" + node.pos() + "\">");
			indent_Renamed_Field++;
			if (node.condition != null)
			{
				node.condition.evaluate(cx, this);
			}
			if (node.thenexpr != null)
			{
				node.thenexpr.evaluate(cx, this);
			}
			if (node.elseexpr != null)
			{
				node.elseexpr.evaluate(cx, this);
			}
			indent_Renamed_Field--;
			output("</ConditionalExpressionNode>");
			return null;
		}
Exemplo n.º 15
0
        private static Node ConstuctNode(BinaryReader br, Guid id, NodeType nodeType, CommandType commandType)
        {
            //Console.WriteLine(nodeType);
            switch (nodeType)
            {
            case NodeType.Script:
            {
                var scriptNode = new ScriptNode();
                scriptNode.Id = id;
                scriptNode.readData(br);
                return(scriptNode);
            }

            case NodeType.Page:
            {
                var pageNode = new PageNode();
                pageNode.Id = id;
                pageNode.readData(br);
                return(pageNode);
            }

            case NodeType.OnceOnly:
            {
                var onceOnly = new OnceOnlyNode();
                onceOnly.Id = id;
                onceOnly.readData(br);
                return(onceOnly);
            }

            case NodeType.ConditionalTrue:
            {
                var node = new ConditionalTrueNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ConditionalFalse:
            {
                var node = new ConditionalFalseNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.OptionsChoice:
            {
                var node = new ShowOptionsNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.Option:
            {
                var node = new OptionNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ParallelNode:
            {
                var node = new ParallelNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.BlockNode:
            {
                var node = new BlockNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.ConditionalIf:
            {
                var node = new ConditionalExpressionNode();
                node.Id = id;
                node.readData(br);
                return(node);
            }

            case NodeType.Command:
            {
                switch (commandType)
                {
                case CommandType.Say:
                {
                    var command = new SayNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.CallPage:
                {
                    var command = new CallPageNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Return:
                {
                    var command = new ReturnNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Wait:
                {
                    var command = new WaitNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.Print:
                {
                    var command = new PrintNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                case CommandType.SetVar:
                {
                    var command = new SetVarNode();
                    command.Id = id;
                    command.readData(br);
                    return(command);
                }

                default:
                    throw new Exception("Unhandled Node Type:" + nodeType + ":" + commandType);
                }
            }

            // case NodeType.Say
            default:
                throw new Exception("Unhandled Node Type:" + nodeType);
            }
            return(null);
        }