Cpp.FunctionDefinition Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the function_definition nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.FunctionDefinition represents the node function_definition in the syntax tree of your code.
// example demonstrating a simple function definition
int add(int a, int b) { return a + b; }The C++ line int add(int a, int b) { return a + b; } contains a function_definition node which corresponds to Cpp.FunctionDefinition in PQL.
Predicates
| Type | Raisable | Printable |
|---|---|---|
FunctionDefinition
| 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 FunctionDefinition &fd)
| Matches a function_definition node and binds it to the
output variable &fd. Use it to select function definition
nodes for further inspection. | This PQL defect checks for any function definition node in a translation unit. defect anyFunction =
when
Cpp.FunctionDefinition.is(&fd)
and fd.nodeText(&txt)
raise "Found function: \"{txt}\""
on fdIn this C++ code the defect finds the top-level function definition.
int add(int a, int b) { return a + b; } |
cast(Cpp.Node.Node node, required FunctionDefinition &cast)
| Checks whether a node (a generic Node) is
a function_definition and if so binds it to
&cast for using FunctionDefinition
predicates. | This PQL defect checks whether a generic node is specifically a
defect castCheck =
when
Cpp.FunctionDeclarator.is(&fd)
and fd.getAnAncestor(&node)
and Cpp.FunctionDefinition.cast(node, &fud)
and fud.nodeText(&txt)
raise "cast to FunctionDefinition matched: \"{txt}\""
on fudIn this C++ code the defect finds a function declarator and then from its list of ancestor node, finds the function definition by cast.
int add(int a, int b) { return a + b; } |
isa(Cpp.Node.Node node)
| Returns true when the given generic node is a
function_definition. Use it for tests or negation. | This PQL defect checks that a node is a
defect isaCheck =
when
Cpp.FunctionDeclarator.is(&fd)
and fd.getAnAncestor(&node)
and Cpp.FunctionDefinition.is(node)
and node.nodeText(&txt)
raise "FunctionDefinition matched: \"{txt}\""
on nodeIn this C++ code the defect verifies that a declarator corresponds to a function definition.
int add(int a, int b) { return a + b; } |
body(FunctionDefinition self, Cpp.Node.Node &child)
| Matches the function body node (the compound statement or
try-body) and binds it to
&child. | This PQL defect checks for function bodies within
defect bodyCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.body(&body)
and body.nodeText(&txt)
raise "Function body: \"{txt}\""
on fdIn this C++ code the defect finds the function definition.
void foo() { return; } |
declarator(FunctionDefinition self, Cpp.Node.Node &child)
| Matches the declarator portion (identifier and parameters) of the function and
binds it to &child. | This PQL defect checks for function declarators like
defect declCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.declarator(&decl)
and decl.nodeText(&txt)
raise "Declarator: \"{txt}\""
on fdIn this C++ code the defect finds the
int add(int a, int b) { return a + b; } |
type(FunctionDefinition self, Cpp.Node.Node &child)
| Matches the return type node of the function and binds it to
&child. | This PQL defect checks for the function return type. defect typeCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.type(&t)
and t.nodeText(&txt)
raise "Return type: \"{txt}\""
on fdIn this C++ code the defect finds the
int add(int a, int b) { return a + b; } |
msDeclspecModifier(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches a Microsoft __declspec(...) modifier attached to the
function and binds it to &child. | This PQL defect checks for defect msdCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.msDeclspecModifier(&ms)
and ms.nodeText(&txt)
raise "ms declspec: \"{txt}\""
on fdIn this C++ code the defect finds the
__declspec(dllexport) void foo() {} |
defaultMethodClause(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches the = default clause on special member functions and
binds it to &child. | This PQL defect checks for defaulted special member functions. defect defaultCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.defaultMethodClause(&d)
and d.nodeText(&txt)
raise "default clause: \"{txt}\""
on fdIn this C++ code the defect finds the
struct S { S() = default; }; |
pureVirtualClause(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches the = 0 pure virtual clause on virtual functions and
binds it to &child. | This PQL defect checks for pure virtual functions. defect pureCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.pureVirtualClause(&pv)
and pv.nodeText(&txt)
raise "pure virtual clause: \"{txt}\""
on fdIn this C++ code the defect finds the
struct I { virtual void f() = 0; }; |
deleteMethodClause(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches the = delete clause on functions and binds it to
&child. | This PQL defect checks for deleted functions. defect deleteCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.deleteMethodClause(&del)
and del.nodeText(&txt)
raise "deleted: \"{txt}\""
on fdIn this C++ code the defect finds the
struct S { S(const S&) = delete; }; |
storageClassSpecifier(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches storage class specifiers like static or
extern on the function and binds it to
&child. | This PQL defect checks for storage class specifiers on functions. defect storageCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.storageClassSpecifier(&sc)
and sc.nodeText(&txt)
raise "storage specifier: \"{txt}\""
on fdIn this C++ code the defect finds the
static void helper() {} |
explicitFunctionSpecifier(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches the explicit specifier on converting operator
functions and binds it to &child. | This PQL defect checks for defect explicitCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.explicitFunctionSpecifier(&efs)
and efs.nodeText(&txt)
raise "explicit specifier: \"{txt}\""
on fdIn this C++ code the defect finds the
struct S { explicit operator bool() const { return true; } }; |
tryStatement(FunctionDefinition self, Cpp.Node.Node &child)
| Matches a function's try block header and its guarded body
and binds it to &child. | This PQL defect checks for function-level defect tryCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.tryStatement(&ts)
and ts.nodeText(&txt)
raise "try statement: \"{txt}\""
on fdIn this C++ code the defect finds the
void foo() try { throw 1; } catch(...) {} |
fieldInitializerList(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches the member initializer list (: a(0), b(1)) in
constructors and binds it to &child. | This PQL defect checks for constructor initializer lists. defect initListCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.fieldInitializerList(&fi)
and fi.nodeText(&txt)
raise "initializer list: \"{txt}\""
on fdIn this C++ code the defect finds the
struct Foo { int bar; Foo(): bar(0) {} }; |
attributeDeclaration(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches attribute declarations attached to the function (e.g.
[[nodiscard]]) and binds it to
&child. | This PQL defect checks for attribute declarations applied to functions. defect attrDeclCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.attributeDeclaration(&ad)
and ad.nodeText(&txt)
raise "attribute decl: \"{txt}\""
on fdIn this C++ code the defect finds the
[[nodiscard]] int foo() { return 1; } |
typeQualifier(FunctionDefinition self, Cpp.Node.Node &child)
| Matches qualifiers on the function like const or
volatile and binds the qualifier node to
&child. | This PQL defect checks for qualifiers on member functions. defect qualifierCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.typeQualifier(&tq)
and tq.nodeText(&txt)
raise "type qualifier: \"{txt}\""
on fdIn this C++ code the defect finds the
struct S { void f() const {} }; |
msCallModifier(FunctionDefinition self, Cpp.Node.Node &child)
| Matches Microsoft calling convention modifiers like
__stdcall and binds it to
&child. | This PQL defect checks for MS calling convention modifiers on functions. defect msCallCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.msCallModifier(&mc)
and mc.nodeText(&txt)
raise "MS call modifier: \"{txt}\""
on fdIn this C++ code the defect finds the
void __stdcall foo() {} |
attributeSpecifier(FunctionDefinition self, Cpp.Node.Node
&child)
| Matches trailing attributes placed after the function declarator like
[[nodiscard]] and binds it to
&child. | This PQL defect checks for trailing attribute specifiers on functions. defect attrSpecCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.attributeSpecifier(&as)
and as.nodeText(&txt)
raise "attribute specifier: \"{txt}\""
on fdIn this C++ code the defect finds
int foo() [[nodiscard]] { return 0; } |
virtual(FunctionDefinition self, Cpp.Node.Node &child)
| Matches the virtual keyword on a member function and binds
it to &child. | This PQL defect checks for functions declared
defect virtualCheck =
when
Cpp.FunctionDefinition.is(&fd)
and fd.virtual(&v)
and v.nodeText(&txt)
raise "virtual keyword: \"{txt}\""
on fdIn this C++ code the defect finds the
struct B { virtual void f() {} }; |
getEnclosingFunctionDefinition(Cpp.Node.Node child, required
FunctionDefinition &parent)
| Finds the nearest enclosing function_definition ancestor of
the given child node and binds it to
&parent. | This PQL defect checks which function encloses a given inner node such as an identifier. defect enclosingCheck =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.FunctionDefinition.getEnclosingFunctionDefinition(node, &fd)
and fd.nodeText(&txt)
raise "Enclosing function: \"{txt}\""
on fdIn this C++ code the defect finds the function that encloses the generic node.
int sum(int x) { return x + 1; } |
isEnclosedInFunctionDefinition(Cpp.Node.Node child)
| Returns true when the given child node has a
function_definition ancestor somewhere above it. | This PQL defect checks whether a node is located inside any function body. defect enclosedCheck =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.FunctionDefinition.isEnclosedInFunctionDefinition(node)
raise "Identifier is inside a function"
on nodeIn this C++ code the defect confirms that the
identifier
int sum(int x) { return x + 1; } |
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)