예제 #1
0
        void AddBuiltInSpecializations()
        {
            SpecializeFunction(_builtinName, "abs", Identity);
            SpecializeFunction(_builtinName, "all", ReturnsBool);
            SpecializeFunction(_builtinName, "any", ReturnsBool);
            SpecializeFunction(_builtinName, "ascii", ReturnsString);
            SpecializeFunction(_builtinName, "bin", ReturnsString);
            SpecializeFunction(_builtinName, "callable", ReturnsBool);
            SpecializeFunction(_builtinName, "chr", ReturnsString);
            if (LanguageVersion.Is2x())
            {
                SpecializeFunction(_builtinName, "cmp", ReturnsInt);
            }
            //SpecializeFunction(_builtinName, "compile", null);
            SpecializeFunction(_builtinName, "dir", ReturnsListOfString);
            //SpecializeFunction(_builtinName, "divmod", null);
            SpecializeFunction(_builtinName, "eval", ReturnsObject);
            //SpecializeFunction(_builtinName, "exec", null);
            SpecializeFunction(_builtinName, "format", ReturnsString);
            SpecializeFunction(_builtinName, "getattr", SpecialGetAttr);
            SpecializeFunction(_builtinName, "globals", ReturnsStringToObjectDict);
            SpecializeFunction(_builtinName, "hasattr", ReturnsBool);
            SpecializeFunction(_builtinName, "hash", ReturnsInt);
            SpecializeFunction(_builtinName, "hex", ReturnsString);
            SpecializeFunction(_builtinName, "id", ReturnsInt);
            if (LanguageVersion.Is3x())
            {
                SpecializeFunction(_builtinName, "input", ReturnsString);
            }
            else
            {
                SpecializeFunction(_builtinName, "input", ReturnsObject);
                SpecializeFunction(_builtinName, "raw_input", ReturnsString);
            }
            SpecializeFunction(_builtinName, "isinstance", ReturnsBool);
            SpecializeFunction(_builtinName, "issubclass", ReturnsBool);
            SpecializeFunction(_builtinName, "iter", SpecialIter);
            SpecializeFunction(_builtinName, "len", ReturnsInt);
            SpecializeFunction(_builtinName, "locals", ReturnsStringToObjectDict);
            SpecializeFunction(_builtinName, "max", ReturnUnionOfInputs);
            SpecializeFunction(_builtinName, "min", ReturnUnionOfInputs);
            SpecializeFunction(_builtinName, "next", SpecialNext);
            SpecializeFunction(_builtinName, "oct", ReturnsString);
            SpecializeFunction(_builtinName, "open", SpecialOpen);
            SpecializeFunction(_builtinName, "ord", ReturnsInt);
            SpecializeFunction(_builtinName, "pow", ReturnUnionOfInputs);
            SpecializeFunction(_builtinName, "range", RangeConstructor);
            SpecializeFunction(_builtinName, "repr", ReturnsString);
            SpecializeFunction(_builtinName, "round", SpecialRound);
            SpecializeFunction(_builtinName, "setattr", SpecialSetAttr);
            SpecializeFunction(_builtinName, "sorted", ReturnsListOfInputIterable);
            SpecializeFunction(_builtinName, "sum", ReturnUnionOfInputs);
            SpecializeFunction(_builtinName, "super", SpecialSuper);
            SpecializeFunction(_builtinName, "vars", ReturnsStringToObjectDict);

            // analyzing the copy module causes an explosion in types (it gets called w/ all sorts of types to be
            // copied, and always returns the same type).  So we specialize these away so they return the type passed
            // in and don't do any analyze.  Ditto for the rest of the functions here...
            SpecializeFunction("copy", "deepcopy", CopyFunction);
            SpecializeFunction("copy", "copy", CopyFunction);
            SpecializeFunction("pickle", "dumps", ReturnsBytes);
            SpecializeFunction("UserDict.UserDict", "update", Nop);
            SpecializeFunction("pprint", "pprint", Nop);
            SpecializeFunction("pprint", "pformat", ReturnsString);
            SpecializeFunction("pprint", "saferepr", ReturnsString);
            SpecializeFunction("pprint", "_safe_repr", ReturnsString);
            SpecializeFunction("pprint", "_format", ReturnsString);
            SpecializeFunction("pprint.PrettyPrinter", "_format", ReturnsString);
            SpecializeFunction("decimal.Decimal", "__new__", Nop);
            SpecializeFunction("StringIO.StringIO", "write", Nop);
            SpecializeFunction("threading.Thread", "__init__", Nop);
            SpecializeFunction("subprocess.Popen", "__init__", Nop);
            SpecializeFunction("Tkinter.Toplevel", "__init__", Nop);
            SpecializeFunction("weakref.WeakValueDictionary", "update", Nop);
            SpecializeFunction("os._Environ", "get", ReturnsString);
            SpecializeFunction("os._Environ", "update", Nop);
            SpecializeFunction("ntpath", "expandvars", ReturnsString);
            SpecializeFunction("idlelib.EditorWindow.EditorWindow", "__init__", Nop);
            SpecializeFunction("_functools", "partial", PartialFunction);
            SpecializeFunction("functools", "partial", PartialFunction);
            SpecializeFunction("functools", "update_wrapper", UpdateWrapperFunction);
            SpecializeFunction("functools", "wraps", WrapsFunction);

            SpecializeFunction("unittest", "_id", Identity);
            SpecializeFunction("unittest", "skip", IdentityDecorator);
            SpecializeFunction("unittest", "skipIf", IdentityDecorator);
            SpecializeFunction("unittest", "skipUnless", IdentityDecorator);

            // cached for quick checks to see if we're a call to clr.AddReference

            SpecializeFunction("wpf", "LoadComponent", LoadComponent);
        }