Ejemplo n.º 1
0
        private ExpressionNode ParseMemberExpression()
        {
            ExpressionNode leftSide = ParsePrimaryExpression();

            while (_token.Id == TokenId.Dot)
            {
                NextToken();

                _rangeRecorder.Begin();
                Identifier  memberName            = ParseIdentifier();
                SourceRange memberNameSourceRange = _rangeRecorder.End();

                if (_token.Id != TokenId.LeftParentheses)
                {
                    PropertyAccessExpression result = new PropertyAccessExpression();
                    result.Target          = leftSide;
                    result.Name            = memberName;
                    result.NameSourceRange = memberNameSourceRange;
                    leftSide = result;
                }
                else
                {
                    ExpressionNode[]           arguments = ParseExpressionList();
                    MethodInvocationExpression result    = new MethodInvocationExpression();
                    result.Target          = leftSide;
                    result.Name            = memberName;
                    result.NameSourceRange = memberNameSourceRange;
                    result.Arguments       = arguments;
                    leftSide = result;
                }
            }

            return(leftSide);
        }
Ejemplo n.º 2
0
 public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
 {
     VisitExpression(expression.Target);
     _writer.Write(".");
     _writer.WriteIdentifier(expression.Name);
     return(expression);
 }
Ejemplo n.º 3
0
		public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements)
		{
			PropertyAccessExpression result = new PropertyAccessExpression();
			result.Target = (ExpressionNode)_target.Clone(alreadyClonedElements);
			result.Name = _name;
			result.NameSourceRange = _nameSourceRange;
			result.Property = _property;

			return result;
		}
Ejemplo n.º 4
0
        public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
        {
            ReflectionPropertyBinding reflectionPropertyBinding = expression.Property as ReflectionPropertyBinding;
            ReflectionFieldBinding    reflectionFieldBinding    = expression.Property as ReflectionFieldBinding;

            if (reflectionPropertyBinding != null)
            {
                EmitCall(reflectionPropertyBinding.PropertyInfo.GetGetMethod(), expression.Target);
                _ilEmitContext.ILGenerator.EmitCall(OpCodes.Call, _unifyNullsMethod, null);
            }
            else if (reflectionFieldBinding != null)
            {
                Label finishLabel   = _ilEmitContext.ILGenerator.DefineLabel();
                Label loadNullLabel = _ilEmitContext.ILGenerator.DefineLabel();
                int   instanceIndex = DeclareLocal();

                Visit(expression.Target);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Stloc, instanceIndex);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, instanceIndex);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Brfalse, loadNullLabel);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, instanceIndex);
                EmitThisArgumentPointer(expression.Target.ExpressionType);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Ldfld, reflectionFieldBinding.FieldInfo);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Br, finishLabel);
                _ilEmitContext.ILGenerator.MarkLabel(loadNullLabel);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Ldnull);
                _ilEmitContext.ILGenerator.MarkLabel(finishLabel);
            }
            else
            {
                Label finishLabel   = _ilEmitContext.ILGenerator.DefineLabel();
                Label loadNullLabel = _ilEmitContext.ILGenerator.DefineLabel();

                int argIndex = DeclareLocal();
                Visit(expression.Target);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Stloc, argIndex);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, argIndex);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Brfalse, loadNullLabel);

                ILParameterDeclaration customPropertyBinding = _ilEmitContext.GetParameters(expression)[0];
                EmitLoadParameter(customPropertyBinding);
                EmitThisArgumentPointer(typeof(PropertyBinding));
                _ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, argIndex);
                _ilEmitContext.ILGenerator.EmitCall(OpCodes.Callvirt, _propertyBindingGetValueMethod, null);
                _ilEmitContext.ILGenerator.EmitCall(OpCodes.Call, _unifyNullsMethod, null);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Br, finishLabel);

                _ilEmitContext.ILGenerator.MarkLabel(loadNullLabel);
                _ilEmitContext.ILGenerator.Emit(OpCodes.Ldnull);

                _ilEmitContext.ILGenerator.MarkLabel(finishLabel);
            }

            return(expression);
        }
        public override AstElement Clone(Dictionary <AstElement, AstElement> alreadyClonedElements)
        {
            PropertyAccessExpression result = new PropertyAccessExpression();

            result.Target          = (ExpressionNode)_target.Clone(alreadyClonedElements);
            result.Name            = _name;
            result.NameSourceRange = _nameSourceRange;
            result.Property        = _property;

            return(result);
        }
Ejemplo n.º 6
0
		public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
		{
			base.VisitPropertyAccessExpression(expression);

			bool isReflectionBinding = expression.Property is ReflectionPropertyBinding ||
			                           expression.Property is ReflectionFieldBinding;
			if (!isReflectionBinding)
				_ilEmitContext.AddParameter(expression, expression.Property, typeof(PropertyBinding));

			return expression;
		}
Ejemplo n.º 7
0
        public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
        {
            _xmlWriter.WriteStartElement("propertyExpression");
            _xmlWriter.WriteAttributeString("identifier", expression.Name.ToSource());
            WriteTypeAttribute(expression.ExpressionType);

            WriteAstNode("target", expression.Target);

            _xmlWriter.WriteEndElement();

            return(expression);
        }
Ejemplo n.º 8
0
        public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
        {
            base.VisitPropertyAccessExpression(expression);

            bool isReflectionBinding = expression.Property is ReflectionPropertyBinding ||
                                       expression.Property is ReflectionFieldBinding;

            if (!isReflectionBinding)
            {
                _ilEmitContext.AddParameter(expression, expression.Property, typeof(PropertyBinding));
            }

            return(expression);
        }
Ejemplo n.º 9
0
        public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
        {
            base.VisitPropertyAccessExpression(expression);

            if (expression.Target is ConstantExpression)
            {
                try
                {
                    return(LiteralExpression.FromTypedValue(expression.GetValue(), expression.ExpressionType));
                }
                catch (RuntimeException ex)
                {
                    _errorReporter.CannotFoldConstants(ex);
                }
            }

            return(expression);
        }
Ejemplo n.º 10
0
		public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
		{
			_xmlWriter.WriteStartElement("propertyExpression");
			_xmlWriter.WriteAttributeString("identifier", expression.Name.ToSource());
			WriteTypeAttribute(expression.ExpressionType);

			WriteAstNode("target", expression.Target);

			_xmlWriter.WriteEndElement();

			return expression;
		}
Ejemplo n.º 11
0
		private static bool VisitPropertyAccessExpression(PropertyAccessExpression node1, PropertyAccessExpression node2)
		{
			return node2 != null &&
			       node1.Name == node2.Name &&
			       Visit(node1.Target, node2.Target);
		}
Ejemplo n.º 12
0
 private static bool VisitPropertyAccessExpression(PropertyAccessExpression node1, PropertyAccessExpression node2)
 {
     return(node2 != null &&
            node1.Name == node2.Name &&
            Visit(node1.Target, node2.Target));
 }
Ejemplo n.º 13
0
		public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
		{
			VisitExpression(expression.Target);
			_writer.Write(".");
			_writer.WriteIdentifier(expression.Name);
			return expression;
		}
Ejemplo n.º 14
0
        private ExpressionNode ParseMemberExpression()
        {
            ExpressionNode leftSide = ParsePrimaryExpression();

            while (_token.Id == TokenId.Dot)
            {
                NextToken();

                _rangeRecorder.Begin();
                Identifier memberName = ParseIdentifier();
                SourceRange memberNameSourceRange = _rangeRecorder.End();

                if (_token.Id != TokenId.LeftParentheses)
                {
                    PropertyAccessExpression result = new PropertyAccessExpression();
                    result.Target = leftSide;
                    result.Name = memberName;
                    result.NameSourceRange = memberNameSourceRange;
                    leftSide = result;
                }
                else
                {
                    ExpressionNode[] arguments = ParseExpressionList();
                    MethodInvocationExpression result = new MethodInvocationExpression();
                    result.Target = leftSide;
                    result.Name = memberName;
                    result.NameSourceRange = memberNameSourceRange;
                    result.Arguments = arguments;
                    leftSide = result;
                }
            }

            return leftSide;
        }
Ejemplo n.º 15
0
 public virtual ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
 {
     expression.Target = VisitExpression(expression.Target);
     return(expression);
 }
Ejemplo n.º 16
0
		public virtual ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
		{
			expression.Target = VisitExpression(expression.Target);
			return expression;
		}
Ejemplo n.º 17
0
		public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
		{
			base.VisitPropertyAccessExpression(expression);

			if (expression.Target is ConstantExpression)
			{
				try
				{
                    return LiteralExpression.FromTypedValue(expression.GetValue(), expression.ExpressionType);
				}
				catch (RuntimeException ex)
				{
					_errorReporter.CannotFoldConstants(ex);
				}
			}

			return expression;
		}
Ejemplo n.º 18
0
        public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
        {
            // Resolve column
            // -- or --
            // Resolve property

            NameExpression targetAsNameExpression = expression.Target as NameExpression;

            if (targetAsNameExpression != null)
            {
                // Ok, the target is a name expression. Lets see whether it refers to a table
                // or constant.

                TableRefBinding tableRefBinding = ResolveTableRef(targetAsNameExpression.NameSourceRange, targetAsNameExpression.Name);
                ConstantBinding constantBinding = ResolveConstant(targetAsNameExpression.NameSourceRange, targetAsNameExpression.Name);

                if (tableRefBinding != null)
                {
                    if (constantBinding != null)
                    {
                        // It can both refer to a constant and a table. We cannot resolve
                        // the ambiguity so we report an error and do nothing.
                        ErrorReporter.AmbiguousReference(expression.NameSourceRange, expression.Name, new Binding[] { constantBinding, tableRefBinding });
                        return expression;
                    }

                    // The target only refers to table. Resolve the column or method on the row type.

                    ColumnRefBinding columnRefBinding = ResolveColumnRef(tableRefBinding, expression.NameSourceRange, expression.Name);

                    if (columnRefBinding != null)
                        return new ColumnExpression(columnRefBinding);

                    if (!(tableRefBinding.TableBinding is DerivedTableBinding) && !(tableRefBinding.TableBinding is CommonTableBinding))
                    {
                        // Check if there is any method with this name declared. This helps to give a better
                        // error message.

                        MethodBinding[] methodBindings = _scope.DataContext.MetadataContext.FindMethod(tableRefBinding.TableBinding.RowType, expression.Name);

                        if (methodBindings != null && methodBindings.Length > 0)
                        {
                            // Report that methods calls require parentheses
                            ErrorReporter.InvocationRequiresParentheses(expression.NameSourceRange, methodBindings);
                            return expression;
                        }
                    }

                    // Report that no column with this name exists.
                    ErrorReporter.UndeclaredColumn(expression.NameSourceRange, tableRefBinding, expression.Name);
                    return expression;
                }

                // NOTE: If name does not refer to a table but to constant
                //       we fall through. The name node is resolved below
                //       (actually it is replaced in VisitNameExpression)
            }

            // Ok, it is not a table. Try to resolve a property.

            expression.Target = VisitExpression(expression.Target);

            if (expression.Target.ExpressionType == null)
                return expression;

            // To support custom properties we check if the target is a named constant or a parameter.

            NamedConstantExpression namedConstantExpression = expression.Target as NamedConstantExpression;
            ParameterExpression parameterExpression = expression.Target as ParameterExpression;

            if (namedConstantExpression == null && parameterExpression == null)
            {
                // We cannot use custom properties in this case. Therfore
                // we resolve the property using type specific properties.

                expression.Property = ResolveTypeProperty(expression.Target.ExpressionType, expression.NameSourceRange, expression.Name);
            }
            else
            {
                // We can use custom properties. Get that value and the dataype.

                IList<PropertyBinding> customProperties;

                if (namedConstantExpression != null)
                    customProperties = namedConstantExpression.Constant.CustomProperties;
                else
                    customProperties = parameterExpression.Parameter.CustomProperties;

                if (customProperties != null)
                {
                    // Resolve instance property.
                    expression.Property = ResolveCustomProperty(customProperties, expression.NameSourceRange, expression.Name);
                }
                else
                {
                    // The constant or parameter did not have custom properties.
                    expression.Property = ResolveTypeProperty(expression.Target.ExpressionType, expression.NameSourceRange, expression.Name);
                }
            }

            if (expression.Property == null)
            {
                // Check if there is any method with this name declared. This helps to give a better
                // error message.

                MethodBinding[] methodBindings = _scope.DataContext.MetadataContext.FindMethod(expression.Target.ExpressionType, expression.Name);

                if (methodBindings != null && methodBindings.Length > 0)
                {
                    // Report that methods calls require parentheses
                    ErrorReporter.InvocationRequiresParentheses(expression.NameSourceRange, methodBindings);
                }
                else
                {
                    // Report that no property with this name exists.
                    ErrorReporter.UndeclaredProperty(expression.NameSourceRange, expression.Target.ExpressionType, expression.Name);
                }
            }

            return expression;
        }
Ejemplo n.º 19
0
		public override ExpressionNode VisitPropertyAccessExpression(PropertyAccessExpression expression)
		{
			ReflectionPropertyBinding reflectionPropertyBinding = expression.Property as ReflectionPropertyBinding;
			ReflectionFieldBinding reflectionFieldBinding = expression.Property as ReflectionFieldBinding;
			if (reflectionPropertyBinding != null)
			{
				EmitCall(reflectionPropertyBinding.PropertyInfo.GetGetMethod(), expression.Target);
				_ilEmitContext.ILGenerator.EmitCall(OpCodes.Call, _unifyNullsMethod, null);
			}
			else if (reflectionFieldBinding != null)
			{
				Label finishLabel = _ilEmitContext.ILGenerator.DefineLabel();
				Label loadNullLabel = _ilEmitContext.ILGenerator.DefineLabel();
				int instanceIndex = DeclareLocal();

				Visit(expression.Target);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Stloc, instanceIndex);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, instanceIndex);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Brfalse, loadNullLabel);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, instanceIndex);
				EmitThisArgumentPointer(expression.Target.ExpressionType);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Ldfld, reflectionFieldBinding.FieldInfo);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Br, finishLabel);
				_ilEmitContext.ILGenerator.MarkLabel(loadNullLabel);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Ldnull);
				_ilEmitContext.ILGenerator.MarkLabel(finishLabel);
			}
			else
			{
				Label finishLabel = _ilEmitContext.ILGenerator.DefineLabel();
				Label loadNullLabel = _ilEmitContext.ILGenerator.DefineLabel();

				int argIndex = DeclareLocal();
				Visit(expression.Target);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Stloc, argIndex);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, argIndex);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Brfalse, loadNullLabel);

				ILParameterDeclaration customPropertyBinding = _ilEmitContext.GetParameters(expression)[0];
				EmitLoadParameter(customPropertyBinding);
				EmitThisArgumentPointer(typeof(PropertyBinding));
				_ilEmitContext.ILGenerator.Emit(OpCodes.Ldloc, argIndex);
				_ilEmitContext.ILGenerator.EmitCall(OpCodes.Callvirt, _propertyBindingGetValueMethod, null);
				_ilEmitContext.ILGenerator.EmitCall(OpCodes.Call, _unifyNullsMethod, null);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Br, finishLabel);

				_ilEmitContext.ILGenerator.MarkLabel(loadNullLabel);
				_ilEmitContext.ILGenerator.Emit(OpCodes.Ldnull);

				_ilEmitContext.ILGenerator.MarkLabel(finishLabel);
			}
			
			return expression;
		}