Exemplo n.º 1
0
        public void Resolve(ResolveContext ec)
        {
            if (Expr == EmptyExpression.Null)
            {
                return;
            }

//			using (ec.With (ResolveContext.Options.DoFlowAnalysis, true)) {
            // Verify that the argument is readable
            if (ArgType != AType.Out)
            {
                Expr = Expr.Resolve(ec);
            }

            // Verify that the argument is writeable
            if (Expr != null && IsByRef)
            {
                Expr = Expr.ResolveLValue(ec, EmptyExpression.OutAccess.Instance);
            }

            if (Expr == null)
            {
                Expr = EmptyExpression.Null;
            }
//			}
        }
Exemplo n.º 2
0
        public override Expression DoResolve(ResolveContext ec)
        {
            bool ok = true;

            source = source.Resolve(ec);

            if (source == null)
            {
                ok     = false;
                source = EmptyExpression.Null;
            }

            target = target.ResolveLValue(ec, source);

            if (target == null || !ok)
            {
                return(null);
            }

            Type target_type = target.Type;
            Type source_type = source.Type;

            eclass = ExprClass.Value;
            type   = target_type;

            if (!(target is IAssignMethod))
            {
                Error_ValueAssignment(ec, loc);
                return(null);
            }

            if ((RootContext.Version == LanguageVersion.ISO_1) &&
                (source is MethodGroupExpr))
            {
                ((MethodGroupExpr)source).ReportUsageError(ec);
                return(null);
            }

            if (!TypeManager.IsEqual(target_type, source_type))
            {
                if (TypeManager.IsDynamicType(source_type))
                {
                    Arguments args = new Arguments(1);
                    args.Add(new Argument(source));
                    return(new DynamicConversion(target_type, false, args, loc).Resolve(ec));
                }

                Expression resolved = ResolveConversions(ec);

                if (resolved != this)
                {
                    return(resolved);
                }
            }

            return(this);
        }
Exemplo n.º 3
0
        public override Expression DoResolve(EmitContext ec)
        {
            bool ok = true;

            source = source.Resolve(ec);

            if (source == null)
            {
                ok     = false;
                source = EmptyExpression.Null;
            }

            target = target.ResolveLValue(ec, source, Location);

            if (target == null || !ok)
            {
                return(null);
            }

            Type target_type = target.Type;
            Type source_type = source.Type;

            eclass = ExprClass.Value;
            type   = target_type;

            if (!(target is IAssignMethod))
            {
                Error_ValueAssignment(loc);
                return(null);
            }

            if ((source.eclass == ExprClass.Type) && (source is TypeExpr))
            {
                source.Error_UnexpectedKind(ec.DeclContainer, "variable or value", loc);
                return(null);
            }
            else if ((RootContext.Version == LanguageVersion.ISO_1) &&
                     (source is MethodGroupExpr))
            {
                ((MethodGroupExpr)source).ReportUsageError();
                return(null);
            }

            if (!TypeManager.IsEqual(target_type, source_type))
            {
                Expression resolved = ResolveConversions(ec);

                if (resolved != this)
                {
                    return(resolved);
                }
            }

            return(this);
        }
Exemplo n.º 4
0
        public void Resolve(ResolveContext ec)
        {
            // Verify that the argument is readable
            if (ArgType != AType.Out)
            {
                Expr = Expr.Resolve(ec);
            }

            // Verify that the argument is writeable
            if (Expr != null && IsByRef)
            {
                Expr = Expr.ResolveLValue(ec, EmptyExpression.OutAccess);
            }

            if (Expr == null)
            {
                Expr = ErrorExpression.Instance;
            }
        }
Exemplo n.º 5
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            bool ok = true;

            source = source.Resolve(ec);

            if (source == null)
            {
                ok     = false;
                source = EmptyExpression.Null;
            }

            target = target.ResolveLValue(ec, source);

            if (target == null || !ok)
            {
                return(null);
            }

            TypeSpec target_type = target.Type;
            TypeSpec source_type = source.Type;

            eclass = ExprClass.Value;
            type   = target_type;

            if (!(target is IAssignMethod))
            {
                Error_ValueAssignment(ec, loc);
                return(null);
            }

            if (target_type != source_type)
            {
                Expression resolved = ResolveConversions(ec);

                if (resolved != this)
                {
                    return(resolved);
                }
            }

            return(this);
        }
Exemplo n.º 6
0
        public void Resolve(ResolveContext ec)
        {
//			using (ec.With (ResolveContext.Options.DoFlowAnalysis, true)) {

            // Keep track of the array initializer, we need it to do array type inference when searching for
            // a matching method.
            if (ec.FileType == SourceFileType.PlayScript)
            {
                if (Expr is AsArrayInitializer)
                {
                    InferArrayInitializer = (AsArrayInitializer)Expr;
                }
                else if (Expr is AsObjectInitializer)
                {
                    InferObjInitializer = (AsObjectInitializer)Expr;
                }
                else if (Expr is AnonymousMethodExpression)
                {
                    Expr = new Cast(new TypeExpression(ec.BuiltinTypes.Delegate, Expr.Location), Expr, Expr.Location);
                }
            }

            // Verify that the argument is readable
            if (ArgType != AType.Out)
            {
                Expr = Expr.Resolve(ec);
            }

            // Verify that the argument is writeable
            if (Expr != null && IsByRef)
            {
                Expr = Expr.ResolveLValue(ec, EmptyExpression.OutAccess);
            }

            if (Expr == null)
            {
                Expr = ErrorExpression.Instance;
            }
//			}
        }
Exemplo n.º 7
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            bool ok = true;

            // PlayScript: resolve LValue first if source is an initializer to be able to
            // infer initializer type correctly.
            if (ec.FileType == SourceFileType.PlayScript &&
                (source is AsArrayInitializer || source is AsObjectInitializer))
            {
                target = target.ResolveLValue(ec, source);

                if (target == null)
                {
                    ok     = false;
                    source = EmptyExpression.Null;
                }

                if (source is AsArrayInitializer)
                {
                    source = ((AsArrayInitializer)source).InferredResolveWithArrayType(ec, target.Type);
                }
                else if (source is AsObjectInitializer)
                {
                    source = ((AsObjectInitializer)source).InferredResolveWithObjectType(ec, target.Type);
                }

                if (source == null)
                {
                    ok     = false;
                    source = EmptyExpression.Null;
                }
            }
            else
            {
                source = source.Resolve(ec);

                if (source == null)
                {
                    ok     = false;
                    source = EmptyExpression.Null;
                }

                target = target.ResolveLValue(ec, source);
            }

            if (target == null || !ok)
            {
                return(null);
            }

            TypeSpec target_type = target.Type;
            TypeSpec source_type = source.Type;

            eclass = ExprClass.Value;
            type   = target_type;

            if (!(target is IAssignMethod))
            {
                target.Error_ValueAssignment(ec, source);
                return(null);
            }

            if (target_type != source_type)
            {
                Expression resolved = ResolveConversions(ec);

                if (resolved != this)
                {
                    return(resolved);
                }
            }

            return(this);
        }
Exemplo n.º 8
0
		public bool Resolve (EmitContext ec, Location loc)
		{
			if (ArgType == AType.Ref) {
				Expr = Expr.Resolve (ec);
				if (Expr == null)
					return false;

				Expr = Expr.ResolveLValue (ec, Expr);
			} else if (ArgType == AType.Out)
				Expr = Expr.ResolveLValue (ec, new EmptyExpression ());
			else
				Expr = Expr.Resolve (ec);

			if (Expr == null)
				return false;

			if (ArgType == AType.Expression)
				return true;

			if (Expr.eclass != ExprClass.Variable){
				//
				// We just probe to match the CSC output
				//
				if (Expr.eclass == ExprClass.PropertyAccess ||
				    Expr.eclass == ExprClass.IndexerAccess){
					Report.Error (
						206, loc,
						"A property or indexer can not be passed as an out or ref " +
						"parameter");
				} else {
					Report.Error (
						1510, loc,
						"An lvalue is required as an argument to out or ref");
				}
				return false;
			}
				
			return true;
		}