Python: Remove BuiltinFunctionObject module as it is clearer and more concise to use ModuleObject::builtin().

This commit is contained in:
Mark Shannon 2019-02-20 11:23:48 +00:00
Родитель 98be27a73e
Коммит adadd4942b
8 изменённых файлов: 28 добавлений и 82 удалений

Просмотреть файл

@ -107,7 +107,7 @@ private predicate brace_pair(PossibleAdvancedFormatString fmt, int start, int en
private predicate advanced_format_call(Call format_expr, PossibleAdvancedFormatString fmt, int args) {
exists(CallNode call |
call = format_expr.getAFlowNode() |
call.getFunction().refersTo(BuiltinFunctionObject::format()) and call.getArg(0).refersTo(_, fmt.getAFlowNode()) and
call.getFunction().refersTo(Object::builtin("format")) and call.getArg(0).refersTo(_, fmt.getAFlowNode()) and
args = count(format_expr.getAnArg()) - 1
or
call.getFunction().(AttrNode).getObject("format").refersTo(_, fmt.getAFlowNode()) and

Просмотреть файл

@ -13,5 +13,5 @@ import python
from CallNode call, ControlFlowNode func
where
major_version() = 2 and call.getFunction() = func and func.refersTo(BuiltinFunctionObject::apply())
major_version() = 2 and call.getFunction() = func and func.refersTo(Object::builtin("apply"))
select call, "Call to the obsolete builtin function 'apply'."

Просмотреть файл

@ -14,5 +14,5 @@ import python
from CallNode call, Context context, ControlFlowNode func
where
context.getAVersion().includes(2, _) and call.getFunction() = func and func.refersTo(context, BuiltinFunctionObject::input(), _, _)
context.getAVersion().includes(2, _) and call.getFunction() = func and func.refersTo(context, Object::builtin("input"), _, _)
select call, "The unsafe built-in function 'input' is used."

Просмотреть файл

@ -128,7 +128,7 @@ predicate function_should_close_parameter(Function func) {
}
predicate function_opens_file(FunctionObject f) {
f = BuiltinFunctionObject::open()
f = Object::builtin("open")
or
exists(EssaVariable v, Return ret |
ret.getScope() = f.getFunction() |

Просмотреть файл

@ -24,7 +24,7 @@ predicate declaredInAll(Module m, StrConst name)
predicate mutates_globals(PythonModuleObject m) {
exists(CallNode globals |
globals = BuiltinFunctionObject::globals().getACall() and
globals = Object::builtin("globals").(FunctionObject).getACall() and
globals.getScope() = m.getModule() |
exists(AttrNode attr | attr.getObject() = globals)
or

Просмотреть файл

@ -196,7 +196,7 @@ predicate function_can_never_return(FunctionObject func) {
not exists(f.getAnExitNode())
)
or
func = BuiltinFunctionObject::sysExit()
func = ModuleObject::named("sys").attr("exit")
}
/** Python specific sub-class of generic EssaNodeDefinition */

Просмотреть файл

@ -376,107 +376,53 @@ class BuiltinFunctionObject extends BuiltinCallable {
}
module BuiltinFunctionObject {
/** The builtin function apply (Python 2 only) */
BuiltinFunctionObject apply() {
result = Object::builtin("apply")
}
/** The builtin function `hasattr` */
BuiltinFunctionObject hasattr() {
result = Object::builtin("hasattr")
}
/** The builtin function `len` */
BuiltinFunctionObject len() {
result = Object::builtin("len")
}
BuiltinFunctionObject format() {
result = Object::builtin("format")
}
/** The builtin function open */
BuiltinFunctionObject open() {
result = Object::builtin("open")
}
/** The builtin function print (Python 2.7 upwards) */
BuiltinFunctionObject print() {
result = Object::builtin("print")
}
/** The builtin function input (Python 2 only) */
BuiltinFunctionObject input() {
result = Object::builtin("input")
}
/** The builtin function locals */
BuiltinFunctionObject locals() {
py_special_objects(result, "locals")
}
/** The builtin function globals */
BuiltinFunctionObject globals() {
py_special_objects(result, "globals")
}
/** The builtin function sys.exit */
BuiltinFunctionObject sysExit() {
py_cmembers_versioned(theSysModuleObject(), "exit", result, major_version().toString())
}
}
/** DEPRECATED -- Use `BuiltinFunctionObject::apply()` instead. */
/** DEPRECATED -- Use `Object::builtin("apply")` instead. */
Object theApplyFunction() {
result = BuiltinFunctionObject::apply()
result = Object::builtin("apply")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::hasattr()` instead. */
/** DEPRECATED -- Use `Object::builtin("hasattr")` instead. */
Object theHasattrFunction() {
result = BuiltinFunctionObject::hasattr()
result = Object::builtin("hasattr")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::len()` instead. */
/** DEPRECATED -- Use `Object::builtin("len")` instead. */
Object theLenFunction() {
result = BuiltinFunctionObject::len()
result = Object::builtin("len")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::format()` instead. */
/** DEPRECATED -- Use `Object::builtin("format")` instead. */
Object theFormatFunction() {
result = BuiltinFunctionObject::format()
result = Object::builtin("format")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::open()` instead. */
/** DEPRECATED -- Use `Object::builtin("open")` instead. */
Object theOpenFunction() {
result = BuiltinFunctionObject::open()
result = Object::builtin("open")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::print()` instead. */
/** DEPRECATED -- Use `Object::builtin("print")` instead. */
Object thePrintFunction() {
result = BuiltinFunctionObject::print()
result = Object::builtin("print")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::input()` instead. */
/** DEPRECATED -- Use `Object::builtin("input")` instead. */
Object theInputFunction() {
result = BuiltinFunctionObject::input()
result = Object::builtin("input")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::locals()` instead. */
/** DEPRECATED -- Use `Object::builtin("locals")` instead. */
Object theLocalsFunction() {
result = BuiltinFunctionObject::locals()
result = Object::builtin("locals")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::globals()` instead. */
/** DEPRECATED -- Use `Object::builtin("globals")()` instead. */
Object theGlobalsFunction() {
result = BuiltinFunctionObject::globals()
result = Object::builtin("globals")
}
/** DEPRECATED -- Use `BuiltinFunctionObject::sysExit()` instead. */
/** DEPRECATED -- Use `Object::builtin("sysExit()` instead. */
Object theExitFunctionObject() {
result = BuiltinFunctionObject::sysExit()
result = ModuleObject::named("sys").attr("exit")
}

Просмотреть файл

@ -18,7 +18,7 @@ predicate tracked_object(ControlFlowNode obj, string attr) {
}
predicate open_file(Object obj) {
obj.(CallNode).getFunction().refersTo(BuiltinFunctionObject::open())
obj.(CallNode).getFunction().refersTo(Object::builtin("open"))
}
predicate string_attribute_any(ControlFlowNode n, string attr) {
@ -28,7 +28,7 @@ predicate string_attribute_any(ControlFlowNode n, string attr) {
if major_version() = 2 then
input = Object::builtin("raw_input")
else
input = BuiltinFunctionObject::input()
input = Object::builtin("input")
)
or
attr = "file-input" and