public override void OnSlicingExpression(SlicingExpression node)
        {
            base.OnSlicingExpression(node);

            if (!node.IsComplexSlicing())
                return;

            if (node.IsTargetOfAssignment())
                return;

            CompleteOmittedExpressions(node);
            ExpandComplexSlicing(node);
        }
Exemplo n.º 2
0
        void SliceMember(SlicingExpression node, IEntity member)
        {
            EnsureRelatedNodeWasVisited(node, member);
            if (node.IsTargetOfAssignment())
            {
                // leave it to LeaveBinaryExpression to resolve
                Bind(node, member);
                return;
            }

            MethodInvocationExpression mie = new MethodInvocationExpression(node.LexicalInfo);
            foreach (Slice index in node.Indices)
            {
                mie.Arguments.Add(index.Begin);
            }

            IMethod getter = null;
            if (EntityType.Ambiguous == member.EntityType)
            {
                IEntity result = ResolveAmbiguousPropertyReference((ReferenceExpression)node.Target, (Ambiguous)member, mie.Arguments);
                IProperty found = result as IProperty;
                if (null != found)
                {
                    getter = found.GetGetMethod();
                }
                else if (EntityType.Ambiguous == result.EntityType)
                {
                    Error(node);
                    return;
                }
            }
            else if (EntityType.Property == member.EntityType)
            {
                getter = ((IProperty)member).GetGetMethod();
            }

            if (null != getter)
            {
                if (AssertParameters(node, getter, mie.Arguments))
                {
                    Expression target = GetIndexedPropertySlicingTarget(node);

                    mie.Target = CodeBuilder.CreateMemberReference(target, getter);
                    BindExpressionType(mie, getter.ReturnType);

                    node.ParentNode.Replace(node, mie);
                }
                else
                {
                    Error(node);
                }
            }
            else
            {
                NotImplemented(node, "slice for anything but arrays and default properties");
            }
        }
Exemplo n.º 3
0
		override public void OnSlicingExpression(SlicingExpression node)
		{
			if (node.IsTargetOfAssignment())
				return;

			Visit(node.Target);
			var type = (IArrayType)PopType();

			if (type.Rank == 1)
				LoadSingleDimensionalArrayElement(node, type);
			else
				LoadMultiDimensionalArrayElement(node, type);

			PushType(type.ElementType);
		}
Exemplo n.º 4
0
		override public void LeaveSlicingExpression(SlicingExpression node)
		{
			if (!IsDuckTyped(node.Target)) return;
			if (node.IsTargetOfAssignment()) return;

			// todo
			// a[foo]
			// RuntimeServices.GetSlice(a, "", (foo,))

			MethodInvocationExpression mie = CodeBuilder.CreateMethodInvocation(
				node.LexicalInfo,
				RuntimeServices_GetSlice,
				GetSlicingTarget(node),
				CodeBuilder.CreateStringLiteral(GetSlicingMemberName(node)),
				GetArrayForIndices(node));
			
			Replace(mie);
		}