chc.cmdline.ParseManager module

class chc.cmdline.ParseManager.ParseManager(projectpath: str, projectname: str, targetpath: str, filter: bool = False, posix: bool = False, verbose: bool = True, keepUnused: bool = False, tgtplatform: str = '-m64')[source]

Bases: object

Utility functions to support preprocessing and parsing source code.

Naming conventions:

  • cfilename base name of cfile analyzed (without extension)

  • cfilename_c idem, with .c extension

  • projectpath full-path in which cfilename_c resides (in case of a

    single file analyzed) or in which the Makefile of the project resides (in case of a multi-file project)

  • targetpath full-path of directory in which results are saved

  • projectname name under which results are saved

Auxiliary names:

  • cchpath full-path of analysis results (targetpath/projectname.cch)

  • cchname base name of cchpath (projectname.cch)

  • cchtarname projectname.cch.tar

  • cchtargzname projectname.cch.tar.gz

  • cchtarfile targetpath/projectname.cch.tar

  • cchtargzfile targetpath/projectname.cch.tar.gz

property analysisresultspath: str
property cchname: str
property cchpath: str
property cchtarfile: str
property cchtargzfile: str
property cchtargzname: str
property cchtarname: str
property filter: bool
get_file_length(fname: str) int[source]

Return the number of lines in named file.

get_platform_index(cmd: List[str]) int[source]
has_platform(cmd: List[str]) bool[source]
initialize_paths() None[source]

Create directories for the target path.

property keepUnused: bool

If true keep variables parsed that are never used.

normalize_filename(filename: str) str[source]

Make filename relative to project directory (if in project directory).

parse_cfiles(copyfiles: bool = True) None[source]

Preprocess (with gcc) and run the CodeHawk C parser on all .c files in the directory.

parse_ifile(ifilename: str) int[source]

Invoke the CodeHawk C parser frontend on preprocessed source file

Parameters

ifilename – preprocessed source code filename relative to cpath

Effects:

invokes the parser frontend to produce an xml representation of the semantics of the file

parse_ifiles(copyfiles: bool = True) None[source]

Run the CodeHawk C parser on all .i files in the directory.

parse_with_ccommands(compilecommands: List[Dict[str, Any]], copyfiles: bool = True) None[source]

Preprocess and call C parser to produce xml semantics files.

property posix: bool
preprocess(ccommand: Dict[str, Any], copyfiles: bool = True) Tuple[Optional[str], Optional[str]][source]

Modify and replay compile_commands.json file produced by bear.

preprocess_file_with_gcc(cfilename: str, copyfiles: bool = True, moreoptions: List[str] = []) str[source]

Invoke gcc preprocessor on c source file.

Parameters
  • cfilename – c source code filename relative to cpath

  • moreoptions – list of additional options to be given to the preprocessor

Effects:

invokes the gcc preprocessor on the c source file and optionally copies the original source file and the generated .i file to the tgtpath/sourcefiles directory

property projectname: str
property projectpath: str
remove_semantics() None[source]
save_semantics() None[source]

Save the semantics directory as a tar.gz file.

property savedsourcepath: str
set_platform(cmd: List[str]) None[source]
property targetpath: str
property tgtplatform: str
property verbose: bool
class chc.cmdline.ParseManager.TargetFiles[source]

Bases: object

add_file(fname: str) None[source]
save_xml_file(tgtpath: str) None[source]