polyspace-query-language
R2026b(System Command) Create and test user-defined coding standards and user-defined coding rules
Since R2026a
Syntax
Description
Note
This Polyspace® command is available in . Here, polyspaceroot\polyspace\bin is the Polyspace installation folder, for instance, polyspacerootC:\Program Files\Polyspace\R2026b (see also Installation Folder (Polyspace Code Prover)
for desktop products or Installation Folder (Polyspace Code Prover)
for server products). To avoid typing the full path to this command, add this
location to the PATH environment variable in your operating
system.
polyspace-query-language init initializes a user-defined coding
standard. In the current directory, it creates the necessary files to create the user
defined coding standard, including main.pql and
pql.json. The file main.pql is the entry
point for subsequent polyspace-query-language commands. Create
your coding standard and coding rules assuming the main.pql file
as the entry point. The file pql.json is a configuration object
and does not need to be modified. In addition, this command copies a folder
.polyspace in the current folder. This folder contains the
definition of supported classes and their predicates.
polyspace-query-language package creates a user-defined coding
standard (.pschk) based on the specification in the file
main.pql located in the current directory.
polyspace-query-language test
runs a Polyspace
Bug Finder™ analysis on TestOptions SourceFile AnalysisOptionsSourceFile using the user-defined coding
standard created by main.pql. The test passes if expected violations
are present in the result. The options in AnalysisOptions are passed
to the Polyspace
Bug Finder analysis.
polyspace-query-language profile
profiles the user defined coding standard and identifies the defects that bottlenecks the
analysis. This commands analyzes the Polyspace Query Language (PQL) project in the folder
ProjectDirectory AnalysisOptionsProjectDirectory. By default, Polyspace assumes the current directory is the
ProjectDirectory.
Examples
Create New User Defined Coding Standard
Open a terminal in the directory of your choice. Initialize the coding standard:
polyspace-query-language init
Open the file
main.pql. Specify your coding standard and coding rules in this file. For example, this content creates a new user defined standard that has a single rule. This rule is a mapping to the Polyspace Bug Finder defectUseless if:package main catalog QuickStart = { // Catalog section QuickStartSection = { // Section rule MappingToMisraRule = { // Rule std.defects.USELESS_IF // Mapping } } }To create the user-defined coding rule following the specification in
main.pql, at the command-line, enter:polyspace-query-language package
Test User Defined Coding Standards and Rules
Test your coding standard to verify that the violations appear as expected in the correct location. Consider this C code:
void foo()
{
int x;
if (x = 0)
{
x = 0;
}
if (x == 0)
{
}
for (x = 0; x < 5; ++x)
{
}
while (x = 0)
{
}
}if and while statements. It also contains
if statements that are always true. Prepare a
coding standard that detects these issue. For later use, copy this code in
src.cppIn a writable folder
syntaxrule, initialize a new user-defined coding standardpolyspace-query-language init
In the file
main.pql, enter this content:package main // Main PQL file defines the catalog of your PQL project. // The catalog is a collection of sections. #[Description("MyStandard")] catalog syntaxrule = { // Define and include sections in this list. #[Description("MySection")] section mysection = { #[Description("myRule"), Id(Rule1)] rule myRule = { defect mydefect = when Cpp.ConditionClause.is(&cc) and cc.parent(&parentCC) and (Cpp.IfStatement.isa(parentCC, &ifStmt) or Cpp.WhileStatement.isa(parentCC,&whilestmt)) and cc.value(&value) and Cpp.AssignmentExpression.isa(value,&discard) and value.nodeText(&NT) raise "Assignment in If or while condition statement \"{NT}\"" on cc }, #[Description("myOtherRule"), Id(Rule2)] rule myOtherRule = { std.defects.USELESS_IF } } }Create the user-defined coding standard
syntaxrule.pschk containing the rulesRule1andRule2. At the command line, enter:Run this command in the folderpolyspace-query-language package
syntaxrule.Annotate the source file to indicate where you expect violations of the rules are:
void foo() { int x; if (x = 0)// expect-1-Rule1 { x = 0; } if (x == 0) // expect-1-Rule2 { } for (x = 0; x < 5; ++x) { } while (x = 0) // expect-1-Rule1 { } }Test your coding standard:
This command runs a Polyspace Bug Finder analysis onpolyspace-query-language test src.cpp
src.cppusing the user-defined coding standardsyntaxrule.pschk and checks where the violation of the rules occur in the expected locations. Because the violations occur in the lines specified using the//expected...comments, the test passes.
Profile User Defined Coding Standard
Consider a user defined coding standard in the folder
ProjectFolder which contains PQL defects addressing C11 code.
To profile this user defined coding standard in , at the command line,
enter
polyspace-query-language profile ProjectFolder -lang C -c-version C11
Input Arguments
Version History
Introduced in R2026a