A pure-python (Python>=3.10) static analysis library providing various interfaces.
Project description
SkyStaticAnalysis
A pure-python (Python>=3.10) static analysis library providing various interfaces.
Interfaces
Clang
Clang interface included some useful functionalities. For example:
The Demo C file "hello.c":
typedef struct
{
int abc;
} StructA;
int a = 32;
int b = 444;
int c = 123;
int *p = 0;
StructA st = {0};
StructA *pst = {0};
extern int extvar = 0;
int f(int);
int use_global(int y, float z)
{
int x;
int c = *p + y;
a = 1045;
f(b);
}
int use_global_2(int y, float z)
{
int x[1900];
int q = a;
x[q];
x[a];
if (y > 100)
{
f(x[y]);
}
else
{
f(x[(int)z]);
}
}
int main()
{
StructA not_global = {0};
return 0;
}
This Python script could parse variable definitions、function parameter declarations and variable references:
c_file = os.path.join("")
root = parse_file(c_file).cursor
# extract local variables
assert {"c", "x"} == get_local_var_defs(func_decl).attributes("spelling").to_set()
# extract referenced variables
assert {"p", "y", "a", "b"} == get_var_refs(func_decl).attributes(
"spelling"
).to_set()
# extract referenced variables with functions
assert {"p", "y", "a", "b", "f"} == get_var_refs(
func_decl, include_funcs=True
).attributes("spelling").to_set()
# extract parameter variables
assert {"y", "z"} == get_param_decls(func_decl).attributes("spelling").to_set()
# extract all global values
assert {"a", "p", "b"} == get_global_ref_names(func_decl).to_set()
In-Repo Third Party Dependencies
JsonObject
As original project used Cython, it might not be compatible with platform without compilation toolchains. So I copied the source code into this project and made it runnable under pure-python.
PyC-CFG
Pyc-cfg is a pure python control flow graph builder for almost all Ansi C programming language.
As the original version only suitable for Python2, I copied its code and made it compatible for python 3.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SkyStaticAnalysis-0.0.4-py3-none-any.whl.
File metadata
- Download URL: SkyStaticAnalysis-0.0.4-py3-none-any.whl
- Upload date:
- Size: 52.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91e6cc1016f855c882db896596b9a4afd152c3237d4ba8f9ca0d610f7b6f89d9
|
|
| MD5 |
90bcff085e9bc489a0baefc71fa0e4e0
|
|
| BLAKE2b-256 |
2850f37cdef494e215acb5112002630b51efb3496f883fa7945d74516cab6800
|