Files
codeql/python/ql/src/analysis/RatioOfDefinitions.ql
Taus Brock-Nannestad f07a7bf8cf Python: Autoformat everything using qlformat.
Will need subsequent PRs fixing up test failures (due to deprecated
methods moving around), but other than that everything should be
straight-forward.
2020-07-07 15:43:52 +02:00

27 lines
739 B
Plaintext

/**
* @name Ratio of jump-to-definitions computed
*/
import python
import DefinitionTracking
predicate want_to_have_definition(Expr e) {
/* not builtin object like len, tuple, etc. */
not exists(Value builtin | e.pointsTo(builtin) and builtin.isBuiltin()) and
(
e instanceof Name and e.(Name).getCtx() instanceof Load
or
e instanceof Attribute and e.(Attribute).getCtx() instanceof Load
or
e instanceof ImportMember
or
e instanceof ImportExpr
)
}
from int yes, int no
where
yes = count(Expr e | want_to_have_definition(e) and exists(getUniqueDefinition(e))) and
no = count(Expr e | want_to_have_definition(e) and not exists(getUniqueDefinition(e)))
select yes, no, yes * 100 / (yes + no) + "%"