Cpp.OperatorName Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the operator_name nodes in the syntax tree of your code
Since R2026a
Description
The PQL class OperatorName represents the node
operator_name in the syntax tree of your code.
struct S {
S operator+(const S&) const;
S operator-(const S&) const;
bool operator==(const S&) const;
};The above C++ struct declares three overloaded operators. Each operator declaration
contains an operator_name node that corresponds to the PQL
OperatorName class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
OperatorName
| Yes | Yes |
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 OperatorName &op)
| Checks whether a node is an operator_name node and returns
it as op; use to directly select operator-name nodes. | This PQL defect checks for any defect find_operator_name =
when
Cpp.OperatorName.is(&op)
and op.nodeText(&txt)
raise "Found operator name: \"{txt}\""
on opIn this C++ code, the defect finds each operator
declaration's name (e.g.,
struct S {
S operator+(const S&) const;
S operator-(const S&) const;
bool operator==(const S&) const;
}; |
cast(Cpp.Node.Node node, required OperatorName &cast)
| Succeeds if node is an operator_name node
and returns that node as cast; useful when you start from a
generic Cpp.Node.Node. | This PQL defect checks for defect cast_to_operator =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.OperatorName.cast(n, &op)
and op.nodeText(&txt)
raise "Casted node is operator: \"{txt}\""
on opIn this C++ code, the defect casts generic parsed
nodes that actually represent operator names like
struct S {
S operator+(const S&) const;
};
int main() { S a, b; (void)(a + b); return 0; } |
isa(Cpp.Node.Node node)
| Returns true if node is an operator_name
node; use in boolean checks or negations. | This PQL defect checks whether a generic node is an
defect isa_operator_node =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.OperatorName.isa(n)
raise "Node is an operator_name"
on nIn this C++ code, the predicate identifies the
struct S {
S operator-(const S&) const;
}; |
identifier(OperatorName self, Cpp.Node.Node &child)
| Matches the child node that holds the textual identifier of the operator (e.g.,
the operator+ token) and returns it as
child. | This PQL defect checks for the identifier child node inside an
defect operator_identifier_text =
when
Cpp.OperatorName.is(&op)
and op.identifier(&id)
and id.nodeText(&txt)
raise "Operator identifier: \"{txt}\""
on op |
getEnclosingOperatorName(Cpp.Node.Node child, required OperatorName
&parent)
| Finds the nearest enclosing operator_name ancestor of
child and returns it as parent; useful when
you have a token inside the operator name and need the whole operator node. | This PQL defect checks for nodes that lie within an
defect enclosing_operator_of_token =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.OperatorName.getEnclosingOperatorName(n, &op)
and op.nodeText(&txt)
raise "Node is child of operator: \"{txt}\""
on nIn this C++ code, the defect locates the syntax nodes
that are children of the
struct S {
S operator+(const S&) const; //matches 'operator' and '+'
}; |
isEnclosedInOperatorName(Cpp.Node.Node child)
| Matches any operator_name ancestor parent
of child. | This PQL defect checks for all defect all_enclosing_operators =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.OperatorName.isEnclosedInOperatorName(n)
and n.nodeText(&txt)
raise "node is enclosed operator: \"{txt}\""
on nIn this C++ code, the defect finds the syntax nodes
that are children of the node
struct S {
S operator-(const S&) const; //matches 'operator' and '-'
}; |
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)