ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
annotation_utils.h
Go to the documentation of this file.
1#pragma once
2
3#include <nlohmann/json.hpp>
4
5#include <string>
6
7// Pure, state-free helpers extracted from python_annotation.h. Each
8// function below is a verbatim move of a previously class-local or
9// namespace-scope helper; no semantic change is intended. The helpers
10// take `const nlohmann::json &` directly — the original code used a
11// `Json` template parameter that was only ever instantiated with
12// `nlohmann::json`.
14{
15// Outcome of type inference. Used by callers of the type-inference
16// dispatcher to distinguish a successfully resolved type from an
17// unknown one.
18enum class InferResult
19{
22};
23
24// Concrete builtin Python type names produced by inspecting a JSON
25// `Constant.value` node. Returns "null", "bool", "int", "float",
26// "str", "array", "object" or "unknown" — the exact strings the
27// previous implementation produced. Callers depend on these spellings.
28std::string get_type_from_json(const nlohmann::json &value);
29
30// Returns true when `node` carries a non-null `annotation` field.
31// `node.empty()` is also accepted as input and yields false.
32bool has_annotation(const nlohmann::json &node);
33
34// True when `body` contains any explicit `return` / `return None` —
35// either at the top level or inside nested `body`/`orelse` blocks.
36bool has_return_none(const nlohmann::json &body);
37
38// Recursively reconstructs a dotted base name for an attribute /
39// subscript chain rooted at a Name node (e.g. `obj.attr[0]`).
40// Returns the empty string on unrecognised shapes.
41std::string get_base_var_name(const nlohmann::json &node);
42
43// Splits `input` on '.', reverses the resulting tokens and rejoins
44// them with '.'. Pure string utility; behaviour must match the
45// original `invert_substrings` byte-for-byte for the values the
46// annotation pass feeds it.
47std::string invert_substrings(const std::string &input);
48
49// Inspects the *second* element of a function-default-arg list and
50// returns a guess of the runtime container/scalar type ("list",
51// "dict", "set", "tuple", "int", "float", "str", "bool", "None")
52// or "Any" if the shape is unrecognised. Returns an empty string
53// when `args_node` is not an array of at least two entries.
54std::string infer_type_from_default_arg_shape(const nlohmann::json &args_node);
55
56} // namespace python_annotation_utils
Definition toml.hpp:1531
Definition annotation_utils.cpp:8
std::string get_base_var_name(const nlohmann::json &node)
Definition annotation_utils.cpp:63
bool has_return_none(const nlohmann::json &body)
Definition annotation_utils.cpp:36
std::string get_type_from_json(const nlohmann::json &value)
Definition annotation_utils.cpp:9
std::string invert_substrings(const std::string &input)
Definition annotation_utils.cpp:78
bool has_annotation(const nlohmann::json &node)
Definition annotation_utils.cpp:30
std::string infer_type_from_default_arg_shape(const nlohmann::json &args_node)
Definition annotation_utils.cpp:103
InferResult
Definition annotation_utils.h:19
@ UNKNOWN
Definition annotation_utils.h:21
@ OK
Definition annotation_utils.h:20