Main Content

polyspace.project.CodeInfo Class

Namespace: polyspace.project

(Python) Store information about types, functions, and globals in parsed source code

Since R2025a

Description

This Python® class contains information about data types, functions, and global variables in your source code. When authoring tests using the Polyspace® Test™ Python API, create an object of this class. Then use the information stored in this object to create test data, parameters, and steps.

Creation

Description

codeInfo = polyspace.project.parseCode(proj) parses the source code in the project proj and stores information about data types, functions, and global variables in the polyspace.project.CodeInfo object codeInfo. For extensions of this syntax, see polyspace.project.parseCode.

If an error occurs during code parsing, the function throws an exception of type polyspace.ErrorWithLog. (since R2026a)

example

Input Arguments

expand all

Polyspace Platform project, specified as a polyspace.project.Project object.

Properties

expand all

Since R2026a

Parse log information, returned as a polyspace.ExecutionLog object.

This polyspace.ExecutionLog object has the following property:

PropertyDescription
Content

Parse log content, specified as a single string.

To display the parse log string from a polyspace.project.CodeInfo object codeInfo in a human readable format, enter:

print(codeInfo.ParseLog.Content)

To save the run log content to a file, use the save() method. For instance, to save the error string from a polyspace.project.CodeInfo object codeInfo to a file logs.txt, enter:

codeInfo.ParseLog.save("logs.txt")

Note

This property contains the logs from a successful code parsing. If an error occurs during code parsing, the polyspace.project.parseCode() function throws an exception of type polyspace.ErrorWithLog. Catch this exception in an except block to see the error log content. For more information, see polyspace.ErrorWithLog.

Functions in the source code, specified as a list of polyspace.project.Function objects. Each object in this list has the following properties.

PropertyValueDescription
Namestr value

Name of the function. For example, "saturate_value".

Signaturestr value

Signature of the function. For example, "int saturate_value(int)".

StubbingSupportTrue or FalseWhether the function is undefined and requires a stub.
IsStubTrue or False

Whether the function has a stub in an external stub file.

This property is set to True only if a function stub is sourced from an external C/C++ file. It is set to False if the function is stubbed with a project-specific polyspace.project.FunctionStub object.

MockingSupportTrue or FalseWhether the function is supported for mocking.
TestingSupportTrue or FalseWhether the function is supported for testing.

Global variables in the source code, specified as a list of polyspace.project.Global objects. Each object in the list contains the following properties.

PropertyValueDescription
Namestr value

Name of the global variable.

StubbingSupportTrue or False

Whether the variable is undefined and requires a stub.

IsStubTrue or False

Whether the variable has a stub in an external stub file.

This property is set to True only if a variable stub is sourced from an external C/C++ file. It is set to False if the variable is stubbed with a project-specific polyspace.project.VariableStub object.

Data types in the source code, specified as a list of polyspace.project.Type objects. Each object in the list contains the following properties.

PropertyValueDescription
Namestr value

Name of the data type.

Examples

collapse all

Import the required modules, create a project, and add the source files.

## Import modules
import polyspace.project
import os

## Create project
examples_path = os.path.join(polyspace.__install_path__, "polyspace", 
                            "examples", "doc_pstest", "getting_started_test_manager")

proj = polyspace.project.Project("parseProject.psprjx")

## Add source files and include path
proj.Code.Files.add(os.path.join(examples_path, "algo.c"))
proj.Code.Files.add(os.path.join(examples_path, "saturate.c"))
proj.IncludePaths.add(os.path.join(examples_path))

Parse the code to get information about the source code in the project proj.

codeInfo = polyspace.project.parseCode(proj)

Identify undefined functions in the project. Use the StubbingSupport property of each polyspace.project.Function object to create a list of functions that require a stub.

undefinedFuncList = [f for f in codeInfo.Functions if f.StubbingSupport]

Identify undefined variables in the project. Use the StubbingSupport property of each polyspace.project.Global object to create a list of variables that require a stub.

undefinedVarList = [v for v in codeInfo.Globals if v.StubbingSupport]

Once you identify the undefined functions and variables, you can create stubs for them in one of these ways:

Methods

expand all

Version History

Introduced in R2025a

expand all