Ejemplo n.º 1
0
		protected override Expression DoResolve (ResolveContext rc)
		{
			var sn = expr as SimpleName;
			const ResolveFlags flags = ResolveFlags.VariableOrValue | ResolveFlags.Type;

			if (sn != null) {
				expr = sn.LookupNameExpression (rc, MemberLookupRestrictions.ReadAccess | MemberLookupRestrictions.ExactArity);

				//
				// Resolve expression which does have type set as we need expression type
				// with disable flow analysis as we don't know whether left side expression
				// is used as variable or type
				//
				if (expr is VariableReference || expr is ConstantExpr || expr is Linq.TransparentMemberAccess) {
					expr = expr.Resolve (rc);
				} else if (expr is TypeParameterExpr) {
					expr.Error_UnexpectedKind (rc, flags, sn.Location);
					expr = null;
				}
			} else {
				expr = expr.Resolve (rc, flags);
			}

			if (expr == null)
				return null;

			TypeSpec expr_type = expr.Type;
			if (expr_type.IsPointer || expr_type.Kind == MemberKind.Void || expr_type == InternalType.NullLiteral || expr_type == InternalType.AnonymousMethod) {
				expr.Error_OperatorCannotBeApplied (rc, loc, ".", expr_type);
				return null;
			}

			if (targs != null) {
				if (!targs.Resolve (rc))
					return null;
			}

			var results = new List<string> ();
			var nexpr = expr as NamespaceExpression;
			if (nexpr != null) {
				string namespaced_partial;

				if (partial_name == null)
					namespaced_partial = nexpr.Namespace.Name;
				else
					namespaced_partial = nexpr.Namespace.Name + "." + partial_name;

				rc.CurrentMemberDefinition.GetCompletionStartingWith (namespaced_partial, results);
				if (partial_name != null)
					results = results.Select (l => l.Substring (partial_name.Length)).ToList ();
			} else {
				var r = MemberCache.GetCompletitionMembers (rc, expr_type, partial_name).Select (l => l.Name);
				AppendResults (results, partial_name, r);
			}

			throw new CompletionResult (partial_name == null ? "" : partial_name, results.Distinct ().ToArray ());
		}
Ejemplo n.º 2
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            Expression expr_resolved = expr.Resolve(ec,
                                                    ResolveFlags.VariableOrValue | ResolveFlags.Type);

            if (expr_resolved == null)
            {
                return(null);
            }

            TypeSpec expr_type = expr_resolved.Type;

            if (expr_type.IsPointer || expr_type.Kind == MemberKind.Void || expr_type == InternalType.NullLiteral || expr_type == InternalType.AnonymousMethod)
            {
                expr_resolved.Error_OperatorCannotBeApplied(ec, loc, ".", expr_type);
                return(null);
            }

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

            var results = new List <string> ();

            if (expr_resolved is Namespace)
            {
                Namespace nexpr = expr_resolved as Namespace;
                string    namespaced_partial;

                if (partial_name == null)
                {
                    namespaced_partial = nexpr.Name;
                }
                else
                {
                    namespaced_partial = nexpr.Name + "." + partial_name;
                }

                ec.CurrentMemberDefinition.GetCompletionStartingWith(namespaced_partial, results);
                if (partial_name != null)
                {
                    results = results.Select(l => l.Substring(partial_name.Length)).ToList();
                }
            }
            else
            {
                var r = MemberCache.GetCompletitionMembers(ec, expr_type, partial_name).Select(l => l.Name);
                AppendResults(results, partial_name, r);
            }

            throw new CompletionResult(partial_name == null ? "" : partial_name, results.Distinct().ToArray());
        }
Ejemplo n.º 3
0
		public Expression CreateCallSiteBinder (ResolveContext ec, Arguments args)
		{
			Arguments binder_args = new Arguments (member != null ? 5 : 3);
			bool is_member_access = member is MemberAccess;

			CSharpBinderFlags call_flags;
			if (!is_member_access && member is SimpleName) {
				call_flags = CSharpBinderFlags.InvokeSimpleName;
				is_member_access = true;
			} else {
				call_flags = 0;
			}

			binder_args.Add (new Argument (new BinderFlags (call_flags, this)));

			if (is_member_access)
				binder_args.Add (new Argument (new StringLiteral (ec.BuiltinTypes, member.Name, member.Location)));

			if (member != null && member.HasTypeArguments) {
				TypeArguments ta = member.TypeArguments;
				if (ta.Resolve (ec)) {
					var targs = new ArrayInitializer (ta.Count, loc);
					foreach (TypeSpec t in ta.Arguments)
						targs.Add (new TypeOf (t, loc));

					binder_args.Add (new Argument (new ImplicitlyTypedArrayCreation (targs, loc)));
				}
			} else if (is_member_access) {
				binder_args.Add (new Argument (new NullLiteral (loc)));
			}

			binder_args.Add (new Argument (new TypeOf (ec.CurrentType, loc)));

			Expression real_args;
			if (args == null) {
				// Cannot be null because .NET trips over
				real_args = new ArrayCreation (
					new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc),
					new ArrayInitializer (0, loc), loc);
			} else {
				real_args = new ImplicitlyTypedArrayCreation (args.CreateDynamicBinderArguments (ec), loc);
			}

			binder_args.Add (new Argument (real_args));

			return new Invocation (GetBinder (is_member_access ? "InvokeMember" : "Invoke", loc), binder_args);
		}
Ejemplo n.º 4
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            Expression expr_resolved = expr.Resolve(ec,
                                                    ResolveFlags.VariableOrValue | ResolveFlags.Type);

            if (expr_resolved == null)
            {
                return(null);
            }

            TypeSpec expr_type = expr_resolved.Type;

            if (expr_type.IsPointer || expr_type.Kind == MemberKind.Void || expr_type == InternalType.NullLiteral || expr_type == InternalType.AnonymousMethod)
            {
                Unary.Error_OperatorCannotBeApplied(ec, loc, ".", expr_type);
                return(null);
            }

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

            var results = new List <string> ();

            if (expr_resolved is Namespace)
            {
                Namespace nexpr = expr_resolved as Namespace;
                string    namespaced_partial;

                if (partial_name == null)
                {
                    namespaced_partial = nexpr.Name;
                }
                else
                {
                    namespaced_partial = nexpr.Name + "." + partial_name;
                }

#if false
                Console.WriteLine("Workign with: namespaced partial {0}", namespaced_partial);
                foreach (var x in ec.TypeContainer.NamespaceEntry.CompletionGetTypesStartingWith(ec.TypeContainer, namespaced_partial))
                {
                    Console.WriteLine("    {0}", x);
                }
#endif

                CompletionSimpleName.AppendResults(
                    results,
                    partial_name,
                    ec.CurrentMemberDefinition.Parent.NamespaceEntry.CompletionGetTypesStartingWith(namespaced_partial));
            }
            else
            {
                var r = MemberCache.GetCompletitionMembers(ec, expr_type, partial_name).Select(l => l.Name);
                AppendResults(results, partial_name, r);
            }

            throw new CompletionResult(partial_name == null ? "" : partial_name, results.Distinct().ToArray());
        }
Ejemplo n.º 5
0
        public override Expression DoResolve(ResolveContext ec)
        {
            Expression expr_resolved = expr.Resolve(ec,
                                                    ResolveFlags.VariableOrValue | ResolveFlags.Type |
                                                    ResolveFlags.Intermediate | ResolveFlags.DisableStructFlowAnalysis);

            if (expr_resolved == null)
            {
                return(null);
            }

            Type expr_type = expr_resolved.Type;

            if (expr_type.IsPointer || expr_type == TypeManager.void_type || expr_type == TypeManager.null_type || expr_type == InternalType.AnonymousMethod)
            {
                Unary.Error_OperatorCannotBeApplied(ec, loc, ".", expr_type);
                return(null);
            }

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

            ArrayList results = new ArrayList();

            if (expr_resolved is Namespace)
            {
                Namespace nexpr = expr_resolved as Namespace;
                string    namespaced_partial;

                if (partial_name == null)
                {
                    namespaced_partial = nexpr.Name;
                }
                else
                {
                    namespaced_partial = nexpr.Name + "." + partial_name;
                }

#if false
                Console.WriteLine("Workign with: namespaced partial {0}", namespaced_partial);
                foreach (var x in ec.TypeContainer.NamespaceEntry.CompletionGetTypesStartingWith(ec.TypeContainer, namespaced_partial))
                {
                    Console.WriteLine("    {0}", x);
                }
#endif

                CompletionSimpleName.AppendResults(
                    results,
                    partial_name,
                    ec.CurrentTypeDefinition.NamespaceEntry.CompletionGetTypesStartingWith(namespaced_partial));
            }
            else
            {
                MemberInfo [] result = expr_type.FindMembers(
                    MemberTypes.All, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
                    CollectingFilter, partial_name);

                foreach (MemberInfo r in result)
                {
                    string name;

                    MethodBase rasb = r as MethodBase;
                    if (rasb != null && rasb.IsSpecialName)
                    {
                        continue;
                    }

                    if (partial_name == null)
                    {
                        name = r.Name;
                    }
                    else
                    {
                        name = r.Name.Substring(partial_name.Length);
                    }

                    if (results.Contains(name))
                    {
                        continue;
                    }
                    results.Add(name);
                }
            }

            throw new CompletionResult(partial_name == null ? "" : partial_name, (string [])results.ToArray(typeof(string)));
        }
Ejemplo n.º 6
0
        protected override Expression DoResolve(ResolveContext rc)
        {
            var sn = expr as SimpleName;
            const ResolveFlags flags = ResolveFlags.VariableOrValue | ResolveFlags.Type;

            //
            // Resolve the expression with flow analysis turned off, we'll do the definite
            // assignment checks later.  This is because we don't know yet what the expression
            // will resolve to - it may resolve to a FieldExpr and in this case we must do the
            // definite assignment check on the actual field and not on the whole struct.
            //
            using (rc.Set(ResolveContext.Options.OmitStructFlowAnalysis)) {
                if (sn != null)
                {
                    expr = sn.LookupNameExpression(rc, MemberLookupRestrictions.ReadAccess | MemberLookupRestrictions.ExactArity);

                    //
                    // Resolve expression which does have type set as we need expression type
                    // with disable flow analysis as we don't know whether left side expression
                    // is used as variable or type
                    //
                    if (expr is VariableReference || expr is ConstantExpr || expr is Linq.TransparentMemberAccess)
                    {
                        using (rc.With(ResolveContext.Options.DoFlowAnalysis, false)) {
                            expr = expr.Resolve(rc);
                        }
                    }
                    else if (expr is TypeParameterExpr)
                    {
                        expr.Error_UnexpectedKind(rc, flags, sn.Location);
                        expr = null;
                    }
                }
                else
                {
                    expr = expr.Resolve(rc, flags);
                }
            }

            if (expr == null)
            {
                return(null);
            }

            TypeSpec expr_type = expr.Type;

            if (expr_type.IsPointer || expr_type.Kind == MemberKind.Void || expr_type == InternalType.NullLiteral || expr_type == InternalType.AnonymousMethod)
            {
                expr.Error_OperatorCannotBeApplied(rc, loc, ".", expr_type);
                return(null);
            }

            if (targs != null)
            {
                if (!targs.Resolve(rc))
                {
                    return(null);
                }
            }

            var results = new List <string> ();

            if (expr is Namespace)
            {
                Namespace nexpr = expr as Namespace;
                string    namespaced_partial;

                if (partial_name == null)
                {
                    namespaced_partial = nexpr.Name;
                }
                else
                {
                    namespaced_partial = nexpr.Name + "." + partial_name;
                }

                rc.CurrentMemberDefinition.GetCompletionStartingWith(namespaced_partial, results);
                if (partial_name != null)
                {
                    results = results.Select(l => l.Substring(partial_name.Length)).ToList();
                }
            }
            else
            {
                var r = MemberCache.GetCompletitionMembers(rc, expr_type, partial_name).Select(l => l.Name);
                AppendResults(results, partial_name, r);
            }

            throw new CompletionResult(partial_name == null ? "" : partial_name, results.Distinct().ToArray());
        }
Ejemplo n.º 7
0
        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));
        }