Beispiel #1
0
        private static void CopyFrom(IAnalysisSet[] args, DictionaryInfo res)
        {
            DictionaryInfo copied = args[0] as DictionaryInfo;

            if (copied != null)
            {
                res.CopyFrom(copied);
            }
        }
Beispiel #2
0
        public override IAnalysisSet GetMember(Node node, AnalysisUnit unit, string name)
        {
            // Must unconditionally call the base implementation of GetMember
            var res = base.GetMember(node, unit, name);

            if (name == "func")
            {
                AddReference(node, unit);
                return(_function);
            }
            else if (name == "args")
            {
                AddReference(node, unit);
                if (_argsTuple == null)
                {
                    _argsTuple = new SequenceInfo(_args.Take(_args.Length - _keywordArgNames.Length)
                                                  .Select(v => {
                        var vd = new VariableDef();
                        vd.AddTypes(unit, v, false);
                        return(vd);
                    }).ToArray(),
                                                  unit.ProjectState.ClassInfos[BuiltinTypeId.Tuple],
                                                  node,
                                                  unit.ProjectEntry
                                                  );
                }
                return(_argsTuple);
            }
            else if (name == "keywords")
            {
                AddReference(node, unit);
                if (_keywordsDict == null)
                {
                    var dict = new DictionaryInfo(unit.ProjectEntry, node);
                    _keywordsDict = dict;
                    for (int i = 0; i < _keywordArgNames.Length; ++i)
                    {
                        int j = i + _args.Length - _keywordArgNames.Length;
                        if (j >= 0 && j < _args.Length)
                        {
                            dict._keysAndValues.AddTypes(
                                unit,
                                unit.ProjectState.GetConstant(_keywordArgNames[i].Name),
                                _args[j],
                                false
                                );
                        }
                    }
                }
                return(_keywordsDict);
            }
            return(res);
        }
Beispiel #3
0
 internal bool CopyFrom(DictionaryInfo other, bool enqueue = true)
 {
     return(_keysAndValues.CopyFrom(other._keysAndValues, enqueue));
 }
Beispiel #4
0
 public UpdateItemsAnalysisUnit(DictionaryInfo dictInfo)
     : base(null, ((ProjectEntry)dictInfo.DeclaringModule).MyScope.Scope)
 {
     _dictInfo = dictInfo;
 }
Beispiel #5
0
 internal bool CopyFrom(DictionaryInfo other, bool enqueue = true) {
     return _keysAndValues.CopyFrom(other._keysAndValues, enqueue);
 }
Beispiel #6
0
        public override IAnalysisSet GetMember(Node node, AnalysisUnit unit, string name) {
            var res = AnalysisSet.Empty;

            if (name == "func") {
                AddReference(node, unit);
                return _function;
            } else if (name == "args") {
                AddReference(node, unit);
                if (_argsTuple == null) {
                    _argsTuple = new SequenceInfo(_args.Take(_args.Length - _keywordArgNames.Length)
                        .Select(v => {
                            var vd = new VariableDef();
                            vd.AddTypes(unit, v, false, DeclaringModule);
                            return vd;
                        }).ToArray(),
                        unit.ProjectState.ClassInfos[BuiltinTypeId.Tuple],
                        node,
                        unit.ProjectEntry
                    );
                }
                return _argsTuple;
            } else if (name == "keywords") {
                AddReference(node, unit);
                if (_keywordsDict == null) {
                    var dict = new DictionaryInfo(unit.ProjectEntry, node);
                    _keywordsDict = dict;
                    for (int i = 0; i < _keywordArgNames.Length; ++i) {
                        int j = i + _args.Length - _keywordArgNames.Length;
                        if (j >= 0 && j < _args.Length) {
                            dict._keysAndValues.AddTypes(
                                unit,
                                unit.ProjectState.GetConstant(_keywordArgNames[i].Name),
                                _args[j],
                                false
                            );
                        }
                    }
                }
                return _keywordsDict;
            }
            return res;
        }
Beispiel #7
0
 public UpdateItemsAnalysisUnit(DictionaryInfo dictInfo)
     : base(null, ((ProjectEntry)dictInfo.DeclaringModule).MyScope.Scope) {
     _dictInfo = dictInfo;
 }
Beispiel #8
0
 private static void CopyFrom(IAnalysisSet[] args, DictionaryInfo res) {
     DictionaryInfo copied = args[0] as DictionaryInfo;
     if (copied != null) {
         res.CopyFrom(copied);
     }
 }
 IAnalysisSet ReturnsStringToObjectDict(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) {
     return unit.Scope.GetOrMakeNodeValue(node, n => {
         var dict = new DictionaryInfo(unit.ProjectEntry, node);
         dict.AddTypes(
             node,
             unit,
             unit.ProjectState.ClassInfos[BuiltinTypeId.Str].Instance,
             unit.ProjectState.ClassInfos[BuiltinTypeId.Object].Instance
         );
         return dict;
     });
 }
Beispiel #10
0
        public IAnalysisSet Finalize(string name, IReadOnlyList <IAnalysisSet> args)
        {
            if (string.IsNullOrEmpty(name) || args == null || args.Count == 0)
            {
                return(null);
            }

            switch (name)
            {
            case "Union":
                return(AnalysisSet.UnionAll(args.Select(a => Finalize(a))));

            case "Optional":
                return(Finalize(args[0]).Add(NoneType));

            case "List":
            case "Tuple":
            case "Container":
            case "MutableSequence":
            case "Sequence":
                try {
                    return(Scope.GetOrMakeNodeValue(_node, NodeValueKind.Sequence, n => {
                        var t = GetSequenceType(name);
                        if (t == null)
                        {
                            throw new KeyNotFoundException(name);
                        }
                        var seq = t.MakeFromIndexes(n, Entry);
                        seq.AddTypes(_unit, args.Select(ToInstance).ToArray());
                        return seq;
                    }));
                } catch (KeyNotFoundException) {
                    return(null);
                }

            case "KeysView":
                return((Scope.GetOrMakeNodeValue(_node, NodeValueKind.DictLiteral, n => {
                    var di = new DictionaryInfo(Entry, n);
                    di.AddTypes(
                        n,
                        _unit,
                        ToInstance(args[0]),
                        None
                        );
                    return di;
                }) as DictionaryInfo)?.GetKeysView(_unit));

            case "ValuesView":
                return((Scope.GetOrMakeNodeValue(_node, NodeValueKind.DictLiteral, n => {
                    var di = new DictionaryInfo(Entry, n);
                    di.AddTypes(
                        n,
                        _unit,
                        None,
                        ToInstance(args[0])
                        );
                    return di;
                }) as DictionaryInfo)?.GetValuesView(_unit));

            case "MutableSet":
            case "Set":
            case "FrozenSet":
                try {
                    return(Scope.GetOrMakeNodeValue(_node, NodeValueKind.Set, n => {
                        return new SetInfo(
                            GetSetType(name) ?? throw new KeyNotFoundException(name),
                            n,
                            Entry,
                            args.Select(ToVariableDef).ToArray()
                            );
                    }));
                } catch (KeyNotFoundException) {
Beispiel #11
0
 internal DictionaryGetMethod(IPythonMethodDescriptor method, PythonAnalyzer projectState, DictionaryInfo myDict)
     : base(method, projectState)
 {
     _myDict = myDict;
 }