Cpp.PointerExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the pointer_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.PointerExpression represents the node pointer_expression in the syntax tree of your code.
int foo(int *p) {
int x = 42;
int *q = &x;
return *q;
}The demo contains pointer_expression nodes for int *p, int *q, &x, and *q. These correspond to the Cpp.PointerExpression PQL class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
PointerExpression
| Yes | No |
This class defines these predicates that act on the objects of this class. In addition, objects of this class can access the predicates defined by the base class AstNodeProperties. An object of this class is an object of AstNodeProperties class.
| Predicates | Description | Example |
|---|---|---|
is(required PointerExpression &pe)
| Matches a pointer_expression node and binds it to
pe for further queries. | This PQL defect checks for any pointer expression node in the code. defect PointerExprIs =
when
Cpp.PointerExpression.is(&pe)
and pe.nodeText(&txt)
raise "Found pointer expression: \"{txt}\""
on peIn this C++ code, the defect finds each pointer
expression such as declarations, unary
int foo(int *p) {
int x = 0;
int *q = &x;
return *q;
} |
cast(Cpp.Node.Node node, required PointerExpression &cast)
| Checks whether a given Node is a
pointer_expression and if so binds it to
cast for inspection. | This PQL defect checks whether a generic defect PointerExprCast =
when
Cpp.ReturnStatement.is(&rt)
and rt.getADescendant(&node)
and Cpp.PointerExpression.cast(node, &pe)
and pe.nodeText(&txt)
raise "Node cast to pointer expression: \"{txt}\""
on peIn this C++ code, the defect demonstrates converting a
different node to
int foo(int *p) {
int x = 42;
int *q = &x;
return *q;
} |
isa(Cpp.Node.Node node)
| Tests whether a given Node is a
pointer_expression. Use this for boolean checks or
negation. | This PQL defect checks if a defect PointerExpris =
when
Cpp.ReturnStatement.is(&rt)
and rt.getADescendant(&node)
and Cpp.PointerExpression.is(node)
and node.nodeText(&txt)
raise "Node is a pointer expression: \"{txt}\""
on odeIn this C++ code, the defect finds a pointer expression inside a return statement.
int foo(int *p) {
int x = 42;
int *q = &x;
return *q;
} |
argument(PointerExpression self, Cpp.Node.Node &child)
| Binds child to the operand of the pointer expression for
example the x in *x or
&x. | This PQL defect checks for pointer expressions and extracts their operand node. defect PointerExprArgument =
when
Cpp.PointerExpression.is(&pe)
and pe.argument(&arg)
and arg.nodeText(&txt)
raise "Pointer expression operand: \"{txt}\""
on peIn this C++ code, the defect finds the operand
int foo() {
int x = 1;
int *p = &x; // operand is x
return *p; // operand is p
} |
operator(PointerExpression self, Cpp.Node.Node &child)
| Binds child to the operator token node of the pointer
expression such as * or &. | This PQL defect checks pointer expressions and extracts the operator token. defect PointerExprOperator =
when
Cpp.PointerExpression.is(&pe)
and pe.operator(&op)
and op.nodeText(&txt)
raise "Pointer expression operator: \"{txt}\""
on opIn this C++ code, the defect finds the
int foo() {
int x = 2;
int *p = &x; // operator is &
return *p; // operator is *
} |
getEnclosingPointerExpression(Cpp.Node.Node child, required
PointerExpression &parent)
| Finds the nearest ancestor pointer_expression that encloses
the supplied child node and binds it to
parent. | This PQL defect checks for the closest pointer expression ancestor of a
given node converted to
defect EnclosingPointerExpr =
when
Cpp.Identifier.is(&id)
and id.toNode(&node)
and Cpp.PointerExpression.getEnclosingPointerExpression(node, &pe)
and pe.nodeText(&txt)
raise "Enclosing pointer expression: \"{txt}\" for identifier"
on idIn this C++ code, the defect finds that
int foo() {
int x = 5;
int *p = &x; // identifier x is enclosed by pointer expression &x
return 0;
} |
isEnclosedInPointerExpression(Cpp.Node.Node child)
| True if the given Node has any
pointer_expression ancestor in the syntax tree. | This PQL defect checks whether a node is inside any pointer expression. defect IdentifierInPointerExpr =
when
Cpp.Identifier.is(&id)
and id.toNode(&node)
and Cpp.PointerExpression.isEnclosedInPointerExpression(node)
raise "Identifier is inside a pointer expression"
on idIn this C++ code, the defect flags identifiers like
int foo() {
int x = 0;
int *p = &x; // identifier x is enclosed in pointer expression &x
return *p; // identifier p is enclosed in pointer expression *p
} |
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)