Cpp.CompoundStatement Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the compound_statement nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.CompoundStatement represents the node compound_statement in the syntax tree of your code.
void f() {
int x = 0;
{
x++;
}
}The outer and inner block bodies in f correspond to compound_statement nodes and are what Cpp.CompoundStatement models.
Predicates
| Type | Raisable | Printable |
|---|---|---|
CompoundStatement
| 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 CompoundStatement &compoundStatement)
| Matches a compound_statement and returns it as the output
variable. Use it to start queries on a block. | This PQL defect checks for a compound statement node. defect d = when
Cpp.CompoundStatement.is(&block)
raise "Found a compound statement" on blockIn this C++ code the defect finds the function body block.
void f() { int x = 0; } |
cast(Cpp.Node.Node node, required CompoundStatement &cast)
| Checks whether the node is a
compound_statement and if so returns it as
cast. | This PQL defect checks whether an arbitrary node can be treated as a
defect d = when
Cpp.Node.is(&n,&,&,&)
and Cpp.CompoundStatement.cast(n, &blk)
raise "Casted node is a compound statement" on blkIn this C++ code the defect finds compound statements.
int g() { return 1; } |
isa(Cpp.Node.Node node)
| Returns true if node is a
compound_statement. Use it when you only need a boolean
check. | This PQL defect checks whether a node is a
defect d = when
Cpp.Node.is(&n,&,&,&)
and Cpp.CompoundStatement.isa(n)
raise "Node is a compound statement" on fnIn this C++ code the defect finds compound statements.
void h() { } |
preprocInclude(CompoundStatement self, Cpp.Node.Node &child)
| Matches an #include directive that appears inside the
compound statement and returns it as child. | This PQL defect checks for defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.preprocInclude(&inc)
raise "include in block" on inc |
statement(CompoundStatement self, Cpp.Node.Node &child)
| Matches a statement (expression or control statement) directly inside the block and binds it. | This PQL defect checks for a statement node inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.statement(&stmt)
raise "statement in block: {stmt}" on stmt |
staticAssertDeclaration(CompoundStatement self, Cpp.Node.Node
&child)
| Matches a static_assert declaration inside the block and
binds it. | This PQL defect checks for defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.staticAssertDeclaration(&sa)
raise "static_assert in block" on sa |
templateDeclaration(CompoundStatement self, Cpp.Node.Node
&child)
| Matches a template declaration placed inside the block and binds it. | This PQL defect checks for a defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.templateDeclaration(&t)
raise "template declaration in block" on t |
templateInstantiation(CompoundStatement self, Cpp.Node.Node
&child)
| Matches an instantiation of a template (e.g.
foo<int>()) inside the block and binds it. | This PQL defect checks for template instantiations within a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.templateInstantiation(&ti)
raise "template instantiation in block" on ti |
typeDefinition(CompoundStatement self, Cpp.Node.Node &child)
| Matches type definition statements like typedef or
using-alias definitions inside the block and binds
them. | This PQL defect checks for type definitions inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.typeDefinition(&td)
raise "type definition in block" on td |
typeSpecifier(CompoundStatement self, Cpp.Node.Node &child)
| Matches a type specifier (like unsigned int or
enum specifier) occurring inside the block and binds
it. | This PQL defect checks for type specifiers used inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.typeSpecifier(&ts)
raise "type specifier in block" on ts |
usingDeclaration(CompoundStatement self, Cpp.Node.Node
&child)
| Matches a using declaration (e.g. using
std::cout;) inside the block and binds it. | This PQL defect checks for defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.usingDeclaration(&u)
raise "using declaration in block" on u |
aliasDeclaration(CompoundStatement self, Cpp.Node.Node
&child)
| Matches an alias declaration like using foo = bar; inside
the block and binds it. | This PQL defect checks for alias declarations in a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.aliasDeclaration(&a)
raise "alias declaration in block" on a |
conceptDefinition(CompoundStatement self, Cpp.Node.Node
&child)
| Matches a C++20 concept definition inside a block and binds
it. | This PQL defect checks for concept definitions nested in compound statements. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.conceptDefinition(&c)
raise "concept inside block" on c |
declaration(CompoundStatement self, Cpp.Node.Node &child)
| Matches general declarations (variable, function, etc.) directly inside the block and binds them. | This PQL defect checks for declarations within a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.declaration(&decl)
raise "declaration in block" on decl |
functionDefinition(CompoundStatement self, Cpp.Node.Node
&child)
| Matches a function definition that appears nested inside the block and binds it. | This PQL defect checks for nested function definitions inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.functionDefinition(&fd)
raise "function definition inside block" on fd |
linkageSpecification(CompoundStatement self, Cpp.Node.Node
&child)
| Matches an extern "C" { ... } linkage specification inside
the block and binds it. | This PQL defect checks for linkage specification blocks inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.linkageSpecification(&ls)
raise "linkage spec in block" on ls |
namespaceAliasDefinition(CompoundStatement self, Cpp.Node.Node
&child)
| Matches a namespace alias like namespace foo = bar; inside
the block and binds it. | This PQL defect checks for namespace alias definitions inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.namespaceAliasDefinition(&na)
raise "namespace alias in block" on na |
namespaceDefinition(CompoundStatement self, Cpp.Node.Node
&child)
| Matches a namespace { ... } definition placed inside the
block and binds it. | This PQL defect checks for namespace definitions nested inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.namespaceDefinition(&ns)
raise "namespace in block" on ns |
preprocCall(CompoundStatement self, Cpp.Node.Node &child)
| Matches preprocessor directives that are calls or conditionals like
#pragma or #ifdef and binds them. | This PQL defect checks for preprocessor calls inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.preprocCall(&pc)
raise "preproc call in block" on pc |
preprocDef(CompoundStatement self, Cpp.Node.Node &child)
| Matches a preprocessor #define inside the block and binds
it. | This PQL defect checks for macro definitions inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.preprocDef(&md)
raise "macro defined in block" on md |
preprocFunctionDef(CompoundStatement self, Cpp.Node.Node
&child)
| Matches function-like macro definitions such as #define FOO(x)
(x) inside the block and binds them. | This PQL defect checks for function-like macro definitions inside a compound statement. defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.preprocFunctionDef(&mf)
raise "function-like macro in block" on mf |
preprocIf(CompoundStatement self, Cpp.Node.Node &child)
| Matches #if / #elif conditional
preprocessor directives inside the block and binds them. | This PQL defect checks for defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.preprocIf(&pi)
raise "preproc if in block" on pi |
preprocIfdef(CompoundStatement self, Cpp.Node.Node &child)
| Matches #ifdef / #ifndef directives
inside the block and binds them. | This PQL defect checks for defect d = when
Cpp.CompoundStatement.is(&blk)
and blk.preprocIfdef(&pd)
raise "preproc ifdef in block" on pd |
getEnclosingCompoundStatement(Cpp.Node.Node child, required
CompoundStatement &parent)
| Finds the nearest ancestor compound_statement of
child and returns it as parent. | This PQL defect checks which compound statement encloses a given node. defect d = when
Cpp.Statement.is(&s)
and s.toNode(&n)
and Cpp.CompoundStatement.getEnclosingCompoundStatement(n, &blk)
raise "enclosing block found" on blk |
isEnclosedInCompoundStatement(Cpp.Node.Node child)
| Returns true if child has any ancestor that is a
compound_statement. | This PQL defect checks whether a node is nested inside any compound statement. defect d = when
Cpp.Declaration.is(&decl)
and decl.toNode(&n)
and Cpp.CompoundStatement.isEnclosedInCompoundStatement(n)
raise "declaration is enclosed in a block" on decl |
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)