Exemplo n.º 1
0
 bool IAnalysisSet.Contains(AnalysisValue item)
 {
     return(((IAnalysisSet)this).Comparer.Equals(this, item));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Returns an analysis value representative of both this and another
 /// analysis value. This should only be called when
 /// <see cref="UnionEquals"/> returns true for the two values.
 /// </summary>
 /// <param name="av">The value to merge with.</param>
 /// <param name="strength">A value matching that passed to
 /// <see cref="UnionEquals"/>.</param>
 /// <returns>A merged analysis value.</returns>
 /// <remarks>
 /// <para>Calling this function when <see cref="UnionEquals"/> returns
 /// false for the same parameters is undefined.</para>
 ///
 /// <para>Where there is no analysis value representative of those
 /// provided, it is preferable to return this rather than
 /// <paramref name="av"/>.</para>
 ///
 /// <para>
 /// <paramref name="strength"/> is used as a key in this function and must
 /// match the value used in <see cref="UnionEquals"/>.
 /// </para>
 /// </remarks>
 internal virtual AnalysisValue UnionMergeTypes(AnalysisValue av, int strength)
 {
     return(this);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Determines whether two analysis values are effectively equivalent.
 /// </summary>
 /// <remarks>
 /// The intent of <paramref name="strength"/> is to allow different
 /// types to merge more aggressively. For example, string constants
 /// may merge into a non-specific string instance at a low strength,
 /// while distinct user-defined types may merge into <c>object</c> only
 /// at higher strengths. There is no defined maximum value.
 /// </remarks>
 internal virtual bool UnionEquals(AnalysisValue av, int strength)
 {
     return(Equals(av));
 }
Exemplo n.º 4
0
 public virtual IAnalysisSet GetDescriptor(Node node, AnalysisValue instance, AnalysisValue context, AnalysisUnit unit)
 {
     return(SelfSet);
 }
Exemplo n.º 5
0
 public virtual IAnalysisSet GetDescriptor(PythonAnalyzer projectState, AnalysisValue instance, AnalysisValue context)
 {
     return(SelfSet);
 }
Exemplo n.º 6
0
        private object GetMemberValueInternal(AnalysisValue type, ModuleInfo declModule, bool isRef)
        {
            SpecializedNamespace specialCallable = type as SpecializedNamespace;

            if (specialCallable != null)
            {
                if (specialCallable.Original == null)
                {
                    return(null);
                }
                return(GetMemberValueInternal(specialCallable.Original, declModule, isRef));
            }

            switch (type.MemberType)
            {
            case PythonMemberType.Function:
                FunctionInfo fi = type as FunctionInfo;
                if (fi != null)
                {
                    if (fi.DeclaringModule.GetModuleInfo() != declModule)
                    {
                        return(GenerateFuncRef(fi));
                    }
                    else
                    {
                        return(GenerateFunction(fi));
                    }
                }

                BuiltinFunctionInfo bfi = type as BuiltinFunctionInfo;
                if (bfi != null)
                {
                    return(GenerateFuncRef(bfi));
                }

                return("function");

            case PythonMemberType.Method:
                BoundMethodInfo mi = type as BoundMethodInfo;
                if (mi != null)
                {
                    return(GenerateMethod(mi));
                }
                return("method");

            case PythonMemberType.Property:
                FunctionInfo prop = type as FunctionInfo;
                if (prop != null)
                {
                    return(GenerateProperty(prop));
                }
                break;

            case PythonMemberType.Class:
                ClassInfo ci = type as ClassInfo;
                if (ci != null)
                {
                    if (isRef || ci.DeclaringModule.GetModuleInfo() != declModule)
                    {
                        // TODO: Save qualified name so that classes defined in classes/function can be resolved
                        return(GetTypeRef(ci.DeclaringModule.ModuleName, ci.Name));
                    }
                    else
                    {
                        return(GenerateClass(ci, declModule));
                    }
                }

                BuiltinClassInfo bci = type as BuiltinClassInfo;
                if (bci != null)
                {
                    return(GetTypeRef(bci.PythonType.DeclaringModule.Name, bci.PythonType.Name));
                }
                return("type");

            case PythonMemberType.Constant:
                ConstantInfo constantInfo = type as ConstantInfo;
                if (constantInfo != null)
                {
                    return(GenerateConstant(constantInfo));
                }
                break;

            case PythonMemberType.Module:
                if (type is ModuleInfo)
                {
                    return(GetModuleName(((ModuleInfo)type).Name));
                }
                else if (type is BuiltinModule)
                {
                    return(GetModuleName(((BuiltinModule)type).Name));
                }
                break;

            case PythonMemberType.Instance:
                return(new Dictionary <string, object> {
                    { "type", GenerateTypeName(type, true) }
                });

            default:
                return(new Dictionary <string, object>()
                {
                    { "type", GenerateTypeName(type.PythonType) }
                });
            }
            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Performs a __get__ on the object.
        /// </summary>
        public static IAnalysisSet GetDescriptor(this IAnalysisSet self, Node node, AnalysisValue instance, AnalysisValue context, AnalysisUnit unit)
        {
            var res = AnalysisSet.Empty;

            foreach (var ns in self)
            {
                res = res.Union(ns.GetDescriptor(node, instance, context, unit));
            }

            return(res);
        }
 bool IAnalysisSet.Contains(AnalysisValue item) => ((IAnalysisSet)this).Comparer.Equals(this, item);
 /// <summary>
 /// Determines whether two analysis values are effectively equivalent.
 /// </summary>
 /// <remarks>
 /// The intent of <paramref name="strength"/> is to allow different
 /// types to merge more aggressively. For example, string constants
 /// may merge into a non-specific string instance at a low strength,
 /// while distinct user-defined types may merge into <c>object</c> only
 /// at higher strengths. There is no defined maximum value.
 /// </remarks>
 internal virtual bool UnionEquals(AnalysisValue av, int strength) => Equals(av);
 /// <summary>
 /// Returns an analysis value representative of both this and another
 /// analysis value. This should only be called when
 /// <see cref="UnionEquals"/> returns true for the two values.
 /// </summary>
 /// <param name="av">The value to merge with.</param>
 /// <param name="strength">A value matching that passed to
 /// <see cref="UnionEquals"/>.</param>
 /// <returns>A merged analysis value.</returns>
 /// <remarks>
 /// <para>Calling this function when <see cref="UnionEquals"/> returns
 /// false for the same parameters is undefined.</para>
 ///
 /// <para>Where there is no analysis value representative of those
 /// provided, it is preferable to return this rather than
 /// <paramref name="av"/>.</para>
 ///
 /// <para>
 /// <paramref name="strength"/> is used as a key in this function and must
 /// match the value used in <see cref="UnionEquals"/>.
 /// </para>
 /// </remarks>
 internal virtual AnalysisValue UnionMergeTypes(AnalysisValue av, int strength) => this;