ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
builtins.cpp File Reference
Include dependency graph for builtins.cpp:

Functions

static void collect_classinfo (const nlohmann::json &node, std::vector< nlohmann::json > &out)
static bool admits_class_object (const std::vector< nlohmann::json > &types)
static exprt evaluate_after (const exprt &binding, const exprt &result)
 result evaluated after binding, or result alone if it is nil.
static exprt list_item_of_scalar_read (const exprt &read, const typet &item_type)
 The list item a read *(T *)item->value of a scalar element comes from, or nil.
static exprt tagged_isinstance_operand (const exprt &obj, const std::string &type_name, const type_handler &types)
 The tagged object whose type_id answers isinstance(obj, type_name): obj itself when it is a tagged scalar, the list item a scalar element read comes from when type_name is a scalar type, else nil.
static std::string isinstance_type_name (const nlohmann::json &node)
static bool is_plain_receiver (const nlohmann::json &node)
static bool is_plain_identifier (const std::string &name)
 A plain identifier with no __: dunder attributes come from object, and a private __x is stored unmangled, so neither matches the class struct.
static bool binds_name (const nlohmann::json &node, const std::string &name)
 Whether node, a single AST node, could bind name: an attribute or name store, any named binder (def, class, import alias, except or match capture), or a generic hook (setattr, dict) that binds any attribute.
static bool may_bind (const nlohmann::json &node, const std::string &name)
static bool may_delete (const nlohmann::json &node, const std::string &attr)
static const nlohmann::json * find_user_class (const std::string &name, const nlohmann::json &ast)
static const nlohmann::json * user_class_of (const typet &type, const nlohmann::json &ast)
 The program's ClassDef for type when it and every base are defined in the program; null otherwise.
static bool is_self_attribute (const nlohmann::json &target, const std::string &self, const std::string &attr)
static bool is_super_init_call (const nlohmann::json &stmt)
static bool assigns_self_attribute (const nlohmann::json &stmt, const std::string &self, const std::string &attr)
static bool init_binds (const nlohmann::json &cls, const std::string &attr, const nlohmann::json &ast)
 Whether every constructed instance of cls has attr: its init (or the one it inherits or delegates to through super().__init__()) assigns self.attr in straight-line code before any return.
static bool base_init_binds (const nlohmann::json &cls, const std::string &attr, const nlohmann::json &ast)
static bool has_subclass (const std::string &name, const nlohmann::json &ast)
static bool imports_other_modules (const nlohmann::json &ast)
 An imported module can subclass a class or bind attributes that the scan of this module does not see; typing and future bind neither.
static bool attribute_decided (const typet &type, const std::string &attr, const nlohmann::json &ast, bool &present)
 Whether attr is decided for every instance whose static type is type: sets present to whether it exists.
static bool runs_call (const nlohmann::json &node, const nlohmann::json &call)
 Whether node holds call where it runs as node runs, not in a nested function, class or generator that may run later.
static bool set_before_call (const nlohmann::json &body, const std::string &name, const std::string &attr, const nlohmann::json &call)
 Whether body binds name and then sets name.
static bool may_intercept (const nlohmann::json &node, const std::string &attr)
 Whether user code can intercept setting, reading or removing attr: a property or method of that name, a descriptor, or an attribute hook.
static bool receiver_given_attribute (const nlohmann::json &receiver, const typet &type, const std::string &attr, const nlohmann::json &call, const python_converter &converter)
 Whether the plain name receiver, an instance of a program class, was given attr in the scope running call before the call (#8508).
static bool body_constructs (const nlohmann::json &body, const std::string &name, const std::string &cls)
static bool is_method_self (const nlohmann::json &ast, const std::vector< std::string > &function, const std::string &name, const std::string &cls)
static bool reads_class_as_value (const nlohmann::json &node, const std::string &cls)
static bool yields_class_object (const nlohmann::json &node)
static bool class_object_escapes (const nlohmann::json &node, bool used=false)
static bool is_exact_self (const nlohmann::json &ast, const std::vector< std::string > &function, const std::string &name, const std::string &cls)
static std::string class_key (const nlohmann::json &node, const nlohmann::json &ast)
 The class a classinfo node names: a collections.abc class as "collections.abc.<name>", any other Name as its id, and otherwise empty.
static const std::vector< std::string > * abc_supers (const std::string &key)
 The collections.abc classes each builtin class and each such ABC is a subclass of, as CPython 3.14 reports them.
static const std::vector< std::string > * abc_hook_methods (const std::string &key)
 The methods by whose presence a structural collections.abc class (one with a subclasshook) admits a class that does not inherit it.
static bool defines_method (const nlohmann::json &cls, const std::string &name)
static std::vector< std::string > class_ancestors (const std::string &cls, const nlohmann::json &ast)
 cls and the classes it inherits, explicitly or implicitly, nearest first.
static bool is_hashable (const std::vector< std::string > &ancestors, const nlohmann::json &ast)
 Whether instances of a class are hashable: the nearest class to define hash or eq decides, as defining eq alone sets hash to None.
static bool is_subclass (const std::vector< std::string > &ancestors, const std::string &target, const nlohmann::json &ast)
 Whether a class with ancestors is a subclass of target: by inheritance, by a builtin's registration with a collections.abc class, or by defining the methods a structural collections.abc class looks for.
static bool is_std_stream (const nlohmann::json &target)

Variables

static const std::string abc_prefix = "collections.abc."

Function Documentation

◆ abc_hook_methods()

const std::vector< std::string > * abc_hook_methods ( const std::string & key)
static

The methods by whose presence a structural collections.abc class (one with a subclasshook) admits a class that does not inherit it.

◆ abc_supers()

const std::vector< std::string > * abc_supers ( const std::string & key)
static

The collections.abc classes each builtin class and each such ABC is a subclass of, as CPython 3.14 reports them.

Hashable here says whether the class itself is hashable, not whether Hashable is among its bases.

◆ admits_class_object()

bool admits_class_object ( const std::vector< nlohmann::json > & types)
static

◆ assigns_self_attribute()

bool assigns_self_attribute ( const nlohmann::json & stmt,
const std::string & self,
const std::string & attr )
static

◆ attribute_decided()

bool attribute_decided ( const typet & type,
const std::string & attr,
const nlohmann::json & ast,
bool & present )
static

Whether attr is decided for every instance whose static type is type: sets present to whether it exists.

Undecided when a path, a subclass, a del or another module can change it.

◆ base_init_binds()

bool base_init_binds ( const nlohmann::json & cls,
const std::string & attr,
const nlohmann::json & ast )
static

◆ binds_name()

bool binds_name ( const nlohmann::json & node,
const std::string & name )
static

Whether node, a single AST node, could bind name: an attribute or name store, any named binder (def, class, import alias, except or match capture), or a generic hook (setattr, dict) that binds any attribute.

◆ body_constructs()

bool body_constructs ( const nlohmann::json & body,
const std::string & name,
const std::string & cls )
static

◆ class_ancestors()

std::vector< std::string > class_ancestors ( const std::string & cls,
const nlohmann::json & ast )
static

cls and the classes it inherits, explicitly or implicitly, nearest first.

For single inheritance this is the method resolution order.

◆ class_key()

std::string class_key ( const nlohmann::json & node,
const nlohmann::json & ast )
static

The class a classinfo node names: a collections.abc class as "collections.abc.<name>", any other Name as its id, and otherwise empty.

◆ class_object_escapes()

bool class_object_escapes ( const nlohmann::json & node,
bool used = false )
static

◆ collect_classinfo()

void collect_classinfo ( const nlohmann::json & node,
std::vector< nlohmann::json > & out )
static

◆ defines_method()

bool defines_method ( const nlohmann::json & cls,
const std::string & name )
static

◆ evaluate_after()

exprt evaluate_after ( const exprt & binding,
const exprt & result )
static

result evaluated after binding, or result alone if it is nil.

◆ find_user_class()

const nlohmann::json * find_user_class ( const std::string & name,
const nlohmann::json & ast )
static

◆ has_subclass()

bool has_subclass ( const std::string & name,
const nlohmann::json & ast )
static

◆ imports_other_modules()

bool imports_other_modules ( const nlohmann::json & ast)
static

An imported module can subclass a class or bind attributes that the scan of this module does not see; typing and future bind neither.

◆ init_binds()

bool init_binds ( const nlohmann::json & cls,
const std::string & attr,
const nlohmann::json & ast )
static

Whether every constructed instance of cls has attr: its init (or the one it inherits or delegates to through super().__init__()) assigns self.attr in straight-line code before any return.

◆ is_exact_self()

bool is_exact_self ( const nlohmann::json & ast,
const std::vector< std::string > & function,
const std::string & name,
const std::string & cls )
static

◆ is_hashable()

bool is_hashable ( const std::vector< std::string > & ancestors,
const nlohmann::json & ast )
static

Whether instances of a class are hashable: the nearest class to define hash or eq decides, as defining eq alone sets hash to None.

◆ is_method_self()

bool is_method_self ( const nlohmann::json & ast,
const std::vector< std::string > & function,
const std::string & name,
const std::string & cls )
static

◆ is_plain_identifier()

bool is_plain_identifier ( const std::string & name)
static

A plain identifier with no __: dunder attributes come from object, and a private __x is stored unmangled, so neither matches the class struct.

◆ is_plain_receiver()

bool is_plain_receiver ( const nlohmann::json & node)
static

◆ is_self_attribute()

bool is_self_attribute ( const nlohmann::json & target,
const std::string & self,
const std::string & attr )
static

◆ is_std_stream()

bool is_std_stream ( const nlohmann::json & target)
static

◆ is_subclass()

bool is_subclass ( const std::vector< std::string > & ancestors,
const std::string & target,
const nlohmann::json & ast )
static

Whether a class with ancestors is a subclass of target: by inheritance, by a builtin's registration with a collections.abc class, or by defining the methods a structural collections.abc class looks for.

◆ is_super_init_call()

bool is_super_init_call ( const nlohmann::json & stmt)
static

◆ isinstance_type_name()

std::string isinstance_type_name ( const nlohmann::json & node)
static

◆ list_item_of_scalar_read()

exprt list_item_of_scalar_read ( const exprt & read,
const typet & item_type )
static

The list item a read *(T *)item->value of a scalar element comes from, or nil.

The cast is the frontend's guess at the element's type; the item's type_id records the type it was stored with.

◆ may_bind()

bool may_bind ( const nlohmann::json & node,
const std::string & name )
static

◆ may_delete()

bool may_delete ( const nlohmann::json & node,
const std::string & attr )
static

◆ may_intercept()

bool may_intercept ( const nlohmann::json & node,
const std::string & attr )
static

Whether user code can intercept setting, reading or removing attr: a property or method of that name, a descriptor, or an attribute hook.

◆ reads_class_as_value()

bool reads_class_as_value ( const nlohmann::json & node,
const std::string & cls )
static

◆ receiver_given_attribute()

bool receiver_given_attribute ( const nlohmann::json & receiver,
const typet & type,
const std::string & attr,
const nlohmann::json & call,
const python_converter & converter )
static

Whether the plain name receiver, an instance of a program class, was given attr in the scope running call before the call (#8508).

◆ runs_call()

bool runs_call ( const nlohmann::json & node,
const nlohmann::json & call )
static

Whether node holds call where it runs as node runs, not in a nested function, class or generator that may run later.

◆ set_before_call()

bool set_before_call ( const nlohmann::json & body,
const std::string & name,
const std::string & attr,
const nlohmann::json & call )
static

Whether body binds name and then sets name.

attr, each in a statement of its own, before the statement that runs call. With name bound nowhere else, the call reads the object that was given attr.

◆ tagged_isinstance_operand()

exprt tagged_isinstance_operand ( const exprt & obj,
const std::string & type_name,
const type_handler & types )
static

The tagged object whose type_id answers isinstance(obj, type_name): obj itself when it is a tagged scalar, the list item a scalar element read comes from when type_name is a scalar type, else nil.

◆ user_class_of()

const nlohmann::json * user_class_of ( const typet & type,
const nlohmann::json & ast )
static

The program's ClassDef for type when it and every base are defined in the program; null otherwise.

A builtin type or base has attributes the program never binds.

◆ yields_class_object()

bool yields_class_object ( const nlohmann::json & node)
static

Variable Documentation

◆ abc_prefix

const std::string abc_prefix = "collections.abc."
static