Cpp.PreprocIfdef Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the preproc_ifdef nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.PreprocIfdef represents the node preproc_ifdef in the syntax tree of your code.
#define FOO #ifdef FOO int x = 1; #else int x = 2; #endif
The #ifdef ... #else ... #endif block in the example corresponds to the
preproc_ifdef node and is represented by
Cpp.PreprocIfdef.
Predicates
| Type | Raisable | Printable |
|---|---|---|
PreprocIfdef
| 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 PreprocIfdef &preprocIfdef)
| Matches a preproc_ifdef node and returns it as
preprocIfdef. | This PQL defect checks for occurrences of
defect preprocifdef_is =
when
Cpp.PreprocIfdef.is(&ifdef)
raise "found ifdef" on ifdefIn this C++ code, the defect
finds the
#ifdef FOO int x = 1; #endif |
cast(Cpp.Node.Node node, required PreprocIfdef &cast)
| Checks whether a generic Node is a
preproc_ifdef and if so returns it as
cast. | This PQL defect checks whether a given defect d =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.PreprocIfdef.cast(node, &ifdef)
raise "node is PreprocIfdef" on ifdefIn this code, the
defect finds the
#ifdef BAR
void bar() {}
#endif |
isa(Cpp.Node.Node node)
| Tests whether a Node is a
preproc_ifdef. | This PQL defect checks whether a generic node is a
defect d =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.PreprocIfdef.isa(node)
raise "isa confirms PreprocIfdef" on tmpThe check
detects the
#ifdef BAZ #include <vector> #endif |
alternative(PreprocIfdef self, Cpp.Node.Node &child)
| Matches the alternative branch (#else or
#elif) of the preproc_ifdef and returns it
as child. | This PQL defect checks for the presence of an defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.alternative(&alt)
raise "found alternative branch" on altIn this code, the
defect locates the
#ifdef FOO int x = 1; #else int x = 2; #endif |
name(PreprocIfdef self, Cpp.Node.Node &child)
| Matches the macro identifier used in the
#ifdef/#ifndef directive and returns it as
child. | This PQL defect checks for the macro name token within a
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.name(&n)
raise "macro name found" on nIn this code, the defect
identifies the macro token following
#ifdef CONFIG_ENABLED int x; #endif |
functionDefinition(PreprocIfdef self, Cpp.Node.Node &child)
| Matches a function definition located inside the
preproc_ifdef block and returns it as
child. | This PQL defect checks for function definitions that appear within an
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.functionDefinition(&fn)
raise "function inside ifdef" on fnIn this code, the
defect finds functions that are conditionally compiled inside the
#ifdef BAR
void bar() {}
#endif |
linkageSpecification(PreprocIfdef self, Cpp.Node.Node &child)
| Matches a linkage specification (for example extern "C" { ...
}) within the preproc_ifdef and returns it as
child. | This PQL defect checks for linkage specifications inside
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.linkageSpecification(&link)
raise "linkage spec in ifdef" on linkIn this code, the
defect detects
#ifdef USE_C
extern "C" {
void c_func();
}
#endif |
namespaceAliasDefinition(PreprocIfdef self, Cpp.Node.Node
&child)
| Matches a namespace alias declaration inside the
preproc_ifdef and returns it as
child. | This PQL defect checks for namespace alias declarations within conditional blocks. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.namespaceAliasDefinition(&alias)
raise "namespace alias in ifdef" on aliasIn this code,
the defect finds
#ifdef ALIAS namespace ns2 = ns1; #endif |
namespaceDefinition(PreprocIfdef self, Cpp.Node.Node &child)
| Matches a namespace block inside the
preproc_ifdef and returns it as
child. | This PQL defect checks for namespace definitions that are conditionally compiled. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.namespaceDefinition(&ns)
raise "namespace in ifdef" on nsIn this code, the defect detects namespaces introduced only under certain macros.
#ifdef ADD_NS
namespace extra { int a; }
#endif |
preprocCall(PreprocIfdef self, Cpp.Node.Node &child)
| Matches nested preprocessor calls inside the preproc_ifdef
and binds them to child. | This PQL defect checks for other preprocessor directives within a
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.preprocCall(&pc)
raise "preprocessor call inside ifdef" on pcIn this
code, the defect finds directives like
#ifdef FOO #define X 1 #endif |
preprocDef(PreprocIfdef self, Cpp.Node.Node &child)
| Matches a #define directive inside the
preproc_ifdef and returns it as
child. | This PQL defect checks specifically for defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.preprocDef(&ddef)
raise "define in ifdef" on ddefIn this code, the defect spots macros defined only when a guard is active.
#ifdef ENABLE_FEATURE #define FEATURE_FLAG 42 #endif |
preprocFunctionDef(PreprocIfdef self, Cpp.Node.Node &child)
| Matches a preprocessor function-like macro definition inside the
preproc_ifdef and returns it as
child. | This PQL defect checks for function-like macro definitions within
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.preprocFunctionDef(&m)
raise "function-like macro in ifdef" on mIn this code, the defect detects macros declared with parameters inside the conditional.
#ifdef MF #define LOG(fmt, ...) printf(fmt, ##__VA_ARGS__) #endif |
preprocIf(PreprocIfdef self, Cpp.Node.Node &child)
| Matches nested #if, #ifdef, or
#ifndef inside the preproc_ifdef and returns
it as child. | This PQL defect checks for nested preprocessor conditional blocks. defect d =
when
Cpp.PreprocIfdef.is(&outer)
and outer.preprocIf(&inner)
raise "nested preproc_if" on innerIn this code, the
defect finds inner
#ifdef OUTER #if INNER int x; #endif #endif |
preprocIfdef(PreprocIfdef self, Cpp.Node.Node &child)
| Matches nested preproc_ifdef nodes (another
#ifdef/#else/#endif)
inside this preproc_ifdef and returns it as
child. | This PQL defect checks for another defect d =
when
Cpp.PreprocIfdef.is(&outer)
and outer.preprocIfdef(&inner)
raise "nested ifdef" on innerIn this code, the defect
locates nested
#ifdef A #ifdef B int y; #endif #endif |
preprocInclude(PreprocIfdef self, Cpp.Node.Node &child)
| Matches #include directives inside the
preproc_ifdef and binds them to
child. | This PQL defect checks for headers included conditionally inside an
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.preprocInclude(&inc)
raise "include in ifdef" on incIn this code, the defect
detects
#ifdef BAZ #include <vector> #endif |
statement(PreprocIfdef self, Cpp.Node.Node &child)
| Matches a top-level statement or declaration inside the
preproc_ifdef and returns it as
child. | This PQL defect checks for general statements or declarations inside the
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.statement(&stmt)
raise "statement in ifdef" on stmtIn this code, the defect finds ordinary code statements that are conditionally compiled.
#ifdef FOO int x = 1; #endif |
staticAssertDeclaration(PreprocIfdef self, Cpp.Node.Node
&child)
| Matches static_assert declarations inside the
preproc_ifdef and binds them to
child. | This PQL defect checks for defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.staticAssertDeclaration(&sa)
raise "static_assert in ifdef" on saIn this code, the defect detects compile-time assertions present only when a macro is set.
#ifdef CHECK static_assert(sizeof(int) == 4, "int must be 4 bytes"); #endif |
templateDeclaration(PreprocIfdef self, Cpp.Node.Node &child)
| Matches template declarations inside the
preproc_ifdef and binds them to
child. | This PQL defect checks for template declarations that are conditionally compiled. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.templateDeclaration(&td)
raise "template in ifdef" on tdIn this code, the defect finds class or function templates present only under certain macros.
#ifdef USE_TEMPL
template<typename T> struct S { T v; };
#endif |
templateInstantiation(PreprocIfdef self, Cpp.Node.Node
&child)
| Matches explicit template instantiations inside the
preproc_ifdef and binds them to
child. | This PQL defect checks for defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.templateInstantiation(&ti)
raise "template instantiation in ifdef" on tiIn this
code, the defect flags
#ifdef INST template class std::vector<int>; #endif |
typeDefinition(PreprocIfdef self, Cpp.Node.Node &child)
| Matches typedef or using type definitions
inside the preproc_ifdef and binds them to
child. | This PQL defect checks for type aliases and typedefs inside conditional blocks. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.typeDefinition(&td)
raise "type definition in ifdef" on tdIn this code, the defect detects types defined only when a macro is active.
#ifdef TDEF using size_t_alias = std::size_t; #endif |
accessSpecifier(PreprocIfdef self, Cpp.Node.Node &child)
| Matches public, protected, or
private labels inside a class body within the
preproc_ifdef and binds them to
child. | This PQL defect checks for access specifiers that are conditionally compiled inside a class. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.accessSpecifier(&as)
raise "access specifier in ifdef" on asIn this code, the
defect finds
class C {
#ifdef MAKE_PUBLIC
public:
#else
private:
#endif
int v;
}; |
typeSpecifier(PreprocIfdef self, Cpp.Node.Node &child)
| Matches type specifiers (like int, struct
X) inside the preproc_ifdef and binds them to
child. | This PQL defect checks for type specifiers inside guarded regions. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.typeSpecifier(&ts)
raise "type specifier in ifdef" on tsIn this code, the defect locates type declarations included conditionally.
#ifdef USE_INT int conditional_var; #endif |
aliasDeclaration(PreprocIfdef self, Cpp.Node.Node &child)
| Matches using alias declarations inside the
preproc_ifdef and binds them to
child. | This PQL defect checks for alias declarations that are conditionally compiled. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.aliasDeclaration(&ad)
raise "alias in ifdef" on adIn this code, the defect
detects
#ifdef ALIAS_T using myint = int; #endif |
usingDeclaration(PreprocIfdef self, Cpp.Node.Node &child)
| Matches using declarations (e.g., using
std::swap;) inside the preproc_ifdef and binds them
to child. | This PQL defect checks for defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.usingDeclaration(&ud)
raise "using declaration in ifdef" on udIn this code, the
defect finds
#ifdef USE_SWAP using std::swap; #endif |
conceptDefinition(PreprocIfdef self, Cpp.Node.Node &child)
| Matches C++20 concept definitions inside the
preproc_ifdef and binds them to
child. | This PQL defect checks for defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.conceptDefinition(&c)
raise "concept in ifdef" on cIn this code, the defect
detects
#ifdef USE_CONCEPT
template<typename T>
concept C = requires(T t) { t.size(); };
#endif |
declaration(PreprocIfdef self, Cpp.Node.Node &child)
| Matches any declaration (variable, function, type) inside the
preproc_ifdef and returns it as
child. | This PQL defect checks for declarations inside the
defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.declaration(&decl)
raise "declaration in ifdef" on declIn this code, the defect finds declarations that exist only when a guard macro is defined.
#ifdef DECL extern int ex; #endif |
enumerator(PreprocIfdef self, Cpp.Node.Node &child)
| Matches enum enumerators defined inside the preproc_ifdef
and binds them to child. | This PQL defect checks for enum members declared under preprocessor guards. defect d =
when
Cpp.PreprocIfdef.is(&ifdef)
and ifdef.enumerator(&e)
raise "enumerator in ifdef" on eIn this code, the defect
identifies enum entries inside an
|
friendDeclaration(PreprocIfdef self, Cpp.Node.Node &child)
| Find friend declarations inside the
preproc_ifdef block. | This PQL defect checks for friend declarations inside a
defect d =
when
Cpp.PreprocIfdef.is(&pi)
and pi.friendDeclaration(&fr)
raise "Found friend declaration"
on piIn this C++ code, the defect matches
#ifdef FOO
class X { friend class Bar; };
#endif |
getEnclosingPreprocIfdef (Cpp.Node.Node child, required PreprocIfdef
&parent) | Find the closest preproc_ifdef ancestor
parent to the node child. | This PQL defect checks for the preprocessor defect detect_enclosing_field =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.PreprocIfdef.getEnclosingFieldDeclaration(node, &fd)
and fd.nodeText(&txt)
raise "Enclosing PreprocIfdef: {txt}"
on fdIn this C++ code the defect locates the
preprocessor
#ifdef FOO #include <bar.h> #endif |
isEnclosedInPreprocIfdef (Cpp.Node.Node child) | Find all nodes that have an ancestor preproc_ifdef | This PQL defect checks for if a generic node is enclosed in a
defect detect_enclosing_field =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.PreprocIf.getEnclosingFieldDeclaration(node, &fd)
and fd.nodeText(&txt)
raise "Enclosing PreprocIf: {txt}"
on fdIn this C++ code the defect finds the syntax nodes
that are inside the preprocessor
#if FOO #include <bar.h> #endif |
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)