Files
codeql/python/ql/src/analysis/RatioOfDefinitions.ql
2020-03-30 11:59:10 +02:00

27 lines
765 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(Object cobj | e.refersTo(cobj) and cobj.isC()) 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) + "%"