![]() |
Qore Programming Language Reference Manual 2.3.0
|
Qore supports conditional parsing with parse defines similar to the C/C++ preprocessor. The following parse directives are supported: %define, %else, %elif, %endif, %if, %ifdef, and %ifndef.
These directives allow for the existence (or lack thereof) of a parse define to affect which code is parsed into the program at parse time.
The %if directive supports C preprocessor-style boolean expressions using the defined() function. This allows for more complex conditional logic than the simple %ifdef directive.
The %if directive supports the following operators:
defined(SYMBOL) - returns true if SYMBOL is defined! - logical NOT operator&& - logical AND operator|| - logical OR operator() - parentheses for groupingThe %elif directive provides else-if functionality, allowing multiple conditions to be tested in sequence. It uses the same expression syntax as %if.
The %ifdef and %ifndef directives provide simple existence checks and remain supported for backwards compatibility:
Basically, the above allow for the existence (or lack thereof) of a parse define to affect which code is parsed into the program at parse time.
Parse defines are defined on the command-line (or through the C++ API when executed in embedded code), as well as created automatically based on sytem options (see Qore::Option for a list of option constants that are also defined as parse defines); all library options (if the option is True, then it is defined as True, if the option is False, then it is not defined at all).
Note that "Unix" is defined on all Unix platforms (also on Cygwin), while "Windows" is defined on native Windows ports (but not on Cygwin, as this is treated as Unix when compiling, as all Unix features are available).
Additionally, the following options are defined in every program (however they are not yet useful when parsing as the value of parse options cannot be used yet at parse time; only the existence or lack thereof can affect parsing in this version of Qore when parsing at least).
Qore Parse Defines
| Define | Value |
QoreVersionString | Version string for the Qore library |
QoreVersionMajor | Major version for the Qore library |
QoreVersionMinor | Minor version for the Qore library |
QoreVersionSub | Sub version for the Qore library |
QoreVersionBuild | Build version for the Qore library |
QoreVersionBits | 32 or 64 depending on the library target |
QorePlatformCPU | The CPU targeted by the library |
QorePlatformOS | The OS targeted by the library |
Additionally, only if the Qore library was compiled with debugging support, the following parse define is present (otherwise it is not defined):
Qore Optional Parse Defines
| Define | Value |
QoreDebug | True |
Here is an example of using parse defines in a program:
Furthermore, parse defines can be manipulated in embedded code using the following functions: