Cpp.Declaration Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the declaration nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.Declaration represents the node declaration in the syntax tree of your code.
int x = 42; static const int y = 7; [[nodiscard]] int f(); virtual void m(); __declspec(dllexport) int z;
The example contains several declaration nodes. Examples: int
x = 42; is a declaration whose type is int,
declarator is x and default value is 42.
Predicates
| Type | Raisable | Printable |
|---|---|---|
Declaration
| 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 Declaration &declaration)
| Match a declaration node and bind it to
declaration. Use this to locate declaration nodes
directly. | This PQL defect checks for any top-level defect decl_is =
when
Cpp.Declaration.is(&decl)
and decl.nodeText(&txt)
raise "Declaration.is matched: \"{txt}\""
on declIn this C++ code the defect finds each complete declaration such as variable and function declarations.
int x = 42; static const int y = 7; |
cast(Cpp.Node.Node node, required Declaration &cast)
| Check whether a Cpp.Node.Node is a
declaration and bind it to cast. Use when
you start from a generic node and need Declaration properties. | This PQL defect checks whether a generic node is a
defect decl_cast =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.Declaration.cast(node, &decl)
and decl.nodeText(&txt)
raise "Declaration.cast matched: \"{txt}\""
on declIn this C++ code the defect find all generic
syntax nodes and then casts to
int x = 42; |
isa(Cpp.Node.Node node)
| Check whether a Cpp.Node.Node is a
declaration. Use for boolean checks or negation. | This PQL defect checks whether a generic node is a
defect decl_isa =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.Declaration.is(node)
raise "Declaration.isa matched on node"
on nodeIn this C++ code the defect verifies that the node
representing
int x = 42; |
declarator(Declaration self, Cpp.Node.Node &child)
| Bind a child node that represents the declarator part of the declaration such as an identifier or declarator list. | This PQL defect checks for declarator child nodes within a
defect decl_declarator =
when
Cpp.Declaration.is(&decl)
and decl.declarator(&d)
and d.nodeText(&txt)
raise "Declaration.declarator matched: \"{txt}\""
on dIn this C++ code the defect finds the declarator
int x = 42; |
defaultValue(Declaration self, Cpp.Node.Node &child)
| Bind the initializer expression node on the right-hand side of a declaration assignment. | This PQL defect checks for default initializer expressions inside declarations. defect decl_defaultValue =
when
Cpp.Declaration.is(&decl)
and decl.defaultValue(&val)
and val.nodeText(&txt)
raise "Declaration.defaultValue matched: \"{txt}\""
on valIn this C++ code the defect finds the initializer
expression
int x = 42; |
type(Declaration self, Cpp.Node.Node &child)
| Bind the child node that represents the type specifier of the declaration. | This PQL defect checks for the type node of a declaration. defect decl_type =
when
Cpp.Declaration.is(&decl)
and decl.type(&t)
and t.nodeText(&txt)
raise "Declaration.type matched: \"{txt}\""
on tIn this C++ code the defect extracts the type
int x = 42; |
value(Declaration self, Cpp.Node.Node &child)
| Bind the expression node representing the value of a declaration when present. | This PQL defect checks for the expression node that represents a declaration's value. defect decl_value =
when
Cpp.Declaration.is(&decl)
and decl.value(&v)
and v.nodeText(&txt)
raise "Declaration.value matched: \"{txt}\""
on vIn this C++ code the defect finds the expression
int x = 42; |
attributeDeclaration(Declaration self, Cpp.Node.Node &child)
| Bind an attribute-declaration child such as [[nodiscard]]
attached to the declaration. | This PQL defect checks for attribute-declaration child nodes on declarations. defect decl_attributeDeclaration =
when
Cpp.Declaration.is(&decl)
and decl.attributeDeclaration(&attr)
and attr.nodeText(&txt)
raise "Declaration.attributeDeclaration matched: \"{txt}\""
on attrIn this C++ code the defect finds the attribute
[[nodiscard]] int f(); |
virtual_(Declaration self, Cpp.Node.Node &child)
| Bind the virtual keyword token when it appears as part of a
declaration. | This PQL defect checks for a defect decl_virtual =
when
Cpp.Declaration.is(&decl)
and decl.virtual_(&v)
and v.nodeText(&txt)
raise "Declaration.virtual matched: \"{txt}\""
on vIn this C++ code the defect finds the
struct C { virtual void m(); }; |
attributeSpecifier(Declaration self, Cpp.Node.Node &child)
| Bind individual attribute specifiers inside an attribute declaration such as
the specifiers within [[...]]. | This PQL defect checks for attribute specifiers on declarations. defect decl_attributeSpecifier =
when
Cpp.Declaration.is(&decl)
and decl.attributeSpecifier(&spec)
and spec.nodeText(&txt)
raise "Declaration.attributeSpecifier matched: \"{txt}\""
on specIn this C++ code the defect locates the inner
specifier like
[[nodiscard]] int f(); |
explicitFunctionSpecifier(Declaration self, Cpp.Node.Node
&child)
| Bind the explicit keyword when used as a function specifier
in a declaration. | This PQL defect checks for the defect decl_explicitFunctionSpecifier =
when
Cpp.Declaration.is(&decl)
and decl.explicitFunctionSpecifier(&e)
and e.nodeText(&txt)
raise "Declaration.explicitFunctionSpecifier matched: \"{txt}\""
on eIn this C++ code the defect finds
struct S { explicit operator bool(); }; |
msDeclspecModifier(Declaration self, Cpp.Node.Node &child)
| Bind Microsoft __declspec(...) modifiers attached to the
declaration. | This PQL defect checks for defect decl_msDeclspecModifier =
when
Cpp.Declaration.is(&decl)
and decl.msDeclspecModifier(&m)
and m.nodeText(&txt)
raise "Declaration.msDeclspecModifier matched: \"{txt}\""
on mIn this C++ code the defect detects
__declspec(dllexport) int z; |
storageClassSpecifier(Declaration self, Cpp.Node.Node &child)
| Bind storage-class specifiers such as static,
extern, or auto in the declaration. | This PQL defect checks for storage-class specifiers on declarations. defect decl_storageClassSpecifier =
when
Cpp.Declaration.is(&decl)
and decl.storageClassSpecifier(&s)
and s.nodeText(&txt)
raise "Declaration.storageClassSpecifier matched: \"{txt}\""
on sIn this C++ code the defect finds the
static const int y = 7; |
typeQualifier(Declaration self, Cpp.Node.Node &child)
| Bind type qualifiers like const,
volatile, or restrict that appear in the
declaration type. | This PQL defect checks for type qualifiers applied in declarations. defect decl_typeQualifier =
when
Cpp.Declaration.is(&decl)
and decl.typeQualifier(&q)
and q.nodeText(&txt)
raise "Declaration.typeQualifier matched: \"{txt}\""
on qIn this C++ code the defect finds the
static const int y = 7; |
getEnclosingDeclaration(Cpp.Node.Node child, required Declaration
&parent)
| Find the closest ancestor declaration for a given
Node and bind it to parent. Use when you
start from a child node and need its declaration. | This PQL defect checks for the nearest enclosing
defect decl_getEnclosingDeclaration =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.Declaration.getEnclosingDeclaration(node, &parent)
and parent.nodeText(&txt)
raise "getEnclosingDeclaration found: \"{txt}\""
on parentIn this C++ code the defect starts from declarator
int x = 42; |
isEnclosedInDeclaration(Cpp.Node.Node child)
| Check whether a given Node has a
declaration ancestor. Use for boolean checks of
containment. | This PQL defect checks whether a node obtained from another syntax node
is enclosed in any
defect decl_isEnclosedInDeclaration =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.Declaration.isEnclosedInDeclaration(node)
raise "Node is enclosed in a Declaration"
on nodeIn this C++ code the defect verifies that the
declarator node for
int x = 42; |
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)