Cpp.ConditionalExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the conditional_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class ConditionalExpression represents the node conditional_expression in the syntax tree of your code.
// example.cpp
int f(int a, int b, int c, bool flag) {
int x = a ? b : c;
int y = (flag ? 1 : 0) + 2;
return x + y;
}The code contains two conditional_expression nodes: a ? b : c and flag ? 1 : 0, which correspond to the PQL ConditionalExpression node.
Predicates
| Type | Raisable | Printable |
|---|---|---|
ConditionalExpression
| 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 ConditionalExpression &ce)
| Matches a conditional_expression node and returns it as
ce. Wse this to directly obtain the conditional-expression
node. |
This PQL defect checks for any defect find_conditional =
when
Cpp.ConditionalExpression.is(&ce)
and ce.nodeText(&txt)
raise "Found conditional: \"{txt}\""
on ceIn this C++ code, the defect finds each ternary expression such as
// main.cpp
int main() {
int a=1,b=2,c=3;
int v = a ? b : c;
return v;
} |
cast(Cpp.Node.Node node, required ConditionalExpression &cast)
| Checks whether a generic Cpp.Node.Node is a
conditional_expression. If so, returns it as
cast. | This PQL defect checks nodes already obtained as generic
defect cast_to_conditional =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.ConditionalExpression.cast(node, &ce)
and ce.nodeText(&txt)
raise "Casted to conditional: \"{txt}\""
on ceIn this C++ code, the defect finds the node
representing
// main.cpp
bool flag=false;
int main() {
int r = flag ? 1 : 0;
return r;
} |
isa(Cpp.Node.Node node)
| Returns true if the given Cpp.Node.Node is a
conditional_expression. Use this predicate for boolean checks
or negation. | This PQL defect checks whether a node is a
defect node_is_conditional =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.ConditionalExpression.isa(node)
raise "Node is a conditional expression"
on nodeIn this C++ code, the defect identifies that
// main.cpp
int a=1,b=2,c=3;
int main() {
int t = a ? b : c;
return t;
} |
condition(ConditionalExpression self, Cpp.Node.Node &child)
| Extracts the condition node from a
conditional_expression. | This PQL defect checks for the condition node of a
defect conditional_condition =
when
Cpp.ConditionalExpression.is(&ce)
and ce.condition(&cond)
and cond.nodeText(&txt)
raise "Condition is \"{txt}\""
on condIn this C++ code, the defect inspects the
condition part
// main.cpp
bool flag=true;
int main() {
int v = flag ? 100 : -1;
return v;
} |
consequence(ConditionalExpression self, Cpp.Node.Node &child)
| Extracts the consequence node from a
conditional_expression. | This PQL defect checks for the consequence node of a
defect conditional_consequence =
when
Cpp.ConditionalExpression.is(&ce)
and ce.consequence(&cons)
and cons.nodeText(&txt)
raise "Consequence is \"{txt}\""
on consIn this C++ code, the defect finds the
true-branch value
// main.cpp
bool flag=false;
int main() {
int v = flag ? 1 : 0;
return v;
} |
alternative(ConditionalExpression self, Cpp.Node.Node &child)
| Extracts the alternative node from a
conditional_expression. |
This PQL defect checks for the alternative subnode of a defect conditional_alternative =
when
Cpp.ConditionalExpression.is(&ce)
and ce.alternative(&alt)
and alt.nodeText(&txt)
raise "Alternative is \"{txt}\""
on altIn this C++ code, the defect inspects the false-branch
// main.cpp
int a=1,b=2,c=5;
int main() {
int v = a ? b : c;
return v;
} |
getEnclosingConditionalExpression(Cpp.Node.Node child, required ConditionalExpression &parent)
| Finds the nearest enclosing conditional_expression that contains the given child node and returns it as parent. | This PQL defect checks which defect find_enclosing_conditional =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.ConditionalExpression.getEnclosingConditionalExpression(node, &parent)
and parent.nodeText(&txt)
raise "Enclosing conditional: \"{txt}\""
on parentIn this C++ code, the defect finds a parent conditional expression that contains a generic syntax node.
// main.cpp
bool flag=false;
int main() {
int v = (flag ? 1 : 0) + 3;
return v;
} |
isEnclosedInConditionalExpression(Cpp.Node.Node child)
| Returns true if the given child node has a
conditional_expression ancestor. | This PQL defect checks whether a defect child_in_conditional =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.NumberLiteral.isa(node)
and Cpp.ConditionalExpression.isEnclosedInConditionalExpression(node)
raise "Node is enclosed in a conditional expression"
on nodeIn this C++ code, the defect detects number literals that are within a conditional expression.
// main.cpp
bool flag=true;
int main() {
int v = flag ? 1 : 0; //mactches
(void)0; // does not match
return v;
} |
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)