Пример #1
0
 public void Add(
     String key,
     PipelineContextData value)
 {
     IndexLookup.Add(key, m_list?.Count ?? 0);
     List.Add(new DictionaryContextDataPair(key, value));
 }
Пример #2
0
        /// <summary>
        /// get cardinal index from offset string name (ie: 12 from "Buttons55")
        /// </summary>
        /// <param name="offsetName"></param>
        /// <returns></returns>
        public static int GetIndex(string offsetName)
        {
            if (!IndexLookup.ContainsKey(offsetName))
            {
                throw new ArgumentOutOfRangeException($"JoystickOffset does not contain the name: {offsetName}.");
            }

            IndexLookup.TryGetValue(offsetName, out var o);
            return(o);
        }
Пример #3
0
        public Boolean TryGetValue(
            String key,
            out PipelineContextData value)
        {
            if (m_list?.Count > 0 &&
                IndexLookup.TryGetValue(key, out var index))
            {
                value = m_list[index].Value;
                return(true);
            }

            value = null;
            return(false);
        }
Пример #4
0
        internal void AllocateIndexRange(int index, int range)
        {
            if ((index + range) > indexToID.Length)
            {
                indexToID.Resize((index + range), NativeArrayOptions.ClearMemory);
            }

            int idInternal, generation;

            // TODO: should make it possible to allocate ids in a range as well, for cache locality
            if (freeIDs.Length >= range)
            {
                var childIndex = index;
                while (range > 0)
                {
                    var freeID = freeIDs.Length - 1;
                    idInternal = freeIDs[freeID];
                    freeIDs.RemoveAt(freeID);

                    generation            = idToIndex[idInternal].generation + 1;
                    idToIndex[idInternal] = new IndexLookup {
                        index = childIndex, generation = generation
                    };

                    indexToID[childIndex] = idInternal + 1;

                    range--;
                    childIndex++;
                }
            }

            if (range <= 0)
            {
                return;
            }

            generation = 1;
            idInternal = idToIndex.Length;
            idToIndex.Resize((idInternal + range), NativeArrayOptions.ClearMemory);

            for (int childIndex = index, lastID = (idInternal + range); idInternal < lastID; idInternal++, childIndex++)
            {
                indexToID[childIndex] = idInternal + 1;
                idToIndex[idInternal] = new IndexLookup {
                    index = childIndex, generation = generation
                };
            }
        }
Пример #5
0
        public PipelineContextData this[String key]
        {
            get
            {
                var index = IndexLookup[key];
                return(m_list[index].Value);
            }

            set
            {
                // Existing
                if (IndexLookup.TryGetValue(key, out var index))
                {
                    key           = m_list[index].Key; // preserve casing
                    m_list[index] = new DictionaryContextDataPair(key, value);
                }
                // New
                else
                {
                    Add(key, value);
                }
            }
        }
Пример #6
0
        public void VisitNode(JSIfStatement ifs)
        {
            var  boe                  = ifs.Condition as JSBinaryOperatorExpression;
            var  uoe                  = ifs.Condition as JSUnaryOperatorExpression;
            var  invocation           = ifs.Condition as JSInvocationExpression;
            bool invocationIsInverted = false;

            if ((boe != null) && (boe.Operator == JSOperator.Equal))
            {
                var leftVar     = boe.Left as JSVariable;
                var leftIgnored = boe.Left as JSIgnoredMemberReference;
                var rightNull   = (JSLiteral)(boe.Right as JSDefaultValueLiteral) ?? (JSLiteral)(boe.Right as JSNullLiteral);

                if (rightNull != null)
                {
                    if (leftVar != null)
                    {
                        NullChecks[leftVar] = new NullCheck {
                            Statement      = ifs,
                            SwitchVariable = leftVar,
                            Goto           = ifs.AllChildrenRecursive.OfType <JSGotoExpression>().FirstOrDefault()
                        };
                    }
                    else if (leftIgnored != null)
                    {
                        var leftField = leftIgnored.Member as FieldInfo;

                        if (leftField != null)
                        {
                            var initializer = Initializers[leftField] = new Initializer {
                                Field     = leftField,
                                Statement = ifs,
                            };

                            foreach (var _invocation in ifs.TrueClause.AllChildrenRecursive.OfType <JSInvocationExpression>())
                            {
                                if (_invocation.JSMethod == null)
                                {
                                    continue;
                                }
                                if (_invocation.JSMethod.Identifier != "Add")
                                {
                                    continue;
                                }
                                if (_invocation.Arguments.Count != 2)
                                {
                                    continue;
                                }

                                var value = _invocation.Arguments[0];
                                var index = _invocation.Arguments[1] as JSIntegerLiteral;
                                if (index == null)
                                {
                                    continue;
                                }

                                initializer.Values[(int)index.Value] = value;
                            }

                            foreach (var iae in ifs.TrueClause.AllChildrenRecursive.OfType <JSInitializerApplicationExpression>())
                            {
                                var targetNew = iae.Target as JSNewExpression;
                                if (targetNew == null)
                                {
                                    continue;
                                }

                                var targetNewJSType = targetNew.Type as JSType;
                                if (targetNewJSType == null)
                                {
                                    continue;
                                }

                                var targetNewType = targetNewJSType.Type as GenericInstanceType;
                                if (targetNewType == null)
                                {
                                    continue;
                                }
                                if (!targetNewType.Name.Contains("Dictionary"))
                                {
                                    continue;
                                }
                                if (targetNewType.GenericArguments.Count != 2)
                                {
                                    continue;
                                }
                                if (targetNewType.GenericArguments[1].MetadataType != MetadataType.Int32)
                                {
                                    continue;
                                }

                                var initArray = iae.Initializer as JSArrayExpression;
                                if (initArray == null)
                                {
                                    continue;
                                }

                                foreach (var item in initArray.Values)
                                {
                                    var itemArray = item as JSArrayExpression;
                                    if (itemArray == null)
                                    {
                                        continue;
                                    }

                                    var value = itemArray.Values.First();
                                    var index = itemArray.Values.Skip(1).First() as JSIntegerLiteral;
                                    if (index == null)
                                    {
                                        continue;
                                    }

                                    initializer.Values[(int)index.Value] = value;
                                }
                            }
                        }
                    }
                }
            }
            else if ((uoe != null) && (uoe.Operator == JSOperator.LogicalNot))
            {
                invocation           = uoe.Expression as JSInvocationExpression;
                invocationIsInverted = true;
            }

            if (
                (invocation != null) &&
                (invocation.Arguments.Count == 2) &&
                (invocation.JSMethod != null) &&
                (invocation.JSMethod.Identifier == "TryGetValue")
                )
            {
                var thisIgnored = invocation.ThisReference as JSIgnoredMemberReference;
                var switchVar   = invocation.Arguments[0] as JSVariable;
                var outRef      = invocation.Arguments[1] as JSPassByReferenceExpression;

                if ((thisIgnored != null) && (switchVar != null) && (outRef != null))
                {
                    var thisField   = thisIgnored.Member as FieldInfo;
                    var outReferent = outRef.Referent as JSReferenceExpression;

                    if ((thisField != null) && (outReferent != null))
                    {
                        var outVar = outReferent.Referent as JSVariable;

                        if (outVar != null)
                        {
                            IndexLookups[outVar] = new IndexLookup {
                                OutputVariable = outVar,
                                SwitchVariable = switchVar,
                                Field          = thisField,
                                Statement      = ifs,
                                Goto           = ifs.TrueClause.AllChildrenRecursive.OfType <JSGotoExpression>().FirstOrDefault(),
                                IsInverted     = invocationIsInverted
                            };

                            if (!invocationIsInverted)
                            {
                                var replacement = ifs.TrueClause;
                                ParentNode.ReplaceChild(ifs, replacement);
                                VisitReplacement(replacement);
                                return;
                            }
                        }
                    }
                }
            }

            VisitChildren(ifs);
        }