Cpp.ArrayDeclarator Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the array_declarator nodes in the syntax tree of your code
Since R2026a
Description
The PQL class ArrayDeclarator represents the node array_declarator in the syntax tree of your code.
// Example showing several kinds of array declarators int a[10]; int b[const 20]; int c[static const 30]; int d[]; int (*e)[40];
The examples above include array_declarator nodes:
a[10], b[const 20], c[static const
30], d[], and the pointer-to-array (*e)[40],
all of which correspond to array_declarator nodes.
Predicates
| Type | Raisable | Printable |
|---|---|---|
ArrayDeclarator
| No | 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 ArrayDeclarator &decl)
| Matches any array_declarator node and returns it as decl. Use this to directly find array declarators in code. |
This PQL defect checks for any array declarator node. defect find_arrays =
when
Cpp.ArrayDeclarator.is(&ad)
and ad.nodeText(&txt)
raise "Found array declarator: \"{txt}\""
on adIn this C++ code, the defect finds simple array declarations like
int a[10]; |
cast(Cpp.Node.Node node, required ArrayDeclarator &cast)
| Checks whether a generic Cpp.Node.Node is an array_declarator; if so, returns it as cast. Use this when you start from a generic node and need array-specific predicates. | This PQL defect checks whether a captured generic node is an array declarator. defect cast_if_array =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.ArrayDeclarator.cast(n, &ad)
and ad.nodeText(&txt)
raise "Node is array_declarator: \"{txt}\""
on adIn this C++ code, the defect finds a generic node that
resolves to the
int a[10]; |
isa(Cpp.Node.Node node)
| True if the provided generic node is an array_declarator. Useful for conditional checks or negations like not Cpp.ArrayDeclarator.isa(n). | This PQL defect checks for nodes that are array declarators. defect isa_check =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.ArrayDeclarator.isa(n)
raise "Node is an array_declarator"
on nIn this C++ code, the defect will identify that the
node corresponding to
int b[20]; |
declarator(ArrayDeclarator self, Cpp.Node.Node &child)
| Returns the nested declarator (the thing being declared) inside the array_declarator, e.g., the identifier or pointer declarator. | This PQL defect checks for the inner declarator node contained in an
defect find_inner_declarator =
when
Cpp.ArrayDeclarator.is(&ad)
and ad.declarator(&inner)
and inner.nodeText(&txt)
raise "Inner declarator: \"{txt}\""
on ad |
size(ArrayDeclarator self, Cpp.Node.Node &child)
| Returns the size expression node inside the brackets (e.g., 10, const 20, 30). |
This PQL defect checks for the size expression of an defect find_size_expr =
when
Cpp.ArrayDeclarator.is(&ad)
and ad.size(&sz)
and sz.nodeText(&txt)
raise "Array size expression: \"{txt}\""
on adIn this C++ code, the defect finds the literal
int a[10]; |
typeQualifier(ArrayDeclarator self, Cpp.Node.Node &child)
| Returns any type qualifier node present in the array size, such as const, static, or combinations like static const. |
This PQL defect checks for type qualifiers used inside an array declarator's size. defect find_type_qualifier =
when
Cpp.ArrayDeclarator.is(&ad)
and ad.typeQualifier(&tq)
and tq.nodeText(&txt)
raise "Array type qualifier: \"{txt}\""
on adIn this C++ code, the defect locates
int b[const 20]; |
getEnclosingArrayDeclarator(Cpp.Node.Node child, required ArrayDeclarator &parent)
| Finds the closest enclosing array_declarator ancestor of child and returns it as parent. Use this to determine which array a subnode belongs to. | This PQL defect checks for a node that has an enclosing array declarator node. defect enclosing_array =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.ArrayDeclarator.getEnclosingArrayDeclarator(n, &ad)
and n.nodeText(&txt)
raise "Node that has a parent array declarator: \"{txt}\""
on nIn this C++ code, the defect find all nodes that are child nodes of the array declarator.
int a[10]; |
isEnclosedInArrayDeclarator(Cpp.Node.Node child) | Matches each array_declarator ancestor parent of child. Use this when you need all array declarator ancestors rather than just the nearest. | This PQL defect checks for generic nodes that have an ancestral array declarator node. defect all_enclosing_arrays =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.ArrayDeclarator.isEnclosedInArrayDeclarator(n)
and n.nodeText(&txt)
raise "Has ancestor array declarator: \"{txt}\""
on nIn this C++ code, the defect finds the array declarator
int a[10]; |
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)