Exemplo n.º 1
0
        public override Value ModulusDivide(RunScope scope, Span span, Value rightValue)
        {
            if (_time.HasValue)
            {
                var right = rightValue.ToTime(scope, span);
                if (right.HasValue)
                {
                    var rightNum = right.Value.Ticks;
                    if (rightNum == 0)
                    {
                        scope.CodeAnalyzer.ReportError(span, CAError.CA0051);                           // Division by zero.
                        return(new TimeValue(DataType, null));
                    }

                    var result = _time.Value.Ticks % rightNum;
                    if (result < 0 || result > 43200)
                    {
                        scope.CodeAnalyzer.ReportError(span, CAError.CA0054);                           // Time math results in an out-of-bounds value.
                        return(new TimeValue(DataType, null));
                    }

                    return(new TimeValue(DataType, new DkTime(result)));
                }
            }

            return(new TimeValue(DataType, null));
        }
Exemplo n.º 2
0
        public override Value ModulusDivide(RunScope scope, Span span, Value rightValue)
        {
            var left = ToNumber(scope, span);

            if (left.HasValue)
            {
                var right = rightValue.ToNumber(scope, span);
                if (right.HasValue)
                {
                    if (right.Value == 0)
                    {
                        scope.CodeAnalyzer.ReportError(span, CAError.CA0051);                           // Division by zero.
                        return(new DateValue(DataType, null));
                    }
                    else
                    {
                        var result = left.Value % right.Value;
                        if (result < 0 || result > 65535)
                        {
                            scope.CodeAnalyzer.ReportError(span, CAError.CA0052);                               // Date math results in an out-of-bounds value.
                            return(new DateValue(DataType, null));
                        }
                        else
                        {
                            return(new DateValue(DataType, result));
                        }
                    }
                }
            }

            return(new DateValue(DataType, null));
        }
Exemplo n.º 3
0
        protected override void Execute(RunScope scope)
        {
            var castScope = scope.Clone();

            base.Execute(castScope);
            scope.Merge(castScope);
        }
Exemplo n.º 4
0
        public override Value Divide(RunScope scope, Span span, Value rightValue)
        {
            if (_char.HasValue)
            {
                var right = rightValue.ToChar(scope, span);
                if (right.HasValue)
                {
                    var rightNum = (int)right.Value;
                    if (rightNum == 0)
                    {
                        scope.CodeAnalyzer.ReportError(span, CAError.CA0051);                           // Division by zero.
                        return(new CharValue(DataType, null));
                    }

                    var result = (int)_char.Value / rightNum;
                    if (result < 0 || result > 65535)
                    {
                        scope.CodeAnalyzer.ReportError(span, CAError.CA0056);                           // Char math results in an out-of-bounds value.
                        return(new CharValue(DataType, null));
                    }

                    return(new CharValue(DataType, (char)result));
                }
            }

            return(new CharValue(DataType, null));
        }
Exemplo n.º 5
0
        public override void Execute(RunScope scope)
        {
            base.Execute(scope);

            if (_initExp != null)
            {
                var initScope = scope.Clone();
                _initExp.ReadValue(initScope);
                scope.Merge(initScope);
            }

            if (_condExp != null)
            {
                var condScope = scope.Clone();
                _condExp.ReadValue(condScope);
                scope.Merge(condScope);
            }

            if (_incExp != null)
            {
                var incScope = scope.Clone();
                _incExp.ReadValue(incScope);
                scope.Merge(incScope);
            }

            var bodyScope = scope.Clone(canBreak: true, canContinue: true);

            foreach (var stmt in _body)
            {
                stmt.Execute(bodyScope);
            }
            scope.Merge(bodyScope, false, false);
        }
Exemplo n.º 6
0
 public override decimal?ToNumber(RunScope scope, Span span)
 {
     if (_time.HasValue)
     {
         return(_time.Value.Ticks);
     }
     return(null);
 }
Exemplo n.º 7
0
 public override decimal?ToNumber(RunScope scope, Span span)
 {
     if (_date.HasValue)
     {
         return((decimal)_date.Value.Number);
     }
     return(null);
 }
Exemplo n.º 8
0
 public override decimal?ToNumber(RunScope scope, Span span)
 {
     if (_ordinal.HasValue)
     {
         return((decimal)_ordinal.Value);
     }
     return(null);
 }
Exemplo n.º 9
0
 public override decimal?ToNumber(RunScope scope, Span span)
 {
     if (_char != null)
     {
         return((decimal)((int)_char.Value));
     }
     return(null);
 }
Exemplo n.º 10
0
 public override string ToStringValue(RunScope scope, Span span)
 {
     if (_char != null)
     {
         return(_char.Value.ToString());
     }
     return(null);
 }
Exemplo n.º 11
0
 public override string ToStringValue(RunScope scope, Span span)
 {
     if (_num.HasValue)
     {
         return(_num.Value.ToString());
     }
     return(null);
 }
Exemplo n.º 12
0
		protected virtual void Execute(RunScope scope)
		{
			var reduceRetries = 3;

			while (true)
			{
				// Find the highest precedence
				var highestPrec = 0;
				foreach (var node in _nodes)
				{
					var prec = node.Precedence;
					if (prec != 0)
					{
						if (highestPrec < prec) highestPrec = prec;
					}
				}

				if (highestPrec == 0) return;
				var numNodesWithPrec = _nodes.Count(n => n.Precedence != 0);

				if (highestPrec % 2 == 0)
				{
					// Left-to-right associativity
					foreach (var node in _nodes)
					{
						if (node.Precedence == highestPrec)
						{
							node.Simplify(scope);
							break;
						}
					}
				}
				else
				{
					// Right-to-left associativity
					for (int i = _nodes.Count - 1; i >= 0; i--)
					{
						var node = _nodes[i];
						if (node.Precedence == highestPrec)
						{
							node.Simplify(scope);
							break;
						}
					}
				}

				// Sanity check to avoid infinite loop
				var afterNum = _nodes.Count(n => n.Precedence != 0);
				if (afterNum == numNodesWithPrec)
				{
					if (--reduceRetries == 0) throw new CAException("Number of nodes with precedence did not change during iteration.");
				}
				else
				{
					reduceRetries = 3;
				}
			}
		}
Exemplo n.º 13
0
        private Value Read_sum(RunScope scope)
        {
            if (_args.Count < 1 || _args.Count > 2)
            {
                ReportError(_funcNameSpan, CAError.CA0057, "1 or 2");                   // Function expects {0} argument(s).
            }

            return(Value.CreateUnknownFromDataType(DataType.Int));
        }
Exemplo n.º 14
0
        public override Value Invert(RunScope scope, Span span)
        {
            if (_num.HasValue)
            {
                return(new NumberValue(DataType, -_num.Value));
            }

            return(new NumberValue(DataType, null));
        }
Exemplo n.º 15
0
        private Value Read_min(RunScope scope)
        {
            if (_args.Count != 1)
            {
                ReportError(_funcNameSpan, CAError.CA0057, 1);                  // Function expects {0} argument(s).
            }

            return(Value.CreateUnknownFromDataType(_args[0].ReadValue(scope).DataType));
        }
Exemplo n.º 16
0
 public override DkTime?ToTime(RunScope scope, Span span)
 {
     scope.CodeAnalyzer.ReportError(span, CAError.CA0055, "char", "time");               // Converting {0} to {1}.
     if (_char.HasValue)
     {
         return(new DkTime((int)_char.Value));
     }
     return(null);
 }
Exemplo n.º 17
0
        public override DkTime?ToTime(RunScope scope, Span span)
        {
            if (_ordinal.HasValue)
            {
                return(new DkTime(_ordinal.Value));
            }

            return(null);
        }
Exemplo n.º 18
0
        public override void Execute(RunScope scope)
        {
            base.Execute(scope);

            foreach (var exp in _colExps)
            {
                exp.ReadValue(scope);
            }
        }
Exemplo n.º 19
0
 public override char?ToChar(RunScope scope, Span span)
 {
     scope.CodeAnalyzer.ReportError(span, CAError.CA0055, "time", "char");               // Converting {0} to {1}.
     if (_time.HasValue)
     {
         return((char)_time.Value.Ticks);
     }
     return(null);
 }
Exemplo n.º 20
0
 public virtual void Execute(RunScope scope)
 {
     if (scope.Returned == TriState.True ||
         scope.Breaked == TriState.True ||
         scope.Continued == TriState.True)
     {
         ReportError(Span, CAError.CA0016);                      // Unreachable code.
     }
 }
Exemplo n.º 21
0
        public override Value ReadValue(RunScope scope)
        {
            if (_arrayAccessExps != null)
            {
                foreach (var exp in _arrayAccessExps)
                {
                    var accessScope = scope.Clone();
                    exp.ReadValue(accessScope);
                    scope.Merge(accessScope);
                }
            }

            if (_subscriptAccessExps != null)
            {
                foreach (var exp in _subscriptAccessExps)
                {
                    var accessScope = scope.Clone();
                    exp.ReadValue(accessScope);
                    scope.Merge(accessScope);
                }
            }

            if (_def is VariableDefinition)
            {
                var v = scope.GetVariable(Text);
                if (v != null)
                {
                    v.IsUsed = true;
                    if (v.IsInitialized != TriState.True && !scope.SuppressInitializedCheck)
                    {
                        ReportError(Span, CAError.CA0110, v.Name);                                                                                              // Use of uninitialized variable '{0}'.
                    }
                    return(v.Value);
                }

                return(base.ReadValue(scope));
            }
            else if (_def is EnumOptionDefinition)
            {
                return(new EnumValue(_def.DataType, _def.Name));
            }
            else if (_def is TableDefinition || _def is ExtractTableDefinition)
            {
                return(new TableValue(_def.DataType, _def.Name));
            }
            else if (_def is RelIndDefinition)
            {
                return(new IndRelValue(_def.DataType, _def.Name));
            }
            else if (_def.CanRead && _def.DataType != null)
            {
                return(Value.CreateUnknownFromDataType(_def.DataType));
            }

            return(base.ReadValue(scope));
        }
Exemplo n.º 22
0
        public override Value ReadValue(RunScope scope)
        {
            var castScope     = scope.Clone();
            var value         = base.ReadValue(castScope);
            var dataTypeValue = Value.CreateUnknownFromDataType(DataType);

            value = dataTypeValue.Convert(scope, Span, value);
            scope.Merge(castScope);
            return(value);
        }
Exemplo n.º 23
0
        public override Value Convert(RunScope scope, Span span, Value value)
        {
            var str = value.ToStringValue(scope, span);

            if (str != null && DataType.IsValidEnumOption(str))
            {
                return(new EnumValue(DataType, str));
            }
            return(new EnumValue(DataType, null, null));
        }
Exemplo n.º 24
0
        public override Value Convert(RunScope scope, Span span, Value value)
        {
            var str = value.ToStringValue(scope, span);

            if (str != null && str.Length == 1)
            {
                return(new CharValue(DataType, str[0]));
            }
            return(new CharValue(DataType, null));
        }
Exemplo n.º 25
0
		public override void Execute(RunScope scope)
		{
			var headerScope = scope.Clone();
			foreach (var stmt in _body)
			{
				stmt.Execute(headerScope);
			}
			// Don't merge the headerScope back into the parent scope because there's no guarantees
			// the header is called asynchronously, or might not be called at all.
		}
Exemplo n.º 26
0
        public override DkDate?ToDate(RunScope scope, Span span)
        {
            scope.CodeAnalyzer.ReportError(span, CAError.CA0055, "time", "date");               // Converting {0} to {1}.

            if (_time.HasValue)
            {
                return(new DkDate(_time.Value.Ticks));
            }
            return(null);
        }
Exemplo n.º 27
0
        public override char?ToChar(RunScope scope, Span span)
        {
            scope.CodeAnalyzer.ReportError(span, CAError.CA0055, "string", "char");             // Converting {0} to {1}.

            if (_value != null && _value.Length == 1)
            {
                return(_value[0]);
            }

            return(null);
        }
Exemplo n.º 28
0
        public override void Execute(RunScope scope)
        {
            base.Execute(scope);

            if (!scope.CanBreak)
            {
                ReportError(Span, CAError.CA0023);                      // 'break' is not valid here.
                return;
            }

            scope.Breaked = TriState.True;
        }
Exemplo n.º 29
0
        public override void Execute(RunScope scope)
        {
            base.Execute(scope);

            if (_root.NumChildren > 0)
            {
                var readScope = scope.Clone();
                readScope.RemoveHeaderString = true;
                _root.ReadValue(readScope);
                scope.Merge(readScope);
            }
        }
Exemplo n.º 30
0
        public override void Execute(RunScope scope)
        {
            base.Execute(scope);

            if (!scope.CanContinue)
            {
                ReportError(Span, CAError.CA0024);                      // 'continue' is not valid here.
                return;
            }

            scope.Continued = TriState.True;
        }