コード例 #1
0
ファイル: CPythonModule.cs プロジェクト: rsumner33/PTVS
 public CPythonModule(TypeDatabase typeDb, string moduleName, string filename, bool isBuiltin)
 {
     _modName   = moduleName;
     _dbFile    = filename;
     _typeDb    = typeDb;
     _isBuiltin = isBuiltin;
 }
コード例 #2
0
        private void LoadMembers(TypeDatabase typeDb, Dictionary <string, object> membersTable)
        {
            foreach (var memberEntry in membersTable)
            {
                var memberName  = memberEntry.Key;
                var memberValue = memberEntry.Value as Dictionary <string, object>;

                if (memberValue != null)
                {
                    typeDb.ReadMember(memberName, memberValue, StoreMember, this);
                }
            }
        }
コード例 #3
0
ファイル: CPythonFunction.cs プロジェクト: rsumner33/PTVS
        private CPythonFunctionOverload[] LoadOverloads(TypeDatabase typeDb, object overloads, bool isMethod)
        {
            var overloadsArr = overloads as IList <object>;

            if (overloadsArr != null)
            {
                CPythonFunctionOverload[] res = new CPythonFunctionOverload[overloadsArr.Count];

                for (int i = 0; i < overloadsArr.Count; i++)
                {
                    res[i] = LoadOverload(typeDb, overloadsArr[i], isMethod);
                }
                return(res);
            }
            return(EmptyOverloads);
        }
コード例 #4
0
        public CPythonType(IMemberContainer parent, TypeDatabase typeDb, string typeName, Dictionary <string, object> typeTable, BuiltinTypeId typeId)
        {
            Debug.Assert(parent is CPythonType || parent is CPythonModule);

            _typeName = typeName;
            _typeId   = typeId;
            _module   = GetDeclaringModule(parent);

            object value;

            if (typeTable.TryGetValue("is_hidden", out value))
            {
                _includeInModule = !Convert.ToBoolean(value);
            }
            else
            {
                _includeInModule = true;
            }

            if (typeTable.TryGetValue("doc", out value))
            {
                _doc = value as string;
            }

            if (typeTable.TryGetValue("builtin", out value))
            {
                _isBuiltin = Convert.ToBoolean(value);
            }
            else
            {
                _isBuiltin = true;
            }

            object membersData;

            if (typeTable.TryGetValue("members", out membersData))
            {
                var membersTable = membersData as Dictionary <string, object>;
                if (membersTable != null)
                {
                    LoadMembers(typeDb, membersTable);
                }
            }
        }
コード例 #5
0
        public CPythonFunctionOverload(TypeDatabase typeDb, Dictionary <string, object> argInfo, bool isMethod)
        {
            if (argInfo != null)
            {
                object         args;
                IList <object> argList;
                if (argInfo.TryGetValue("args", out args))
                {
                    argList = (IList <object>)args;
                    if (argList != null)
                    {
                        if (argList.Count == 0 || (isMethod && argList.Count == 1))
                        {
                            _parameters = EmptyParameters;
                        }
                        else
                        {
                            _parameters = new CPythonParameterInfo[isMethod ? argList.Count - 1 : argList.Count];
                            for (int i = 0; i < _parameters.Length; i++)
                            {
                                _parameters[i] = new CPythonParameterInfo(typeDb, (isMethod ? argList[i + 1] : argList[i]) as Dictionary <string, object>);
                            }
                        }
                    }
                }

                object docObj;
                if (argInfo.TryGetValue("doc", out docObj))
                {
                    _doc = docObj as string;
                }

                if (argInfo.TryGetValue("return_doc", out docObj))
                {
                    _returnDoc = docObj as string;
                }

                object retTypeObj;
                argInfo.TryGetValue("ret_type", out retTypeObj);

                typeDb.LookupType(retTypeObj, (value) => _retType = value);
            }
        }
コード例 #6
0
        public CPythonParameterInfo(TypeDatabase typeDb, Dictionary <string, object> parameterTable)
        {
            if (parameterTable != null)
            {
                object typeObj;

                if (parameterTable.TryGetValue("type", out typeObj))
                {
                    typeDb.LookupType(typeObj, (value) => _type = value);
                }
                _typeObj = typeObj;

                object nameObj;
                if (parameterTable.TryGetValue("name", out nameObj))
                {
                    _name = nameObj as string;
                }

                object docObj;
                if (parameterTable.TryGetValue("doc", out docObj))
                {
                    _doc = docObj as string;
                }

                object defaultValueObj;
                if (parameterTable.TryGetValue("default_value", out defaultValueObj))
                {
                    _defaultValue = defaultValueObj as string;
                }

                object argFormatObj;
                if (parameterTable.TryGetValue("arg_format", out argFormatObj))
                {
                    switch (argFormatObj as string)
                    {
                    case "*": _isSplat = true; break;

                    case "**": _isKeywordSplat = true; break;
                    }
                }
            }
        }
コード例 #7
0
        public IPythonInterpreter CreateInterpreter()
        {
            lock (_interpreters) {
                if (_typeDb == null)
                {
                    _typeDb = MakeTypeDatabase();
                }
                else if (_typeDb.DatabaseDirectory != GetConfiguredDatabasePath() && ConfigurableDatabaseExists())
                {
                    // database has been generated for this interpreter, switch to the specific version.
                    _typeDb = new TypeDatabase(GetConfiguredDatabasePath(), Is3x);
                }

                var res = new CPythonInterpreter(_typeDb);

                if (!ConfigurableDatabaseExists())
                {
                    _interpreters.Add(new WeakReference(res));
                }
                return(res);
            }
        }
コード例 #8
0
ファイル: CPythonFunction.cs プロジェクト: rsumner33/PTVS
        public CPythonFunction(TypeDatabase typeDb, string name, Dictionary <string, object> functionTable, IMemberContainer declaringType, bool isMethod = false)
        {
            _name = name;

            object doc;

            if (functionTable.TryGetValue("doc", out doc))
            {
                _doc = doc as string;
            }

            object value;

            if (functionTable.TryGetValue("builtin", out value))
            {
                _isBuiltin = Convert.ToBoolean(value);
            }
            else
            {
                _isBuiltin = true;
            }

            if (functionTable.TryGetValue("static", out value))
            {
                _isStatic = Convert.ToBoolean(value);
            }
            else
            {
                _isStatic = true;
            }

            _declaringModule = (declaringType as CPythonModule) ?? (CPythonModule)((CPythonType)declaringType).DeclaringModule;
            object overloads;

            functionTable.TryGetValue("overloads", out overloads);
            _overloads     = LoadOverloads(typeDb, overloads, isMethod);
            _declaringType = declaringType as CPythonType;
        }
コード例 #9
0
        private bool GenerateCompletionDatabaseWorker(GenerateDatabaseOptions options, Action databaseGenerationCompleted)
        {
            if (String.IsNullOrEmpty(Configuration.InterpreterPath))
            {
                return(false);
            }

            string outPath = GetConfiguredDatabasePath();

            if (!Directory.Exists(outPath))
            {
                Directory.CreateDirectory(outPath);
            }

            var psi = new ProcessStartInfo();

            psi.CreateNoWindow  = true;
            psi.UseShellExecute = false;
            psi.FileName        = Configuration.InterpreterPath;
            psi.Arguments       =
                "\"" + Path.Combine(GetPythonToolsInstallPath(), "PythonScraper.py") + "\"" + // script to run
                " \"" + outPath + "\"" +                                                      // output dir
                " \"" + GetBaselineDatabasePath() + "\"";                                     // baseline file

            var proc = new Process();

            proc.StartInfo = psi;
            proc.Start();
            proc.WaitForExit();

            if (proc.ExitCode == 0 && (options & GenerateDatabaseOptions.StdLibDatabase) != 0)
            {
                Thread t = new Thread(x => {
                    psi = new ProcessStartInfo();
                    psi.CreateNoWindow  = true;
                    psi.UseShellExecute = false;
                    psi.FileName        = Path.Combine(GetPythonToolsInstallPath(), "Microsoft.PythonTools.Analyzer.exe");
                    if (File.Exists(psi.FileName))
                    {
                        psi.Arguments = "/dir " + "\"" + Path.Combine(Path.GetDirectoryName(Configuration.InterpreterPath), "Lib") + "\"" +
                                        " /version V" + this.Configuration.Version.ToString().Replace(".", "") +
                                        " /outdir " + "\"" + outPath + "\"" +
                                        " /indir " + "\"" + outPath + "\"";

                        proc           = new Process();
                        proc.StartInfo = psi;
                        proc.Exited   += (sender, args) => {
                            if (proc.ExitCode == 0)
                            {
                                lock (_interpreters) {
                                    _typeDb = new TypeDatabase(outPath, Is3x);
                                    OnNewDatabaseAvailable();
                                }
                            }

                            databaseGenerationCompleted();
                        };
                        proc.Start();
                    }
                });
                t.Start();
                return(true);
            }
            else if (proc.ExitCode == 0)
            {
                databaseGenerationCompleted();
                lock (_interpreters) {
                    _typeDb = new TypeDatabase(outPath, Is3x);

                    OnNewDatabaseAvailable();
                }
            }
            return(false);
        }
コード例 #10
0
ファイル: CPythonFunction.cs プロジェクト: rsumner33/PTVS
 private CPythonFunctionOverload LoadOverload(TypeDatabase typeDb, object overloadObj, bool isMethod)
 {
     return(new CPythonFunctionOverload(typeDb, overloadObj as Dictionary <string, object>, isMethod));
 }
コード例 #11
0
 public CPythonMethodDescriptor(TypeDatabase typeDb, string name, Dictionary <string, object> valueDict, IMemberContainer declaringType)
 {
     _name = name;
     _func = new CPythonFunction(typeDb, name, valueDict, declaringType, isMethod: true);
 }
コード例 #12
0
ファイル: CPythonInterpreter.cs プロジェクト: rsumner33/PTVS
 public CPythonInterpreter(TypeDatabase typeDb)
 {
     _typeDb = typeDb;
 }