public override DynamicMetaObject FallbackSetMember (DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create (); var source = ctx.CreateCompilerExpression (argumentInfo [1], value); var expr = ctx.CreateCompilerExpression (argumentInfo [0], target); // Field assignment expr = new Compiler.MemberAccess (expr, Name); // Compound assignment under dynamic context does not convert result // expression but when setting member type we need to do explicit // conversion to ensure type match between member type and dynamic // expression type if ((flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0) { expr = new Compiler.RuntimeExplicitAssign (expr, source); } else { expr = new Compiler.SimpleAssign (expr, source); } expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); binder.AddRestrictions (value); return binder.Bind (ctx, callingContext); }
public override DynamicMetaObject FallbackGetMember (DynamicMetaObject target, DynamicMetaObject errorSuggestion) { var expr = CSharpBinder.CreateCompilerExpression (argumentInfo [0], target); expr = new Compiler.MemberAccess (expr, Name); expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); return binder.Bind (callingContext, target); }
public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var c_args = ctx.CreateCompilerArguments(argumentInfo.Skip(1), args); var t_args = typeArguments == null ? null : new Compiler.TypeArguments(typeArguments.Select(l => new Compiler.TypeExpression(ctx.ImportType(l), Compiler.Location.Null)).ToArray()); var expr = ctx.CreateCompilerExpression(argumentInfo[0], target); // // Simple name invocation is actually member access invocation // to capture original this argument. This brings problem when // simple name is resolved as a static invocation and member access // has to be reduced back to simple name without reporting an error // if ((flags & CSharpBinderFlags.InvokeSimpleName) != 0) { var value = expr as Compiler.RuntimeValueExpression; if (value != null) { value.IsSuggestionOnly = true; } } expr = new Compiler.MemberAccess(expr, Name, t_args, Compiler.Location.Null); expr = new Invocation(expr, c_args, this); if ((flags & CSharpBinderFlags.ResultDiscarded) == 0) { expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); } else { expr = new Compiler.DynamicResultCast(ctx.ImportType(ReturnType), expr); } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); binder.AddRestrictions(args); if ((flags & CSharpBinderFlags.InvokeSpecialName) != 0) { binder.ResolveOptions |= Compiler.ResolveContext.Options.InvokeSpecialName; } return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); expr = new Compiler.MemberAccess(expr, Name); expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); return(binder.Bind(ctx, callingContext)); }
public override DynamicMetaObject FallbackSetMember (DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create (); var source = ctx.CreateCompilerExpression (argumentInfo [1], value); var expr = ctx.CreateCompilerExpression (argumentInfo [0], target); // Field assignment expr = new Compiler.MemberAccess (expr, Name); expr = new Compiler.SimpleAssign (expr, source); expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); binder.AddRestrictions (value); return binder.Bind (ctx, callingContext); }
public override DynamicMetaObject FallbackInvokeMember (DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) { var c_args = CSharpBinder.CreateCompilerArguments (argumentInfo.Skip (1), args); var t_args = typeArguments == null ? null : new Compiler.TypeArguments (typeArguments.Select (l => new Compiler.TypeExpression (TypeImporter.Import (l), Compiler.Location.Null)).ToArray ()); var expr = CSharpBinder.CreateCompilerExpression (argumentInfo[0], target); // // Simple name invocation is actually member access invocation // to capture original this argument. This brings problem when // simple name is resolved as a static invocation and member access // has to be reduced back to simple name without reporting an error // if ((flags & CSharpBinderFlags.InvokeSimpleName) != 0) { var value = expr as Compiler.RuntimeValueExpression; if (value != null) value.IsSuggestionOnly = true; } expr = new Compiler.MemberAccess (expr, Name, t_args, Compiler.Location.Null); expr = new Compiler.Invocation (expr, c_args); if ((flags & CSharpBinderFlags.ResultDiscarded) == 0) expr = new Compiler.Cast (new Compiler.TypeExpression (TypeImporter.Import (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); else expr = new Compiler.DynamicResultCast (TypeImporter.Import (ReturnType), expr); var binder = new CSharpBinder (this, expr, errorSuggestion); binder.AddRestrictions (target); binder.AddRestrictions (args); if ((flags & CSharpBinderFlags.InvokeSpecialName) != 0) binder.ResolveOptions |= Compiler.ResolveContext.Options.InvokeSpecialName; return binder.Bind (callingContext, target); }
public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion) { var ctx = DynamicContext.Create(); var source = ctx.CreateCompilerExpression(argumentInfo [1], value); var expr = ctx.CreateCompilerExpression(argumentInfo [0], target); // Field assignment expr = new Compiler.MemberAccess(expr, Name); // Compound assignment under dynamic context does not convert result // expression but when setting member type we need to do explicit // conversion to ensure type match between member type and dynamic // expression type if ((flags & CSharpBinderFlags.ValueFromCompoundAssignment) != 0) { expr = new Compiler.RuntimeExplicitAssign(expr, source); } else { expr = new Compiler.SimpleAssign(expr, source); } expr = new Compiler.Cast(new Compiler.TypeExpression(ctx.ImportType(ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null); if ((flags & CSharpBinderFlags.CheckedContext) != 0) { expr = new Compiler.CheckedExpr(expr, Compiler.Location.Null); } var binder = new CSharpBinder(this, expr, errorSuggestion); binder.AddRestrictions(target); binder.AddRestrictions(value); return(binder.Bind(ctx, callingContext)); }
public override object Visit (MemberAccess memberAccess) { var result = new MemberReferenceExpression (); result.AddChild ((INode)memberAccess.LeftExpression.Accept (this), MemberReferenceExpression.Roles.TargetExpression); result.AddChild (new Identifier (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier); if (memberAccess.TypeArguments != null) { var location = LocationsBag.GetLocations (memberAccess); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MemberReferenceExpression.Roles.LChevron); // AddTypeArguments (result, location, memberAccess.TypeArguments); if (location != null && location.Count > 1) result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MemberReferenceExpression.Roles.RChevron); } return result; }
void case_361() #line 2975 "cs-parser.jay" { var lt = (LocatedToken) yyVals[-2+yyTop]; yyVal = new MemberAccess ((ATypeNameExpression) yyVals[-3+yyTop], lt.Value, (TypeArguments) yyVals[-1+yyTop], lt.Location); lbag.AddLocation (yyVal, GetLocation (yyVals[0+yyTop])); }
public override bool Resolve(BlockContext bc) { if (!base.Resolve(bc)) { return(false); } Arguments args = new Arguments(0); type = expr.Type; // // The await expression is of dynamic type // if (type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { result_type = type; awaiter = ((AsyncTaskStorey)machine_initializer.Storey).AddAwaiter(type, loc); expr = new Invocation(new MemberAccess(expr, "GetAwaiter"), args).Resolve(bc); return(true); } // // Check whether the expression is awaitable // Expression ama = new AwaitableMemberAccess(expr).Resolve(bc); if (ama == null) { return(false); } var errors_printer = new SessionReportPrinter(); var old = bc.Report.SetPrinter(errors_printer); ama = new Invocation(ama, args).Resolve(bc); bc.Report.SetPrinter(old); if (errors_printer.ErrorsCount > 0 || !MemberAccess.IsValidDotExpression(ama.Type)) { bc.Report.Error(1986, expr.Location, "The `await' operand type `{0}' must have suitable GetAwaiter method", expr.Type.GetSignatureForError()); return(false); } var awaiter_type = ama.Type; awaiter = ((AsyncTaskStorey)machine_initializer.Storey).AddAwaiter(awaiter_type, loc); expr = ama; // // Predefined: bool IsCompleted { get; } // is_completed = MemberCache.FindMember(awaiter_type, MemberFilter.Property("IsCompleted", bc.Module.Compiler.BuiltinTypes.Bool), BindingRestriction.InstanceOnly) as PropertySpec; if (is_completed == null || !is_completed.HasGet) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } // // Predefined: OnCompleted (Action) // if (bc.Module.PredefinedTypes.Action.Define()) { on_completed = MemberCache.FindMember(awaiter_type, MemberFilter.Method("OnCompleted", 0, ParametersCompiled.CreateFullyResolved(bc.Module.PredefinedTypes.Action.TypeSpec), bc.Module.Compiler.BuiltinTypes.Void), BindingRestriction.InstanceOnly) as MethodSpec; if (on_completed == null) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } } // // Predefined: GetResult () // // The method return type is also result type of await expression // get_result = MemberCache.FindMember(awaiter_type, MemberFilter.Method("GetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.InstanceOnly) as MethodSpec; if (get_result == null) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } result_type = get_result.ReturnType; return(true); }
public virtual object Visit (MemberAccess memberAccess) { return null; }
public void Resolve () { if (RootContext.Unsafe) { // // Emits [assembly: SecurityPermissionAttribute (SecurityAction.RequestMinimum, SkipVerification = true)] // when -unsafe option was specified // Location loc = Location.Null; MemberAccess system_security_permissions = new MemberAccess (new MemberAccess ( new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Security", loc), "Permissions", loc); Arguments pos = new Arguments (1); pos.Add (new Argument (new MemberAccess (new MemberAccess (system_security_permissions, "SecurityAction", loc), "RequestMinimum"))); Arguments named = new Arguments (1); named.Add (new NamedArgument ("SkipVerification", loc, new BoolLiteral (true, loc))); GlobalAttribute g = new GlobalAttribute (new NamespaceEntry (module, null, null, null), "assembly", new MemberAccess (system_security_permissions, "SecurityPermissionAttribute"), new Arguments[] { pos, named }, loc, false); g.AttachTo (module, module); if (g.Resolve () != null) { declarative_security = new Dictionary<SecurityAction, PermissionSet> (); g.ExtractSecurityPermissionSet (declarative_security); } } if (module.OptAttributes == null) return; // Ensure that we only have GlobalAttributes, since the Search isn't safe with other types. if (!module.OptAttributes.CheckTargets()) return; cls_attribute = module.ResolveAssemblyAttribute (Compiler.PredefinedAttributes.CLSCompliant); if (cls_attribute != null) { is_cls_compliant = cls_attribute.GetClsCompliantAttributeValue (); } if (added_modules != null && RootContext.VerifyClsCompliance && is_cls_compliant) { foreach (var m in added_modules) { if (!m.IsCLSCompliant) { Report.Error (3013, "Added modules must be marked with the CLSCompliant attribute to match the assembly", m.Name); } } } Attribute a = module.ResolveAssemblyAttribute (Compiler.PredefinedAttributes.RuntimeCompatibility); if (a != null) { var val = a.GetNamedValue ("WrapNonExceptionThrows") as BoolConstant; if (val != null) wrap_non_exception_throws = val.Value; } }
public override bool Resolve(BlockContext bc) { if (bc.CurrentBlock is Linq.QueryBlock) { bc.Report.Error(1995, loc, "The `await' operator may only be used in a query expression within the first collection expression of the initial `from' clause or within the collection expression of a `join' clause"); return(false); } if (bc.HasSet(ResolveContext.Options.CatchScope)) { bc.Report.Error(1985, loc, "The `await' operator cannot be used in the body of a catch clause"); } if (!base.Resolve(bc)) { return(false); } type = expr.Type; Arguments args = new Arguments(0); // // The await expression is of dynamic type // if (type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { result_type = type; expr = new Invocation(new MemberAccess(expr, "GetAwaiter"), args).Resolve(bc); return(true); } // // Check whether the expression is awaitable // Expression ama = new AwaitableMemberAccess(expr).Resolve(bc); if (ama == null) { return(false); } var errors_printer = new SessionReportPrinter(); var old = bc.Report.SetPrinter(errors_printer); ama = new Invocation(ama, args).Resolve(bc); bc.Report.SetPrinter(old); if (errors_printer.ErrorsCount > 0 || !MemberAccess.IsValidDotExpression(ama.Type)) { bc.Report.Error(1986, expr.Location, "The `await' operand type `{0}' must have suitable GetAwaiter method", expr.Type.GetSignatureForError()); return(false); } var awaiter_type = ama.Type; awaiter_definition = bc.Module.GetAwaiter(awaiter_type); if (!awaiter_definition.IsValidPattern) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } if (!awaiter_definition.INotifyCompletion) { bc.Report.Error(4027, loc, "The awaiter type `{0}' must implement interface `{1}'", awaiter_type.GetSignatureForError(), bc.Module.PredefinedTypes.INotifyCompletion.GetSignatureForError()); return(false); } expr = ama; result_type = awaiter_definition.GetResult.ReturnType; return(true); }
void ResolveStringSwitchMap (ResolveContext ec) { FullNamedExpression string_dictionary_type; if (TypeManager.generic_ienumerable_type != null) { MemberAccess system_collections_generic = new MemberAccess (new MemberAccess ( new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Collections", loc), "Generic", loc); string_dictionary_type = new MemberAccess (system_collections_generic, "Dictionary", new TypeArguments ( new TypeExpression (TypeManager.string_type, loc), new TypeExpression (TypeManager.int32_type, loc)), loc); } else { MemberAccess system_collections_generic = new MemberAccess ( new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Collections", loc); string_dictionary_type = new MemberAccess (system_collections_generic, "Hashtable", loc); } var ctype = ec.CurrentMemberDefinition.Parent.PartialContainer; Field field = new Field (ctype, string_dictionary_type, Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, new MemberName (CompilerGeneratedClass.MakeName (null, "f", "switch$map", unique_counter++), loc), null); if (!field.Define ()) return; ctype.AddField (field); var init = new List<Expression> (); int counter = 0; Elements.Clear (); string value = null; foreach (SwitchSection section in Sections) { int last_count = init.Count; foreach (SwitchLabel sl in section.Labels) { if (sl.Label == null || sl.Converted == SwitchLabel.NullStringCase) continue; value = (string) sl.Converted; var init_args = new List<Expression> (2); init_args.Add (new StringLiteral (value, sl.Location)); init_args.Add (new IntConstant (counter, loc)); init.Add (new CollectionElementInitializer (init_args, loc)); } // // Don't add empty sections // if (last_count == init.Count) continue; Elements.Add (counter, section.Labels [0]); ++counter; } Arguments args = new Arguments (1); args.Add (new Argument (new IntConstant (init.Count, loc))); Expression initializer = new NewInitialize (string_dictionary_type, args, new CollectionOrObjectInitializers (init, loc), loc); switch_cache_field = new FieldExpr (field, loc); string_dictionary = new SimpleAssign (switch_cache_field, initializer.Resolve (ec)); }
public ArrayList CreateDynamicBinderArguments() { ArrayList all = new ArrayList(args.Count); Location loc = Location.Null; 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(0, loc); if (a.Expr is Constant) { // Any constant is emitted as a literal info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "LiteralConstant", 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)); } 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)); } else if (a.ArgType == Argument.AType.DynamicStatic) { info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "IsStaticType", loc)); } if (!TypeManager.IsDynamicType(a.Expr.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.Value; } else { named_value = null; } dargs.Add(new Argument(info_flags)); dargs.Add(new Argument(new StringLiteral(named_value, loc))); all.Add(new New(new MemberAccess(binder, "CSharpArgumentInfo", loc), dargs, loc)); } return(all); }
void case_431() #line 3215 "cs-parser.jay" { var lt = (Tokenizer.LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess ((Expression) yyVals[-3+yyTop], lt.Value, (TypeArguments) yyVals[0+yyTop], lt.Location) { DotLocation = GetLocation (yyVals[-2+yyTop]) }; }
public virtual object Visit(MemberAccess memberAccess) { return(null); }
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(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), 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), loc); info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc), 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), loc); info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc), 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), loc); } var arg_type = a.Expr.Type; if (arg_type != InternalType.Dynamic && arg_type != InternalType.Null) { 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 == TypeManager.void_type || 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), 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), loc); named_value = na.Name; } else { named_value = null; } dargs.Add(new Argument(info_flags)); dargs.Add(new Argument(new StringLiteral(named_value, loc))); all.Add(new Invocation(new MemberAccess(new MemberAccess(binder, "CSharpArgumentInfo", loc), "Create", loc), dargs)); } return(all); }
public void Resolve() { if (Compiler.Settings.Unsafe && module.PredefinedTypes.SecurityAction.Define()) { // // Emits [assembly: SecurityPermissionAttribute (SecurityAction.RequestMinimum, SkipVerification = true)] // when -unsafe option was specified // Location loc = Location.Null; MemberAccess system_security_permissions = new MemberAccess(new MemberAccess( new QualifiedAliasMember(QualifiedAliasMember.GlobalAlias, "System", loc), "Security", loc), "Permissions", loc); var req_min = module.PredefinedMembers.SecurityActionRequestMinimum.Resolve(loc); Arguments pos = new Arguments(1); pos.Add(new Argument(req_min.GetConstant(null))); Arguments named = new Arguments(1); named.Add(new NamedArgument("SkipVerification", loc, new BoolLiteral(Compiler.BuiltinTypes, true, loc))); Attribute g = new Attribute("assembly", new MemberAccess(system_security_permissions, "SecurityPermissionAttribute"), new Arguments[] { pos, named }, loc, false); g.AttachTo(module, module); var ctor = g.Resolve(); if (ctor != null) { g.ExtractSecurityPermissionSet(ctor, ref declarative_security); } } if (module.OptAttributes == null) { return; } // Ensure that we only have GlobalAttributes, since the Search isn't safe with other types. if (!module.OptAttributes.CheckTargets()) { return; } cls_attribute = module.ResolveAssemblyAttribute(module.PredefinedAttributes.CLSCompliant); if (cls_attribute != null) { is_cls_compliant = cls_attribute.GetClsCompliantAttributeValue(); } if (added_modules != null && Compiler.Settings.VerifyClsCompliance && is_cls_compliant) { foreach (var m in added_modules) { if (!m.IsCLSCompliant) { Report.Error(3013, "Added modules must be marked with the CLSCompliant attribute to match the assembly", m.Name); } } } Attribute a = module.ResolveAssemblyAttribute(module.PredefinedAttributes.RuntimeCompatibility); if (a != null) { var val = a.GetNamedValue("WrapNonExceptionThrows") as BoolConstant; if (val != null) { wrap_non_exception_throws = val.Value; } } }
Method GenerateNumberMatcher() { var loc = Location; var parameters = ParametersCompiled.CreateFullyResolved( new [] { new Parameter(new TypeExpression(Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), new Parameter(new TypeExpression(Compiler.BuiltinTypes.Object, loc), "value", 0, null, loc), new Parameter(new TypeExpression(Compiler.BuiltinTypes.Bool, loc), "enumType", 0, null, loc), }, new [] { Compiler.BuiltinTypes.Object, Compiler.BuiltinTypes.Object, Compiler.BuiltinTypes.Bool }); var m = new Method(this, new TypeExpression(Compiler.BuiltinTypes.Bool, loc), Modifiers.PUBLIC | Modifiers.STATIC | Modifiers.DEBUGGER_HIDDEN, new MemberName("NumberMatcher", loc), parameters, null); parameters [0].Resolve(m, 0); parameters [1].Resolve(m, 1); parameters [2].Resolve(m, 2); ToplevelBlock top_block = new ToplevelBlock(Compiler, parameters, loc); m.Block = top_block; // // if (enumType) // return Equals (obj, value); // var equals_args = new Arguments(2); equals_args.Add(new Argument(top_block.GetParameterReference(0, loc))); equals_args.Add(new Argument(top_block.GetParameterReference(1, loc))); var if_type = new If( top_block.GetParameterReference(2, loc), new Return(new Invocation(new SimpleName("Equals", loc), equals_args), loc), loc); top_block.AddStatement(if_type); // // if (obj is Enum || obj == null) // return false; // var if_enum = new If( new Binary(Binary.Operator.LogicalOr, new Is(top_block.GetParameterReference(0, loc), new TypeExpression(Compiler.BuiltinTypes.Enum, loc), loc), new Binary(Binary.Operator.Equality, top_block.GetParameterReference(0, loc), new NullLiteral(loc))), new Return(new BoolLiteral(Compiler.BuiltinTypes, false, loc), loc), loc); top_block.AddStatement(if_enum); var system_convert = new MemberAccess(new QualifiedAliasMember("global", "System", loc), "Convert", loc); var expl_block = new ExplicitBlock(top_block, loc, loc); // // var converted = System.Convert.ChangeType (obj, System.Convert.GetTypeCode (value)); // var lv_converted = LocalVariable.CreateCompilerGenerated(Compiler.BuiltinTypes.Object, top_block, loc); var arguments_gettypecode = new Arguments(1); arguments_gettypecode.Add(new Argument(top_block.GetParameterReference(1, loc))); var gettypecode = new Invocation(new MemberAccess(system_convert, "GetTypeCode", loc), arguments_gettypecode); var arguments_changetype = new Arguments(1); arguments_changetype.Add(new Argument(top_block.GetParameterReference(0, loc))); arguments_changetype.Add(new Argument(gettypecode)); var changetype = new Invocation(new MemberAccess(system_convert, "ChangeType", loc), arguments_changetype); expl_block.AddStatement(new StatementExpression(new SimpleAssign(new LocalVariableReference(lv_converted, loc), changetype, loc))); // // return converted.Equals (value) // var equals_arguments = new Arguments(1); equals_arguments.Add(new Argument(top_block.GetParameterReference(1, loc))); var equals_invocation = new Invocation(new MemberAccess(new LocalVariableReference(lv_converted, loc), "Equals"), equals_arguments); expl_block.AddStatement(new Return(equals_invocation, loc)); var catch_block = new ExplicitBlock(top_block, loc, loc); catch_block.AddStatement(new Return(new BoolLiteral(Compiler.BuiltinTypes, false, loc), loc)); top_block.AddStatement(new TryCatch(expl_block, new List <Catch> () { new Catch(catch_block, loc) }, loc, false)); m.Define(); m.PrepareEmit(); AddMember(m); return(m); }
protected override Expression DoResolve(ResolveContext ec) { right = right.Resolve(ec); if (right == null) { return(null); } MemberAccess ma = target as MemberAccess; using (ec.Set(ResolveContext.Options.CompoundAssignmentScope)) { target = target.Resolve(ec); } if (target == null) { return(null); } if (target is MethodGroupExpr) { ec.Report.Error(1656, loc, "Cannot assign to `{0}' because it is a `{1}'", ((MethodGroupExpr)target).Name, target.ExprClassName); return(null); } var event_expr = target as EventExpr; if (event_expr != null) { source = Convert.ImplicitConversionRequired(ec, right, target.Type, loc); if (source == null) { return(null); } Expression rside; if (op == Binary.Operator.Addition) { rside = EmptyExpression.EventAddition; } else if (op == Binary.Operator.Subtraction) { rside = EmptyExpression.EventSubtraction; } else { rside = null; } target = target.ResolveLValue(ec, rside); if (target == null) { return(null); } eclass = ExprClass.Value; type = event_expr.Operator.ReturnType; return(this); } // // Only now we can decouple the original source/target // into a tree, to guarantee that we do not have side // effects. // if (left == null) { left = new TargetExpression(target); } source = new Binary(op, left, right, true, loc); if (target is DynamicMemberAssignable) { Arguments targs = ((DynamicMemberAssignable)target).Arguments; source = source.Resolve(ec); Arguments args = new Arguments(targs.Count + 1); args.AddRange(targs); args.Add(new Argument(source)); var binder_flags = CSharpBinderFlags.ValueFromCompoundAssignment; // // Compound assignment does target conversion using additional method // call, set checked context as the binary operation can overflow // if (ec.HasSet(ResolveContext.Options.CheckedScope)) { binder_flags |= CSharpBinderFlags.CheckedContext; } if (target is DynamicMemberBinder) { source = new DynamicMemberBinder(ma.Name, binder_flags, args, loc).Resolve(ec); // Handles possible event addition/subtraction if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction) { args = new Arguments(targs.Count + 1); args.AddRange(targs); args.Add(new Argument(right)); string method_prefix = op == Binary.Operator.Addition ? Event.AEventAccessor.AddPrefix : Event.AEventAccessor.RemovePrefix; var invoke = DynamicInvocation.CreateSpecialNameInvoke( new MemberAccess(right, method_prefix + ma.Name, loc), args, loc).Resolve(ec); args = new Arguments(targs.Count); args.AddRange(targs); source = new DynamicEventCompoundAssign(ma.Name, args, (ExpressionStatement)source, (ExpressionStatement)invoke, loc).Resolve(ec); } } else { source = new DynamicIndexBinder(binder_flags, args, loc).Resolve(ec); } return(source); } return(base.DoResolve(ec)); }
public void Resolve() { if (RootContext.Unsafe) { // // Emits [assembly: SecurityPermissionAttribute (SecurityAction.RequestMinimum, SkipVerification = true)] // when -unsafe option was specified // Location loc = Location.Null; MemberAccess system_security_permissions = new MemberAccess(new MemberAccess( new QualifiedAliasMember(QualifiedAliasMember.GlobalAlias, "System", loc), "Security", loc), "Permissions", loc); Arguments pos = new Arguments(1); pos.Add(new Argument(new MemberAccess(new MemberAccess(system_security_permissions, "SecurityAction", loc), "RequestMinimum"))); Arguments named = new Arguments(1); named.Add(new NamedArgument(new LocatedToken(loc, "SkipVerification"), (new BoolLiteral(true, loc)))); GlobalAttribute g = new GlobalAttribute(new NamespaceEntry(null, null, null), "assembly", new MemberAccess(system_security_permissions, "SecurityPermissionAttribute"), new Arguments[] { pos, named }, loc, false); g.AttachTo(this, this); if (g.Resolve() != null) { declarative_security = new ListDictionary(); g.ExtractSecurityPermissionSet(declarative_security); } } if (OptAttributes == null) { return; } // Ensure that we only have GlobalAttributes, since the Search isn't safe with other types. if (!OptAttributes.CheckTargets()) { return; } ClsCompliantAttribute = ResolveAttribute(PredefinedAttributes.Get.CLSCompliant); if (ClsCompliantAttribute != null) { is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue(); } Attribute a = ResolveAttribute(PredefinedAttributes.Get.RuntimeCompatibility); if (a != null) { object val = a.GetPropertyValue("WrapNonExceptionThrows"); if (val != null) { wrap_non_exception_throws = (bool)val; } } }
void case_530() #line 3827 "cs-parser.jay" { var lt = (Tokenizer.LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess ((Expression) yyVals[-3+yyTop], lt.Value, (int) yyVals[0+yyTop], lt.Location) { DotLocation = GetLocation (yyVals[-2+yyTop]) }; }
public void Resolve () { if (RootContext.Unsafe) { // // Emits [assembly: SecurityPermissionAttribute (SecurityAction.RequestMinimum, SkipVerification = true)] // when -unsafe option was specified // Location loc = Location.Null; MemberAccess system_security_permissions = new MemberAccess (new MemberAccess ( new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Security", loc), "Permissions", loc); Arguments pos = new Arguments (1); pos.Add (new Argument (new MemberAccess (new MemberAccess (system_security_permissions, "SecurityAction", loc), "RequestMinimum"))); Arguments named = new Arguments (1); named.Add (new NamedArgument ("SkipVerification", loc, new BoolLiteral (true, loc))); GlobalAttribute g = new GlobalAttribute (new NamespaceEntry (null, null, null), "assembly", new MemberAccess (system_security_permissions, "SecurityPermissionAttribute"), new Arguments[] { pos, named }, loc, false); g.AttachTo (this, this); if (g.Resolve () != null) { declarative_security = new Dictionary<SecurityAction, PermissionSet> (); g.ExtractSecurityPermissionSet (declarative_security); } } if (OptAttributes == null) return; // Ensure that we only have GlobalAttributes, since the Search isn't safe with other types. if (!OptAttributes.CheckTargets()) return; ClsCompliantAttribute = ResolveAttribute (PredefinedAttributes.Get.CLSCompliant); if (ClsCompliantAttribute != null) { is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue (); } Attribute a = ResolveAttribute (PredefinedAttributes.Get.RuntimeCompatibility); if (a != null) { var val = a.GetPropertyValue ("WrapNonExceptionThrows") as BoolConstant; if (val != null) wrap_non_exception_throws = val.Value; } }
public override bool Resolve(BlockContext bc) { if (!base.Resolve(bc)) { return(false); } type = expr.Type; // // The task result is of dynamic type // if (expr.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { throw new NotImplementedException("dynamic await"); } // // Check whether the expression is awaitable // Expression ama = new AwaitableMemberAccess(expr).Resolve(bc); if (ama == null) { return(false); } Arguments args = new Arguments(0); var errors_printer = new SessionReportPrinter(); var old = bc.Report.SetPrinter(errors_printer); ama = new Invocation(ama, args).Resolve(bc); if (errors_printer.ErrorsCount > 0 || !MemberAccess.IsValidDotExpression(ama.Type)) { bc.Report.SetPrinter(old); Error_WrongGetAwaiter(bc, loc, expr.Type); return(false); } var awaiter_type = ama.Type; awaiter = ((AsyncTaskStorey)machine_initializer.Storey).AddAwaiter(awaiter_type, loc); expr = ama; // // Predefined: bool IsCompleted { get; } // var is_completed_ma = new MemberAccess(expr, "IsCompleted").Resolve(bc); if (is_completed_ma != null) { is_completed = is_completed_ma as PropertyExpr; if (is_completed != null && is_completed.Type.BuiltinType == BuiltinTypeSpec.Type.Bool && is_completed.IsInstance && is_completed.Getter != null) { // valid } else { bc.Report.SetPrinter(old); Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } } bc.Report.SetPrinter(old); if (errors_printer.ErrorsCount > 0) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } // // Predefined: OnCompleted (Action) // if (bc.Module.PredefinedTypes.Action.Define()) { on_completed = MemberCache.FindMember(awaiter_type, MemberFilter.Method("OnCompleted", 0, ParametersCompiled.CreateFullyResolved(bc.Module.PredefinedTypes.Action.TypeSpec), bc.Module.Compiler.BuiltinTypes.Void), BindingRestriction.InstanceOnly) as MethodSpec; if (on_completed == null) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } } // // Predefined: GetResult () // // The method return type is also result type of await expression // get_result = MemberCache.FindMember(awaiter_type, MemberFilter.Method("GetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.InstanceOnly) as MethodSpec; if (get_result == null) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } return(true); }
void case_432() #line 3222 "cs-parser.jay" { var lt = (Tokenizer.LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess (new BaseThis (GetLocation (yyVals[-3+yyTop])), lt.Value, (TypeArguments) yyVals[0+yyTop], lt.Location) { DotLocation = GetLocation (yyVals[-2+yyTop]) }; }
public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args) { Arguments binder_args = new Arguments(member != null ? 5 : 3); MemberAccess binder = GetBinderNamespace(loc); bool is_member_access = member is MemberAccess; string call_flags; if (!is_member_access && member is SimpleName) { call_flags = "SimpleNameCall"; is_member_access = true; } else { call_flags = "None"; } binder_args.Add(new Argument(new MemberAccess(new MemberAccess(binder, "CSharpCallFlags", loc), call_flags, loc))); if (is_member_access) { binder_args.Add(new Argument(new StringLiteral(member.Name, member.Location))); } binder_args.Add(new Argument(new TypeOf(new TypeExpression(ec.CurrentType, loc), loc))); if (member != null && member.HasTypeArguments) { TypeArguments ta = member.TypeArguments; if (ta.Resolve(ec)) { ArrayList targs = new ArrayList(ta.Count); foreach (Type t in ta.Arguments) { targs.Add(new TypeOf(new TypeExpression(t, loc), loc)); } binder_args.Add(new Argument(new ImplicitlyTypedArrayCreation("[]", targs, loc))); } } else if (is_member_access) { binder_args.Add(new Argument(new NullLiteral(loc))); } Expression real_args; if (args == null) { // Cannot be null because .NET trips over real_args = new ArrayCreation(new MemberAccess(binder, "CSharpArgumentInfo", loc), "[]", new ArrayList(0), loc); } else { real_args = new ImplicitlyTypedArrayCreation("[]", args.CreateDynamicBinderArguments(), loc); } binder_args.Add(new Argument(real_args)); return(new New(new MemberAccess(binder, is_member_access ? "CSharpInvokeMemberBinder" : "CSharpInvokeBinder", loc), binder_args, loc)); }
void case_531() #line 3835 "cs-parser.jay" { var tne = (ATypeNameExpression) yyVals[-3+yyTop]; if (tne.HasTypeArguments) Error_TypeExpected (GetLocation (yyVals[0+yyTop])); var lt = (Tokenizer.LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess (tne, lt.Value, (int) yyVals[0+yyTop], lt.Location) { DotLocation = GetLocation (yyVals[-2+yyTop]) }; }
void case_536() #line 3874 "cs-parser.jay" { var lt = (LocatedToken) yyVals[0+yyTop]; yyVal = new MemberAccess ((Expression) yyVals[-2+yyTop], lt.Value, lt.Location); lbag.AddLocation (yyVal, savedLocation, GetLocation (yyVals[-1+yyTop])); }
public override bool Resolve (BlockContext ec) { Block variables_block = variable.local_info.Block; copy = TemporaryVariableReference.Create (for_each.expr.Type, variables_block, loc); copy.Resolve (ec); int rank = length_exprs.Length; Arguments list = new Arguments (rank); for (int i = 0; i < rank; i++) { var v = TemporaryVariableReference.Create (TypeManager.int32_type, variables_block, loc); variables[i] = v; counter[i] = new StatementExpression (new UnaryMutator (UnaryMutator.Mode.PostIncrement, v, loc)); counter[i].Resolve (ec); if (rank == 1) { length_exprs [i] = new MemberAccess (copy, "Length").Resolve (ec); } else { lengths[i] = TemporaryVariableReference.Create (TypeManager.int32_type, variables_block, loc); lengths[i].Resolve (ec); Arguments args = new Arguments (1); args.Add (new Argument (new IntConstant (i, loc))); length_exprs [i] = new Invocation (new MemberAccess (copy, "GetLength"), args).Resolve (ec); } list.Add (new Argument (v)); } access = new ElementAccess (copy, list, loc).Resolve (ec); if (access == null) return false; Expression var_type = for_each.type; VarExpr ve = var_type as VarExpr; if (ve != null) { // Infer implicitly typed local variable from foreach array type var_type = new TypeExpression (access.Type, ve.Location); } var_type = var_type.ResolveAsTypeTerminal (ec, false); if (var_type == null) return false; conv = Convert.ExplicitConversion (ec, access, var_type.Type, loc); if (conv == null) return false; bool ok = true; ec.StartFlowBranching (FlowBranching.BranchingType.Loop, loc); ec.CurrentBranching.CreateSibling (); variable.local_info.Type = conv.Type; variable.Resolve (ec); ec.StartFlowBranching (FlowBranching.BranchingType.Embedded, loc); if (!statement.Resolve (ec)) ok = false; ec.EndFlowBranching (); // There's no direct control flow from the end of the embedded statement to the end of the loop ec.CurrentBranching.CurrentUsageVector.Goto (); ec.EndFlowBranching (); return ok; }
void case_538() #line 3890 "cs-parser.jay" { var tne = (ATypeNameExpression) yyVals[-3+yyTop]; if (tne.HasTypeArguments) Error_TypeExpected (GetLocation (yyVals[0+yyTop])); var lt = (LocatedToken) yyVals[-1+yyTop]; var ma = new MemberAccess (tne, lt.Value, (int) yyVals[0+yyTop], lt.Location); yyVal = ma; lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ()); }
public ArrayInitializer CreateDynamicBinderArguments(ResolveContext rc) { Location loc = Location.Null; var all = new ArrayInitializer(args.Count, loc); MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace(rc, 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)); } TypeSpec arg_type; if (rc.FileType == SourceFileType.PlayScript && a.Expr is ArrayInitializer || a.Expr is AsObjectInitializer) { if (a.Expr is ArrayInitializer) { arg_type = rc.Module.PredefinedTypes.AsArray.Resolve(); } else { arg_type = rc.Module.PredefinedTypes.AsExpandoObject.Resolve(); } } else { arg_type = a.Expr.Type; } if (arg_type.BuiltinType != BuiltinTypeSpec.Type.Dynamic && arg_type != InternalType.NullLiteral) { MethodGroupExpr mg = a.Expr as MethodGroupExpr; bool wasConverted = false; // In PlayScript, we try to implicity convert to dynamic, which handles conversions of method groups to delegates, and // anon methods to delegates. if (rc.FileType == SourceFileType.PlayScript && (mg != null || arg_type == InternalType.AnonymousMethod)) { var expr = Convert.ImplicitConversion(rc, a.Expr, rc.BuiltinTypes.Dynamic, loc); if (expr != null) { a.Expr = expr; arg_type = rc.BuiltinTypes.Dynamic; wasConverted = true; } } // Failed.. check the C# error if (!wasConverted) { 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", arg_type.GetSignatureForError()); } } 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); }
public override object Visit (MemberAccess memberAccess) { Expression result; if (memberAccess.LeftExpression is Indirection) { var ind = memberAccess.LeftExpression as Indirection; result = new PointerReferenceExpression (); result.AddChild ((Expression)ind.Expr.Accept (this), PointerReferenceExpression.Roles.TargetExpression); result.AddChild (new CSharpTokenNode (Convert (ind.Location), "->".Length), PointerReferenceExpression.ArrowRole); } else { result = new MemberReferenceExpression (); if (memberAccess.LeftExpression != null) { var leftExpr = memberAccess.LeftExpression.Accept (this); result.AddChild ((Expression)leftExpr, MemberReferenceExpression.Roles.TargetExpression); } if (!memberAccess.DotLocation.IsNull) { result.AddChild (new CSharpTokenNode (Convert (memberAccess.DotLocation), 1), MemberReferenceExpression.Roles.Dot); } } result.AddChild (Identifier.Create (memberAccess.Name, Convert (memberAccess.Location)), MemberReferenceExpression.Roles.Identifier); if (memberAccess.TypeArguments != null) { AddTypeArguments (result, memberAccess.TypeArguments); } return result; }
public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args) { Arguments binder_args = new Arguments (3); MemberAccess sle = new MemberAccess (new MemberAccess ( new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc); MemberAccess binder = GetBinderNamespace (loc); binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), name, loc))); binder_args.Add (new Argument (new BoolLiteral (ec.HasSet (ResolveContext.Options.CheckedScope), loc))); binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (), loc))); return new New (new MemberAccess (binder, "CSharpUnaryOperationBinder", loc), binder_args, loc); }
public override object Visit(MemberAccess memberAccess) { Expression result; var ind = memberAccess.LeftExpression as Indirection; if (ind != null) { result = new PointerReferenceExpression(); result.AddChild((Expression)ind.Expr.Accept(this), Roles.TargetExpression); result.AddChild(new CSharpTokenNode(Convert(ind.Location), PointerReferenceExpression.ArrowRole), PointerReferenceExpression.ArrowRole); } else { result = new MemberReferenceExpression(); if (memberAccess.LeftExpression != null) { var leftExpr = memberAccess.LeftExpression.Accept(this); result.AddChild((Expression)leftExpr, Roles.TargetExpression); } var loc = LocationsBag.GetLocations(memberAccess); if (loc != null) { result.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Dot), Roles.Dot); } } result.AddChild(Identifier.Create(memberAccess.Name, Convert(memberAccess.Location)), Roles.Identifier); AddTypeArguments(result, memberAccess); return result; }
void case_439() #line 3273 "cs-parser.jay" { var lt = (LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess (new BaseThis (GetLocation (yyVals[-3+yyTop])), lt.Value, (TypeArguments) yyVals[0+yyTop], lt.Location); lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop])); }
public override bool Resolve(BlockContext bc) { if (bc.CurrentBlock is Linq.QueryBlock) { bc.Report.Error(1995, loc, "The `await' operator may only be used in a query expression within the first collection expression of the initial `from' clause or within the collection expression of a `join' clause"); return(false); } if (!base.Resolve(bc)) { return(false); } Arguments args = new Arguments(0); type = expr.Type; // // The await expression is of dynamic type // if (type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { result_type = type; expr = new Invocation(new MemberAccess(expr, "GetAwaiter"), args).Resolve(bc); return(true); } // // Check whether the expression is awaitable // Expression ama = new AwaitableMemberAccess(expr).Resolve(bc); if (ama == null) { return(false); } var errors_printer = new SessionReportPrinter(); var old = bc.Report.SetPrinter(errors_printer); ama = new Invocation(ama, args).Resolve(bc); bc.Report.SetPrinter(old); if (errors_printer.ErrorsCount > 0 || !MemberAccess.IsValidDotExpression(ama.Type)) { bc.Report.Error(1986, expr.Location, "The `await' operand type `{0}' must have suitable GetAwaiter method", expr.Type.GetSignatureForError()); return(false); } var awaiter_type = ama.Type; expr = ama; // // Predefined: bool IsCompleted { get; } // is_completed = MemberCache.FindMember(awaiter_type, MemberFilter.Property("IsCompleted", bc.Module.Compiler.BuiltinTypes.Bool), BindingRestriction.InstanceOnly) as PropertySpec; if (is_completed == null || !is_completed.HasGet) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } // // Predefined: GetResult () // // The method return type is also result type of await expression // get_result = MemberCache.FindMember(awaiter_type, MemberFilter.Method("GetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.InstanceOnly) as MethodSpec; if (get_result == null) { Error_WrongAwaiterPattern(bc, awaiter_type); return(false); } // // Predefined: INotifyCompletion.OnCompleted (System.Action) // var nc = bc.Module.PredefinedTypes.INotifyCompletion; if (nc.Define() && !awaiter_type.ImplementsInterface(nc.TypeSpec, false)) { bc.Report.Error(4027, loc, "The awaiter type `{0}' must implement interface `{1}'", awaiter_type.GetSignatureForError(), nc.GetSignatureForError()); return(false); } result_type = get_result.ReturnType; return(true); }
void case_537() #line 3881 "cs-parser.jay" { var lt = (LocatedToken) yyVals[-1+yyTop]; var ma = new MemberAccess ((Expression) yyVals[-3+yyTop], lt.Value, (int) yyVals[0+yyTop], lt.Location); yyVal = ma; lbag.AddLocation (yyVal, savedLocation, GetLocation (yyVals[-2+yyTop])); lbag.AddLocation (ma.TypeArguments, Lexer.GetGenericDimensionLocations ()); }
void case_537() #line 3676 "cs-parser.jay" { var lt = (Tokenizer.LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess ((Expression) yyVals[-3+yyTop], lt.Value, (int) yyVals[0+yyTop], lt.Location); }
void case_547() #line 3968 "cs-parser.jay" { var lt = (LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess (new Indirection ((Expression) yyVals[-3+yyTop], GetLocation (yyVals[-2+yyTop])), lt.Value, (TypeArguments) yyVals[0+yyTop], lt.Location); }
void case_538() #line 3682 "cs-parser.jay" { var te = ((MemberName) yyVals[-3+yyTop]).GetTypeExpression (); if (te.HasTypeArguments) Error_TypeExpected (GetLocation (yyVals[0+yyTop])); var lt = (Tokenizer.LocatedToken) yyVals[-1+yyTop]; yyVal = new MemberAccess (te, lt.Value, (int) yyVals[0+yyTop], lt.Location); }
public override Expression CreateExpressionTree (ResolveContext ec) { MemberAccess ma = new MemberAccess (new MemberAccess (new QualifiedAliasMember ("global", "System", loc), "Delegate", loc), "CreateDelegate", loc); Arguments args = new Arguments (3); args.Add (new Argument (new TypeOf (type, loc))); if (method_group.InstanceExpression == null) args.Add (new Argument (new NullLiteral (loc))); else args.Add (new Argument (method_group.InstanceExpression)); args.Add (new Argument (method_group.CreateExpressionTree (ec))); Expression e = new Invocation (ma, args).Resolve (ec); if (e == null) return null; e = Convert.ExplicitConversion (ec, e, type, loc); if (e == null) return null; return e.CreateExpressionTree (ec); }
void case_544() #line 3741 "cs-parser.jay" { var lt = (Tokenizer.LocatedToken) yyVals[0+yyTop]; yyVal = new MemberAccess (new Indirection ((Expression) yyVals[-2+yyTop], GetLocation (yyVals[-1+yyTop])), lt.Value, lt.Location); }
public Expression CreateCallSiteBinder(ResolveContext ec, Arguments args) { Arguments binder_args = new Arguments (4); MemberAccess sle = new MemberAccess (new MemberAccess ( new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Linq", loc), "Expressions", loc); var flags = ec.HasSet (ResolveContext.Options.CheckedScope) ? CSharpBinderFlags.CheckedContext : 0; binder_args.Add (new Argument (new BinderFlags (flags, this))); binder_args.Add (new Argument (new MemberAccess (new MemberAccess (sle, "ExpressionType", loc), name, loc))); binder_args.Add (new Argument (new TypeOf (new TypeExpression (ec.CurrentType, loc), loc))); binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc))); return new Invocation (GetBinder ("UnaryOperation", loc), binder_args); }
Method GenerateNumberMatcher () { var loc = Location; var parameters = ParametersCompiled.CreateFullyResolved ( new [] { new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "value", 0, null, loc), new Parameter (new TypeExpression (Compiler.BuiltinTypes.Bool, loc), "enumType", 0, null, loc), }, new [] { Compiler.BuiltinTypes.Object, Compiler.BuiltinTypes.Object, Compiler.BuiltinTypes.Bool }); var m = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc), Modifiers.PUBLIC | Modifiers.STATIC | Modifiers.DEBUGGER_HIDDEN, new MemberName ("NumberMatcher", loc), parameters, null); parameters [0].Resolve (m, 0); parameters [1].Resolve (m, 1); parameters [2].Resolve (m, 2); ToplevelBlock top_block = new ToplevelBlock (Compiler, parameters, loc); m.Block = top_block; // // if (enumType) // return Equals (obj, value); // var equals_args = new Arguments (2); equals_args.Add (new Argument (top_block.GetParameterReference (0, loc))); equals_args.Add (new Argument (top_block.GetParameterReference (1, loc))); var if_type = new If ( top_block.GetParameterReference (2, loc), new Return (new Invocation (new SimpleName ("Equals", loc), equals_args), loc), loc); top_block.AddStatement (if_type); // // if (obj is Enum || obj == null) // return false; // var if_enum = new If ( new Binary (Binary.Operator.LogicalOr, new Is (top_block.GetParameterReference (0, loc), new TypeExpression (Compiler.BuiltinTypes.Enum, loc), loc), new Binary (Binary.Operator.Equality, top_block.GetParameterReference (0, loc), new NullLiteral (loc))), new Return (new BoolLiteral (Compiler.BuiltinTypes, false, loc), loc), loc); top_block.AddStatement (if_enum); var system_convert = new MemberAccess (new QualifiedAliasMember ("global", "System", loc), "Convert", loc); var expl_block = new ExplicitBlock (top_block, loc, loc); // // var converted = System.Convert.ChangeType (obj, System.Convert.GetTypeCode (value)); // var lv_converted = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Object, top_block, loc); var arguments_gettypecode = new Arguments (1); arguments_gettypecode.Add (new Argument (top_block.GetParameterReference (1, loc))); var gettypecode = new Invocation (new MemberAccess (system_convert, "GetTypeCode", loc), arguments_gettypecode); var arguments_changetype = new Arguments (1); arguments_changetype.Add (new Argument (top_block.GetParameterReference (0, loc))); arguments_changetype.Add (new Argument (gettypecode)); var changetype = new Invocation (new MemberAccess (system_convert, "ChangeType", loc), arguments_changetype); expl_block.AddStatement (new StatementExpression (new SimpleAssign (new LocalVariableReference (lv_converted, loc), changetype, loc))); // // return converted.Equals (value) // var equals_arguments = new Arguments (1); equals_arguments.Add (new Argument (top_block.GetParameterReference (1, loc))); var equals_invocation = new Invocation (new MemberAccess (new LocalVariableReference (lv_converted, loc), "Equals"), equals_arguments); expl_block.AddStatement (new Return (equals_invocation, loc)); var catch_block = new ExplicitBlock (top_block, loc, loc); catch_block.AddStatement (new Return (new BoolLiteral (Compiler.BuiltinTypes, false, loc), loc)); top_block.AddStatement (new TryCatch (expl_block, new List<Catch> () { new Catch (catch_block, loc) }, loc, false)); m.Define (); m.PrepareEmit (); AddMember (m); return m; }
protected override bool DoDefineMembers () { if (!base.DoDefineMembers ()) return false; Location loc = Location; var equals_parameters = ParametersCompiled.CreateFullyResolved ( new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), Compiler.BuiltinTypes.Object); Method equals = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc), Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc), equals_parameters, null); equals_parameters[0].Resolve (equals, 0); Method tostring = new Method (this, new TypeExpression (Compiler.BuiltinTypes.String, loc), Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc), Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null); ToplevelBlock equals_block = new ToplevelBlock (Compiler, equals.ParameterInfo, loc); TypeExpr current_type; if (CurrentTypeParameters != null) { var targs = new TypeArguments (); for (int i = 0; i < CurrentTypeParameters.Count; ++i) { targs.Add (new TypeParameterExpr (CurrentTypeParameters[i], Location)); } current_type = new GenericTypeExpr (Definition, targs, loc); } else { current_type = new TypeExpression (Definition, loc); } var li_other = LocalVariable.CreateCompilerGenerated (CurrentType, equals_block, loc); equals_block.AddStatement (new BlockVariableDeclaration (new TypeExpression (li_other.Type, loc), li_other)); var other_variable = new LocalVariableReference (li_other, loc); MemberAccess system_collections_generic = new MemberAccess (new MemberAccess ( new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc); Expression rs_equals = null; Expression string_concat = new StringConstant (Compiler.BuiltinTypes, "{", loc); Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc); for (int i = 0; i < parameters.Count; ++i) { var p = parameters [i]; var f = (Field) Members [i * 2]; MemberAccess equality_comparer = new MemberAccess (new MemberAccess ( system_collections_generic, "EqualityComparer", new TypeArguments (new SimpleName (CurrentTypeParameters [i].Name, loc)), loc), "Default", loc); Arguments arguments_equal = new Arguments (2); arguments_equal.Add (new Argument (new MemberAccess (new This (f.Location), f.Name))); arguments_equal.Add (new Argument (new MemberAccess (other_variable, f.Name))); Expression field_equal = new Invocation (new MemberAccess (equality_comparer, "Equals", loc), arguments_equal); Arguments arguments_hashcode = new Arguments (1); arguments_hashcode.Add (new Argument (new MemberAccess (new This (f.Location), f.Name))); Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer, "GetHashCode", loc), arguments_hashcode); IntConstant FNV_prime = new IntConstant (Compiler.BuiltinTypes, 16777619, loc); rs_hashcode = new Binary (Binary.Operator.Multiply, new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode), FNV_prime); Expression field_to_string = new Conditional (new BooleanExpression (new Binary (Binary.Operator.Inequality, new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc))), new Invocation (new MemberAccess ( new MemberAccess (new This (f.Location), f.Name), "ToString"), null), new StringConstant (Compiler.BuiltinTypes, string.Empty, loc), loc); if (rs_equals == null) { rs_equals = field_equal; string_concat = new Binary (Binary.Operator.Addition, string_concat, new Binary (Binary.Operator.Addition, new StringConstant (Compiler.BuiltinTypes, " " + p.Name + " = ", loc), field_to_string)); continue; } // // Implementation of ToString () body using string concatenation // string_concat = new Binary (Binary.Operator.Addition, new Binary (Binary.Operator.Addition, string_concat, new StringConstant (Compiler.BuiltinTypes, ", " + p.Name + " = ", loc)), field_to_string); rs_equals = new Binary (Binary.Operator.LogicalAnd, rs_equals, field_equal); } string_concat = new Binary (Binary.Operator.Addition, string_concat, new StringConstant (Compiler.BuiltinTypes, " }", loc)); // // Equals (object obj) override // var other_variable_assign = new TemporaryVariableReference (li_other, loc); equals_block.AddStatement (new StatementExpression ( new SimpleAssign (other_variable_assign, new As (equals_block.GetParameterReference (0, loc), current_type, loc), loc))); Expression equals_test = new Binary (Binary.Operator.Inequality, other_variable, new NullLiteral (loc)); if (rs_equals != null) equals_test = new Binary (Binary.Operator.LogicalAnd, equals_test, rs_equals); equals_block.AddStatement (new Return (equals_test, loc)); equals.Block = equals_block; equals.Define (); Members.Add (equals); // // GetHashCode () override // Method hashcode = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Int, loc), Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("GetHashCode", loc), Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null); // // Modified FNV with good avalanche behavior and uniform // distribution with larger hash sizes. // // const int FNV_prime = 16777619; // int hash = (int) 2166136261; // foreach (int d in data) // hash = (hash ^ d) * FNV_prime; // hash += hash << 13; // hash ^= hash >> 7; // hash += hash << 3; // hash ^= hash >> 17; // hash += hash << 5; ToplevelBlock hashcode_top = new ToplevelBlock (Compiler, loc); Block hashcode_block = new Block (hashcode_top, loc, loc); hashcode_top.AddStatement (new Unchecked (hashcode_block, loc)); var li_hash = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Int, hashcode_top, loc); hashcode_block.AddStatement (new BlockVariableDeclaration (new TypeExpression (li_hash.Type, loc), li_hash)); LocalVariableReference hash_variable_assign = new LocalVariableReference (li_hash, loc); hashcode_block.AddStatement (new StatementExpression ( new SimpleAssign (hash_variable_assign, rs_hashcode))); var hash_variable = new LocalVariableReference (li_hash, loc); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.Addition, hash_variable, new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 13, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable, new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 7, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.Addition, hash_variable, new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 3, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable, new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 17, loc))))); hashcode_block.AddStatement (new StatementExpression ( new CompoundAssign (Binary.Operator.Addition, hash_variable, new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 5, loc))))); hashcode_block.AddStatement (new Return (hash_variable, loc)); hashcode.Block = hashcode_top; hashcode.Define (); Members.Add (hashcode); // // ToString () override // ToplevelBlock tostring_block = new ToplevelBlock (Compiler, loc); tostring_block.AddStatement (new Return (string_concat, loc)); tostring.Block = tostring_block; tostring.Define (); Members.Add (tostring); return true; }
public override Expression DoResolve(ResolveContext ec) { right = right.Resolve(ec); if (right == null) { return(null); } MemberAccess ma = target as MemberAccess; using (ec.Set(ResolveContext.Options.CompoundAssignmentScope)) { target = target.Resolve(ec); } if (target == null) { return(null); } if (target is MethodGroupExpr) { ec.Report.Error(1656, loc, "Cannot assign to `{0}' because it is a `{1}'", ((MethodGroupExpr)target).Name, target.ExprClassName); return(null); } if (target is EventExpr) { return(new EventAddOrRemove(target, op, right, loc).DoResolve(ec)); } // // Only now we can decouple the original source/target // into a tree, to guarantee that we do not have side // effects. // if (left == null) { left = new TargetExpression(target); } source = new Binary(op, left, right, true); // TODO: TargetExpression breaks MemberAccess composition if (target is DynamicMemberBinder) { Arguments targs = ((DynamicMemberBinder)target).Arguments; source = source.Resolve(ec); Arguments args = new Arguments(2); args.AddRange(targs); args.Add(new Argument(source)); source = new DynamicMemberBinder(true, ma.Name, args, loc).Resolve(ec); // Handles possible event addition/subtraction if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction) { args = new Arguments(2); args.AddRange(targs); args.Add(new Argument(right)); string method_prefix = op == Binary.Operator.Addition ? Event.AEventAccessor.AddPrefix : Event.AEventAccessor.RemovePrefix; Expression invoke = new DynamicInvocation( new MemberAccess(right, method_prefix + ma.Name, loc), args, loc).Resolve(ec); args = new Arguments(1); args.AddRange(targs); source = new DynamicEventCompoundAssign(ma.Name, args, (ExpressionStatement)source, (ExpressionStatement)invoke, loc).Resolve(ec); } return(source); } return(base.DoResolve(ec)); }