示例#1
0
        /// <inheritdoc />
        protected override void flowThrough()
        {
            // Create the name of the variable in global controls
            // Should be unique for each function
            var varNameInGlobalStore = new VariableName("static_" + _variableName.Value + OwningPPGraph.FunctionName + OwningScript);

            // Get the variable from global store
            var variableInGlobalStore = OutSet.GetControlVariable(varNameInGlobalStore);

            // Initialize the variable with _initializer if it may be uninitialized and has an initializer
            var values = variableInGlobalStore.ReadMemory(OutSnapshot);

            if (_initializer != null && values.PossibleValues.Any(a => a is UndefinedValue))
            {
                var newValues = new List <Value> (values.PossibleValues.Where(a => !(a is UndefinedValue)));
                newValues.AddRange(_initializer.Values.PossibleValues);
                variableInGlobalStore.WriteMemory(OutSnapshot, new MemoryEntry(newValues), true);
            }
            else if (_initializer == null)
            {
                variableInGlobalStore.WriteMemory(OutSnapshot, new MemoryEntry(OutSnapshot.UndefinedValue), true);
            }

            // Static variable is an alias of the variable from global store (this respects the implementation in official PHP interpreter)
            _variable.LValue.SetAliases(OutSnapshot, variableInGlobalStore);
        }