public virtual void EmitSetMember(BoundSetMember node)
 {
     var constant = node.Index as BoundConstant;
     if (constant != null && constant.ValueType == BoundValueType.String)
     {
         // Load the target to store in.
         Generator.EmitBox(Generator.EmitExpression(node.Expression));
         // Load the index.
         IL.EmitConstant(Generator._identifierManager.ResolveIdentifier((string)constant.Value));
         // Load the expression.
         Generator.EmitBox(Generator.EmitExpression(node.Value));
         // Store the expression by index.
         IL.EmitCall(_runtimeSetMemberByIndex, BoundValueType.Unset);
     }
     else
     {
         Generator.EmitPop(Generator.EmitOperationCall(Operation.SetMember, node.Expression, node.Index, node.Value));
     }
 }
            public override void EmitSetMember(BoundSetMember node)
            {
                if (node.Index.ValueType == BoundValueType.Number)
                {
                    // Load a reference to the box.
                    IL.Emit(OpCodes.Ldloca, Local);
                    // Load the index.
                    Generator.EmitExpression(node.Index);
                    // Load the value.
                    Generator.EmitBox(Generator.EmitExpression(node.Value));
                    // Store into the box by index.
                    IL.EmitCall(_setProperty);
                    return;
                }

                base.EmitSetMember(node);
            }
            public override void EmitSetMember(BoundSetMember node)
            {
                var constant = node.Index as BoundConstant;
                if (constant != null)
                {
                    int index;
                    FieldInfo cacheSlot;
                    if (TryGetCacheSlot(node.Expression, constant, out index, out cacheSlot))
                    {
                        // Load the reference to the box.
                        IL.Emit(OpCodes.Ldloca, Local);
                        // Load the index.
                        IL.EmitConstant(index);
                        // Load the value.
                        Generator.EmitBox(Generator.EmitExpression(node.Value));
                        // Load the cache slot.
                        IL.Emit(OpCodes.Ldsflda, cacheSlot);
                        // Store into the box.
                        IL.EmitCall(_setProperty);
                        return;
                    }
                }

                base.EmitSetMember(node);
            }
            public override void EmitSetMember(BoundSetMember node)
            {
                var constant = node.Index as BoundConstant;
                if (constant != null)
                {
                    int index;
                    FieldInfo cacheSlot;
                    if (TryGetCacheSlot(node.Expression, constant, out index, out cacheSlot))
                    {
                        // Load the target to store to.
                        Generator.EmitBox(Generator.EmitExpression(node.Expression));
                        // Load the index.
                        IL.EmitConstant(index);
                        // Load the value.
                        Generator.EmitBox(Generator.EmitExpression(node.Value));
                        // Load the cache slot.
                        IL.Emit(OpCodes.Ldsflda, cacheSlot);
                        // Store into the object.
                        IL.EmitCall(_objectSetPropertyCached, BoundValueType.Unset);
                        return;
                    }

                    if (constant.ValueType == BoundValueType.String)
                    {
                        // Load the target to store to.
                        Generator.EmitBox(Generator.EmitExpression(node.Expression));
                        // Load the index.
                        IL.EmitConstant(Generator._identifierManager.ResolveIdentifier(
                            (string)constant.Value
                        ));
                        // Load the value.
                        Generator.EmitBox(Generator.EmitExpression(node.Value));
                        // Store into the object.
                        IL.EmitCall(_objectSetProperty, BoundValueType.Unset);
                        return;
                    }
                }

                Generator.EmitPop(Generator.EmitOperationCall(Operation.SetMember, node.Expression, node.Index, node.Value));
            }
示例#5
0
 public virtual void VisitSetMember(BoundSetMember node)
 {
     DefaultVisit(node);
 }
示例#6
0
            public override void VisitSetMember(BoundSetMember node)
            {
                var getVariable = node.Expression as BoundGetVariable;
                if (getVariable != null)
                {
                    var type = node.Index.ValueType == BoundValueType.Number
                        ? SpeculatedType.Array
                        : SpeculatedType.Object;

                    _scope.SpeculateType(getVariable.Variable, type, false);
                }

                base.VisitSetMember(node);
            }
示例#7
0
        private BoundIf BuildSetWithScope(BlockBuilder builder, WithScope withScope, IIdentifier fallback, BoundTemporary value)
        {
            var withLocal = builder.CreateTemporary();

            builder.Add(new BoundSetVariable(
                withLocal,
                new BoundGetVariable(_withIdentifiers[withScope.Identifier]), SourceLocation.Missing
            ));

            var setter = new BoundSetMember(
                new BoundGetVariable(withLocal),
                BoundConstant.Create(fallback.Name),
                new BoundGetVariable(value),
                SourceLocation.Missing
            );

            BoundBlock @else;

            if (withScope.Parent == null)
            {
                @else = BuildBlock(BuildSet(
                    fallback,
                    new BoundGetVariable(value)
                ));
            }
            else
            {
                @else = BuildBlock(BuildSetWithScope(
                    builder,
                    withScope.Parent,
                    fallback,
                    value
                ));
            }

            return new BoundIf(
                new BoundHasMember(
                    new BoundGetVariable(withLocal),
                    fallback.Name
                ),
                BuildBlock(setter),
                @else,
                SourceLocation.Missing
            );
        }
示例#8
0
        private void EmitSetMember(BoundSetMember node)
        {
            // Check whether we have an emitter for this statement.
            var emitter = GetEmitter(node.Expression);
            if (emitter != null)
            {
                emitter.EmitSetMember(node);
                return;
            }

            // When the index is a constant string, we shortcut to
            // resolving the identifier here and inserting the ID of the
            // identifier instead of emitting the string.

            var constant = node.Index as BoundConstant;
            if (constant != null && constant.ValueType == BoundValueType.String)
                EmitSetMember(node.Expression, _identifierManager.ResolveIdentifier((string)constant.Value), node.Value);
            else
                EmitSetMember(node.Expression, node.Index, node.Value);
        }