Exemplo n.º 1
0
 public virtual IAnalysisSet GetAsyncEnumeratorTypes(Node node, AnalysisUnit unit) => AnalysisSet.Empty;
 public static IAnalysisSet Resolve(this IAnalysisSet self, AnalysisUnit unit) => Resolve(self, unit, ResolutionContext.Complete, out _);
Exemplo n.º 3
0
 public SetComprehensionAnalysisUnit(Comprehension node, PythonAst parent, AnalysisUnit outerUnit, InterpreterScope outerScope)
     : base(node, parent,
            new ComprehensionScope(new SetInfo(outerUnit.State, node, outerUnit.ProjectEntry), node, outerScope),
            outerUnit)
 {
 }
        /// <summary>
        /// Returns the set of types which are accessible when code enumerates
        /// over the object
        /// in a for statement.
        /// </summary>
        public static IAnalysisSet GetAsyncEnumeratorTypes(this IAnalysisSet self, Node node, AnalysisUnit unit)
        {
            var res = AnalysisSet.Empty;

            foreach (var ns in self)
            {
                res = res.Union(ns.GetAsyncEnumeratorTypes(node, unit));
            }
            return(res);
        }
        /// <summary>
        /// Performs the specified operation on the value and the rhs value.
        /// </summary>
        public static IAnalysisSet BinaryOperation(this IAnalysisSet self, Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs)
        {
            var res = AnalysisSet.Empty;

            foreach (var ns in self)
            {
                res = res.Union(ns.BinaryOperation(node, unit, operation, rhs));
            }
            return(res);
        }
Exemplo n.º 6
0
 IAnalysisSet ReturnsListOfInputIterable(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
 {
     // TODO: Grab the input iterable and create a list containing them
     return(unit.State.ClassInfos[BuiltinTypeId.List].Instance);
 }
 /// <summary>
 /// Performs a delete index operation propagating the index types into
 /// the provided object.
 /// </summary>
 public static void DeleteIndex(this IAnalysisSet self, Node node, AnalysisUnit unit, IAnalysisSet index)
 {
 }
Exemplo n.º 8
0
 public virtual IAnalysisSet GetReturnForYieldFrom(Node node, AnalysisUnit unit) => AnalysisSet.Empty;
Exemplo n.º 9
0
 /// <summary>
 /// If required, returns the resolved version of this value. If there is nothing
 /// to resolve, returns <c>this</c>.
 /// </summary>
 public IAnalysisSet Resolve(AnalysisUnit unit) => Resolve(unit, ResolutionContext.Complete);
Exemplo n.º 10
0
 public virtual IAnalysisSet GetDescriptor(Node node, AnalysisValue instance, AnalysisValue context, AnalysisUnit unit) => SelfSet;
Exemplo n.º 11
0
 public virtual IAnalysisSet Await(Node node, AnalysisUnit unit) => AnalysisSet.Empty;
Exemplo n.º 12
0
 public virtual void SetIndex(Node node, AnalysisUnit unit, IAnalysisSet index, IAnalysisSet value)
 {
 }
Exemplo n.º 13
0
 public virtual IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index)
 => GetTypeMember(node, unit, "__getitem__").Call(node, unit, new[] { index }, ExpressionEvaluator.EmptyNames);
Exemplo n.º 14
0
 public virtual IAnalysisSet GetAsyncIterator(Node node, AnalysisUnit unit)
 => GetTypeMember(node, unit, "__aiter__")
 .Call(node, unit, ExpressionEvaluator.EmptySets, ExpressionEvaluator.EmptyNames)
 .Await(node, unit);
Exemplo n.º 15
0
        IAnalysisSet SpecialSuper(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
        {
            if (args.Length < 0 || args.Length > 2)
            {
                return(AnalysisSet.Empty);
            }

            var classes   = AnalysisSet.Empty;
            var instances = AnalysisSet.Empty;

            if (args.Length == 0)
            {
                if (unit.State.LanguageVersion.Is3x())
                {
                    // No-arg version is magic in 3k - first arg is implicitly the enclosing class, and second is implicitly
                    // the first argument of the enclosing method. Look up that information from the scope.
                    // We want to find the nearest enclosing class scope, and the function scope that is immediately beneath
                    // that class scope. If there is no such combo, a no-arg super() is invalid.
                    var           scopes     = unit.Scope;
                    ClassScope    classScope = null;
                    FunctionScope funcScope  = null;
                    foreach (var s in scopes.EnumerateTowardsGlobal)
                    {
                        funcScope = s as FunctionScope;
                        if (funcScope != null)
                        {
                            classScope = s.OuterScope as ClassScope;
                            if (classScope != null)
                            {
                                break;
                            }
                        }
                    }

                    if (classScope != null && funcScope != null)
                    {
                        classes = classScope.Class.SelfSet;
                        // Get first arg of function.
                        if (funcScope.Function.FunctionDefinition.ParametersInternal.Length > 0)
                        {
                            instances = classScope.Class.Instance.SelfSet;
                        }
                    }
                }
            }
            else
            {
                classes = args[0];
                if (args.Length > 1)
                {
                    instances = args[1];
                }
            }

            if (classes == null)
            {
                return(AnalysisSet.Empty);
            }

            return(unit.Scope.GetOrMakeNodeValue(node, NodeValueKind.Super, _ => {
                var res = AnalysisSet.Empty;
                foreach (var classInfo in classes.OfType <ClassInfo>())
                {
                    res = res.Add(new SuperInfo(classInfo, instances));
                }
                return res;
            }));
        }
Exemplo n.º 16
0
 /// <summary>
 /// If required, returns the resolved version of this value given a specific context.
 /// </summary>
 /// <remarks>
 internal virtual IAnalysisSet Resolve(AnalysisUnit unit, ResolutionContext context) => this;
Exemplo n.º 17
0
 IAnalysisSet ReturnUnionOfInputs(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
 {
     return(AnalysisSet.UnionAll(args));
 }
Exemplo n.º 18
0
 internal virtual void AddReference(Node node, AnalysisUnit analysisUnit)
 {
 }
Exemplo n.º 19
0
        IAnalysisSet LoadComponent(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
        {
            if (args.Length == 2 && unit.State.Interpreter is IDotNetPythonInterpreter)
            {
                var self = args[0];
                var xaml = args[1];

                foreach (var arg in xaml)
                {
                    var strConst = arg.GetConstantValueAsString();
                    if (string.IsNullOrEmpty(strConst))
                    {
                        continue;
                    }

                    // process xaml file, add attributes to self
                    string           xamlPath = Path.Combine(Path.GetDirectoryName(unit.DeclaringModule.ProjectEntry.FilePath), strConst);
                    XamlProjectEntry xamlProject;
                    if (unit.State._xamlByFilename.TryGetValue(xamlPath, out xamlProject))
                    {
                        // TODO: Get existing analysis if it hasn't changed.
                        var analysis = xamlProject.Analysis;

                        if (analysis == null)
                        {
                            xamlProject.Analyze(CancellationToken.None);
                            analysis = xamlProject.Analysis;
                            if (analysis == null)
                            {
                                AnalysisLog.Assert(false, "No Xaml analysis");
                                return(self);
                            }
                        }

                        xamlProject.AddDependency(unit.ProjectEntry);

                        var evalUnit = unit.CopyForEval();

                        // add named objects to instance
                        foreach (var keyValue in analysis.NamedObjects)
                        {
                            var type = keyValue.Value;
                            if (type.Type.UnderlyingType != null)
                            {
                                var ns  = unit.State.GetAnalysisValueFromObjects(((IDotNetPythonInterpreter)unit.State.Interpreter).GetBuiltinType(type.Type.UnderlyingType));
                                var bci = ns as BuiltinClassInfo;
                                if (bci != null)
                                {
                                    ns = bci.Instance;
                                }
                                self.SetMember(node, evalUnit, keyValue.Key, ns.SelfSet);
                            }

                            // TODO: Better would be if SetMember took something other than a node, then we'd
                            // track references w/o this extra effort.
                            foreach (var inst in self)
                            {
                                InstanceInfo instInfo = inst as InstanceInfo;
                                if (instInfo != null && instInfo.InstanceAttributes != null)
                                {
                                    VariableDef def;
                                    if (instInfo.InstanceAttributes.TryGetValue(keyValue.Key, out def))
                                    {
                                        def.AddAssignment(
                                            new EncodedLocation(
                                                new LocationInfo(xamlProject.FilePath, xamlProject.DocumentUri, type.LineNumber, type.LineOffset),
                                                null
                                                ),
                                            xamlProject
                                            );
                                    }
                                }
                            }
                        }

                        // add references to event handlers
                        foreach (var keyValue in analysis.EventHandlers)
                        {
                            // add reference to methods...
                            var member = keyValue.Value;

                            // TODO: Better would be if SetMember took something other than a node, then we'd
                            // track references w/o this extra effort.
                            foreach (var inst in self)
                            {
                                InstanceInfo instInfo = inst as InstanceInfo;
                                if (instInfo != null)
                                {
                                    ClassInfo ci = instInfo.ClassInfo;

                                    VariableDef def;
                                    if (ci.Scope.TryGetVariable(keyValue.Key, out def))
                                    {
                                        def.AddReference(
                                            new EncodedLocation(
                                                new LocationInfo(xamlProject.FilePath, xamlProject.DocumentUri, member.LineNumber, member.LineOffset),
                                                null
                                                ),
                                            xamlProject
                                            );
                                    }
                                }
                            }
                        }
                    }
                }
                // load component returns self
                return(self);
            }

            return(AnalysisSet.Empty);
        }
Exemplo n.º 20
0
 public bool AddTypes(AnalysisUnit unit, IEnumerable <AnalysisValue> newTypes, bool enqueue = true)
 {
     return(AddTypes(unit.ProjectEntry, newTypes, enqueue));
 }
 /// <summary>
 /// Performs an augmented assignment propagating the value into the
 /// object.
 /// </summary>
 public static void AugmentAssign(this IAnalysisSet self, AugmentedAssignStatement node, AnalysisUnit unit, IAnalysisSet value)
 {
     foreach (var ns in self)
     {
         ns.AugmentAssign(node, unit, value);
     }
 }
Exemplo n.º 22
0
 IAnalysisSet Nop(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
 {
     return(AnalysisSet.Empty);
 }
        /// <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);
        }
Exemplo n.º 24
0
 IAnalysisSet Identity(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
 {
     return(args.Length > 0 ? args[0] : AnalysisSet.Empty);
 }
        /// <summary>
        /// Gets the returned value for a yield from.
        /// </summary>
        public static IAnalysisSet GetReturnForYieldFrom(this IAnalysisSet self, Node node, AnalysisUnit unit)
        {
            var res = AnalysisSet.Empty;

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

            return(res);
        }
Exemplo n.º 26
0
 IAnalysisSet RangeConstructor(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
 {
     return(unit.Scope.GetOrMakeNodeValue(node, NodeValueKind.Range, (nn) => new RangeInfo(unit.State.Types[BuiltinTypeId.List], unit.State)));
 }
Exemplo n.º 27
0
        public ComprehensionAnalysisUnit(Comprehension node, PythonAst parent, InterpreterScope scope, AnalysisUnit outerUnit)
            : base(node, parent, scope, false)
        {
            _outerUnit = outerUnit;
            _parent    = parent;

            AnalysisLog.NewUnit(this);
        }
Exemplo n.º 28
0
 IAnalysisSet ReturnsString(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
 {
     return(unit.State.ClassInfos[BuiltinTypeId.Str].Instance);
 }
Exemplo n.º 29
0
 public DictionaryComprehensionAnalysisUnit(Comprehension node, PythonAst parent, AnalysisUnit outerUnit, InterpreterScope outerScope)
     : base(node, parent,
            new ComprehensionScope(new DictionaryInfo(outerUnit.ProjectEntry, node), node, outerScope),
            outerUnit)
 {
 }
Exemplo n.º 30
0
 public virtual IAnalysisSet GetEnumeratorTypes(Node node, AnalysisUnit unit) =>
 // TODO: need more than constant 0...
 //index = (VariableRef(ConstantInfo(0, self.ProjectState, False)), )
 //self.AssignTo(self._state.IndexInto(listRefs, index), node, node.Left)
 GetIndex(node, unit, unit.State.ClassInfos[BuiltinTypeId.Int].SelfSet);