Example #1
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));
        }
Example #2
0
        public override void WriteValue(RunScope scope, Value value)
        {
            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.Value         = v.Value.Convert(scope, Span, value);
                    v.IsInitialized = TriState.True;
                    return;
                }

                base.WriteValue(scope, value);
            }
            else if (_def.CanWrite)
            {
            }
            else
            {
                base.WriteValue(scope, value);
            }
        }