예제 #1
0
        //
        // For named arguments when the order of execution is different
        // to order of invocation
        //
        public Arguments MarkOrderedArgument(NamedArgument a)
        {
            //
            // An expression has no effect on left-to-right execution
            //
            if (a.Expr.IsSideEffectFree)
            {
                return(this);
            }

            ArgumentsOrdered ra = this as ArgumentsOrdered;

            if (ra == null)
            {
                ra = new ArgumentsOrdered(this);

                for (int i = 0; i < args.Count; ++i)
                {
                    var la = args [i];
                    if (la == a)
                    {
                        break;
                    }

                    //
                    // When the argument is filled later by default expression
                    //
                    if (la == null)
                    {
                        continue;
                    }

                    var ma = la as MovableArgument;
                    if (ma == null)
                    {
                        ma         = new MovableArgument(la);
                        ra.args[i] = ma;
                    }

                    ra.AddOrdered(ma);
                }
            }

            ra.AddOrdered(a);
            return(ra);
        }
예제 #2
0
        public ArrayInitializer CreateDynamicBinderArguments(ResolveContext rc)
        {
            Location loc = Location.Null;
            var      all = new ArrayInitializer(args.Count, loc);

            MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace(loc);

            foreach (Argument a in args)
            {
                Arguments dargs = new Arguments(2);

                // CSharpArgumentInfoFlags.None = 0
                const string info_flags_enum = "CSharpArgumentInfoFlags";
                Expression   info_flags      = new IntLiteral(rc.BuiltinTypes, 0, loc);

                if (a.Expr is Constant)
                {
                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "Constant", loc));
                }
                else if (a.ArgType == Argument.AType.Ref)
                {
                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "IsRef", loc));
                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc));
                }
                else if (a.ArgType == Argument.AType.Out)
                {
                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "IsOut", loc));
                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc));
                }
                else if (a.ArgType == Argument.AType.DynamicTypeName)
                {
                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "IsStaticType", loc));
                }

                var arg_type = a.Expr.Type;

                if (arg_type.BuiltinType != BuiltinTypeSpec.Type.Dynamic && arg_type != InternalType.NullLiteral)
                {
                    MethodGroupExpr mg = a.Expr as MethodGroupExpr;
                    if (mg != null)
                    {
                        rc.Report.Error(1976, a.Expr.Location,
                                        "The method group `{0}' cannot be used as an argument of dynamic operation. Consider using parentheses to invoke the method",
                                        mg.Name);
                    }
                    else if (arg_type == InternalType.AnonymousMethod)
                    {
                        rc.Report.Error(1977, a.Expr.Location,
                                        "An anonymous method or lambda expression cannot be used as an argument of dynamic operation. Consider using a cast");
                    }
                    else if (arg_type.Kind == MemberKind.Void || arg_type == InternalType.Arglist || arg_type.IsPointer)
                    {
                        rc.Report.Error(1978, a.Expr.Location,
                                        "An expression of type `{0}' cannot be used as an argument of dynamic operation",
                                        TypeManager.CSharpName(arg_type));
                    }

                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc));
                }

                string        named_value;
                NamedArgument na = a as NamedArgument;
                if (na != null)
                {
                    info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags,
                                            new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "NamedArgument", loc));

                    named_value = na.Name;
                }
                else
                {
                    named_value = null;
                }

                dargs.Add(new Argument(info_flags));
                dargs.Add(new Argument(new StringLiteral(rc.BuiltinTypes, named_value, loc)));
                all.Add(new Invocation(new MemberAccess(new MemberAccess(binder, "CSharpArgumentInfo", loc), "Create", loc), dargs));
            }

            return(all);
        }
예제 #3
0
		//
		// For named arguments when the order of execution is different
		// to order of invocation
		//
		public Arguments MarkOrderedArgument (NamedArgument a)
		{
			//
			// An expression has no effect on left-to-right execution
			//
			if (a.Expr.IsSideEffectFree)
				return this;

			ArgumentsOrdered ra = this as ArgumentsOrdered;
			if (ra == null) {
				ra = new ArgumentsOrdered (this);

				for (int i = 0; i < args.Count; ++i) {
					var la = args [i];
					if (la == a)
						break;

					//
					// When the argument is filled later by default expression
					//
					if (la == null)
						continue;

					var ma = la as MovableArgument;
					if (ma == null) {
						ma = new MovableArgument (la);
						ra.args[i] = ma;
					}

					ra.AddOrdered (ma);
				}
			}

			ra.AddOrdered (a);
			return ra;
		}
예제 #4
0
void case_80()
#line 886 "cs-parser.jay"
{
		if (lang_version <= LanguageVersion.V_3)
			FeatureIsNotAvailable (GetLocation (yyVals[-3+yyTop]), "named argument");
			
		/* Avoid boxing in common case (no modifier)*/
		var arg_mod = yyVals[-1+yyTop] == null ? Argument.AType.None : (Argument.AType) yyVals[-1+yyTop];
			
		var lt = (Tokenizer.LocatedToken) yyVals[-3+yyTop];
		yyVal = new NamedArgument (lt.Value, lt.Location, (Expression) yyVals[0+yyTop], arg_mod);
		lbag.AddLocation (yyVal, GetLocation(yyVals[-2+yyTop]));
	  }
예제 #5
0
void case_79()
#line 876 "cs-parser.jay"
{
	  	--lexer.parsing_block;
	  	var lt = (Tokenizer.LocatedToken) yyVals[-3+yyTop];
		yyVal = new NamedArgument (lt.Value, lt.Location, (Expression) yyVals[0+yyTop]);	  
		lbag.AddLocation (yyVal, GetLocation(yyVals[-2+yyTop]));
	  }
예제 #6
0
void Error_NamedArgumentExpected (NamedArgument a)
{
	report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
}