Cpp.CallExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the call_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class CallExpression represents the node call_expression in the syntax tree of your code.
// example.cpp
void foo(int, int);
void bar();
void baz(int, int);
void test() {
foo(1, 2);
bar();
int x = 42;
baz(x, x + 1);
}
int main() {
test();
return 0;
}The sample shows several call_expression nodes such as foo(1,
2), bar(), test() and baz(x, x +
1), which matches with the CallExpression PQL class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
CallExpression
| 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 CallExpression &ce)
| Checks that a given node is a call_expression and returns it as &ce for further inspection. |
This PQL defect checks for a node that is a defect check_call_is =
when
Cpp.CallExpression.is(&ce)
and ce.nodeText(&txt)
raise "Found call: \"{txt}\""
on ceIn this C++ code, the defect finds top-level call expressions such as simple function calls.
void foo(int, int);
void test() {
foo(1, 2); // matches
}
int main() { test(); /*matches*/ return 0; } |
cast(Cpp.Node.Node node, required CallExpression &cast)
| Checks whether an arbitrary Cpp.Node.Node is a call_expression; if so, exposes it as &cast. | This PQL defect checks whether a generic node is a
defect check_call_cast =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.CallExpression.cast(node, &ce)
and ce.nodeText(&txt)
raise "Node is a call: \"{txt}\""
on ceIn this C++ code, the defect checks for the node
that corresponds to the calls
void bar();
void f() {
bar();
}
int main() { f(); return 0; } |
isa(Cpp.Node.Node node)
| Tests whether a given Cpp.Node.Node is a call_expression (usable in positive or negative tests). | This PQL defect checks for nodes that are not
defect non_call_nodes =
when
Cpp.Node.is(&node, &,&,&)
and not Cpp.CallExpression.isa(node)
and node.nodeText(&txt)
raise "Not a call node: \"{txt}\""
on nodeIn this C++ code, the defect flags all nodes that are not call expressions.
void foo();
void f() {
int x = 1; // identifier/initializer is not a call_expression
foo(); // this is a call_expression
}
int main() { f(); return 0; } |
arguments(CallExpression self, Cpp.Node.Node &child)
| Returns the arguments node (the argument list subtree) of the call expression as &child. | This PQL defect checks for call expressions and extracts their argument list nodes. defect call_with_args =
when
Cpp.CallExpression.is(&ce)
and ce.arguments(&args)
and args.nodeText(&txt)
raise "Call arguments: \"{txt}\""
on ceIn this C++ code, the defect flags the
comma-separated argument list
void baz(int, int);
void test() {
int x = 0;
baz(x, x + 1); // arguments node is "(x, x + 1)"
}
|
function(CallExpression self, Cpp.Node.Node &child)
| Returns the node corresponding to the function being called in the call
expression as &child. | This PQL defect checks for call expressions and extracts the functionbeing called. defect call_function =
when
Cpp.CallExpression.is(&ce)
and ce.function(&func)
and func.nodeText(&txt)
raise "Callee: \"{txt}\""
on ceIn this C++ code, the defect identifies the
function
void foo(int, int);
void test() {
foo(1, 2); // callee node is "foo"
}
|
getEnclosingCallExpression(Cpp.Node.Node child, required CallExpression &parent)
| Finds the nearest ancestor call_expression that encloses a given node, returning it as &parent. | This PQL defect checks for nodes that are nested inside a call expression and reports the enclosing call. defect enclosing_call =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.CallExpression.getEnclosingCallExpression(node, &parent)
and parent.nodeText(&txt)
raise "Enclosing call: \"{txt}\""
on parentIn this C++ code, the defect checks all nodes
and finds the parent node
void baz(int, int);
void test() {
int x = 1;
baz(x, x + 1);
}
|
isEnclosedInCallExpression(Cpp.Node.Node child)
| Checks whether a given node has any call_expression as an ancestor. | This PQL defect checks nodes to see if they appear inside a call expression and reports those that do. defect inside_call =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.CallExpression.isEnclosedInCallExpression(node)
and node.nodeText(&txt)
raise "Node inside call: \"{txt}\""
on nodeIn this C++ code, the defect finds all child nodes of the call expression.
void baz(int, int);
void test() {
int x = 2;
baz(x, x + 1); // all child nodes are flagged
}
int main() { test(); 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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)