Cpp.CharLiteral Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the char_literal nodes in the syntax tree of your code
Since R2026a
Description
The PQL class CharLiteral represents the node
char_literal in the syntax tree of your code.
// Demonstrates various char_literal nodes
#include <iostream>
void char_literals() {
char a = 'a';
char newline = '\n';
char hex = '\x20';
char octal = '\101';
char quote = '\'';
char backslash = '\\';
char unicode = u'\u00E9';
char wide = L'a';
char utf8 = u8'a';
char utf16 = u'a';
char utf32 = U'a';
(void)a; (void)newline; (void)hex; (void)octal;
(void)quote; (void)backslash; (void)unicode;
(void)wide; (void)utf8; (void)utf16; (void)utf32;
}
int main() { return 0; }The C++ sample contains multiple char_literal instances, such as
'a', '\n' and '\x20'. These syntax
nodes are matched by PQL CharLiteral class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
CharLiteral
| 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 CharLiteral &lit)
| Checks whether a node is a char_literal node and returns it as lit. Use this to directly match character literals. | This PQL defect checks for plain character literals anywhere in the code. defect find_char_literal =
when
Cpp.CharLiteral.is(&lit)
and lit.nodeText(&txt)
raise "Found char literal: {txt}"
on litIn this C++ code, the defect finds direct
character literals like
#include <iostream>
void f() {
char c = 'a';
char n = '\n';
(void)c; (void)n;
}
int main() { return 0; } |
cast(Cpp.Node.Node node, required CharLiteral &cast)
| Checks whether an arbitrary node is a
char_literal and, if so, returns it as cast.
Use when you start from a generic AST node. | This PQL defect checks for nodes that can be interpreted as
defect cast_from_node =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.CharLiteral.cast(node, &lit)
and lit.nodeText(&txt)
raise "Casted node to char literal: {txt}"
on litIn this C++ code, the defect finds a
void g() {
char x = 'x';
(void)x;
}
int main() { return 0; } |
isa(Cpp.Node.Node node)
| Returns true if node is a char_literal. Useful for negative checks like not Cpp.CharLiteral.isa(n). | This PQL defect checks for a generic nodes that are not
defect check_not_char_literal =
when
Cpp.Node.is(&node, &,&,&)
and not Cpp.CharLiteral.isa(node)
raise "Node is not a char literal"
on nodeIn this C++ code, the defect finds the syntax
nodes that are not
void h() {
int i = 0;
char z = 'z';
(void)i; (void)z;
}
int main() { return 0; } |
character(CharLiteral self, Cpp.Character.Character &content)
| Extracts the raw character content from a char_literal. That
is, from the character literal 'lit', this predicate retrieves
the content lit and returns it as
content. | This PQL defect checks for defect extract_char_value =
when
Cpp.CharLiteral.is(&lit)
and lit.character(&content)
and content.nodeText(&val)
raise "Char literal value: {val}"
on litIn this C++ code, the defect retrieves the inner
token for
void k() {
char a = 'a'; // matches and fetches the character a
char nl = '\n'; // does not match
(void)a; (void)nl;
}
int main() { return 0; } |
escapeSequence(CharLiteral self, Cpp.EscapeSequence.EscapeSequence &escape)
| Finds an escape sequence inside a char_literal (like '\n', '\\', '\x20') and returns it as escape. | This PQL defect checks for character literals that contain an escape sequence. defect find_escape_sequence =
when
Cpp.CharLiteral.is(&lit)
and lit.escapeSequence(&escape)
and escape.nodeText(&val)
raise "Escape sequence in char literal: {val}"
on litIn this C++ code, the defect retrieves the inner
token for
void k() {
char a = 'a'; // does not match
char nl = '\n'; // matches and fetches the token \n
(void)a; (void)nl;
}
int main() { return 0; } |
getEnclosingCharLiteral(Cpp.Node.Node child, required CharLiteral &parent)
| Finds the nearest enclosing char_literal that contains the given child node and returns it as parent. | This PQL defect checks for nodes that are inside a
defect enclosing_char_literal =
when
Cpp.Node.is(&inner, &,&,&)
and Cpp.CharLiteral.getEnclosingCharLiteral(inner, &lit)
and lit.nodeText(&txt)
raise "Inner node is inside char literal: {txt}"
on litIn this C++ code, the defect locates the
void n() {
char nl = '\n';
(void)nl;
}
|
isEnclosedInCharLiteral(Cpp.Node.Node child)
| Returns true when the given child node has a
char_literal ancestor. Use for finding nodes that appear inside
character literals. | This PQL defect checks whether a node sits somewhere within a
defect node_within_char_literal =
when
Cpp.Node.is(&inner, &,&,&)
and Cpp.CharLiteral.isEnclosedInCharLiteral(inner)
raise "Node is enclosed in a char literal"
on innerIn this C++ code, the defect finds all child
nodes of a
void p() {
char t = '\t';
(void)t;
}
|
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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- 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)