srcSlice is a fast, lightweight srcML tool for static slicing. srcSlice reads srcML output files and produces variable slices in JSON, these slices contain details such as where a variable is used and defined, passed into a function as an argument, function of origin, class it is contained in, variables that are data-dependent of it, and potential aliases.
# Install srcML Develop if not installed on your local machine, after running 'make' when building srcML run 'make install' to ensure cmake can find the srcML package when building srcSlice git clone --recursive -b develop https://github.com/srcML/srcML.git# Clone srcSlice repository git clone --recursive https://github.com/srcML/srcSlice.git # (This guide assumes the cloned directory and build directory are at the same working directory) mkdir build cd build # Run cmake to create the build files and run make to build the executable cmake ../srcSlice # You can run make but it will take longer make srcsliceInput: A srcML file of source code with --position and --hash options. srcML file can be a single unit (one source code file) or an archive (multiple source code files).
srcml shell_sort.cpp -o shell_sort.cpp.xml --position --hash Output: A JSON file containing the slice information about each variable contained in the input file.
./srcslice -i shell_sort.cpp.xml -o results.json Display the srcslice help page
./srcslice --help Output debugging info to stdout
./srcslice -i shell_sort.cpp.xml --verbose Set the input srcML output file to read in
./srcslice -i shell_sort.cpp.xml Write the output to file. By default, it writes to standard output
./srcslice -i shell_sort.cpp.xml -o results.json Generate slices and write output to standard output
./srcslice -i shell_sort.cpp.xml Generate slices and write output to slices.json
./srcslice -i shell_sort.cpp.xml -o slices.json | Attribute | Description |
|---|---|
File | File path of the source code the slice variable originates from |
Language | Language of the source code file |
Namespace | List of namespaces the slice variable is contained in |
Class | Name of the class containing the slice variable |
Function | Name of the function containing the slice variable |
Type | Data type of the slice variable |
Name | Variable name of the slice variable |
Dependence | A list of variable-position pairs, containing:
|
Aliases | A list of potential targets of a pointer or reference |
Calls | A list of function calls where the slice variable is used as an argument. This includes:
|
Use | A set of positions where the slice variable is used |
Definition | A set of positions where the slice variable is defined or redefined |