Cpp.ExpressionStatement Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the expression_statement nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.ExpressionStatement represents the node expression_statement in the syntax tree of your code.
void test_expression_stmt() {
int x = 0;
x = 42;
a = 1, b = 2;
(void)printf("%d\n", x);
}The function body contains several expression_statement nodes such as x = 42;, a = 1, b = 2; and the cast-expression statement (void)printf("%d\n", x); which correspond to Cpp.ExpressionStatement in PQL.
Predicates
| Type | Raisable | Printable |
|---|---|---|
ExpressionStatement
| 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 ExpressionStatement &expressionStatement)
| Matches an expression_statement node and binds it to the
output variable. Use this to obtain the node itself for further predicates. | This PQL defect checks for any expression statement node and reports its text. defect check_expr_stmt =
when
Cpp.ExpressionStatement.is(&exprStmt)
and exprStmt.nodeText(&txt)
raise "Found expression statement: \"{txt}\""
on exprStmtIn this C++ code the defect finds each top-level expression statement inside the function body.
#include <cstdio>
void f() {
int x = 0;
x = 42;
}
int main() {
f();
return 0;
} |
cast(Cpp.Node.Node node, required ExpressionStatement &cast)
| Checks whether a given Node is an
expression_statement and if so binds that node to the output
cast. | This PQL defect checks whether an arbitrary defect check_cast =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.ExpressionStatement.cast(n, &exprStmt)
and exprStmt.nodeText(&txt)
raise "Node cast to expression_statement: \"{txt}\""
on exprStmtIn this C++ code the defect checks nodes
discovered generically and reports those that are expression statements such as
#include <cstdio>
void f() {
int x;
x = 42;
}
int main() { f(); return 0; } |
isa(Cpp.Node.Node node)
| Returns true when the given Node is an
expression_statement. Use it for boolean checks or
negations. | This PQL defect checks nodes with a boolean test to find expression statements. defect check_isa =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.ExpressionStatement.isa(n)
and n.nodeText( &txt)
raise "Node is an expression_statement: \"{txt}\""
on nIn this C++ example the defect finds
#include <cstdio>
void g() {
int x;
x = 42;
}
int main() { g(); return 0; } |
expression(ExpressionStatement self, Cpp.Node.Node &child)
| Matches the subnode that is the expression inside an
expression_statement and binds it to
child. | This PQL defect checks for expression statements and extracts their contained expression. defect check_expression =
when
Cpp.ExpressionStatement.is(&stmt)
and stmt.expression(&expr)
and expr.nodeText(&txt)
raise "Expression statement contains: \"{txt}\""
on stmtIn this C++ code the defect extracts the inner
expressions like
#include <cstdio>
void h() {
int x;
x = 42;
}
int main() { h(); return 0; } |
commaExpression(ExpressionStatement self, Cpp.Node.Node
&child)
| Matches the comma expression used as the statement's expression and binds that comma-expression node. | This PQL defect checks for expression statements whose expression is a
comma expression such as defect check_comma_expr =
when
Cpp.ExpressionStatement.is(&stmt)
and stmt.commaExpression(&comma)
and comma.nodeText(&txt)
raise "Comma expression statement: \"{txt}\""
on stmtIn this C++ example the defect finds the
#include <cstdio>
void k() {
int a = 0, b = 0;
a = 1, b = 2;
}
int main() { k(); return 0; } |
getEnclosingExpressionStatement(Cpp.Node.Node child, required
ExpressionStatement &parent)
| Finds the nearest enclosing expression_statement ancestor of
the provided child node and binds it to
parent. | This PQL defect checks for nodes inside an expression and reports their enclosing expression statement. defect check_enclosing_expr_stmt =
when
Cpp.Node.is(&inner, &,&,&)
and Cpp.ExpressionStatement.getEnclosingExpressionStatement(inner, &stmt)
and stmt.nodeText(&txt)
raise "Enclosing expression statement: \"{txt}\""
on stmtIn this C++ example the defect locates the
#include <cstdio>
void m() {
(void)printf("%d\n", 1);
}
int main() { m(); return 0; } |
isEnclosedInExpressionStatement(Cpp.Node.Node child)
| Returns true when the given child has an
expression_statement as an ancestor. | This PQL defect checks whether a node lies inside any expression statement. defect check_is_enclosed =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.ExpressionStatement.isEnclosedInExpressionStatement(n)
and n.nodeText(n, &txt)
raise "Node is enclosed in expression statement: \"{txt}\""
on nIn this C++ example the defect detects the
#include <cstdio>
void p() {
(void)printf("%d\n", 1);
}
int main() { p(); 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)