Exemplo n.º 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);
 }
Exemplo n.º 2
0
 public BuiltinMethodInfo(IPythonFunction function, PythonMemberType memType, PythonAnalyzer projectState)
     : base(projectState.Types.BuiltinMethodDescriptor, projectState)
 {
     _memberType  = memType;
     _function    = function;
     _returnTypes = Utils.GetReturnTypes(function, projectState);
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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>();
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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));
        }
Exemplo n.º 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;
 }
Exemplo n.º 22
0
 internal static IAnalysisSet GetReturnTypes(IPythonFunction func, PythonAnalyzer projectState)
 {
     return(AnalysisSet.UnionAll(func.Overloads
                                 .Where(fn => fn.ReturnType != null)
                                 .Select(fn => projectState.GetAnalysisSetFromObjects(fn.ReturnType))));
 }
Exemplo n.º 23
0
 public AstPythonBoundMethod(IPythonFunction function, IPythonType selfType)
 {
     Function = function;
     SelfType = selfType;
 }
Exemplo n.º 24
0
 public SpecializedBuiltinFunction(PythonAnalyzer state, IPythonFunction function, Func <CallExpression, AnalysisUnit, ISet <Namespace>[], ISet <Namespace> > call)
     : base(function, state)
 {
     _call = call;
 }