Esempio n. 1
0
        private bool _readBeforeInitialized; // the variable is read before it's initialized and therefore needs an init check

        #endregion Fields

        #region Constructors

        public TotemVariable(string name, VariableKind kind, ScopeStatement/*!*/ scope)
        {
            Assert.NotNull(scope);
            _name = name;
            _kind = kind;
            _scope = scope;
        }
Esempio n. 2
0
 public PythonVariable(SymbolId name, Type/*!*/ type, VariableKind kind, ScopeStatement/*!*/ scope) {
     Assert.NotNull(type, scope);
     _name = name;
     _type = type;
     _kind = kind;
     _scope = scope;
 }
Esempio n. 3
0
        public TotemVariable(string name, VariableKind kind, ScopeStmt scope)
        {
            ContractUtils.RequiresNotNull(scope, "totemCode");

            _name = name;
            _kind = kind;
            _scope = scope;
        }
Esempio n. 4
0
        private Variable(SymbolId name, VariableKind kind, CodeBlock block, Type type, Expression defaultValue, bool parameterArray)
        {
            _name = name;
            _kind = kind;
            _block = block;

            Debug.Assert(new List<Variable>(block.Variables).Find(x => x.Name == name) == null);

            // enables case:
            //
            // temp = CreateVariable(..., expression.Type, ...)
            // Ast.Assign(temp, expression)
            //
            // where Type is void.
            _type = (type != typeof(void)) ? type : typeof(object);

            _defaultValue = defaultValue;
            _parameterArray = parameterArray;
        }
Esempio n. 5
0
        BoundVariable CreateVariable(VariableName name, VariableKind kind, Func<BoundExpression> initializer)
        {
            switch (kind)
            {
                case VariableKind.LocalVariable:
                    Debug.Assert(initializer == null);
                    return new BoundLocal(new SourceLocalSymbol(_routine, name.Value, kind));

                case VariableKind.StaticVariable:
                    return new BoundStaticLocal(new SourceLocalSymbol(_routine, name.Value, kind), initializer?.Invoke());

                case VariableKind.GlobalVariable:
                    Debug.Assert(initializer == null);
                    return new BoundGlobalVariable(name);

                default:
                    Debug.Assert(initializer == null);
                    throw Roslyn.Utilities.ExceptionUtilities.UnexpectedValue(kind);
            }
        }
Esempio n. 6
0
 //internal TotemReference Reference(string name)
 //{
 //    if (_references == null)
 //    {
 //        _references = new Dictionary<string, TotemReference>(StringComparer.Ordinal);
 //    }
 //    TotemReference reference;
 //    if (!_references.TryGetValue(name, out reference))
 //    {
 //        _references[name] = reference = new TotemReference(name);
 //    }
 //    return reference;
 //}
 //internal bool IsReferenced(string name)
 //{
 //    TotemReference reference;
 //    return _references != null && _references.TryGetValue(name, out reference);
 //}
 internal TotemVariable CreateVariable(string name, VariableKind kind)
 {
     EnsureVariables();
     Debug.Assert(!_variables.ContainsKey(name));
     TotemVariable variable;
     _variables[name] = variable = new TotemVariable(name, kind, this);
     return variable;
 }
Esempio n. 7
0
        private bool _uninitialized;    // Variable ever used either uninitialized or after deletion

        private Variable(SymbolId name, VariableKind kind, CodeBlock block, Type type, Expression defaultValue)
            : this(name, kind, block, type, defaultValue, true)
        {
        }
Esempio n. 8
0
 internal static Variable Create(SymbolId name, VariableKind kind, CodeBlock block, Type type, Expression defaultValue)
 {
     Contract.Requires(defaultValue == null || TypeUtils.CanAssign(type, defaultValue.Type));
     Contract.Requires(kind != VariableKind.Parameter, "kind");
     return(new Variable(name, kind, block, type, defaultValue));
 }
 public GetVariableOption(VariableKind kind, string defaultName = null) : base(kind, defaultName)
 {
 }
 public SetDictionaryVariableItemNodeOption(VariableKind kind, string defaultName = null) : base(kind, defaultName)
 {
 }
Esempio n. 11
0
        public ILVariable RegisterVariable(VariableKind kind, StackType stackType, string name = null)
        {
            var type = Method.Compilation.FindType(stackType.ToKnownTypeCode());

            return(RegisterVariable(kind, type, stackType, name));
        }
Esempio n. 12
0
 public VariableSymbol(string name, SourceRange source, Type type, VariableKind kind)
 => (Name, Source, Type, Kind) = (name, source, type, kind);
Esempio n. 13
0
 public BoxedVariable(bool slack)
 {
     this.var      = default(Variable);
     this.innerVar = new InnerVariable();
     this.varKind  = slack ? VariableKind.Slack: VariableKind.NoFramework;
 }
Esempio n. 14
0
 protected IDisposable NameRefTag(VariableKind kind, string name = null, string fullName = null)
 {
     return(Tag(NameRefElementName, VariableKindAttribute(kind), NameAttribute(name), FullNameAttribute(fullName)));
 }
Esempio n. 15
0
 protected RDomBaseVariable(string name, string typeName, IExpression initializer, bool isImplicitlyTyped, bool isAliased, VariableKind variableKind)
     : this(name, initializer, isImplicitlyTyped, isAliased, variableKind)
 {
     _type = new RDomReferencedType(this, typeName, isAliased);
 }
 /// <summary>
 /// Returns the name of the given variable kind.
 /// </summary>
 /// <param name="variableKind">The variable kind whose name is to be returned.</param>
 /// <returns></returns>
 public static string VariableKindName(VariableKind variableKind)
 {
     return(CNTKLib.VariableKindName(variableKind));
 }
Esempio n. 17
0
 private RDomBaseVariable(string name, IExpression initializer, bool isImplicitlyTyped, bool isAliased, VariableKind variableKind)
     : base()
 {
     _name              = name;
     _initializer       = initializer;
     _isImplicitlyTyped = IsImplicitlyTyped;
     _isAliased         = isAliased;
     _variableKind      = variableKind;
 }
        public static void Add(ListView view, string sfOffset, string name, string type, string value, VariableKind kind, IntPtr sf, IntPtr pc, int callDepth)
        {
            var s = new SFItem {
                Name = name, SFOffset = sfOffset, Type = type, Value = value, Kind = kind, SF = sf, PC = pc, CallDepth = callDepth
            };
            var item = new ListViewItem {
                Content = s
            };

            switch (kind)
            {
            case VariableKind.Global:
                item.Foreground = Brushes.DimGray;
                break;

            case VariableKind.Input:
                item.Foreground = Brushes.Black;
                break;

            case VariableKind.Output:
                item.Foreground = Brushes.Black;
                break;

            case VariableKind.Local:
                item.Foreground = Brushes.Black;
                break;

            case VariableKind.Pseudo:
                item.Foreground = Brushes.Red;
                break;
            }

            view.Items.Add(item);
        }
Esempio n. 19
0
 /// <summary>
 /// Create virtual reference according to originatedVariable
 /// </summary>
 /// <param name="originatedVariable">Variable determining reference target</param>
 /// <param name="kind">Kind of virtual reference</param>
 /// <param name="stamp">Context stamp of virtual reference</param>
 internal VirtualReference(VariableName originatedVariable, VariableKind kind, int stamp)
 {
     OriginatedVariable = originatedVariable;
     Kind         = kind;
     ContextStamp = stamp;
 }
Esempio n. 20
0
 public ZVariable(VariableKind variableKind)
 {
     _variableKind = variableKind;
 }
Esempio n. 21
0
 internal static Variable Create(SymbolId name, VariableKind kind, CodeBlock block, Type type)
 {
     return Create(name, kind, block, type, null);
 }
Esempio n. 22
0
 /*!*/
 internal JVariable CreateVariable(string name, VariableKind kind)
 {
     EnsureVariables();
     JVariable variable;
     _variables[name] = variable = new JVariable(name, kind, this);
     return variable;
 }
Esempio n. 23
0
 internal static Variable Create(SymbolId name, VariableKind kind, CodeBlock block, Type type, Expression defaultValue)
 {
     Contract.Requires(defaultValue == null || TypeUtils.CanAssign(type, defaultValue.Type));
     Contract.Requires(kind != VariableKind.Parameter, "kind");
     return new Variable(name, kind, block, type, defaultValue);
 }
Esempio n. 24
0
        private Variable(int index, Type type, VariableKind kind, string name)
        {
            this.index = index;

            this.type = type;
            this.kind = kind;
            this.name = name;
            options = new OptionsHash();
            usersArray = new NodeArray();
        }
Esempio n. 25
0
 internal void LiftToClosure()
 {
     switch(_kind) {
         case VariableKind.Local:
         case VariableKind.Parameter:
             _lift = true;
             Block.HasEnvironment = true;
             break;
       case VariableKind.Temporary:
             _kind = VariableKind.Local;
             goto case VariableKind.Local;
         default:
             throw new InvalidOperationException(String.Format("Cannot lift variable of kind {0} to a closure ('{1}')", _kind, _name));
     }
 }
Esempio n. 26
0
        // Update a field in a table entry. Create new entry if necessary.
        // Returns null on success, otherwise error message.
        public string PutField(string parameterNameOrIndex, string fieldNameOrId, object value)
        {
            string result = null;

            if (!String.IsNullOrWhiteSpace(parameterNameOrIndex) && value != null)
            {
                DeviceParameter d     = Find(parameterNameOrIndex);
                bool            isNew = (d == null);
                if (isNew)
                {
                    d = new DeviceParameter(parameterNameOrIndex);
                }
                switch (DeviceParameter.GetFieldId(fieldNameOrId))
                {
                case DeviceParameter.FieldId.IndexField:
                    try {
                        int v = (int)value;
                        if (v >= 0)
                        {
                            if (!isNew && d.ParamIndex >= 0)
                            {
                                IndexTable.Remove(d.ParamIndex);
                            }
                            d.ParamIndex = v;
                            isNew        = true;
                        }
                        else
                        {
                            result = "Error: negative index.";
                        }
                    } catch (Exception) {
                        result = "Error: invalid index type.";
                    }
                    break;

                case DeviceParameter.FieldId.CategoryField:
                    try {
                        int v = (int)value;
                        if (v >= 0)
                        {
                            d.ParamCategory = v;
                        }
                        else
                        {
                            result = "Error: negative category.";
                        }
                    } catch (Exception) {
                        result = "Error: invalid category type.";
                    }
                    break;

                case DeviceParameter.FieldId.VariableKindField:
                    try {
                        VariableKind v = VariableValue.StringToVK(value.ToString());
                        d.ParamVarKind = v;
                        if (v == VariableKind.VK_None)
                        {
                            result = "Error: bad representation kind.";
                        }
                    } catch (Exception) {
                        result = "Error: invalid representation kind type.";
                    }
                    break;

                case DeviceParameter.FieldId.SizeField:
                    try {
                        int v = (int)value;
                        if (v >= 0)
                        {
                            d.ParamSize = v;
                        }
                        else
                        {
                            d.ParamSize = VariableValue.DataSize(d.ParamVarKind);
                        }
                    } catch (Exception) {
                        result = "Error: invalid size value.";
                    }
                    break;

                case DeviceParameter.FieldId.StorageFlagsField:
                    try {
                        StorageFlags v = VariableValue.StringToSF(value.ToString());
                        d.ParamStorageFlags = v;
                        if (v == StorageFlags.SF_None)
                        {
                            result = "Error: bad storage flags.";
                        }
                    } catch (Exception) {
                        result = "Error: invalid storage flags type.";
                    }
                    break;

                case DeviceParameter.FieldId.MinValueField:
                    try {
                        d.MinValue = new VariableValue(d.ParamVarKind, value.ToString());
                    } catch (Exception) {
                        result = "Error: invalid min value type.";
                    }
                    break;

                case DeviceParameter.FieldId.MaxValueField:
                    try {
                        d.MaxValue = new VariableValue(d.ParamVarKind, value.ToString());
                    } catch (Exception) {
                        result = "Error: invalid max value type.";
                    }
                    break;

                case DeviceParameter.FieldId.DefaultValueField:
                    try {
                        d.DefaultValue = new VariableValue(d.ParamVarKind, value.ToString());
                    } catch (Exception) {
                        result = "Error: invalid default value type.";
                    }
                    break;

                case DeviceParameter.FieldId.RamValueField:
                    try {
                        d.RamValue = new VariableValue(d.ParamVarKind, value.ToString());
                    } catch (Exception) {
                        result = "Error: invalid ram value type.";
                    }
                    break;

                case DeviceParameter.FieldId.EepromValueField:
                    try {
                        d.EEPromValue = new VariableValue(d.ParamVarKind, value.ToString());
                    } catch (Exception) {
                        result = "Error: invalid Eeprom value type.";
                    }
                    break;

                case DeviceParameter.FieldId.NameField:
                    try {
                        string s = value.ToString().Trim().ToLower();
                        if (!isNew && !String.IsNullOrWhiteSpace(d.ParamName))
                        {
                            NameTable.Remove(d.ParamName);
                        }
                        d.ParamName = s;
                        isNew       = true;
                    } catch (Exception) {
                        result = "Error: invalid index type.";
                    }
                    break;

                default:
                    result = "Error: invalid field name or Id.";
                    break;
                }
                if (isNew && result == null)
                {
                    Add(d);
                }
            }
            return(result);
        }
Esempio n. 27
0
        private bool _uninitialized; // Variable ever used either uninitialized or after deletion

        #endregion Fields

        #region Constructors

        private Variable(SymbolId name, VariableKind kind, CodeBlock block, Type type, Expression defaultValue)
            : this(name, kind, block, type, defaultValue, true)
        {
        }
Esempio n. 28
0
 protected BoundVariable(VariableKind kind)
 {
     this.VariableKind = kind;
 }
Esempio n. 29
0
 internal VariableDefinition(VariableDescriptor[] variables, Expression[] initializers, VariableKind kind)
 {
     _initializers = initializers;
     _variables    = variables;
     _kind         = kind;
 }
Esempio n. 30
0
 public PlusEqualNodeOption(VariableKind kind, string defaultName = null) : base(kind, defaultName)
 {
 }
Esempio n. 31
0
        /// <summary>
        /// Gets local variable or create local if not yet.
        /// </summary>
        public BoundVariable BindVariable(VariableName varname, VariableKind kind, Func<BoundExpression> initializer = null)
        {
            BoundVariable value;

            if (_dict.TryGetValue(varname, out value))
            {
                if (value.VariableKind != kind)
                {
                    // variable redeclared with a different kind
                    throw new ArgumentException("", nameof(kind));
                }
            }
            else
            {
                _dict[varname] = value = CreateVariable(varname, kind, initializer);
            }

            //
            Debug.Assert(value != null);
            return value;
        }
Esempio n. 32
0
 internal static Variable Create(SymbolId name, VariableKind kind, CodeBlock block, Type type)
 {
     return(Create(name, kind, block, type, null));
 }
Esempio n. 33
0
 internal PythonVariable/*!*/ CreateVariable(string name, VariableKind kind) {
     EnsureVariables();
     Debug.Assert(!_variables.ContainsKey(name));
     PythonVariable variable;
     _variables[name] = variable = new PythonVariable(name, kind, this);
     return variable;
 }
 public RDomVariableDeclaration( string name, IReferencedType type, IExpression initializer = null,
       bool isImplicitlyTyped = false, bool isAliased = false, VariableKind variableKind = VariableKind.Local)
     : base(name, type, initializer, isImplicitlyTyped, isAliased, variableKind)
 {
 }
Esempio n. 35
0
        private bool _accessedInNestedScope;    // the variable is accessed in a nested scope and therefore needs to be a closure var

        internal PythonVariable(string name, VariableKind kind, ScopeStatement/*!*/ scope) {
            _name = name;
            _kind = kind;
            _scope = scope;
        }
Esempio n. 36
0
 internal PythonVariable/*!*/ CreateVariable(string name, VariableKind kind) {
     EnsureVariables();
     PythonVariable variable;
     _variables[name] = variable = new PythonVariable(name, kind, this);
     return variable;
 }
Esempio n. 37
0
        private AttributeInfo VariableKindAttribute(VariableKind kind)
        {
            if (kind == VariableKind.None)
            {
                return AttributeInfo.Empty;
            }

            return new AttributeInfo(VariableKindAttributeName, GetVariableKindText(kind));
        }
Esempio n. 38
0
 public ZVariable(VariableKind variableKind, byte variableNumber)
     : this(variableKind)
 {
     _variableNumber = variableNumber;
 }
Esempio n. 39
0
 internal PythonVariable CreateVariable(SymbolId name, VariableKind kind) {
     EnsureVariables();
     Debug.Assert(!_variables.ContainsKey(name));
     PythonVariable variable;
     _variables[name] = variable = new PythonVariable(name, typeof(object), kind, this);
     return variable;
 }
        private bool _accessedInNestedScope;    // the variable is accessed in a nested scope and therefore needs to be a closure var

        internal PythonVariable(string name, VariableKind kind, ScopeStatement /*!*/ scope)
        {
            _name  = name;
            _kind  = kind;
            _scope = scope;
        }
Esempio n. 41
0
 public ILVariable RegisterVariable(VariableKind kind, IType type, string name = null)
 {
     return(RegisterVariable(kind, type, type.GetStackType(), name));
 }
Esempio n. 42
0
 protected IDisposable NameRefTag(VariableKind kind)
 {
     return Tag(NameRefElementName, VariableKindAttribute(kind));
 }
Esempio n. 43
0
        public static String Format(VariableKind kind, double val, int size)
        {
            switch (kind)
            {
            case VariableKind.VK_OnOff:
            case VariableKind.VK_Enum:
                return(String.Format("0x{0:x2}", (Byte)val));

            case VariableKind.VK_Bits:
                if (size < 0)
                {
                    size = DataSize(kind);
                }
                switch (size)
                {
                case 4:
                    return(String.Format("0x{0:x8}", (UInt32)val));

                case 2:
                    return(String.Format("0x{0:x4}", (UInt16)val));

                default:
                    return(String.Format("0x{0:x2}", (Byte)val));
                }

            case VariableKind.VK_Byte:
                return(String.Format("0x{0:x2}", (Byte)val));

            case VariableKind.VK_UShort:
                return(String.Format("0x{0:x4}", (ushort)val));

            case VariableKind.VK_UInt:
                return(String.Format("0x{0:x8}", (UInt32)val));

            case VariableKind.VK_ULong:
                return(String.Format("0x{0:x16}", (UInt64)val));

            case VariableKind.VK_ID:
                return(String.Format("0x{0:x8}", (UInt32)val));

            case VariableKind.VK_LID:
                return(String.Format("0x{0:x16}", (UInt64)val));

            case VariableKind.VK_String:
                return("\"" + DoubleToString(val) + "\"");

            case VariableKind.VK_Float:
                return(((float)val).ToString());

            case VariableKind.VK_Double:
                return(val.ToString());

            case VariableKind.VK_SByte:
            case VariableKind.VK_Short:
            case VariableKind.VK_Int:
            case VariableKind.VK_Long:
                return(val.ToString());

            default:
                break;
            }
            return("0");
        }
Esempio n. 44
0
 private static string GetVariableKindText(VariableKind kind)
 {
     switch (kind)
     {
         case VariableKind.Property:
             return "property";
         case VariableKind.Method:
             return "method";
         case VariableKind.Field:
             return "field";
         case VariableKind.Local:
             return "local";
         case VariableKind.Unknown:
             return "unknown";
         default:
             throw new InvalidOperationException("Invalid SymbolKind: " + kind.ToString());
     }
 }
Esempio n. 45
0
 public VariableValue(VariableKind kind, byte[] ary, int startIndex, int len)
 {
     Kind = kind;
     SetValue(ary, startIndex, len);
 }
Esempio n. 46
0
 protected IDisposable NameRefTag(VariableKind kind, string name = null, string fullName = null)
 {
     return Tag(NameRefElementName, VariableKindAttribute(kind), NameAttribute(name), FullNameAttribute(fullName));
 }
Esempio n. 47
0
 internal BoundLocal(SourceLocalSymbol symbol, VariableKind kind = VariableKind.LocalVariable)
     : base(kind)
 {
     Debug.Assert(kind == VariableKind.LocalVariable || kind == VariableKind.LocalTemporalVariable);
     _symbol = symbol;
 }
Esempio n. 48
0
        internal Variable(Type type, VariableKind kind)
        {
            index = freeIndex++;

            this.type = type;
            this.kind = kind;
            options = new OptionsHash();
            usersArray = new NodeArray();

            switch (kind)
            {
                case VariableKind.Local:
                    name = "Loc" + index;
                    break;

                case VariableKind.Parameter:
                    name = "Arg" + index;
                    break;

                case VariableKind.ArgList:
                    name = "ArgList";
                    break;
            }
        }
 public DecrementUnitOption(VariableKind kind, string defaultName = null) : base(kind, defaultName)
 {
 }
Esempio n. 50
0
        public Variable CreateVar(Type type, VariableKind kind)
        {
            Variable var = new Variable(type,kind);
            vars.Add(var.Index,var);

            if (var.Kind != VariableKind.Local)
                mapper.Add(var);

            return var;
        }
Esempio n. 51
0
 public static IEnumerable <string> GetVariableNameSuggestions(VariableKind kind, GraphReference reference)
 {
     return(LinqUtility.Concat <string>(GetPredefinedVariableNames(kind, reference), GetDynamicVariableNames(kind, reference)).Distinct().OrderBy(name => name));
 }