Пример #1
0
 public override void Visit(WhenNode node)
 {
     if (node.Descendants.Length == 0)
     {
         ReportLackOfWhenReturnExpression(node);
     }
 }
Пример #2
0
        private WhenThenNode[] ComposeWhenThenNodes()
        {
            var nodes = new List <WhenThenNode>();

            while (!IsElseNode(Current))
            {
                WhenNode when = null;
                ThenNode then = null;

                switch (Current.TokenType)
                {
                case StatementType.When:
                    when = new WhenNode(ConsumeAndGetToken(), ComposeWhere());
                    goto case StatementType.Then;

                case StatementType.Then:
                    then = new ThenNode(ConsumeAndGetToken(), ComposeWhere());
                    break;

                default:
                    throw new NotSupportedException();
                }

                if (when == null || then == null)
                {
                    throw new NullReferenceException();
                }

                nodes.Add(new WhenThenNode(when, then));
            }

            return(nodes.ToArray());
        }
Пример #3
0
        /// <summary>
        ///     Visit When node in DFS manner.
        /// </summary>
        /// <param name="node">When node that will be visited.</param>
        public void Visit(WhenNode node)
        {
            while (_contextChangeTracker.Count > 0)
            {
                _contextChangeTracker.Pop();
                _scope = _scope.OuterScope;
            }

            _scope = new ScopeContext(_scope, _functionScopeTable, "when");
        }
Пример #4
0
        /// <summary>
        ///     Performs "When" specific operations.
        /// </summary>
        /// <param name="node">The "When" node.</param>
        public virtual void Visit(WhenNode node)
        {
            var elseNode = node.Parent.Parent.Else;

            if (node.Parent.ArrayOrder == node.Parent.Parent.WhenThenExpressions.Length - 1) //is last node.
            {
                Instructions.Add(new JumpToLabelNotEqual($"else_{elseNode.FullSpan.Start}{elseNode.FullSpan.End}"));
            }
            else
            {
                var nextWhenNode = node.Parent.Parent.Descendants[node.Parent.ArrayOrder + 1];
                Instructions.Add(
                    new JumpToLabelNotEqual($"when_{nextWhenNode.FullSpan.Start}{nextWhenNode.FullSpan.End}"));
            }
        }
Пример #5
0
 private RuntimeResult VisitWhenNode(WhenNode node, Context context)
 {
     Values.Value variable = context.GetSymbol(node.Token.Value.ToString());
     if (variable == null)
     {
         return(new RuntimeResult(new RuntimeError(node.Token.Position, "Variable '" + node.Token.Value + "' not defined", context)));
     }
     for (int i = 0; i < node.Cases.Count; i++)
     {
         RuntimeResult condResult = Visit(node.Cases[i].Item1, context);
         if (condResult.HasError)
         {
             return(condResult);
         }
         if (condResult.Value.Equals(variable).Value.GetAsBoolean())
         {
             return(Visit(node.Cases[i].Item2, context));
         }
     }
     //if (node.ElseCase != null)
     //    return Visit(node.ElseCase, context);
     return(new RuntimeResult(new Values.NullValue().SetPositionAndContext(node.Token.Position, context)));
 }
Пример #6
0
 /// <summary>
 ///     Visit When node in DFS manner.
 /// </summary>
 /// <param name="node">When node that will be visited.</param>
 public virtual void Visit(WhenNode node)
 {
     node.Descendant.Accept(this);
     node.Accept(_visitor);
 }
Пример #7
0
 private void ReportLackOfWhenReturnExpression(WhenNode node)
 {
     AddSyntaxError(node.FullSpan, string.Format(AnalysisMessage.LackOfWhenReturnExpression, node.Parent),
                    SyntaxErrorKind.LackOfExpression);
 }
Пример #8
0
 public override void Visit(WhenNode node) => ProduceDebuggerInstructions(node, n => base.Visit(n));
Пример #9
0
 /// <summary>
 ///     Visit When node.
 /// </summary>
 /// <param name="node">When node of AST</param>
 public abstract void Visit(WhenNode node);
Пример #10
0
 /// <summary>
 ///     Visit When node in BFS manner.
 /// </summary>
 /// <param name="node">When node that will be visited.</param>
 public override void Visit(WhenNode node)
 {
     node.Accept(Visitor);
     node.Descendant.Accept(this);
     _contextChangeTracker.Push(true);
 }