Пример #1
0
        private IAnalysisSet AddCall(Node node, NameExpression[] keywordArgNames, AnalysisUnit unit, IAnalysisSet[] args)
        {
            var init     = GetMemberNoReferences(node, unit, "__init__", false);
            var initArgs = Utils.Concat(_instanceInfo.SelfSet, args);

            foreach (var initFunc in init)
            {
                initFunc.Call(node, unit, initArgs, keywordArgNames);
            }

            // TODO: If we checked for metaclass, we could pass it in as the cls arg here
            var  n         = GetMemberNoReferences(node, unit, "__new__", false);
            var  newArgs   = Utils.Concat(SelfSet, args);
            var  newResult = AnalysisSet.Empty;
            bool anyCustom = false;

            foreach (var newFunc in n)
            {
                if (!(newFunc is BuiltinFunctionInfo) && !(newFunc is SpecializedCallable))
                {
                    anyCustom = true;
                }
                newResult = newResult.Union(newFunc.Call(node, unit, newArgs, keywordArgNames).Resolve(unit));
            }

            if (anyCustom)
            {
                return(newResult);
            }



            if (newResult.Count == 0 || newResult.All(ns => ns.IsOfType(unit.State.ClassInfos[BuiltinTypeId.Object])))
            {
                if (_baseSpecialization != null && _baseSpecialization.Count != 0)
                {
                    var specializedInstances = _baseSpecialization.Call(
                        node, unit, args, keywordArgNames
                        );

                    var res = (SpecializedInstanceInfo)unit.Scope.GetOrMakeNodeValue(
                        node,
                        NodeValueKind.SpecializedInstance,
                        (node_) => new SpecializedInstanceInfo(this, specializedInstances)
                        );

                    res._instances = specializedInstances;
                    return(res);
                }

                return(_instanceInfo.SelfSet);
            }
            return(newResult);
        }
Пример #2
0
        public override IAnalysisSet Call(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames)
        {
            var newArgs = _args.Take(_args.Length - _keywordArgNames.Length)
                          .Concat(args.Take(args.Length - keywordArgNames.Length))
                          .Concat(_args.Skip(_args.Length - _keywordArgNames.Length))
                          .Concat(args.Skip(args.Length - keywordArgNames.Length))
                          .ToArray();

            var newKwArgs = _keywordArgNames.Concat(keywordArgNames).ToArray();

            return(_function.Call(node, unit, newArgs, newKwArgs));
        }