From 5994321cd7dc6b02b32aa16b2745e8310510fae6 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 19 Aug 2019 15:26:32 +0200 Subject: [PATCH] preprocessor: submodule update --- doc/manual/source/the-model-file.rst | 19 ++++++++++++++----- preprocessor | 2 +- tests/example1_macro.mod | 18 +++++++++++++++--- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index d07adff17..2655f394c 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -10313,7 +10313,7 @@ directives are: * ``@#includepath``, paths to search for files that are to be included, * ``@#include``, for file inclusion, * ``@#define``, for defining a macro processor variable, - * ``@#if, @#ifdef, @#ifndef, @#else, @#endif`` for conditional statements, + * ``@#if, @#ifdef, @#ifndef, @#elseif, @#else, @#endif`` for conditional statements, * ``@#for, @#endfor`` for constructing loops. The macro processor maintains its own list of variables (distinct from model @@ -10629,20 +10629,29 @@ Macro directives .. macrodir:: @#if MACRO_EXPRESSION @#ifdef MACRO_VARIABLE @#ifndef MACRO_VARIABLE + @#elseif MACRO_EXPRESSION @#else @#endif |br| Conditional inclusion of some part of the ``.mod`` file. The lines - between ``@#if``, ``@#ifdef``, or ``@#ifndef`` and the next ``@#else`` or - ``@#endif`` is executed only if the condition evaluates to ``true``. The - ``@#else`` branch is optional and, if present, is only evaluated if the - condition evaluates to ``false``. + between ``@#if``, ``@#ifdef``, or ``@#ifndef`` and the next ``@#elseif``, + ``@#else`` or ``@#endif`` is executed only if the condition evaluates to + ``true``. Following the ``@#if`` body, you can zero or more ``@#elseif`` + branches. An ``@#elseif`` condition is only evaluated if the preceding + ``@#if`` or ``@#elseif`` condition evaluated to ``false``. The ``@#else`` + branch is optional and is only evaluated if all ``@#if`` and ``@#elseif`` + statements evaluate to false. Note that when using ``@#ifdef``, the condition will evaluate to ``true`` if the MACRO_VARIABLE has been previously defined, regardless of its value. Conversely, ``@#ifndef`` will evaluate to true if the MACRO_VARIABLE has not yet been defined. + Note that when using ``@#elseif`` you can check whether or not a variable + has been defined by using the ``defined`` operator. Hence, to enter the + body of an ``@#elseif`` branch if the variable ``X`` has not been defined, + you would write: ``@#elseif !defined(X)``. + Note that if a real appears as the result of the MACRO_EXPRESSION, it will be interpreted as a boolean; a value of ``0`` is interpreted as ``false``, otherwise it is interpreted as ``true``. Further note that because of the diff --git a/preprocessor b/preprocessor index 75b000a0b..588896b50 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 75b000a0b5f36893e2d32d97abcfe17bc1a3f71b +Subproject commit 588896b5091ddee650a9548088a2df164df5c22b diff --git a/tests/example1_macro.mod b/tests/example1_macro.mod index 9173e07eb..0d95d40bb 100644 --- a/tests/example1_macro.mod +++ b/tests/example1_macro.mod @@ -95,9 +95,9 @@ e = 0; u = 0; end; -@#define DEFINED=0 +@#define DEFINEDvar=0 -@#ifndef DEFINED +@#ifndef DEFINEDvar @#error "IFNDEF PROBLEM" @#else shocks; @@ -107,12 +107,24 @@ var e, u = phi*0.009*0.009; end; @#endif -@#ifdef DEFINED +@#ifdef DEFINEDvar stoch_simul; +@#elseif true +@#error "ELSEIF PROBLEM" @#else @#error "IFDEF PROBLEM" @#endif +@#if false +@#error "IF ERROR" +@#elseif false +@#error "ELSEIF ERROR" +@#elseif defined(DEFINEDvar) +@#echo "Good" +@#else +@#error "ELSE ERROR" +@#endif + @#define a = 1 @#define f(x) = x + a @#define a = 2