Cpp.AssignmentExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the assignment_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class AssignmentExpression represents the node
assignment_expression in the syntax tree of your code.
// demo.cpp
#include <vector>
int main() {
int a = 0;
int b = 1;
a = b + 1;
b += 2;
a *= b;
int arr[4];
arr[1] = 5;
return a;
}The C++ demo contains several assignment_expression occurrences such as a = b + 1, b += 2, a *= b, and arr[1] = 5, each corresponding to the assignment_expression node.
Predicates
| Type | Raisable | Printable |
|---|---|---|
AssignmentExpression
| 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 AssignmentExpression &ae)
| Checks whether there exists an assignment_expression node and returns it as ae for further inspection. |
This PQL defect checks for any defect DetectAnyAssignment =
when
Cpp.AssignmentExpression.is(&ae)
and ae.nodeText(&txt)
raise "Found assignment: \"{txt}\""
on aeIn this C++ code, the defect finds any assignment statements like simple, compound, or subscript assignments.
#include <vector>
int main() {
int a = 0;
a = 5; // detected
a += 2; // detected
return 0;
} |
cast(Cpp.Node.Node node, required AssignmentExpression &cast)
| Interprets a generic Node as an assignment_expression; returns cast when the node is an assignment expression. | This PQL defect checks whether a generic node is an
defect cast_node_to_assignment =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.AssignmentExpression.cast(n, &ae)
and ae.nodeText(&txt)
raise "Casted node is assignment: \"{txt}\""
on aeIn this C++ code, the defect checks a generic node that can be cast to an assignment expression.
int main() {
int a = 1;
int b = 2;
a = b + 1;
return a;
} |
isa(Cpp.Node.Node node)
| Determines whether a given Node is an assignment_expression; useful for boolean checks or negation. | This PQL defect checks whether a node is an
defect node_is_assignment =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.AssignmentExpression.isa(n)
raise "Node is an assignment expression"
on nIn this C++ code, the predicate identifies
int main() {
int a = 0, b = 0;
b += 2;
int arr[3];
arr[1] = 7;
return 0;
} |
left(AssignmentExpression self, Cpp.Node.Node &child)
| Returns the left-hand side subnode of an assignment expression (the target being assigned). |
This PQL defect checks for the left-hand side (LHS) of assignment expressions. defect check_assignment_left =
when
Cpp.AssignmentExpression.is(&ae)
and ae.left(&lhs)
and lhs.nodeText(&txt)
raise "Assignment LHS: \"{txt}\""
on aeIn this C++ code, the defect extracts LHS like
int main() {
int a = 0;
int b = 1;
a = b + 1;
b += 3;
int arr[2];
arr[1] = 4;
return 0;
} |
operator(AssignmentExpression self, Cpp.Node.Node &child)
| Returns the assignment operator token node, e.g., =, +=, *=, etc., from the assignment expression. |
This PQL defect checks which assignment operator is used in each assignment expression. defect check_assignment_operator =
when
Cpp.AssignmentExpression.is(&ae)
and ae.operator(&op)
and op.nodeText(&txt)
raise "Assignment operator: \"{txt}\""
on aeIn this C++ code, the defect finds operators like
int main() {
int a = 0;
a = 1;
a += 2;
a *= 3;
return a;
} |
right(AssignmentExpression self, Cpp.Node.Node &child)
| Returns the right-hand side subnode of an assignment expression (the value or expression assigned). |
This PQL defect checks the right-hand side (RHS) expressions of assignments. defect check_assignment_right =
when
Cpp.AssignmentExpression.is(&ae)
and ae.right(&rhs)
and rhs.nodeText(&txt)
raise "Assignment RHS: \"{txt}\""
on aeIn this C++ code, the defect inspects RHS expressions like
int main() {
int b = 1, z = 3;
int a;
a = b + 1;
b = 2;
a *= z;
return a;
} |
getEnclosingAssignmentExpression(Cpp.Node.Node child, required AssignmentExpression &parent)
| Finds the nearest ancestor assignment_expression that contains the given child node and returns it as parent. | This PQL defect checks for the closest assignment expression that surrounds a given node. defect find_enclosing_assignment =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.AssignmentExpression.getEnclosingAssignmentExpression(n, &ae)
and ae.nodeText(&txt)
raise "Enclosing assignment: \"{txt}\""
on aeIn this C++ code, the defect locates
int main() {
int a = 0, b = 2;
a = b + 1;
return 0;
} |
isEnclosedInAssignmentExpression(Cpp.Node.Node child)
| Returns true when the given node has any assignment_expression ancestor. | This PQL defect checks whether a node appears inside an assignment expression anywhere above it. defect node_inside_assignment =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.AssignmentExpression.isEnclosedInAssignmentExpression(n)
raise "Node is inside an assignment expression"
on nIn this C++ code, the predicate matches the all child nodes of the assignment expression..
int main() {
int a = 0, b = 1;
a = b + 1;
return 0;
} |
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)