Cpp.GnuAsmExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the gnu_asm_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.GnuAsmExpression represents the node gnu_asm_expression in the syntax tree of your code.
void foo(int input, int result) {
asm("mov %0, %1" : "=r"(result) : "r"(input) : "memory");
asm volatile("nop");
asm goto("jmp %l0" : : : : mylabel);
mylabel:
return;
}The example contains three GNU inline-assembly expressions and each asm(...) occurrence corresponds to a gnu_asm_expression node matched by Cpp.GnuAsmExpression.
Predicates
| Type | Raisable | Printable |
|---|---|---|
GnuAsmExpression
| 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 GnuAsmExpression &gae)
| Matches a gnu_asm_expression and binds it to
gae for further queries on that assembly expression. | This PQL defect checks for any GNU inline-assembly expressions in the source. defect has_asm =
when
Cpp.GnuAsmExpression.is(&gae)
and gae.nodeText(&txt)
raise "Found asm: \"{txt}\""
on gaeIn this C++ code, the defect finds each
void f() { asm("nop"); } |
cast(Cpp.Node.Node node, required GnuAsmExpression &cast)
| Checks whether a Cpp.Node.Node instance is a
gnu_asm_expression and if so binds it to
cast for GnuAsmExpression-specific predicates. | This PQL defect checks whether a generic node represents a GNU inline-assembly expression. defect node_to_asm =
when
Cpp.ExpressionStatement.is(&expr)
and expr.getADescendant(&node)
and Cpp.GnuAsmExpression.cast(node, &gae)
and gae.nodeText(&txt)
raise "Node cast to GnuAsmExpression: \"{txt}\""
on gaeIn this C++ code, the defect finds a gnu asm expression node within an expression statement.
void g() { asm volatile("nop"); } |
isa(Cpp.Node.Node node)
| Returns true when the given Cpp.Node.Node is a
gnu_asm_expression enabling boolean checks or negation. | This PQL defect checks for nodes that are specifically
defect node_to_asm =
when
Cpp.ExpressionStatement.is(&expr)
and expr.getADescendant(&node)
and Cpp.GnuAsmExpression.isa(node)
and node.nodeText(&txt)
raise "Node cast to GnuAsmExpression: \"{txt}\""
on nodeIn this C++ code, the defect finds asm nodes within expression statements.
void h() { asm("mov %0, %1" : "=r"(0) : "r"(1)); } |
assemblyCode(GnuAsmExpression self, Cpp.Node.Node &child)
| Matches the assembly template string portion of the asm(...)
expression and binds that child node to child. | This PQL defect checks for the assembly template (the quoted instruction
string) inside a
defect check_assembly_code =
when
Cpp.GnuAsmExpression.is(&gae)
and gae.assemblyCode(&ac)
and ac.nodeText(&txt)
raise "Assembly template: \"{txt}\""
on gaeIn this C++ code, the defect extracts the
void f2(int in, int &out) {
asm("mov %0, %1" : "=r"(out) : "r"(in));
} |
clobbers(GnuAsmExpression self, Cpp.Node.Node &child)
| Matches each clobber-list entry in the asm expression and
binds that entry to child. | This PQL defect checks for clobber entries such as
defect check_clobber =
when
Cpp.GnuAsmExpression.is(&gae)
and gae.clobbers(&cl)
and cl.nodeText(&txt)
raise "Clobber: \"{txt}\""
on gaeIn this C++ code, the defect finds the
void f3() { asm("mov %0, %1" : : : "memory"); } |
gotoLabels(GnuAsmExpression self, Cpp.Node.Node &child)
| Matches label identifiers listed in an asm goto(...)
expression and binds each label to child. | This PQL defect checks for goto labels referenced by an defect check_goto_label =
when
Cpp.GnuAsmExpression.is(&gae)
and gae.gotoLabels(&gl)
and gl.nodeText(&txt)
raise "Goto label: \"{txt}\""
on gaeIn this C++ code, the defect detects the
void f4() {
asm goto("jmp %l0" : : : : mylabel);
mylabel:
return;
} |
inputOperands(GnuAsmExpression self, Cpp.Node.Node &child)
| Matches each input operand (constraint plus expression) in the
asm(...) input operand list and binds it to
child. | This PQL defect checks for input operand expressions like
defect check_input_operand =
when
Cpp.GnuAsmExpression.is(&gae)
and gae.inputOperands(&io)
and io.nodeText(&txt)
raise "Input operand: \"{txt}\""
on gaeIn this C++ code, the defect finds the
void f5(int input) {
int out;
asm("mov %0, %1" : "=r"(out) : "r"(input));
} |
outputOperands(GnuAsmExpression self, Cpp.Node.Node &child)
| Matches each output operand (constraint plus lvalue) in the
asm(...) output list and binds it to
child. | This PQL defect checks for output operands such as
defect check_output_operand =
when
Cpp.GnuAsmExpression.is(&gae)
and gae.outputOperands(&oo)
and oo.nodeText(&txt)
raise "Output operand: \"{txt}\""
on gaeIn this C++ code, the defect captures the
void f6(int input, int &result) {
asm("mov %0, %1" : "=r"(result) : "r"(input));
} |
gnuAsmQualifier(GnuAsmExpression self, Cpp.Node.Node &child)
| Matches qualifiers applied to the asm keyword such as
volatile or inline and binds the qualifier
token to child. | This PQL defect checks for qualifiers like defect check_qualifier =
when
Cpp.GnuAsmExpression.is(&gae)
and gae.gnuAsmQualifier(&q)
and q.nodeText(&txt)
raise "Gnu asm qualifier: \"{txt}\""
on gaeIn this C++ code, the defect identifies the
void f7() { asm volatile("nop"); } |
getEnclosingGnuAsmExpression(Cpp.Node.Node child, required GnuAsmExpression
&parent)
| Finds the nearest ancestor gnu_asm_expression node that
encloses the given child node and binds it to
parent. | This PQL defect checks for the closest enclosing
defect enclosing_asm =
when
Cpp.StringLiteral.is(&SL)
and SL.toNode(&inner)
and Cpp.GnuAsmExpression.getEnclosingGnuAsmExpression(inner, &gae)
and gae.nodeText(&txt)
raise "Enclosing asm: \"{txt}\""
on gaeIn this C++ code, the defect locates the asm
expression that contains the string literal
void f8(int in, int &out) {
asm("mov %0, %1" : "=r"(out) : "r"(in));
} |
isEnclosedInGnuAsmExpression(Cpp.Node.Node child)
| Returns true when the provided child node has any ancestor
that is a gnu_asm_expression. | This PQL defect checks whether a atring literal node is located anywhere
inside a
defect inside_asm =
when
Cpp.StringLiteral.is(&SL)
and SL.toNode(&tok)
and Cpp.GnuAsmExpression.isEnclosedInGnuAsmExpression(tok)
raise "String literal is inside an asm expression"
on tokIn this C++ code, the defect flags string literals inside the asm expression.
void f9() { asm("nop"); } |
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)