Exemplo n.º 1
0
 internal void SetIndex(AnalysisUnit unit, int index, IAnalysisSet value)
 {
     if (index >= IndexTypes.Length)
     {
         var newTypes = new VariableDef[index + 1];
         for (int i = 0; i < newTypes.Length; ++i)
         {
             if (i < IndexTypes.Length)
             {
                 newTypes[i] = IndexTypes[i];
             }
             else
             {
                 newTypes[i] = new VariableDef();
             }
         }
         IndexTypes = newTypes;
     }
     IndexTypes[index].AddTypes(unit, value);
 }
Exemplo n.º 2
0
        internal override SequenceInfo MakeFromIndexes(Node node, ProjectEntry entry)
        {
            if (_tupleTypes != null)
            {
                return(new SequenceInfo(_tupleTypes.Select(t => {
                    var v = new VariableDef();
                    v.AddTypes(entry, t);
                    return v;
                }).ToArray(), this, node, entry));
            }

            if (_indexTypes.Length > 0)
            {
                var vals = _indexTypes.Zip(VariableDef.Generator, (t, v) => { v.AddTypes(entry, t, false, entry); return(v); }).ToArray();
                return(new SequenceInfo(vals, this, node, entry));
            }
            else
            {
                return(new SequenceInfo(VariableDef.EmptyArray, this, node, entry));
            }
        }
Exemplo n.º 3
0
 internal void SetIndex(AnalysisUnit unit, int index, IAnalysisSet value)
 {
     if (index >= IndexTypes.Length)
     {
         var newTypes = new VariableDef[index + 1];
         for (int i = 0; i < newTypes.Length; ++i)
         {
             if (i < IndexTypes.Length)
             {
                 newTypes[i] = IndexTypes[i];
             }
             else
             {
                 newTypes[i] = new VariableDef();
             }
         }
         IndexTypes = newTypes;
     }
     IndexTypes[index].MakeUnionStrongerIfMoreThan(ProjectState.Limits.IndexTypes, value);
     IndexTypes[index].AddTypes(unit, value, true, DeclaringModule);
 }
Exemplo n.º 4
0
        public GeneratorInfo(FunctionInfo functionInfo)
            : base(functionInfo.ProjectState._generatorType)
        {
            _functionInfo = functionInfo;
            ISet <Namespace> nextMeth;

            if (functionInfo._analysisUnit.ProjectState.LanguageVersion.Is3x())
            {
                nextMeth = this["__next__"];
            }
            else
            {
                nextMeth = this["next"];
            }
            var sendMeth = this["send"];

            _nextMethod = new GeneratorNextBoundBuiltinMethodInfo(this, (BuiltinMethodInfo)nextMeth.First());
            _sendMethod = new GeneratorSendBoundBuiltinMethodInfo(this, (BuiltinMethodInfo)sendMeth.First());

            _sends = new VariableDef();
        }
Exemplo n.º 5
0
        public override void SetMember(Node node, AnalysisUnit unit, string name, IAnalysisSet value)
        {
            if (_functionAttrs == null)
            {
                _functionAttrs = new Dictionary <string, VariableDef>();
            }

            VariableDef varRef;

            if (!_functionAttrs.TryGetValue(name, out varRef))
            {
                _functionAttrs[name] = varRef = new VariableDef();
            }
            varRef.AddAssignment(node, unit);
            varRef.AddTypes(unit, value, true, DeclaringModule);

            if (name == "__doc__")
            {
                _doc = string.Join(Environment.NewLine, varRef.TypesNoCopy.OfType <ConstantInfo>()
                                   .Select(ci => (ci.Value as string) ?? (ci.Value as AsciiString)?.String)
                                   .Where(s => !string.IsNullOrEmpty(s) && (_doc == null || !_doc.Contains(s)))
                                   );
            }
        }
Exemplo n.º 6
0
 public DictParameterVariableDef(AnalysisUnit unit, Node location, VariableDef copy)
     : base(unit.DeclaringModule.ProjectEntry, location, copy)
 {
     Dict = new StarArgsDictionaryInfo(unit.ProjectEntry, location);
     AddTypes(unit, Dict, false, Entry);
 }
Exemplo n.º 7
0
 public SingleIteratorValue(VariableDef indexTypes, BuiltinClassInfo iterType, IPythonProjectEntry declModule)
     : base(iterType)
 {
     _indexTypes = indexTypes;
     _declModule = declModule;
 }
Exemplo n.º 8
0
 internal FunctionInfo(AnalysisUnit unit)
     : base(unit)
 {
     _returnValue = new VariableDef();
     _declVersion = unit.ProjectEntry.Version;
 }
Exemplo n.º 9
0
 public NamespaceProtocol(ProtocolInfo self, string name) : base(self)
 {
     _name   = name;
     _values = new VariableDef();
 }
Exemplo n.º 10
0
        public override ISet <Namespace> GetMember(Node node, AnalysisUnit unit, string name)
        {
            // __getattribute__ takes precedence over everything.
            ISet <Namespace> getattrRes = EmptySet <Namespace> .Instance;
            var getAttribute            = _classInfo.GetMemberNoReferences(node, unit.CopyForEval(), "__getattribute__");

            if (getAttribute.Count > 0)
            {
                foreach (var getAttrFunc in getAttribute)
                {
                    var func = getAttrFunc as BuiltinMethodInfo;
                    if (func != null && func.Function.Overloads.Count == 1 && func.Function.DeclaringType == ProjectState.Types.Object)
                    {
                        continue;
                    }
                    // TODO: We should really do a get descriptor / call here
                    // FIXME: new string[0]
                    getattrRes = getattrRes.Union(getAttrFunc.Call(node, unit, new[] { SelfSet, ProjectState._stringType.Instance.SelfSet }, new string[0]));
                }
                if (getattrRes.Count > 0)
                {
                    return(getattrRes);
                }
            }

            // then check class members
            var classMem = _classInfo.GetMemberNoReferences(node, unit, name).GetDescriptor(this, unit);

            if (classMem.Count > 0)
            {
                // TODO: Check if it's a data descriptor...
                return(classMem);
            }

            // ok, it most be an instance member...
            if (_instanceAttrs == null)
            {
                _instanceAttrs = new Dictionary <string, VariableDef>();
            }
            VariableDef def;

            if (!_instanceAttrs.TryGetValue(name, out def))
            {
                _instanceAttrs[name] = def = new VariableDef();
            }
            def.AddReference(node, unit);
            def.AddDependency(unit);

            var res = def.Types;

            if (res.Count == 0)
            {
                // and if that doesn't exist fall back to __getattr__
                var getAttr = _classInfo.GetMemberNoReferences(node, unit, "__getattr__");
                if (getAttr.Count > 0)
                {
                    foreach (var getAttrFunc in getAttr)
                    {
                        // TODO: We should really do a get descriptor / call here
                        //FIXME: new string[0]
                        getattrRes = getattrRes.Union(getAttrFunc.Call(node, unit, new[] { SelfSet, _classInfo._analysisUnit.ProjectState._stringType.Instance.SelfSet }, new string[0]));
                    }
                }
                return(getattrRes);
            }
            return(res);
        }