メインコンテンツ

polyspace.project.Type Class

R2026b

Namespace: polyspace.project

(Python) Store information about a C/C++ type in parsed source code

Since R2025a

Description

This Python® class represents a C/C++ type from your parsed source code. Use polyspace.project.Type objects when creating a test variable using its type. You typically create test variables using types when creating test parameters, test data or observables in scripted tests.

You obtain polyspace.project.Type objects from the Types property of a polyspace.project.CodeInfo object, or by using the getType method.

Creation

Description

typeList = codeInfo.Types returns a list of polyspace.project.Type objects for all the types in the parsed source code. Here, codeInfo is a polyspace.project.CodeInfo object.

example

typeObj = codeInfo.getType(typeName) returns the polyspace.project.Type object for the specified type typeName.

Input Arguments

expand all

C/C++ type name, specified as a string.

Example: "int"

Example: "struct MyStruct"

Properties

expand all

Name of the C/C++ type, returned as a string.

Example: "int"

Example: "struct MyStruct"

Examples

collapse all

Parse source code and list all available types.

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("listTypes.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.

codeInfo = polyspace.project.parseCode(proj)

Iterate over the types and print their names.

for t in codeInfo.Types:
    print(f"Type: {t.Name}")

You see an output like the following:

Type: char32_t
Type: char16_t
Type: __uint128_t
Type: __int128_t
...

Version History

Introduced in R2025a