Cpp.Variable Class
Namespace: Cpp
Superclasses: ObjectWithPosition
Description
Variable class represents variables in your code. This class inherits
from the class ObjectWithPosition. You can use the predicates associated with this class and
the base class with objects of this object.
Predicates
You can report a defect on Raisable types. If a type is
Printable, it can be reported in the message. For
Variable objects, print the string obtained by the predicate
Cpp.Variable.name.
| Type | Raisable | Printable |
|---|---|---|
Lang.Int
| No | Yes |
Lang.String
| No | Yes |
Variable
| Yes | No |
This class defines these predicates that act on the Variable
objects. In addition, objects of Variable class can access the
predicates defined by the base class ObjectWithPosition. An object of Variable class is an
object of ObjectWithPosition class.
| Predicates | Description |
|---|---|
is(Variable &variable)
| Retrieves all Variable objects in your code. |
name(Variable self, Lang.String &name)
| Retrieves the name of the variable self and stores it in name. |
isUnnamed(Variable self)
| Retrieves Variable objects that are unnamed. |
qualifiedName(Variable self, Lang.String &name)
| Retrieves the fully qualified name of the variable self and stores it in name. |
type(Variable self, Cpp.Type.Type &type)
| Retrieves the type of the variable self and stores it in type. |
namespace(Variable self, Cpp.Namespace.Namespace &namespace)
| Retrieves the namespace in which the variable self is declared and stores it in namespace. |
isGloballyVisible(Variable self)
| Retrieves variables that have global visibility (not static or local). |
isFileStatic(Variable self)
| Retrieves variables that are file-static (declared with static at file scope). |
isFunctionNonStaticLocal(Variable self)
| Retrieves variables that are local to a function and not declared static. |
isFunctionParameter(Variable self)
| Retrieves variables that are function parameters. |
isFunctionStaticLocal(Variable self)
| Retrieves variables that are static locals in a function. |
isClassStatic(Variable self)
| Retrieves variables that are static members of a class. |
isDefined(Variable self)
| Retrieves variables that are defined (not just declared). |
isDeclaredAuto(Variable self)
| Retrieves variables that are declared with the auto keyword. |
isConstexpr(Variable self)
| Retrieves variables that are declared as constexpr. |
isInitializedAtDeclaration(Variable self) | Retrieves variables that are initialized at declaration. |
Examples
In a new folder
Field, initialize a new coding standard. At the command line, enter:polyspace-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. catalog FieldExample = { #[Description("Example Section")] section ExampleSection = { #[Description("Unused public field in header"),Id(myRule)] rule ExampleRule = { defect Exampledefect = when Cpp.Field.is(&field) and field.isUnused() and field.isPublic() and field.extension(&ext) and ext == ".h" and field.filename(&fnstr) raise "Unused public field in header: \"{fnstr}\"" on field } } }Create the coding standard
Field.pschk using this command at the command line:polyspace-query-language package
Using the generated coding standard, run a Bug Finder analysis on your source file. Foe example, at the command line, enter:
The analysis reports defects on the unused member variablepolyspace-bug-finder -sources src.cpp -lang cpp -checkers-activation-file Field.pschk
unusedFieldin the header filesrc.h.
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)