Esempio n. 1
0
 public SequenceBuiltinClassInfo(IPythonType classObj, PythonAnalyzer projectState)
     : base(classObj, projectState) {
     var seqType = classObj as IPythonSequenceType;
     if (seqType != null && seqType.IndexTypes != null) {
         _indexTypes = projectState.GetAnalysisSetFromObjects(seqType.IndexTypes).GetInstanceType();
     } else {
         _indexTypes = AnalysisSet.Empty;
     }
 }
 public GeneratorInfo(PythonAnalyzer projectState, IPythonProjectEntry entry)
     : base(projectState.ClassInfos[BuiltinTypeId.Generator]) {
     
     _declaringModule = entry;
     _declaringVersion = entry.AnalysisVersion;
     Yields = new VariableDef();
     Sends = new VariableDef();
     Returns = new VariableDef();
 }
Esempio n. 3
0
        public CoroutineInfo(PythonAnalyzer projectState, IPythonProjectEntry entry)
            : base(projectState.ClassInfos[BuiltinTypeId.Generator]) {
            // Internally, coroutines are represented by generators with a CO_*
            // flag on the code object. Here we represent it as a separate info,
            // but reuse the underlying class info.

            _declaringModule = entry;
            _declaringVersion = entry.AnalysisVersion;
            Returns = new VariableDef();
        }
Esempio n. 4
0
        public static ConstantInfo Create(PythonAnalyzer state, object value) {
            var constant = value as IPythonConstant;
            var constantType = constant?.Type;
            var av = state.GetAnalysisValueFromObjectsThrowOnNull(constantType ?? state.GetTypeFromObject(value));

            var ci = av as ConstantInfo;
            if (ci != null) {
                return ci;
            }
            var bci = av as BuiltinClassInfo;
            if (bci != null) {
                return new ConstantInfo(bci, value, constant?.MemberType ?? PythonMemberType.Constant);
            }
            return null;
        }
Esempio n. 5
0
        private static void SignatureTest(int location, string sourceCode, string expectedExpression, int paramIndex)
        {
            if (location < 0) {
                location = sourceCode.Length + location;
            }

            var analyzer = new PythonAnalyzer(new MockDlrRuntimeHost(), new MockErrorProviderFactory());
            var buffer = new MockTextBuffer(sourceCode);
            var snapshot = (MockTextSnapshot)buffer.CurrentSnapshot;
            var context = analyzer.GetSignatures(snapshot, buffer, new MockTrackingSpan(snapshot, location, 1));
            AreEqual(context.Text, expectedExpression);
            AreEqual(context.ParameterIndex, paramIndex);
        }
Esempio n. 6
0
 public ConstantInfo(IPythonConstant value, PythonAnalyzer projectState)
     : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)) {
     _value = value;
     _memberType = value.MemberType;
     _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(value.Type)).Instance;
 }
Esempio n. 7
0
 public RangeInfo(IPythonType seqType, PythonAnalyzer state)
     : base(state.ClassInfos[BuiltinTypeId.List]) {
 }
Esempio n. 8
0
 public ConstantInfo(object value, PythonAnalyzer projectState)
     : base((BuiltinClassInfo)projectState.GetAnalysisValueFromObjectsThrowOnNull(projectState.GetTypeFromObject(value))) {
     _value = value;
     _memberType = PythonMemberType.Constant;
     _builtinInfo = ((BuiltinClassInfo)projectState.GetAnalysisValueFromObjects(_type)).Instance;
 }
Esempio n. 9
0
 public BuiltinModule(IPythonModule module, PythonAnalyzer projectState)
     : base(module, projectState)
 {
     _interpreterModule = module;
 }
Esempio n. 10
0
 public SetInfo(PythonAnalyzer projectState, Node node, ProjectEntry entry)
     : base(VariableDef.EmptyArray, projectState.ClassInfos[BuiltinTypeId.Set], node, entry) { }
Esempio n. 11
0
 public DictBuiltinClassInfo(IPythonType classObj, PythonAnalyzer projectState)
     : base(classObj, projectState) {
 }
Esempio n. 12
0
 public BuiltinPropertyInfo(IBuiltinProperty value, PythonAnalyzer projectState)
     : base(value.Type, projectState)
 {
     _value = value;
     _doc   = null;
 }
Esempio n. 13
0
        private static ExpressionAnalysis AnalyzeExpression(int location, string sourceCode)
        {
            if (location < 0) {
                location = sourceCode.Length + location;
            }

            var analyzer = new PythonAnalyzer(new MockDlrRuntimeHost(), new MockErrorProviderFactory());
            var buffer = new MockTextBuffer(sourceCode);
            var textView = new MockTextView(buffer);
            var item = analyzer.AnalyzeTextView(textView);
            while (item.IsAnalyzed) {
                Thread.Sleep(100);
            }

            var snapshot = (MockTextSnapshot)buffer.CurrentSnapshot;

            return analyzer.AnalyzeExpression(snapshot, buffer, new MockTrackingSpan(snapshot, location, 0));
        }
Esempio n. 14
0
 public void Register(PythonAnalyzer analyzer)
 {
     _analyzer = analyzer;
 }
Esempio n. 15
0
 private PythonAnalyzer MakeTestAnalyzer()
 {
     return(PythonAnalyzer.CreateAsync(InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(2, 7))).GetAwaiter().GetResult());
 }
Esempio n. 16
0
 public ReloadModulesQueueItem(PythonAnalyzer analyzer)
 {
     _analyzer = analyzer;
 }
Esempio n. 17
0
 internal static string GetDefaultValue(PythonAnalyzer state, Parameter curParam, PythonAst tree)
 {
     if (curParam.DefaultValue != null)
     {
         // TODO: Support all possible expressions for default values, we should
         // probably have a PythonAst walker for expressions or we should add ToCodeString()
         // onto Python ASTs so they can round trip
         ConstantExpression defaultValue = curParam.DefaultValue as ConstantExpression;
         if (defaultValue != null)
         {
             return(defaultValue.GetConstantRepr(state.LanguageVersion));
         }
         else
         {
             NameExpression nameExpr = curParam.DefaultValue as NameExpression;
             if (nameExpr != null)
             {
                 return(nameExpr.Name);
             }
             else
             {
                 DictionaryExpression dict = curParam.DefaultValue as DictionaryExpression;
                 if (dict != null)
                 {
                     if (dict.Items.Count == 0)
                     {
                         return("{}");
                     }
                     else
                     {
                         return("{...}");
                     }
                 }
                 else
                 {
                     ListExpression list = curParam.DefaultValue as ListExpression;
                     if (list != null)
                     {
                         if (list.Items.Count == 0)
                         {
                             return("[]");
                         }
                         else
                         {
                             return("[...]");
                         }
                     }
                     else
                     {
                         TupleExpression tuple = curParam.DefaultValue as TupleExpression;
                         if (tuple != null)
                         {
                             if (tuple.Items.Count == 0)
                             {
                                 return("()");
                             }
                             else
                             {
                                 return("(...)");
                             }
                         }
                         else
                         {
                             return(curParam.DefaultValue.ToCodeString(tree).Trim());
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 18
0
 public EnumInstanceInfo(object value, PythonAnalyzer projectState)
     : base(value, projectState) {
 }
Esempio n. 19
0
 public void Initialize(PythonAnalyzer state) {
 }
Esempio n. 20
0
 internal static string UnaryOpToString(PythonAnalyzer state, PythonOperator operation) {
     string op = null;
     switch (operation) {
         case PythonOperator.Not: op = state.LanguageVersion.Is3x() ? "__bool__" : "__nonzero__"; break;
         case PythonOperator.Pos: op = "__pos__"; break;
         case PythonOperator.Invert: op = "__invert__"; break;
         case PythonOperator.Negate: op = "__neg__"; break;
     }
     return op;
 }
Esempio n. 21
0
 public EnumInstanceInfo(object value, PythonAnalyzer projectState)
     : base(projectState.ClassInfos[BuiltinTypeId.Int], value, PythonMemberType.EnumInstance) {
 }