Cpp.GenericExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the generic_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.GenericExpression represents the node generic_expression in the syntax tree of your code.
// c11 example using _Generic expression
#include <stdio.h>
int main(void) {
int x = 3;
int y = _Generic(x, int: 1, float: 2);
(void)y;
return 0;
}The _Generic(x, int: 1, float: 2) expression in the code corresponds to the generic_expression node and is represented by Cpp.GenericExpression in PQL.
Predicates
| Type | Raisable | Printable |
|---|---|---|
GenericExpression
| 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 GenericExpression &ge)
| Checks whether a syntax node is a generic_expression and
binds it to ge for further queries. | This PQL defect checks for defect FindGenericIs =
when
Cpp.GenericExpression.is(&ge)
and ge.nodeText(&txt)
raise "Found generic expression: \"{txt}\""
on geIn this C++ code the defect finds occurrences of the
C11
int main(void) {
int a = 0;
int b = _Generic(a, int: 10, default: 0);
(void)b;
return 0;
} |
cast(Cpp.Node.Node node, required GenericExpression &cast)
| If node is a generic_expression this
binds that generic_expression to cast so you
can query its properties. | This PQL defect checks for defect FindGenericCast =
when
Cpp.ReturnStatement.is(&ret)
and ret.getADescendant(&node)
and Cpp.GenericExpression.cast(node, &cast)
and cast.nodeText(&txt)
raise "Cast to GenericExpression matched: \"{txt}\""
on castIn this C++ code the defect finds the generic expression in the return statement.
int foo(int x) {
return _Generic(x, int: 1, float: 2);
} |
isa(Cpp.Node.Node node)
| Checks whether the general Node is specifically a
generic_expression and returns true or false. | This PQL defect checks whether the value of a declarator is a
defect FindGenericIsa =
when
Cpp.Declaration.is(&dec)
and dec.getADescendant(&value)
and Cpp.GenericExpression.isa(value)
and value.nodeText(&txt)
raise "isa confirms generic_expression: \"{txt}\""
on valueIn this C++ code the defect finds generic expressions on the right side of a declaration statement.
#include <stdio.h>
int main(void) {
int v = 1;
int r = _Generic(v, int: 9, default: 0);
(void)r;
return 0;
} |
typeDescriptor(GenericExpression self, Cpp.Node.Node &child)
| Selects the type_descriptor child of a
generic_expression and binds it to
child. | This PQL defect checks for defect FindTypeDescriptor =
when
Cpp.GenericExpression.is(&ge)
and ge.typeDescriptor(&td)
and td.nodeText(&txt)
raise "GenericExpression.typeDescriptor: \"{txt}\""
on geIn this C++ code the defect extracts the type label
part such as
int main(void) {
int v = 2;
int x = _Generic(v, int: 1, float: 2);
(void)x;
return 0;
} |
expression(GenericExpression self, Cpp.Node.Node &child)
| Selects the expression child of a
generic_expression and binds it to
child. | This PQL defect checks for the expression child inside a
defect FindGenericExpressionChild =
when
Cpp.GenericExpression.is(&ge)
and ge.expression(&ex)
and ex.nodeText(&txt)
raise "GenericExpression.expression: \"{txt}\""
on geIn this C++ code the defect identifies the controlling
expression
int main(void) {
int v = 5;
int y = _Generic(v, int: 1, float: 2);
(void)y;
return 0;
} |
getEnclosingGenericExpression(Cpp.Node.Node child, required
GenericExpression &parent)
| Finds the nearest ancestor generic_expression that encloses
the child node and binds it to parent. | This PQL defect checks for an identifier and then finds its closest parent generic expression. defect EnclosingGeneric =
when
Cpp.Identifier.is(&id)
and id.toNode(&n)
and Cpp.GenericExpression.getEnclosingGenericExpression(n, &parent)
and parent.nodeText(&txt)
raise "Enclosing generic expression: \"{txt}\""
on parentIn this C++ code the defect finds the
int main(void) {
int v = 0;
int r = _Generic(v, int: 1, float: 2); // identifier 'v' is enclosed in the generic expression
(void)r;
return 0;
} |
isEnclosedInGenericExpression(Cpp.Node.Node child)
| Matches if child has any ancestor that is a
generic_expression. | This PQL defect checks whether a lnumber literal node occurs anywhere
inside a
defect EnclosedInGeneric =
when
Cpp.Literal.is(&lit)
and lit.toNode(&n)
and Cpp.GenericExpression.isEnclosedInGenericExpression(n)
and n.nodeText(&txt)
raise "Literal enclosed in generic_expression: \"{txt}\""
on nIn this C++ code the defect detects number literal
result expressions such as
int main(void) {
int v = 0;
int r = _Generic(v, int: 1, float: 2); // the literal 1 is enclosed in the generic expression
(void)r;
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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)