HasAny() публичный Метод

public HasAny ( Options options ) : bool
options Options
Результат bool
Пример #1
0
		protected override Expression DoResolve (ResolveContext rc)
		{
			if (rc.HasSet (ResolveContext.Options.ConstantScope)) {
				rc.Report.Error (1706, loc, "Anonymous methods and lambda expressions cannot be used in the current context");
				return null;
			}

			//
			// Update top-level block generated duting parsing with actual top-level block
			//
			if (rc.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer) && rc.CurrentMemberDefinition.Parent.PartialContainer.PrimaryConstructorParameters != null) {
				var tb = rc.ConstructorBlock.ParametersBlock.TopBlock;
				if (Block.TopBlock != tb) {
					Block b = Block;
					while (b.Parent != Block.TopBlock && b != Block.TopBlock)
						b = b.Parent;

					b.Parent = tb;
					tb.IncludeBlock (Block, Block.TopBlock);
					b.ParametersBlock.TopBlock = tb;
				}
			}

			eclass = ExprClass.Value;

			//
			// This hack means `The type is not accessible
			// anywhere', we depend on special conversion
			// rules.
			// 
			type = InternalType.AnonymousMethod;

			if (!DoResolveParameters (rc))
				return null;

			return this;
		}
Пример #2
0
        /// <remarks>
        ///   7.5.2: Simple Names. 
        ///
        ///   Local Variables and Parameters are handled at
        ///   parse time, so they never occur as SimpleNames.
        ///
        ///   The `intermediate' flag is used by MemberAccess only
        ///   and it is used to inform us that it is ok for us to 
        ///   avoid the static check, because MemberAccess might end
        ///   up resolving the Name as a Type name and the access as
        ///   a static type access.
        ///
        ///   ie: Type Type; .... { Type.GetType (""); }
        ///
        ///   Type is both an instance variable and a Type;  Type.GetType
        ///   is the static method not an instance method of type.
        /// </remarks>
        Expression DoSimpleNameResolve(ResolveContext ec, Expression right_side, bool intermediate)
        {
            Expression e = null;

            //
            // Stage 1: Performed by the parser (binding to locals or parameters).
            //
            Block current_block = ec.CurrentBlock;
            if (current_block != null){
                LocalInfo vi = current_block.GetLocalInfo (Name);
                if (vi != null){
                    e = new LocalVariableReference (ec.CurrentBlock, Name, loc);

                    if (right_side != null) {
                        e = e.ResolveLValue (ec, right_side);
                    } else {
                        if (intermediate) {
                            using (ec.With (ResolveContext.Options.DoFlowAnalysis, false)) {
                                e = e.Resolve (ec, ResolveFlags.VariableOrValue);
                            }
                        } else {
                            e = e.Resolve (ec, ResolveFlags.VariableOrValue);
                        }
                    }

                    if (HasTypeArguments && e != null)
                        e.Error_TypeArgumentsCannotBeUsed (ec.Report, loc, null, 0);

                    return e;
                }

                e = current_block.Toplevel.GetParameterReference (Name, loc);
                if (e != null) {
                    if (right_side != null)
                        e = e.ResolveLValue (ec, right_side);
                    else
                        e = e.Resolve (ec);

                    if (HasTypeArguments && e != null)
                        e.Error_TypeArgumentsCannotBeUsed (ec.Report, loc, null, 0);

                    return e;
                }
            }

            //
            // Stage 2: Lookup members
            //
            int arity = HasTypeArguments ? Arity : -1;
            //			TypeSpec almost_matched_type = null;
            //			IList<MemberSpec> almost_matched = null;
            for (TypeSpec lookup_ds = ec.CurrentType; lookup_ds != null; lookup_ds = lookup_ds.DeclaringType) {
                e = MemberLookup (ec.Compiler, ec.CurrentType, lookup_ds, Name, arity, BindingRestriction.NoOverrides, loc);
                if (e != null) {
                    PropertyExpr pe = e as PropertyExpr;
                    if (pe != null) {
                        // since TypeManager.MemberLookup doesn't know if we're doing a lvalue access or not,
                        // it doesn't know which accessor to check permissions against
                        if (pe.PropertyInfo.Kind == MemberKind.Property && pe.IsAccessibleFrom (ec.CurrentType, right_side != null))
                            break;
                    } else if (e is EventExpr) {
                        if (((EventExpr) e).IsAccessibleFrom (ec.CurrentType))
                            break;
                    } else if (HasTypeArguments && e is TypeExpression) {
                        e = new GenericTypeExpr (e.Type, targs, loc).ResolveAsTypeStep (ec, false);
                        break;
                    } else {
                        break;
                    }
                    e = null;
                }
            /*
                if (almost_matched == null && almost_matched_members.Count > 0) {
                    almost_matched_type = lookup_ds;
                    almost_matched = new List<MemberSpec>(almost_matched_members);
                }
            */
            }

            if (e == null) {
            /*
                if (almost_matched == null && almost_matched_members.Count > 0) {
                    almost_matched_type = ec.CurrentType;
                    almost_matched = new List<MemberSpec> (almost_matched_members);
                }
            */
                e = ResolveAsTypeStep (ec, true);
            }

            if (e == null) {
                if (current_block != null) {
                    IKnownVariable ikv = current_block.Explicit.GetKnownVariable (Name);
                    if (ikv != null) {
                        LocalInfo li = ikv as LocalInfo;
                        // Supress CS0219 warning
                        if (li != null)
                            li.Used = true;

                        Error_VariableIsUsedBeforeItIsDeclared (ec.Report, Name);
                        return null;
                    }
                }

                if (RootContext.EvalMode){
                    FieldInfo fi = Evaluator.LookupField (Name);
                    if (fi != null)
                        return new FieldExpr (Import.CreateField (fi, null), loc).Resolve (ec);
                }
            /*
                if (almost_matched != null)
                    almost_matched_members = almost_matched;
                if (almost_matched_type == null)
                    almost_matched_type = ec.CurrentType;
            */
                string type_name = ec.MemberContext.CurrentType == null ? null : ec.MemberContext.CurrentType.Name;
                return Error_MemberLookupFailed (ec, ec.CurrentType, null, ec.CurrentType, Name, arity,
                    type_name, MemberKind.All, BindingRestriction.AccessibleOnly);
            }

            if (e is MemberExpr) {
                MemberExpr me = (MemberExpr) e;

                Expression left;
                if (me.IsInstance) {
                    if (ec.IsStatic || ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer | ResolveContext.Options.ConstantScope)) {
                        //
                        // Note that an MemberExpr can be both IsInstance and IsStatic.
                        // An unresolved MethodGroupExpr can contain both kinds of methods
                        // and each predicate is true if the MethodGroupExpr contains
                        // at least one of that kind of method.
                        //
            /*
                        if (!me.IsStatic &&
                            (!intermediate || !IdenticalNameAndTypeName (ec, me, loc))) {
                            Error_ObjectRefRequired (ec, loc, me.GetSignatureForError ());
                            return null;
                        }
            */
                        //
                        // Pass the buck to MemberAccess and Invocation.
                        //
                        left = EmptyExpression.Null;
                    } else {
                        left = ec.GetThis (loc);
                    }
                } else {
                    left = new TypeExpression (ec.CurrentType, loc);
                }

                me = me.ResolveMemberAccess (ec, left, loc, null);
                if (me == null)
                    return null;

                if (HasTypeArguments) {
                    if (!targs.Resolve (ec))
                        return null;

                    me.SetTypeArguments (ec, targs);
                }

                if (!me.IsStatic && (me.InstanceExpression != null && me.InstanceExpression != EmptyExpression.Null) &&
                    TypeManager.IsNestedFamilyAccessible (me.InstanceExpression.Type, me.DeclaringType) &&
                    me.InstanceExpression.Type != me.DeclaringType &&
                    !TypeManager.IsFamilyAccessible (me.InstanceExpression.Type, me.DeclaringType) &&
                    (!intermediate || !IdenticalNameAndTypeName (ec, e, loc))) {
                    ec.Report.Error (38, loc, "Cannot access a nonstatic member of outer type `{0}' via nested type `{1}'",
                        TypeManager.CSharpName (me.DeclaringType), TypeManager.CSharpName (me.InstanceExpression.Type));
                    return null;
                }

                return (right_side != null)
                    ? me.DoResolveLValue (ec, right_side)
                    : me.Resolve (ec);
            }

            return e;
        }
Пример #3
0
		public override Expression DoResolve (ResolveContext ec)
		{
			count = count.Resolve (ec);
			if (count == null)
				return null;
			
			if (count.Type != TypeManager.uint32_type){
				count = Convert.ImplicitConversionRequired (ec, count, TypeManager.int32_type, loc);
				if (count == null)
					return null;
			}

			Constant c = count as Constant;
			if (c != null && c.IsNegative) {
				ec.Report.Error (247, loc, "Cannot use a negative size with stackalloc");
				return null;
			}

			if (ec.HasAny (ResolveContext.Options.CatchScope | ResolveContext.Options.FinallyScope)) {
				ec.Report.Error (255, loc, "Cannot use stackalloc in finally or catch");
			}

			TypeExpr texpr = t.ResolveAsTypeTerminal (ec, false);
			if (texpr == null)
				return null;

			otype = texpr.Type;

			if (!TypeManager.VerifyUnManaged (otype, loc))
				return null;

			type = TypeManager.GetPointerType (otype);
			eclass = ExprClass.Value;

			return this;
		}
Пример #4
0
        public override Expression DoResolveLValue(ResolveContext ec, Expression right_side)
        {
            IVariableReference var = InstanceExpression as IVariableReference;
            if (var != null && var.VariableInfo != null)
                var.VariableInfo.SetFieldAssigned (ec, Name);

            bool lvalue_instance = !spec.IsStatic && TypeManager.IsValueType (spec.DeclaringType);
            bool out_access = right_side == EmptyExpression.OutAccess.Instance || right_side == EmptyExpression.LValueMemberOutAccess;

            Expression e = DoResolve (ec, lvalue_instance, out_access);

            if (e == null)
                return null;

            spec.MemberDefinition.SetIsAssigned ();

            if ((right_side == EmptyExpression.UnaryAddress || right_side == EmptyExpression.OutAccess.Instance) &&
                    (spec.Modifiers & Modifiers.VOLATILE) != 0) {
                ec.Report.Warning (420, 1, loc,
                    "`{0}': A volatile field references will not be treated as volatile",
                    spec.GetSignatureForError ());
            }

            if (spec.IsReadOnly) {
                // InitOnly fields can only be assigned in constructors or initializers
                if (!ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.ConstructorScope))
                    return Report_AssignToReadonly (ec, right_side);

                if (ec.HasSet (ResolveContext.Options.ConstructorScope)) {

                    // InitOnly fields cannot be assigned-to in a different constructor from their declaring type
                    if (!TypeManager.IsEqual (ec.CurrentMemberDefinition.Parent.Definition, DeclaringType.GetDefinition ()))
                        return Report_AssignToReadonly (ec, right_side);
                    // static InitOnly fields cannot be assigned-to in an instance constructor
                    if (IsStatic && !ec.IsStatic)
                        return Report_AssignToReadonly (ec, right_side);
                    // instance constructors can't modify InitOnly fields of other instances of the same type
                    if (!IsStatic && !(InstanceExpression is This))
                        return Report_AssignToReadonly (ec, right_side);
                }
            }

            if (right_side == EmptyExpression.OutAccess.Instance &&
                !IsStatic && !(InstanceExpression is This) && TypeManager.mbr_type != null && TypeManager.IsSubclassOf (DeclaringType, TypeManager.mbr_type)) {
                ec.Report.SymbolRelatedToPreviousError (DeclaringType);
                ec.Report.Warning (197, 1, loc,
                        "Passing `{0}' as ref or out or taking its address may cause a runtime exception because it is a field of a marshal-by-reference class",
                        GetSignatureForError ());
            }

            eclass = ExprClass.Variable;
            return this;
        }
Пример #5
0
		public static bool IsThisAvailable (ResolveContext ec)
		{
			if (ec.IsStatic || ec.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer | ResolveContext.Options.ConstantScope))
				return false;

			if (ec.CurrentAnonymousMethod == null)
				return true;

			if (ec.CurrentType.IsValueType && ec.CurrentIterator == null)
				return false;

			return true;
		}