Cpp.PreprocIf Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the preproc_if nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.PreprocIf represents the node preproc_if in the syntax tree of your code.
#if FOO int x = 1; #else int x = 2; #endif
The example contains a preproc_if block that corresponds to Cpp.PreprocIf. The whole #if ... #else ... #endif region is the node matched by this class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
PreprocIf
| 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 PreprocIf &preprocIf)
| Match a preproc_if node and return as output variable. Use
when you want to select whole preprocessor-if blocks. | This PQL defect checks for any top-level defect d =
when
Cpp.PreprocIf.is(&pi)
raise "Found preproc_if"
on piIn this C++ code, the defect finds the
#define FOO 1 #if FOO int x = 1; #endif |
cast(Cpp.Node.Node node, required PreprocIf &cast)
| Check whether a generic Node is a
preproc_if and if so return it as a
PreprocIf for further predicates. | This PQL defect checks whether a general node is a
defect d =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.PreprocIf.cast(n, &pi)
raise "Node is PreprocIf"
on piIn this C++ code, the defect converts the
generic AST node covering the
#if defined(BAR) int y = 3; #endif |
isa(Cpp.Node.Node node)
| Return true if the given Node is a
preproc_if node. Use 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.PreprocIf.isa(n)
raise "Node isa PreprocIf"
on nIn this C++ code, the predicate recognizes the
#if FOO int x = 1; #endif |
alternative(PreprocIf self, Cpp.Node.Node &child)
| Finds the #else or #elif alternative
branch node inside the preproc_if. | This PQL defect checks for the presence of an alternative branch inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.alternative(&alt)
raise "Found alternative branch"
on piIn this C++ code, the defect finds the
#if FOO int x = 1; #else int x = 2; #endif |
condition(PreprocIf self, Cpp.Node.Node &child)
| Find the conditional expression of the #if or
#elif such as defined(X) or macro
names. | This PQL defect checks for the condition expression inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.condition(&cond)
raise "Found preproc_if condition"
on piIn this C++ code, the defect inspects the
#if defined(BAR) int y = 3; #endif |
statement(PreprocIf self, Cpp.Node.Node &child)
| Find a normal statement or declaration node contained directly in the
preproc_if body. | This PQL defect checks for executable statements inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.statement(&stmt)
raise "Found statement in preproc_if"
on piIn this C++ code, the defect finds the
#if FOO int x = 1; #endif |
staticAssertDeclaration(PreprocIf self, Cpp.Node.Node &child)
| Find static_assert declarations that appear inside the
preproc_if body. | This PQL defect checks for defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.staticAssertDeclaration(&sa)
raise "Found static_assert"
on piIn this C++ code, the defect matches the
#if FOO static_assert(sizeof(int) == 4); #endif |
templateDeclaration(PreprocIf self, Cpp.Node.Node &child)
| Find template declarations appearing inside the preproc_if,
such as template <...> struct. | This PQL defect checks for template declarations inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.templateDeclaration(&td)
raise "Found template declaration"
on piIn this C++ code, the defect finds the template
#if FOO
template<typename T> struct S {};
#endif |
templateInstantiation(PreprocIf self, Cpp.Node.Node &child)
| Find template instantiation expressions inside the
preproc_if, e.g., S<int> s;. | This PQL defect checks for template instantiations within a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.templateInstantiation(&ti)
raise "Found template instantiation"
on piIn this C++ code, the defect finds
#if FOO S<int> s; #endif |
typeDefinition(PreprocIf self, Cpp.Node.Node &child)
| Find type definition nodes inside the preproc_if such as
typedef or using-alias definitions. | This PQL defect checks for type definitions inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.typeDefinition(&td)
raise "Found type definition"
on piIn this C++ code, the defect matches the
#if FOO typedef int myint; #endif |
accessSpecifier(PreprocIf self, Cpp.Node.Node &child)
| Find access specifier labels such as public:,
protected:, or private: inside the
preproc_if. | This PQL defect checks for access specifiers inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.accessSpecifier(&as)
raise "Found access specifier"
on piIn this C++ code, the defect finds a
#if FOO
class C { public: int x; };
#endif |
typeSpecifier(PreprocIf self, Cpp.Node.Node &child)
| Find a type specifier node inside the preproc_if such as
int, double, or a class name used as a
type. | This PQL defect checks for type specifiers inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.typeSpecifier(&ts)
raise "Found type specifier"
on piIn this C++ code, the defect sees the
#if FOO int; #endif |
aliasDeclaration(PreprocIf self, Cpp.Node.Node &child)
| Find using alias = type; alias declarations appearing inside
the preproc_if. | This PQL defect checks for alias declarations inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.aliasDeclaration(&ad)
raise "Found alias declaration"
on piIn this C++ code, the defect matches
#if FOO using myint = int; #endif |
usingDeclaration(PreprocIf self, Cpp.Node.Node &child)
| Find using declarations such as type introductions or
using namespace declarations inside the
preproc_if. | This PQL defect checks for defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.usingDeclaration(&ud)
raise "Found using declaration"
on piIn this C++ code, the defect finds
#if FOO using MyType = int; #endif |
conceptDefinition(PreprocIf self, Cpp.Node.Node &child)
| Find concept definitions inside the preproc_if such as
template<...> concept C = .... | This PQL defect checks for concept definitions inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.conceptDefinition(&cd)
raise "Found concept definition"
on piIn this C++ code, the defect matches the
#if FOO
template<typename T> concept C = requires(T t) { t.foo(); };
#endif |
declaration(PreprocIf self, Cpp.Node.Node &child)
| Find general declarations such as variable or typedef declarations inside the
preproc_if. | This PQL defect checks for declarations inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.declaration(&decl)
raise "Found declaration"
on piIn this C++ code, the defect finds
#if FOO int z; #endif |
enumerator(PreprocIf self, Cpp.Node.Node &child)
| Find enumerator entries inside an enum that is located
within the preproc_if. | This PQL defect checks for enum members inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.enumerator(&e)
raise "Found enumerator"
on piIn this C++ code, the defect matches
#if FOO
enum E { A, B, D };
#endif |
fieldDeclaration(PreprocIf self, Cpp.Node.Node &child)
| Find members declared inside a class or struct that appear within the
preproc_if. | This PQL defect checks for field declarations inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.fieldDeclaration(&fd)
raise "Found field declaration"
on piIn this C++ code, the defect finds a class field
such as
#if FOO
class C { int field; };
#endif |
friendDeclaration(PreprocIf self, Cpp.Node.Node &child)
| Find friend declarations inside the
preproc_if block. | This PQL defect checks for friend declarations inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.friendDeclaration(&fr)
raise "Found friend declaration"
on piIn this C++ code, the defect matches
#if FOO
class X { friend class Bar; };
#endif |
functionDefinition(PreprocIf self, Cpp.Node.Node &child)
| Find function definitions inside the preproc_if
block. | This PQL defect checks for function definitions inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.functionDefinition(&fd)
raise "Found function definition"
on piIn this C++ code, the defect finds
#if FOO
void foo() {}
#endif |
linkageSpecification(PreprocIf self, Cpp.Node.Node &child)
| Find linkage specifications such as extern "C" { ... } that
appear inside the preproc_if. | This PQL defect checks for linkage specifications inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.linkageSpecification(&ls)
raise "Found linkage specification"
on piIn this C++ code, the defect recognizes
#if FOO
extern "C" { int x3; }
#endif |
namespaceAliasDefinition(PreprocIf self, Cpp.Node.Node
&child)
| Find namespace alias definitions inside the preproc_if such
as namespace foo = bar;. | This PQL defect checks for namespace alias definitions inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.namespaceAliasDefinition(&nad)
raise "Found namespace alias"
on piIn this C++ code, the defect finds
#if FOO namespace sfoo = std; #endif |
namespaceDefinition(PreprocIf self, Cpp.Node.Node &child)
| Find nested namespace definitions inside the
preproc_if. | This PQL defect checks for namespace definitions inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.namespaceDefinition(&nd)
raise "Found namespace definition"
on piIn this C++ code, the defect matches
#if FOO
namespace bar { int x; }
#endif |
preprocCall(PreprocIf self, Cpp.Node.Node &child)
| Find preprocessor directive calls inside the preproc_if such
as #pragma lines. | This PQL defect checks for preprocessor calls inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.preprocCall(&pc)
raise "Found preproc call"
on piIn this C++ code, the defect finds
#if FOO #pragma once #endif |
preprocDef(PreprocIf self, Cpp.Node.Node &child)
| Find preprocessor #define definitions that appear within the
preproc_if. | This PQL defect checks for macro definitions inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.preprocDef(&pd)
raise "Found preproc define"
on piIn this C++ code, the defect matches
#if FOO #define BAR 1 #endif |
preprocFunctionDef(PreprocIf self, Cpp.Node.Node &child)
| Find function-like macro definitions inside the preproc_if
such as #define FOO(x) .... | This PQL defect checks for function-style macro definitions inside a
defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.preprocFunctionDef(&pfd)
raise "Found function-like macro"
on piIn this C++ code, the defect sees
#if FOO #define FOO(x) (x+1) #endif |
preprocIf(PreprocIf self, Cpp.Node.Node &child)
| Find nested preprocessor if blocks located inside the
current preproc_if. | This PQL defect checks for nested defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.preprocIf(&pif)
raise "Found nested preproc_if"
on piIn this C++ code, the defect matches the inner
#if FOO #if BAR int y; #endif #endif |
preprocIfdef(PreprocIf self, Cpp.Node.Node
&child) | Find nested preprocessor ifdef blocks located inside the
current preproc_if | This PQL defect checks for nested defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.preprocIfdef(&pif)
raise "Found nested ideff"
on piIn this C++ code, the defect matches the inner
#if FOO #ifdef BAR int y; #endif #endif |
preprocInclude(PreprocIf self, Cpp.Node.Node
&child) | Find preprocessor #include located inside the current
preproc_if | This PQL defect checks for nested defect d =
when
Cpp.PreprocIf.is(&pi)
and pi.preprocInclude(&pif)
raise "Found nested include"
on piIn this C++ code, the defect matches the inner
#if FOO #include <bar.h> #endif |
getEnclosingPreprocIf (Cpp.Node.Node child, required PreprocIf
&parent) | Find the closest preproc_if ancestor
parent to the node child. | This PQL defect checks for the preprocessor 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 locates the
preprocessor
#if FOO #include <bar.h> #endif |
isEnclosedInPreprocIf (Cpp.Node.Node child) | Find all nodes that have an ancestor preproc_if | 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.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)