ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
converter_symbols.cpp File Reference
#include <python-frontend/json_utils.h>
#include <python-frontend/python_converter.h>
#include <filesystem>
#include <python-frontend/symbol_id.h>
#include <util/arith/arith_tools.h>
#include <util/message/message.h>
#include <algorithm>
#include <functional>
#include <optional>
#include <regex>
#include <set>
#include <utility>
Include dependency graph for converter_symbols.cpp:

Typedefs

using scope_bindings = python_converter::scope_bindings

Functions

static std::pair< std::string, std::string > from_import_binding (const nlohmann::json &ast, const std::string &bound)
 Module file and the name that module defines, for the top-level from <module> import <bound> binding bound; an empty path when none does.
static std::string base_class_name (const nlohmann::json &base_class_node)
 Class name a bases entry denotes.
static bool alias_binds_name (const nlohmann::json &alias, const std::string &name)
 Whether import alias alias binds name: import a.b binds a, and from m import * may bind any name.
static bool binds_by_name (const nlohmann::json &node, const std::string &type, const std::string &name, bool any_scope)
 Whether node of type type names name as what it binds: an import alias, a parameter, or a def or class statement.
static bool may_bind_name (const nlohmann::json &node, const std::string &name, bool any_scope)
 Whether node, a statement or part of one, may bind name.
static bool may_bind_within (const nlohmann::json &node, const std::string &type, const std::string &name, bool any_scope)
 Whether anything node of type type holds may bind name, reading a node that binds by itself rather than through a child.
static bool names_contain (const nlohmann::json &names, const std::string &name)
static bool record_declaration (const nlohmann::json &node, const std::string &type, const std::string &name, scope_bindings &found)
 Records an import of name, or a declaration handing it to an outer scope.
static void collect_scope_bindings (const nlohmann::json &node, const std::string &name, scope_bindings &found)
 Records how node binds name in its own scope.
static bool declares_global (const nlohmann::json &node, const std::string &name)
static std::runtime_error undecided_module_binding (const std::string &name, const nlohmann::json &use)
static std::pair< int, int > source_position (const nlohmann::json &node, bool end)
static bool deferred_at (const nlohmann::json &node, std::pair< int, int > at)
 Whether the code at at, under node, runs only when something defined there is called or iterated, which need not follow the statements before it.
static bool module_level_binding_is_import (const nlohmann::json &body, const std::string &name, const nlohmann::json &use)
 At module level, with every binding of name a plain top-level statement and use run in order, the last binding to complete before use is the one it reads.
static std::optional< bool > function_binding_is_import (const nlohmann::json &function, const std::string &name, const nlohmann::json &use)
 How function binds name: by an import alone (true), as a parameter or another local (false), or not at all (empty).
static void collect_class_nodes (const nlohmann::json &node, std::vector< const nlohmann::json * > &classes)
static bool names_attribute_hook (const nlohmann::json &node)
 Whether node names a hook (setattr, dict, ...) that can reach any attribute.
static bool may_store (const nlohmann::json &node)
 Whether node is not known to be only read.
static const nlohmann::json * attribute_store_target (const nlohmann::json &node, const std::string &type)
 The attribute an assignment statement stores a value into, or null.
static std::string import_lookup_name (const std::string &id, const ::symbol_id &parsed)
 The name id asks for, as an import would spell it.
static std::optional< std::string > imported_module_name (const nlohmann::json &obj, const std::string &lookup_name)

Typedef Documentation

◆ scope_bindings

Function Documentation

◆ alias_binds_name()

bool alias_binds_name ( const nlohmann::json & alias,
const std::string & name )
static

Whether import alias alias binds name: import a.b binds a, and from m import * may bind any name.

◆ attribute_store_target()

const nlohmann::json * attribute_store_target ( const nlohmann::json & node,
const std::string & type )
static

The attribute an assignment statement stores a value into, or null.

◆ base_class_name()

std::string base_class_name ( const nlohmann::json & base_class_node)
static

Class name a bases entry denotes.

A qualified base (module.Class) parses as an Attribute carrying attr instead of id – reading id unconditionally aborted on any model-provided base such as unittest.TestCase (#6745). The symbol id uses the bare name either way.

◆ binds_by_name()

bool binds_by_name ( const nlohmann::json & node,
const std::string & type,
const std::string & name,
bool any_scope )
static

Whether node of type type names name as what it binds: an import alias, a parameter, or a def or class statement.

◆ collect_class_nodes()

void collect_class_nodes ( const nlohmann::json & node,
std::vector< const nlohmann::json * > & classes )
static

◆ collect_scope_bindings()

void collect_scope_bindings ( const nlohmann::json & node,
const std::string & name,
scope_bindings & found )
static

Records how node binds name in its own scope.

Function, class, lambda and comprehension bodies are scopes of their own and are not entered.

◆ declares_global()

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

◆ deferred_at()

bool deferred_at ( const nlohmann::json & node,
std::pair< int, int > at )
static

Whether the code at at, under node, runs only when something defined there is called or iterated, which need not follow the statements before it.

◆ from_import_binding()

std::pair< std::string, std::string > from_import_binding ( const nlohmann::json & ast,
const std::string & bound )
static

Module file and the name that module defines, for the top-level from <module> import <bound> binding bound; an empty path when none does.

A bare from m import B leaves only the class name at the use site, so the module cannot be read off the base expression the way m.B spells it (#6745). Python binds the last import of a name, so later statements win, and an as alias hides the name the module really defines.

◆ function_binding_is_import()

std::optional< bool > function_binding_is_import ( const nlohmann::json & function,
const std::string & name,
const nlohmann::json & use )
static

How function binds name: by an import alone (true), as a parameter or another local (false), or not at all (empty).

◆ import_lookup_name()

std::string import_lookup_name ( const std::string & id,
const ::symbol_id & parsed )
static

The name id asks for, as an import would spell it.

from_string parses the @C@/@F@ markers but not the trailing segment; when an id carries one, that segment is the name and the class/function are only its scope. Reading the function instead made every name used inside def acos() resolve to math.acos from an unrelated import math (#6895).

◆ imported_module_name()

std::optional< std::string > imported_module_name ( const nlohmann::json & obj,
const std::string & lookup_name )
static

◆ may_bind_name()

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

Whether node, a statement or part of one, may bind name.

Bindings in nested function and class bodies count only with any_scope, which a call site needs: it sees the scope it stands in as well as the module's.

◆ may_bind_within()

bool may_bind_within ( const nlohmann::json & node,
const std::string & type,
const std::string & name,
bool any_scope )
static

Whether anything node of type type holds may bind name, reading a node that binds by itself rather than through a child.

◆ may_store()

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

Whether node is not known to be only read.

◆ module_level_binding_is_import()

bool module_level_binding_is_import ( const nlohmann::json & body,
const std::string & name,
const nlohmann::json & use )
static

At module level, with every binding of name a plain top-level statement and use run in order, the last binding to complete before use is the one it reads.

Whether that is an import; throws otherwise.

◆ names_attribute_hook()

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

Whether node names a hook (setattr, dict, ...) that can reach any attribute.

◆ names_contain()

bool names_contain ( const nlohmann::json & names,
const std::string & name )
static

◆ record_declaration()

bool record_declaration ( const nlohmann::json & node,
const std::string & type,
const std::string & name,
scope_bindings & found )
static

Records an import of name, or a declaration handing it to an outer scope.

Whether node is such a statement.

◆ source_position()

std::pair< int, int > source_position ( const nlohmann::json & node,
bool end )
static

◆ undecided_module_binding()

std::runtime_error undecided_module_binding ( const std::string & name,
const nlohmann::json & use )
static