private static long HashModuleFileSizes(IImportChildrenSource source)
        {
            var hash  = 0L;
            var names = source.GetChildrenNames();

            foreach (var name in names)
            {
                if (source.TryGetChildImport(name, out var child))
                {
                    if (child is ModuleImport moduleImport)
                    {
                        if (moduleImport.ModuleFileSize == 0)
                        {
                            continue; // Typically test case, memory-only module.
                        }
                        hash = unchecked (hash * 31 ^ moduleImport.ModuleFileSize);
                    }

                    if (child is IImportChildrenSource childSource)
                    {
                        hash = unchecked (hash * 31 ^ HashModuleFileSizes(childSource));
                    }
                }
            }

            return(hash);
        }
Exemple #2
0
        private IMember GetValueFromImports(PythonVariableModule parentModule, IImportChildrenSource childrenSource, string memberName)
        {
            if (childrenSource == null || !childrenSource.TryGetChildImport(memberName, out var childImport))
            {
                return(Interpreter.UnknownType);
            }

            switch (childImport)
            {
            case ModuleImport moduleImport:
                var module = ModuleResolution.GetOrLoadModule(moduleImport.FullName);
                return(module != null?GetOrCreateVariableModule(module, parentModule, moduleImport.Name) : Interpreter.UnknownType);

            case ImplicitPackageImport packageImport:
                return(GetOrCreateVariableModule(packageImport.FullName, parentModule, memberName));

            default:
                return(Interpreter.UnknownType);
            }
        }
Exemple #3
0
        private static long HashModuleFileSizes(IImportChildrenSource source)
        {
            var hash  = 0L;
            var names = source.GetChildrenNames();

            foreach (var name in names)
            {
                if (source.TryGetChildImport(name, out var child))
                {
                    if (child is ModuleImport moduleImport)
                    {
                        hash = unchecked (hash * 31 ^ moduleImport.ModuleFileSize);
                    }

                    if (child is IImportChildrenSource childSource)
                    {
                        hash = unchecked (hash * 31 ^ HashModuleFileSizes(childSource));
                    }
                }
            }

            return(hash);
        }
 public bool TryGetChildImport(string name, out IImportSearchResult child) => _childrenSource.TryGetChildImport(name, out child);