ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
python_annotation< Json > Class Template Reference

#include <python_annotation.h>

Public Member Functions

 python_annotation (Json &ast, global_scope &gs)
bool preprocess_constructor_calls (Json &node)
void preprocess_method_calls (const Json &node)
void preprocess_receiver_method_calls ()
 Types the unannotated parameters of a method from its obj.m(args) calls at module level, where obj is a name bound once to an instance of a module class, when every such call passes one type (#8923).
bool is_instance_call (const Json &func) const
 Whether func names neither a module class nor a module function, so a call through it can only reach an instance's __call__.
Json * class_method (const std::string &cls, const Json &method)
 The FunctionDef of method in module-level class cls, or null.
bool preprocess_function_calls (Json &root)
 Infer unannotated parameter types of top-level functions from the argument types at every plain f(arg1, arg2) call site (i.e.
std::string promote_to_float_operand (const Json &stmt, const std::string &type)
 True division of an int or bool yields a float, and so does other arithmetic with a float operand, but the type above is read from the left operand alone (n / 2 or n * 0.5 with an int n).
bool annotate_from_call_sites (Json &root, Json &param, const std::pair< std::string, size_t > &key, std::set< std::string > types, const std::set< std::string > &top_level_funcs)
 Annotates param when its call sites agree on one type.
void collect_function_call_arg_types (Json &node, std::map< std::pair< std::string, size_t >, std::set< std::string > > &param_types, const std::set< std::string > &top_level_funcs, std::set< std::pair< std::string, size_t > > &dynamically_typed_params)
void add_type_annotation ()
void add_type_annotation (const std::string &func_name)
void add_extra_subscript_inference_source (const Json &ast)

Static Public Member Functions

static const std::string & unresolved_arg_type ()
 Sentinel recorded for a call-site argument this pass cannot type; never a valid Python type name, so it can only block, never be annotated.

Constructor & Destructor Documentation

◆ python_annotation()

template<class Json>
python_annotation< Json >::python_annotation ( Json & ast,
global_scope & gs )
inline

Member Function Documentation

◆ add_extra_subscript_inference_source()

template<class Json>
void python_annotation< Json >::add_extra_subscript_inference_source ( const Json & ast)

◆ add_type_annotation() [1/2]

template<class Json>
void python_annotation< Json >::add_type_annotation ( )

◆ add_type_annotation() [2/2]

template<class Json>
void python_annotation< Json >::add_type_annotation ( const std::string & func_name)

◆ annotate_from_call_sites()

template<class Json>
bool python_annotation< Json >::annotate_from_call_sites ( Json & root,
Json & param,
const std::pair< std::string, size_t > & key,
std::set< std::string > types,
const std::set< std::string > & top_level_funcs )

Annotates param when its call sites agree on one type.

A site whose argument is unresolved may depend on the function itself, as an element of a list built from its own results does. Such a parameter is annotated with the one type the other sites agree on only if, under that annotation, every site resolves to it.

◆ class_method()

template<class Json>
Json * python_annotation< Json >::class_method ( const std::string & cls,
const Json & method )

The FunctionDef of method in module-level class cls, or null.

◆ collect_function_call_arg_types()

template<class Json>
void python_annotation< Json >::collect_function_call_arg_types ( Json & node,
std::map< std::pair< std::string, size_t >, std::set< std::string > > & param_types,
const std::set< std::string > & top_level_funcs,
std::set< std::pair< std::string, size_t > > & dynamically_typed_params )

◆ is_instance_call()

template<class Json>
bool python_annotation< Json >::is_instance_call ( const Json & func) const

Whether func names neither a module class nor a module function, so a call through it can only reach an instance's __call__.

◆ preprocess_constructor_calls()

template<class Json>
bool python_annotation< Json >::preprocess_constructor_calls ( Json & node)

◆ preprocess_function_calls()

template<class Json>
bool python_annotation< Json >::preprocess_function_calls ( Json & root)

Infer unannotated parameter types of top-level functions from the argument types at every plain f(arg1, arg2) call site (i.e.

Returns
true if this pass wrote at least one parameter annotation.

Call.func._type == "Name"). Method calls on instances and class constructors are out of scope — they are handled by preprocess_method_calls and preprocess_constructor_calls.

Conflict policy: a parameter is annotated only when every call site that yields a non-empty inferred type agrees on the same type. Calls passing different concrete classes (e.g. polymorphic dispatch over a shared base) leave the parameter unannotated, preserving the pre-existing behaviour where the symex layer handles the dispatch. Explicit annotations are always preserved.

Scope tracking: when descending into a FunctionDef, the current function name context is updated so get_argument_type can resolve Name arguments by looking them up in the enclosing function's scope (parameters, local assignments). Without this, calls nested inside def main(): ... f(local_var) would fail to type-infer local_var, since find_var_decl searches by function name.

◆ preprocess_method_calls()

template<class Json>
void python_annotation< Json >::preprocess_method_calls ( const Json & node)

◆ preprocess_receiver_method_calls()

template<class Json>
void python_annotation< Json >::preprocess_receiver_method_calls ( )

Types the unannotated parameters of a method from its obj.m(args) calls at module level, where obj is a name bound once to an instance of a module class, when every such call passes one type (#8923).

Calls inside a def are skipped: this pass has no scope to resolve their receiver in.

◆ promote_to_float_operand()

template<class Json>
std::string python_annotation< Json >::promote_to_float_operand ( const Json & stmt,
const std::string & type )

True division of an int or bool yields a float, and so does other arithmetic with a float operand, but the type above is read from the left operand alone (n / 2 or n * 0.5 with an int n).

◆ unresolved_arg_type()

template<class Json>
const std::string & python_annotation< Json >::unresolved_arg_type ( )
inlinestatic

Sentinel recorded for a call-site argument this pass cannot type; never a valid Python type name, so it can only block, never be annotated.


The documentation for this class was generated from the following files: