Beispiel #1
0
 public FunctionView(IModuleContext context, string name, IPythonFunction member, bool isMethod)
     : base(context, name, member)
 {
     _function = member;
     _isMethod = isMethod;
     _returnTypes = new Lazy<IEnumerable<IAnalysisItemView>>(CalculateReturnTypes);
 }
Beispiel #2
0
 public BuiltinMethodInfo(IPythonFunction function, PythonMemberType memType, PythonAnalyzer projectState)
     : base(projectState.Types.BuiltinMethodDescriptor, projectState)
 {
     _memberType  = memType;
     _function    = function;
     _returnTypes = Utils.GetReturnTypes(function, projectState);
 }
        public void AddMember(IPythonType member)
        {
            if (member == this)
            {
                return;
            }

            if (member is AstPythonMultipleTypes mt)
            {
                AddMembers(mt._members);
            }

            if (member is IPythonMultipleMembers mm)
            {
                AddMembers(mm.Members.OfType <IPythonType>());
                return;
            }

            var old = _members;

            if (!old.Contains(member))
            {
                _members = old.Concat(Enumerable.Repeat(member, 1)).ToArray();
            }
            else if (!old.Any())
            {
                _members = new[] { member };
            }
            _constructor = null;
        }
Beispiel #4
0
 public FunctionView(IModuleContext context, string name, IPythonFunction member, bool isMethod)
     : base(context, name, member)
 {
     _function    = member;
     _isMethod    = isMethod;
     _returnTypes = new Lazy <IEnumerable <IAnalysisItemView> >(CalculateReturnTypes);
 }
Beispiel #5
0
        public BuiltinMethodInfo(IPythonMethodDescriptor method, PythonAnalyzer projectState)
            : base(projectState.Types[BuiltinTypeId.BuiltinMethodDescriptor], projectState)
        {
            var function = method.Function;

            _memberType  = method.MemberType;
            _function    = function;
            _returnTypes = Utils.GetReturnTypes(function, projectState);
        }
 public BuiltinMethodInfo(IPythonFunction function, PythonMemberType memType, PythonAnalyzer projectState)
     : base(projectState.Types[
                memType == PythonMemberType.Function ? BuiltinTypeId.Function : BuiltinTypeId.Method
            ], projectState)
 {
     MemberType  = memType;
     Function    = function;
     ReturnTypes = GetReturnTypes(function, projectState);
 }
Beispiel #7
0
        public IPythonFunction GetConstructors() {
            if (_ctors == null) {
                if (!Interpreter.Remote.TypeGroupHasNewOrInitMethods(Value)) {
                    _ctors = GetClrOverloads();
                }

                if (_ctors == null) {
                    _ctors = GetMember(null, "__new__") as IPythonFunction;
                }
            }
            return _ctors;
        }
        private IMember GetValueFromFunction(IPythonFunction fn, Expression expr)
        {
            var returnType = GetFunctionReturnType(fn.Overloads.FirstOrDefault());

            if (IsUnknown(returnType))
            {
                // Function may not have been walked yet. Do it now.
                _functionWalkers.ProcessFunction(fn.FunctionDefinition);
                returnType = GetFunctionReturnType(fn.Overloads.FirstOrDefault());
            }
            return(!IsUnknown(returnType) ? new AstPythonConstant(returnType, GetLoc(expr)) : null);
        }
Beispiel #9
0
 internal AstPythonFunction(IPythonFunction original)
 {
     DeclaringModule = original.DeclaringModule;
     DeclaringType   = original.DeclaringType;
     Name            = original.Name;
     // Copy the null if _doc isn't set in the original; otherwise calculate the docs
     _doc          = (original is AstPythonFunction apf) ? apf._doc : original.Documentation;
     IsClassMethod = original.IsClassMethod;
     IsStatic      = original.IsStatic;
     _overloads    = original.Overloads.ToList();
     Locations     = (original as ILocatedMember)?.Locations ?? Array.Empty <LocationInfo>();
 }
Beispiel #10
0
        public IPythonFunction GetConstructors() {
            if (_ctors == null) {
                var ri = RemoteInterpreter;
                if (ri != null && !ri.PythonTypeHasNewOrInitMethods(Value)) {
                    _ctors = GetClrOverloads();
                }

                if (_ctors == null) {
                    _ctors = GetMember(null, "__new__") as IPythonFunction;
                }
            }
            return _ctors;
        }
Beispiel #11
0
        public void AddMembers(IEnumerable <IPythonType> members)
        {
            var old = _members;

            if (old.Any())
            {
                _members = old.Union(members.Where(m => m != this)).ToArray();
            }
            else
            {
                _members = members.Where(m => m != this).ToArray();
            }
            _constructor = null;
        }
Beispiel #12
0
        internal static ISet <Namespace> GetReturnTypes(IPythonFunction func, PythonAnalyzer projectState)
        {
            var result = new HashSet <Namespace>();
            var found  = new HashSet <IPythonType>();

            foreach (var target in func.Overloads)
            {
                var pyType = target.ReturnType;
                if (!found.Contains(pyType))
                {
                    result.Add(((BuiltinClassInfo)projectState.GetNamespaceFromObjects(pyType)).Instance);
                    found.Add(pyType);
                }
            }
            return(result);
        }
Beispiel #13
0
        public IPythonFunction GetConstructors()
        {
            if (_ctors == null)
            {
                if (!Interpreter.Remote.PythonTypeHasNewOrInitMethods(Value))
                {
                    _ctors = GetClrOverloads();
                }

                if (_ctors == null)
                {
                    _ctors = GetMember(null, "__new__") as IPythonFunction;
                }
            }
            return(_ctors);
        }
Beispiel #14
0
        public IPythonFunction GetConstructors()
        {
            if (_ctors == null)
            {
                var ri = RemoteInterpreter;
                if (ri != null && !ri.TypeGroupHasNewOrInitMethods(Value))
                {
                    _ctors = GetClrOverloads();
                }

                if (_ctors == null)
                {
                    _ctors = GetMember(null, "__new__") as IPythonFunction;
                }
            }
            return(_ctors);
        }
Beispiel #15
0
 public IPythonFunction GetConstructors()
 {
     if (_constructor == null)
     {
         var fns = _members.Select(m => m.GetConstructors()).Where(c => c != null).ToList();
         if (fns.Count == 0)
         {
             return(null);
         }
         var fn = new AstPythonFunction(fns[0]);
         foreach (var o in fns.Skip(1).SelectMany(f => f.Overloads))
         {
             fn.AddOverload(o);
         }
         _constructor = fn;
     }
     return(_constructor);
 }
Beispiel #16
0
 public BoundBuiltinMethodInfo(IPythonFunction function, PythonAnalyzer projectState)
     : this(new BuiltinMethodInfo(function, PythonMemberType.Method, projectState))
 {
 }
 public BuiltinFunctionInfo(IPythonFunction function, PythonAnalyzer projectState)
     : base(projectState.Types[BuiltinTypeId.BuiltinFunction], projectState)
 {
     _function    = function;
     _returnTypes = Utils.GetReturnTypes(function, projectState);
 }
Beispiel #18
0
        internal static IEnumerable <KeyValuePair <string, string> > GetRichDescription(string def, IPythonFunction function)
        {
            var needNewline = false;

            foreach (var overload in function.Overloads.OrderByDescending(o => o.GetParameters().Length))
            {
                if (needNewline)
                {
                    yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, "\r\n"));
                }
                needNewline = true;

                yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, def));

                yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Name, GetFullName(function.DeclaringType, function.Name)));

                yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, "("));

                foreach (var kv in GetParameterString(overload))
                {
                    yield return(kv);
                }
                yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.Misc, ")"));
            }
            yield return(new KeyValuePair <string, string>(WellKnownRichDescriptionKinds.EndOfDeclaration, string.Empty));
        }
Beispiel #19
0
 public BuiltinFunctionInfo(IPythonFunction function, PythonAnalyzer projectState)
     : base(projectState.Types[BuiltinTypeId.BuiltinFunction], projectState)
 {
     Function     = function;
     _returnTypes = new Lazy <IAnalysisSet>(() => Utils.GetReturnTypes(function, projectState).GetInstanceType());
 }
 public BuiltinFunctionInfo(IPythonFunction function, PythonAnalyzer projectState)
     : base(projectState.Types[BuiltinTypeId.Function], projectState)
 {
     Function = function;
 }
 public AstPythonUnboundMethod(IPythonFunction function) : base(function, function.DeclaringModule)
 {
     _pf = function;
 }
 internal static IAnalysisSet GetReturnTypes(IPythonFunction func, PythonAnalyzer projectState)
 {
     return(AnalysisSet.UnionAll(func.Overloads
                                 .Where(fn => fn.ReturnType != null)
                                 .Select(fn => projectState.GetAnalysisSetFromObjects(fn.ReturnType))));
 }
Beispiel #23
0
 public AstPythonBoundMethod(IPythonFunction function, IPythonType selfType)
 {
     Function = function;
     SelfType = selfType;
 }
 public SpecializedBuiltinFunction(PythonAnalyzer state, IPythonFunction function, Func <CallExpression, AnalysisUnit, ISet <Namespace>[], ISet <Namespace> > call)
     : base(function, state)
 {
     _call = call;
 }