주요 콘텐츠

Cpp.ObjectWithPosition Class

Namespace: Cpp

Represents an object that has a known position

Since R2026a

Description

ObjectWithPosition class represents an object that has a position, such as call sites, variables, types, casts, fields, and functions. These objects are represented by classes that inherit from ObjectWithPosition.

The class ObjectWithPosition is a superclass. It cannot interact with your C/C++ code directly. The child classes of this class can invoke the predicates of this class to analyze your C/C++ code.

Predicates

expand all

Child Classes

The class ObjectWithpsotion has these child classes.

Child ClassDescription
Cpp.CallSite Represents function call sites.
Cpp.Cast Represents casts.
Cpp.Field Represents member variables of starctures, classes, and unions.
Cpp.Function Represents a callable function.
Cpp.Type Represent a built-in or user-defined type.
Cpp.Variable Represents a variable.

Examples

collapse all

  1. In a new folder ObjectWithExample, initialize a new coding standard. At the command line, enter:

    polyspace-query-language init

  2. 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.
    catalog ObjectWithpositionExample = {
    	#[Description("Example Section")]
    	section ExampleSection = {
    		#[Description("Local variable shadows global variable"),Id(myRule)]
    		rule ExampleRule = {
    			defect Exampledefect = 
    			when Cpp.Variable.is(&gVar)
    			and gVar.isFileStatic()
    			and gVar.name(&GlobalName)
    			and Cpp.Function.is(&Function)
    			and Function.localVariable(&localVar)
    			and localVar.name(&LocalName)
    			and LocalName == GlobalName
    			and localVar.isInSameFile(gVar)
    			raise "Local and global share name\"{LocalName}\""
    			on localVar
    
    		}
    	}
    }
    
    

  3. Create the coding standard ObjectWithExample.pschk using this command at the command line:

    polyspace-query-language package

  4. Using the generated coding standard, run a Bug Finder anal;ysis on your source file. Foe example, at the command line, enter:

    polyspace-bug-finder -sources src.cpp -lang cpp -checkers-activation-file ObjectWithExample.pschk
    The analysis reports the variable shadowing on the local variable named counter.

Version History

Introduced in R2026a