Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • normann/preprocessor
  • Dynare/preprocessor
  • FerhatMihoubi/preprocessor
  • MichelJuillard/preprocessor
  • sebastien/preprocessor
  • lnsongxf/preprocessor
  • albop/preprocessor
  • DoraK/preprocessor
  • amg/preprocessor
  • wmutschl/preprocessor
  • JohannesPfeifer/preprocessor
11 results
Select Git revision
Show changes
Commits on Source (1209)
Showing with 595 additions and 2125 deletions
# This file should be kept in sync with the one in dynare.git (which also
# contains more explanations).
Language: Cpp
Standard: c++20
ColumnLimit: 100
BasedOnStyle: GNU
AllowShortFunctionsOnASingleLine: None
AlwaysBreakTemplateDeclarations: Yes
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
Cpp11BracedListStyle: true
DeriveLineEnding: false
IndentPPDirectives: AfterHash
InsertNewlineAtEOF: true
PackConstructorInitializers: NextLine
PPIndentWidth: 1
PointerAlignment: Left
# RemoveParentheses: ReturnStatement
# RemoveSemicolon: true
SpaceAfterTemplateKeyword: false
SpaceBeforeParens: ControlStatements
SpaceBeforeCpp11BracedList: true
# TODO: add the following check families:
# - bugprone-*
# - cppcoreguidelines-
# NB: as of clang-tidy 16, we get several false positives inside boost, notably this one:
# https://github.com/llvm/llvm-project/issues/40486
Checks: 'performance-*,modernize-*,-modernize-use-trailing-return-type,-clang-diagnostic-unqualified-std-cast-call'
# For checking that no file has been unduly ignored, run:
# $ git ls-files -i --exclude-per-directory=.gitignore
# Any file that is displayed should be removed from the ignore list
# (possibly by an exclusion rule beginning with an exclamation mark)
# Generic ignore rules
*~ *~
*.o
*.a
*.fig
\#*\#
*.txt
# Build system rules
build-aux/*
.deps
Makefile
Makefile.in
configure
config.log
config.status
aclocal.m4
autom4te.cache
TAGS
# Preprocessor
/src/dynare_m
/src/dynare_m.exe
/src/DynareBison.cc
/src/DynareBison.hh
/src/FlexLexer.h
/src/DynareFlex.cc
/src/location.hh
/src/position.hh
/src/stack.hh
/src/macro/Parser.cc
/src/macro/Parser.hh
/src/macro/Tokenizer.cc
/src/macro/location.hh
/src/macro/position.hh
/src/macro/stack.hh
/src/doc/
# macOS stuff
.DS_Store
# Doc rules
*.pdf
*.aux
*.log
*.nav
*.out
*.snm
*.toc
*.vrb
!/doc/macroprocessor/new-design.pdf
!/doc/macroprocessor/old-design.pdf
# test files
checksum
*.mod
*.tex
*.json
+*
# Bison verbose output file
*.output
variables: variables:
TERM: linux TERM: linux
MINGW32_BOOST_VERSION: 1.71.0-1 MINGW64_BOOST_VERSION: 1.88.0-2
MINGW64_BOOST_VERSION: 1.71.0-1
WGET_OPTIONS: '--no-verbose --no-use-server-timestamps --retry-connrefused --retry-on-host-error' WGET_OPTIONS: '--no-verbose --no-use-server-timestamps --retry-connrefused --retry-on-host-error'
# To ensure that "false && true" fails, see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/25394#note_412609647
FF_ENABLE_BASH_EXIT_CODE_CHECK: 'true'
before_script: build_linux_x86_64:
- 'export REMOTE_PATH=https://www.dynare.org/preprocessor/$CI_COMMIT_SHORT_SHA'
stages:
- build
- prepare
build_linux_32:
stage: build stage: build
script: script:
- autoreconf -si - meson setup -D buildtype=release build
- './configure LDFLAGS="-m32 -static -static-libgcc -static-libstdc++" CXXFLAGS=-m32' - meson compile -C build -v
- make -j$(nproc)
- strip src/dynare_m
- mkdir -p bin
- mv src/dynare_m bin
- mkdir -p $CI_COMMIT_SHORT_SHA/linux/32
- tar cfz $CI_COMMIT_SHORT_SHA/linux/32/preprocessor.tar.gz bin
- cd $CI_COMMIT_SHORT_SHA/linux/32 && sha256sum preprocessor.tar.gz > sha256sum
artifacts: artifacts:
paths: paths:
- $CI_COMMIT_SHORT_SHA/linux/32/* - build/src/dynare-preprocessor
expire_in: 1 hour
build_linux_64: build_linux_arm64:
stage: build stage: build
script: script:
- autoreconf -si - meson setup -D buildtype=release --cross-file scripts/linux-arm64-cross.ini build
- './configure LDFLAGS="-static -static-libgcc -static-libstdc++"' - meson compile -C build -v
- make -j$(nproc)
- strip src/dynare_m
- mkdir -p bin
- mv src/dynare_m bin
- mkdir -p $CI_COMMIT_SHORT_SHA/linux/64
- tar cfz $CI_COMMIT_SHORT_SHA/linux/64/preprocessor.tar.gz bin
- cd $CI_COMMIT_SHORT_SHA/linux/64 && sha256sum preprocessor.tar.gz > sha256sum
artifacts: artifacts:
paths: paths:
- $CI_COMMIT_SHORT_SHA/linux/64/* - build/src/dynare-preprocessor
expire_in: 1 hour
build_windows_32: build_windows_x86_64:
stage: build stage: build
script: script:
- mkdir -p ~/tarballs - mkdir -p tarballs
- '[[ -f ~/tarballs/mingw-w64-i686-boost-$MINGW32_BOOST_VERSION-any.pkg.tar.xz ]] || wget $WGET_OPTIONS -P ~/tarballs http://repo.msys2.org/mingw/i686/mingw-w64-i686-boost-$MINGW32_BOOST_VERSION-any.pkg.tar.xz' - '[[ -f tarballs/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.zst ]] || wget $WGET_OPTIONS -P tarballs http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.zst'
- mkdir -p deps - mkdir -p deps
- tar xf ~/tarballs/mingw-w64-i686-boost-$MINGW32_BOOST_VERSION-any.pkg.tar.xz --directory deps - tar xf tarballs/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.zst --directory deps
- autoreconf -si - echo -e "[properties]\nboost_root = '$(pwd)/deps/mingw64/'" > boost.ini
- './configure --host=i686-w64-mingw32 --with-boost=$(pwd)/deps/mingw32/include LDFLAGS="-static -static-libgcc -static-libstdc++"' - meson setup -D buildtype=release --cross-file scripts/windows-cross.ini --cross-file boost.ini build
- make -j$(nproc) - meson compile -C build -v
- i686-w64-mingw32-strip src/dynare_m.exe cache:
- mkdir -p bin # This cache is shared between all branches, to save space
- mv src/dynare_m.exe bin key: $CI_JOB_NAME
- mkdir -p $CI_COMMIT_SHORT_SHA/windows/32 paths:
- tar cfz $CI_COMMIT_SHORT_SHA/windows/32/preprocessor.tar.gz bin - tarballs/
- cd $CI_COMMIT_SHORT_SHA/windows/32 && sha256sum preprocessor.tar.gz > sha256sum
artifacts: artifacts:
paths: paths:
- $CI_COMMIT_SHORT_SHA/windows/32/* - build/src/dynare-preprocessor.exe
expire_in: 1 hour
build_windows_64: build_macos_x86_64:
stage: build stage: build
tags:
- macOS
script: script:
- mkdir -p ~/tarballs - arch -x86_64 meson setup -D buildtype=release --native-file scripts/homebrew-native-x86_64.ini build
- '[[ -f ~/tarballs/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.xz ]] || wget $WGET_OPTIONS -P ~/tarballs http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.xz' - arch -x86_64 meson compile -C build -v
- mkdir -p deps
- tar xf ~/tarballs/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.xz --directory deps
- autoreconf -si
- './configure --host=x86_64-w64-mingw32 --with-boost=$(pwd)/deps/mingw64/include LDFLAGS="-static -static-libgcc -static-libstdc++"'
- make -j$(nproc)
- x86_64-w64-mingw32-strip src/dynare_m.exe
- mkdir -p bin
- mv src/dynare_m.exe bin
- mkdir -p $CI_COMMIT_SHORT_SHA/windows/64
- tar cfz $CI_COMMIT_SHORT_SHA/windows/64/preprocessor.tar.gz bin
- cd $CI_COMMIT_SHORT_SHA/windows/64 && sha256sum preprocessor.tar.gz > sha256sum
artifacts: artifacts:
paths: paths:
- $CI_COMMIT_SHORT_SHA/windows/64/* - build/src/dynare-preprocessor
expire_in: 1 hour
build_macOS: build_macos_arm64:
stage: build stage: build
tags: tags:
- macOS - macOS
script: script:
- autoreconf -si - export PATH="/opt/homebrew/bin:$PATH"
- './configure CXX=g++-9 CXXFLAGS=-static-libgcc' - arch -arm64 meson setup -D buildtype=release --native-file scripts/homebrew-native-arm64.ini build
- make -j$(nproc) - arch -arm64 meson compile -C build -v
- strip src/dynare_m
- mkdir -p bin
- mv src/dynare_m bin
- mkdir -p $CI_COMMIT_SHORT_SHA/macOS/64
- tar cfz $CI_COMMIT_SHORT_SHA/macOS/64/preprocessor.tar.gz bin
- cd $CI_COMMIT_SHORT_SHA/macOS/64 && sha256sum preprocessor.tar.gz > sha256sum
artifacts: artifacts:
paths: paths:
- $CI_COMMIT_SHORT_SHA/macOS/64/* - build/src/dynare-preprocessor
expire_in: 1 hour
aggregate_builds: test_clang_format:
stage: prepare stage: test
dependencies:
- build_linux_32
- build_linux_64
- build_windows_32
- build_windows_64
- build_macOS
script: script:
- linux32sha=$(cut -f 1 -d ' ' < $CI_COMMIT_SHORT_SHA/linux/32/sha256sum) - meson setup build-clang-format
- linux64sha=$(cut -f 1 -d ' ' < $CI_COMMIT_SHORT_SHA/linux/64/sha256sum) - ninja -C build-clang-format clang-format-check
- windows32sha=$(cut -f 1 -d ' ' < $CI_COMMIT_SHORT_SHA/windows/32/sha256sum) needs: []
- windows64sha=$(cut -f 1 -d ' ' < $CI_COMMIT_SHORT_SHA/windows/64/sha256sum)
- macOS64sha=$(cut -f 1 -d ' ' < $CI_COMMIT_SHORT_SHA/macOS/64/sha256sum) test_clang_tidy:
- cd $CI_COMMIT_SHORT_SHA stage: test
- echo 'PREPROCESSOR_VERSION = "'$CI_COMMIT_SHORT_SHA'"' > julia.conf script:
- echo 'REMOTE_PATH = "https://www.dynare.org/preprocessor/'$CI_COMMIT_SHORT_SHA'"' >> julia.conf # Hack needed for meson < 1.6.0 which only looks for unversioned clang-tidy
- echo -e "\n" >> julia.conf - mkdir -p ~/.local/bin && ln -s /usr/bin/clang-tidy-19 ~/.local/bin/clang-tidy
- echo "download_info = Dict(" >> julia.conf - export PATH="$HOME/.local/bin:$PATH"
- echo " Linux(:i686, :glibc) => ("\"\$REMOTE_PATH/linux/32/preprocessor.tar.gz\"", "\"$linux32sha\"")," >> julia.conf - meson setup build-clang-tidy
- echo " Linux(:x86_64, :glibc) => ("\"\$REMOTE_PATH/linux/64/preprocessor.tar.gz\"", "\"$linux64sha\"")," >> julia.conf # Generate Flex and Bison files
- echo " Windows(:i686) => ("\"\$REMOTE_PATH/windows/32/preprocessor.tar.gz\"", "\"$windows32sha\"")," >> julia.conf - meson compile -C build-clang-tidy
- echo " Windows(:x86_64) => ("\"\$REMOTE_PATH/windows/64/preprocessor.tar.gz\"", "\"$windows64sha\"")," >> julia.conf - ninja -C build-clang-tidy clang-tidy
- echo " MacOS() => ("\"\$REMOTE_PATH/macOS/64/preprocessor.tar.gz\"", "\"$macOS64sha\"")," >> julia.conf needs: []
- echo " )" >> julia.conf when: manual
artifacts:
paths:
- $CI_COMMIT_SHORT_SHA/*/*/*
- $CI_COMMIT_SHORT_SHA/julia.conf
expire_in: 1 week
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
...@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found. ...@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail. Also add information on how to contact you by electronic and paper mail.
...@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". ...@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school, You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>. <https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>. <https://www.gnu.org/licenses/why-not-lgpl.html>.
SUBDIRS = src doc
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = \
license.txt \
COPYING
dist-hook:
rm -rf `find $(distdir) -name '.git*'`
...@@ -9,12 +9,9 @@ ...@@ -9,12 +9,9 @@
The Dynare Preprocessor defines the Dynare model language. It takes in a `.mod` The Dynare Preprocessor defines the Dynare model language. It takes in a `.mod`
file, computes the derivatives of the model represented therein, and produces file, computes the derivatives of the model represented therein, and produces
MATLAB/Octave, C, Julia, or JSON output. MATLAB/Octave, Julia, or JSON output.
There is more to come here. For the moment, see the [Dynare
repository](https://git.dynare.org/Dynare/dynare)
# License # License
Most of the source files are covered by the GNU General Public Licence version Most of the source files are covered by the GNU General Public Licence version
3 or later. There are some exceptions. See [license.txt](license.txt) for specifics. 3 or later. There are some exceptions, see the respective file headers.
dnl Process this file with autoconf to produce a configure script.
dnl Copyright © 2009-2019 Dynare Team
dnl
dnl This file is part of Dynare.
dnl
dnl Dynare is free software: you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation, either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl Dynare is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with Dynare. If not, see <http://www.gnu.org/licenses/>.
AC_PREREQ([2.62])
AC_INIT([dynare-preprocessor], [4.6-unstable])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_SRCDIR([src/DynareMain.cc])
AM_INIT_AUTOMAKE([1.11 -Wall -Wno-portability foreign no-dist-gzip dist-xz tar-pax])
AC_PROG_CC
AC_PROG_CXX
AX_CXX_COMPILE_STDCXX_17
AC_CANONICAL_HOST
case ${host_os} in
*mingw32*)
# On Windows, we don't want dynamic linking
AM_LDFLAGS="-static"
AC_SUBST([AM_LDFLAGS])
;;
*cygwin*)
AC_MSG_WARN([You are compiling for the Cygwin target. This means that the preprocessor will])
AC_MSG_WARN([not run from MATLAB unless you add the Cygwin DLL to the path.])
AC_MSG_WARN([This is probably not what you want. Consider using a MinGW cross-compiler.])
;;
esac
# Use C++ for testing headers
AC_LANG([C++])
AM_CXXFLAGS="-Wall -Wno-parentheses -Wold-style-cast"
AC_SUBST([AM_CXXFLAGS])
# If default 'ar' is not available, try to find one with a host prefix (see ticket #145)
AC_CHECK_PROGS([AR], [ar ${host_alias}-ar])
AC_PROG_RANLIB
AM_PROG_AR
AM_PROG_LEX
# Hack to get lex include dir, ticket #575
AC_PATH_PROG([LEXPATH], [$LEX])
AC_SUBST([LEXINC], [$(eval "echo $LEXPATH | sed 's|\(.*\)$LEX$|\1../include|'")])
AC_CHECK_PROG([YACC], [bison], [bison])
if test -z "$YACC"; then
unset YACC # AM_MISSING_PROG needs an unset variable: an empty variable won't do
AM_MISSING_PROG([YACC], [bison])
fi
# We need 1.36 because of unordered_{set,hash} used by Dynare++
AX_BOOST_BASE([1.36], [], [AC_MSG_ERROR([Can't find Boost >= 1.36])])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
AC_CHECK_HEADERS([boost/graph/adjacency_list.hpp], [], [AC_MSG_ERROR([Can't find Boost Graph Library])])
AC_CHECK_HEADERS([boost/algorithm/string/trim.hpp], [], [AC_MSG_ERROR([Can't find Boost String Library])])
AC_CHECK_HEADERS([boost/algorithm/string/split.hpp], [], [AC_MSG_ERROR([Can't find Boost String Library])])
CPPFLAGS="$CPPFLAGS_SAVED"
# Don't use deprecated hash structures
AC_DEFINE([BOOST_NO_HASH], [], [Don't use deprecated STL hash structures])
# Check if internal documentation can be built
AC_CHECK_PROG([DOXYGEN], [doxygen], [doxygen])
AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
# Check if user documentation can be built
AC_ARG_ENABLE([doc], AS_HELP_STRING([--disable-doc], [disable compilation of documentation]), [], [enable_doc=yes])
AM_CONDITIONAL([ENABLE_DOC], [test "$enable_doc" = yes])
if test "$enable_doc" = yes; then
AC_CHECK_PROG([PDFLATEX], [pdflatex], [pdflatex], [no])
test "$PDFLATEX" = no && AC_MSG_ERROR([pdflatex cannot be found. If you want to skip the compilation of the documentation, pass the --disable-doc flag.])
AC_CHECK_PROG([BIBTEX], [bibtex], [bibtex], [no])
test "$BIBTEX" = no && AC_MSG_ERROR([bibtex cannot be found. If you want to skip the compilation of the documentation, pass the --disable-doc flag.])
AX_LATEX_CLASS([beamer], [ax_latex_have_beamer], [], [AC_MSG_ERROR([beamer cannot be found. If you want to skip the compilation of the documentation, pass the --disable-doc flag.])])
fi
AC_CONFIG_FILES([Makefile
src/Makefile
src/macro/Makefile
doc/Makefile
doc/preprocessor/Makefile
doc/macroprocessor/Makefile
])
if test -n "$DOXYGEN"; then
BUILD_INTERNAL_DOC="yes"
else
BUILD_INTERNAL_DOC="no (missing doxygen)"
fi
if test "$enable_doc" = yes; then
BUILD_DOC="yes"
else
BUILD_DOC="no"
fi
AC_MSG_NOTICE([
The Dynare Preprocessor is now configured to build...
Binaries (with "make")
Dynare preprocessor: yes
PDF documentation (with "make pdf"):
Preprocessor & Macroprocessor presentations: $BUILD_DOC
HTML documentation (with "make html"):
Dynare preprocessor internal doc: $BUILD_INTERNAL_DOC
])
AC_OUTPUT
SUBDIRS = preprocessor macroprocessor
EXTRA_DIST = logos
doc/logos/dlogo.png

37 KiB | W: 0px | H: 0px

doc/logos/dlogo.png

55.6 KiB | W: 0px | H: 0px

doc/logos/dlogo.png
doc/logos/dlogo.png
doc/logos/dlogo.png
doc/logos/dlogo.png
  • 2-up
  • Swipe
  • Onion skin
if ENABLE_DOC
pdf-local: macroprocessor.pdf
endif
SRC = macroprocessor.tex new-design.pdf
EXTRA_DIST = $(SRC)
macroprocessor.pdf: $(SRC)
$(PDFLATEX) macroprocessor
$(PDFLATEX) macroprocessor
clean-local:
rm -f macroprocessor.pdf *.toc *.aux *.log *.nav *.snm *.vrb *.out *~
\documentclass{beamer} \documentclass[aspectratio=169]{beamer}
\usepackage[utf8]{inputenc} \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} \usepackage[T1]{fontenc}
\usepackage{lmodern} \usepackage{lmodern}
\usepackage{upquote}
\usepackage{amsmath} \usepackage{amsmath}
\usepackage[copyright]{ccicons} \usepackage[copyright]{ccicons}
\usetheme{Boadilla} \usetheme{Boadilla}
\titlegraphic{\includegraphics{../logos/dlogo.png}} \graphicspath{{../logos/}}
\title{The Dynare Macro Processor} \title{The Dynare Macro Processor}
\author{Sébastien Villemot}
\pgfdeclareimage[height=0.8cm]{logo}{dlogo}
\institute[Dynare Team]{\pgfuseimage{logo}}
\author[S. Villemot, H.Bastani]{Sébastien Villemot \and Houtan Bastani} \date{31 May 2024}
\institute[CEPREMAP]{\includegraphics[scale=0.15]{../logos/cepremap.jpg}}
\date{28 June 2019}
\setbeamertemplate{title page}
{
\vbox{}
\begingroup
\centering
{\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par}\vskip1em
\begin{beamercolorbox}[sep=8pt,center]{title}
\usebeamerfont{title}\inserttitle\par%
\ifx\insertsubtitle\@empty%
\else%
\vskip0.25em%
{\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
\fi%
\end{beamercolorbox}%
\vskip1em\par
\begin{beamercolorbox}[sep=8pt,center]{author}
\usebeamerfont{author}\insertauthor
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center]{institute}
\usebeamerfont{institute}\insertinstitute
\end{beamercolorbox}
\begin{beamercolorbox}[sep=8pt,center]{date}
\usebeamerfont{date}\insertdate
\end{beamercolorbox}
\endgroup
\vfill
}
\AtBeginSection[] \AtBeginSection[]
{ {
...@@ -58,18 +29,6 @@ ...@@ -58,18 +29,6 @@
\begin{frame} \begin{frame}
\titlepage \titlepage
\begin{columns}[T]
\column{0.2\textwidth}
\column{0.09\textwidth}
\ccbysa
\column{0.71\textwidth}
\tiny
Copyright © 2008--2019 Dynare Team \\
Licence: \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative
Commons Attribution-ShareAlike 4.0}
\end{columns}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
...@@ -90,7 +49,7 @@ ...@@ -90,7 +49,7 @@
\item The \textbf{Dynare macro language} adds a programmatic element to Dynare \item The \textbf{Dynare macro language} adds a programmatic element to Dynare
\begin{itemize} \begin{itemize}
\item Introduces conditionals, loops, and other simple programmatic directives \item Introduces conditionals, loops, and other simple programmatic directives
\item Used to speed model development \item Used to speed up model development
\item Useful in various situations \item Useful in various situations
\begin{itemize} \begin{itemize}
\item Multi-country models \item Multi-country models
...@@ -106,7 +65,7 @@ ...@@ -106,7 +65,7 @@
\begin{frame} \begin{frame}
\frametitle{Design of the macro language} \frametitle{Design of the macro language}
\begin{itemize} \begin{itemize}
\item The Dynare macro language provides a new set of \textbf{macro commands} that can be used in \texttt{.mod} files \item The Dynare macro language provides a set of \textbf{macro commands} that can be used in \texttt{.mod} files
\item The macro processor transforms a \texttt{.mod} file with macro commands into a \texttt{.mod} file without macro commands (doing text expansions/inclusions) and then feeds it to the Dynare parser \item The macro processor transforms a \texttt{.mod} file with macro commands into a \texttt{.mod} file without macro commands (doing text expansions/inclusions) and then feeds it to the Dynare parser
\item The key point to understand is that the macro processor only does \textbf{text substitution} (like the C preprocessor or the PHP language) \item The key point to understand is that the macro processor only does \textbf{text substitution} (like the C preprocessor or the PHP language)
\end{itemize} \end{itemize}
...@@ -127,35 +86,34 @@ ...@@ -127,35 +86,34 @@
\item Main directives are: \item Main directives are:
\begin{itemize} \begin{itemize}
\item file inclusion: \verb+@#include+ \item file inclusion: \verb+@#include+
\item definition of a macro processor variable: \verb+@#define+ \item definition of a macro processor variable or function: \verb+@#define+
\item conditional statements: \verb+@#if/@#ifdef/@#ifndef/@#else/@#endif+ \item conditional statements: \verb+@#if/@#ifdef/@#ifndef/@#else/@#elseif/@#endif+
\item loop statements: \verb+@#for/@#endfor+ \item loop statements: \verb+@#for/@#endfor+
\end{itemize} \end{itemize}
\item Most directives fit on one line. If needed however, two backslashes (i.e. \verb+\\+) at the end of a line indicate that the directive is continued on the next line. \item Most directives fit on one line. If needed however, two backslashes (\textit{i.e.} \verb+\\+) at the end of a line indicate that the directive is continued on the next line.
\item Directives are not terminated with a semicolon
\end{itemize} \end{itemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Variables} \frametitle{Values}
\begin{itemize}
\item The macro processor has its own list of variables which are different than model variables and MATLAB/Octave variables
\item There are 6 types of macro-variables:
\begin{itemize} \begin{itemize}
\item boolean \item The macro processor can handle values of 5 different types:
\item real \begin{enumerate}
\item string \item boolean (logical value, true or false)
\item real (double precision floating point number)
\item string (of characters)
\item tuple \item tuple
\item array \item array
\item function \end{enumerate}
\end{itemize} \item Values of the types listed above can be cast to other types
\item Variables/literals of the types listed above can be cast to other types
\begin{itemize} \begin{itemize}
\item \texttt{(bool) -1 \&\& (bool) 2} $\rightarrow$ \texttt{true} \item \texttt{(real) "3.1"} $\rightarrow$ \texttt{3.1}
\item \texttt{(real) ``3.1''} $\rightarrow$ \texttt{3.1} \item \texttt{(string) 3.1} $\rightarrow$ \texttt{"3.1"}
\item \texttt{(array) 4} $\rightarrow$ \texttt{[4]} \item \texttt{(array) 4} $\rightarrow$ \texttt{[4]}
\item \texttt{(real) [5]} $\rightarrow$ \texttt{5} \item \texttt{(real) [5]} $\rightarrow$ \texttt{5}
\item \texttt{(real) [6, 7]} $\rightarrow$ \texttt{error} \item \texttt{(real) [6, 7]} $\rightarrow$ \texttt{error}
\item \texttt{(bool) -1 \&\& (bool) 2} $\rightarrow$ \texttt{true}
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -163,12 +121,12 @@ ...@@ -163,12 +121,12 @@
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (1/8)} \frametitle{Macro-expressions (1/8)}
\begin{itemize} \begin{itemize}
\item Macro-expressions are constructed using literals of the 6 basic types \item Macro-expressions are constructed using literals (\textit{i.e.} fixed values) of the 5 basic types
described above, macro-variables, comprehensions, and standard operators. described above, macro-variables, standard operators, function calls and comprehensions.
\item Macro-expressions can be used in two places: \item Macro-expressions can be used in two places:
\begin{itemize} \begin{itemize}
\item inside macro directives; no special markup is required \item inside macro directives; no special markup is required
\item in the body of the \texttt{.mod} file, between an at sign and curly braces (like \verb+@{expr}+); the macro processor will substitute the expression with its value \item in the body of the \texttt{.mod} file, between an ``at''-sign and curly braces (like \verb+@{expr}+); the macro processor will substitute the expression with its value
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -176,11 +134,16 @@ ...@@ -176,11 +134,16 @@
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (2/8): Boolean} \frametitle{Macro-expressions (2/8): Boolean}
It is possible to construct macro-expressions using standard operators. Boolean literals are \texttt{true} and \texttt{false}.
\begin{block}{Operators on booleans} \begin{block}{Operators on booleans}
\begin{itemize} \begin{itemize}
\item comparison operators: \texttt{== !=} \item comparison operators: \texttt{== !=}
\item logical operators: \verb+&& || !+ \item logical operators:
\begin{itemize}
\item conjunction (“and”): \texttt{\&\&}
\item disjunction (“or”): \texttt{||}
\item negation (“not”): \texttt{!}
\end{itemize}
\end{itemize} \end{itemize}
\end{block} \end{block}
\end{frame} \end{frame}
...@@ -192,24 +155,26 @@ ...@@ -192,24 +155,26 @@
\item arithmetic operators: \texttt{+ - * / \^{}} \item arithmetic operators: \texttt{+ - * / \^{}}
\item comparison operators: \texttt{< > <= >= == !=} \item comparison operators: \texttt{< > <= >= == !=}
\item logical operators: \verb+&& || !+ \item logical operators: \verb+&& || !+
\item range with increment of \texttt{1}: \texttt{1:4} is equivalent to real array \texttt{[1, 2, 3, 4]}. NB \texttt{[1:4]} is equivalent to an array containing an array of reals \texttt{[[1, 2, 3, 4]]} \item range with unit increment: \texttt{1:4} is equivalent to
\item range with user-defined increment: \texttt{4:-1.1:-1} is equivalent to real array \texttt{[4, 2.9, 1.8, 0.7, -0.4]}. real array \texttt{[1, 2, 3, 4]} \\ (NB: \texttt{[1:4]} is equivalent to an
array containing an array of reals, \textit{i.e.} \texttt{[[1, 2, 3, 4]]})
\item range with user-defined increment: \\ \texttt{4:-1.1:-1} is equivalent to real array \texttt{[4, 2.9, 1.8, 0.7, -0.4]}
\end{itemize} \end{itemize}
\end{block} \end{block}
\begin{block}{Functions for reals} \begin{block}{Functions for reals}
\begin{itemize} \begin{itemize}
\item \texttt{min, max, exp, ln (or log), log10} \item \texttt{min}, \texttt{max}, \texttt{exp}, \texttt{ln} (or \texttt{log}), \texttt{log10}
\item \texttt{sin, cos, tan, asin, acos, atan} \item \texttt{sign}, \texttt{floor}, \texttt{ceil}, \texttt{trunc}, \texttt{round}, \texttt{mod}
\item \texttt{sqrt, cbrt, sign, floor, ceil, trunc, mod} \item \texttt{sin}, \texttt{cos}, \texttt{tan}, \texttt{asin}, \texttt{acos}, \texttt{atan}
\item \texttt{erf, erfc, normpdf, normcdf, gamma, lgamma, round} \item \texttt{sqrt}, \texttt{cbrt}, \texttt{erf}, \texttt{erfc}, \texttt{normpdf}, \texttt{normcdf}, \texttt{gamma}, \texttt{lgamma}
\end{itemize} \end{itemize}
\end{block} \end{block}
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (4/8): String} \frametitle{Macro-expressions (4/8): String}
String literals have to be declared between \textit{double} quotes, e.g. \texttt{``string''} String literals have to be declared between \textit{double} quotes, e.g. \texttt{"string"}
\begin{block}{Operators on character strings} \begin{block}{Operators on character strings}
\begin{itemize} \begin{itemize}
\item comparison operators: \texttt{< > <= >= == !=} \item comparison operators: \texttt{< > <= >= == !=}
...@@ -223,48 +188,67 @@ ...@@ -223,48 +188,67 @@
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (5/8): Tuple} \frametitle{Macro-expressions (5/8): Tuple}
Tuples are enclosed by parenthesis and elements separated by commas (like Tuples are enclosed by parentheses and elements are separated by commas (like
\texttt{(a,b,c)} or \texttt{(1,2.2,c)}). \texttt{(a,b,c)} or \texttt{(1,2.2,c)}).
\begin{block}{Operators on tuples} \begin{block}{Operators on tuples}
\begin{itemize} \begin{itemize}
\item comparison operators: \texttt{== !=} \item comparison operators: \texttt{== !=}
\item functions: \texttt{length, isempty} \item functions: \texttt{length()}, \texttt{isempty()}
\item testing membership in tuple: \texttt{in} operator \\ (example: \item testing membership in tuple: \texttt{in} operator \\ (example:
\texttt{"b" in ("a", "b", "c")} returns \texttt{1}) \texttt{"b" in ("a", "b", "c")} returns \texttt{true})
\end{itemize} \end{itemize}
\end{block} \end{block}
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (6/8): Array} \frametitle{Macro-expressions (6/8): Array (1/2)}
Arrays are enclosed by brackets, and their elements are separated by commas Arrays are enclosed by brackets, and their elements are separated by commas
(like \texttt{[1,[2,3],4]} or \texttt{[``US'', ``EA'']}). (like \texttt{[1,[2,3],4]} or \texttt{["US", "EA"]}).
\begin{block}{Operators on arrays} \begin{block}{Operators on arrays}
\begin{itemize} \begin{itemize}
\item comparison operators: \texttt{== !=} \item comparison operators: \texttt{== !=}
\item dereferencing: if \texttt{v} is an array, then \texttt{v[2]} is its $2^{\textrm{nd}}$ element \item dereferencing: if \texttt{v} is an array, then \texttt{v[2]} is its $2^{\textrm{nd}}$ element
\item concatenation: \texttt{+} \item concatenation: \texttt{+}
\item functions: \texttt{sum, length, isempty} \item functions: \texttt{sum()}, \texttt{length()}, \texttt{isempty()}
\item difference \texttt{-}: returns the first operand from which the elements of the second operand have been removed
\item Cartesian product of two arrays: \texttt{*}
\item Cartesian product of one array \texttt{N} times: \texttt{\^{}N}
\item extraction of sub-arrays: \textit{e.g.} \texttt{v[4:6]} \item extraction of sub-arrays: \textit{e.g.} \texttt{v[4:6]}
\item testing membership of an array: \texttt{in} operator \\ (example: \item testing membership of an array: \texttt{in} operator \\ (example:
\texttt{"b" in ["a", "b", "c"]} returns \texttt{1}) \texttt{"b" in ["a", "b", "c"]} returns \texttt{true})
\end{itemize} \end{itemize}
\end{block} \end{block}
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (6/8): Array (2/2)}
Arrays can be seen as representing a set of elements (assuming no element
appears twice in the array). Several set operations can thus be performed on
arrays: union, intersection, difference, Cartesian product and power.
\begin{block}{Set operations on arrays}
\begin{itemize}
\item set union: \texttt{|}
\item set intersection: \texttt{\&}
\item set difference: \texttt{-}
\item Cartesian product of two arrays: \texttt{*}
\item Cartesian power of an array: \texttt{\^}
\end{itemize}
\end{block}
For example: if \texttt{A} and \texttt{B} are arrays, then the following
set operations are valid: \texttt{A|B}, \texttt{A\&B}, \texttt{A-B},
\texttt{A*B}, \texttt{A\^{}3}.
NB: the array resulting from Cartesian product or power has tuples as its elements.
\end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (7/8): Comprehension (1/3)} \frametitle{Macro-expressions (7/8): Comprehension (1/3)}
Comprehensions are a shorthand way of creating arrays from other arrays. This is done by filtering, mapping, or filtering and mapping Comprehensions are a shorthand way of creating arrays from other arrays. This is done by filtering, mapping, or both.
\begin{block}{Filtering} \begin{block}{Filtering}
\begin{itemize} \begin{itemize}
\item Allows one to choose those elements from an array for which a condition holds \item Allows one to choose those elements from an array for which a condition holds
\item Syntax: \texttt{[variable/tuple IN array WHEN condition]} \item Syntax: \texttt{[} \textit{variable/tuple} \texttt{in} \textit{array} \texttt{when}
\textit{condition} \texttt{]}
\item Example: Choose even numbers from array \item Example: Choose even numbers from array
\begin{itemize} \begin{itemize}
\item Code: \texttt{@\{[ i in 1:5 when mod(i,2) == 0 ]\}} \item Code: \texttt{[ i in 1:5 when mod(i,2) == 0 ]}
\item Result: \texttt{[2, 4]} \item Result: \texttt{[2, 4]}
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
...@@ -276,15 +260,16 @@ ...@@ -276,15 +260,16 @@
\begin{block}{Mapping} \begin{block}{Mapping}
\begin{itemize} \begin{itemize}
\item Allows one to apply a transformation to every element of an array \item Allows one to apply a transformation to every element of an array
\item Syntax: \texttt{[expr for variable/tuple IN array]} \item Syntax: \texttt{[} \textit{expr} \texttt{for} \textit{variable/tuple}
\texttt{in} \textit{array} \texttt{]}
\item Example: Square elements in array \item Example: Square elements in array
\begin{itemize} \begin{itemize}
\item Code: \texttt{@\{[ i\^{}2 for i in 1:5 ]\}} \item Code: \texttt{[ i\^{}2 for i in 1:5 ]}
\item Result: \texttt{[1, 4, 9, 16, 25]} \item Result: \texttt{[1, 4, 9, 16, 25]}
\end{itemize} \end{itemize}
\item Example: Reverse order of elements in array \item Example: Swap pairs of an array
\begin{itemize} \begin{itemize}
\item Code: \texttt{@\{[ (j,i) for (i,j) in (1:2)\^{}2 ]\}} \item Code: \texttt{[ (j,i) for (i,j) in (1:2)\^{}2 ]}
\item Result: \texttt{[(1, 1), (2, 1), (1, 2), (2, 2)]} \item Result: \texttt{[(1, 1), (2, 1), (1, 2), (2, 2)]}
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
...@@ -296,10 +281,11 @@ ...@@ -296,10 +281,11 @@
\begin{block}{Mapping and Filtering} \begin{block}{Mapping and Filtering}
\begin{itemize} \begin{itemize}
\item Allows one to apply a transformation to the elements selected from an array \item Allows one to apply a transformation to the elements selected from an array
\item Syntax: \texttt{[expr for variable/tuple IN array WHEN condition]} \item Syntax: \texttt{[} \textit{expr} \texttt{for} \textit{variable/tuple}
\item Example: Square odd numbers from array \texttt{in} \textit{array} \texttt{when} \textit{condition} \texttt{]}
\item Example: Square of odd numbers between 1 and 5
\begin{itemize} \begin{itemize}
\item Code: \texttt{@\{[ i\^{}2 for i in 1:5 when mod(i,2) == 1 ]\}} \item Code: \texttt{[ i\^{}2 for i in 1:5 when mod(i,2) == 1 ]}
\item Result: \texttt{[1, 9, 25]} \item Result: \texttt{[1, 9, 25]}
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
...@@ -310,15 +296,30 @@ ...@@ -310,15 +296,30 @@
\frametitle{Macro-expressions (8/8): Functions} \frametitle{Macro-expressions (8/8): Functions}
\begin{itemize} \begin{itemize}
\item Can take any number of arguments \item Can take any number of arguments
\item Dynamic binding: is evaluated when invoked, not when defined \item Dynamic binding: is evaluated when invoked during the macroprocessing stage, not when defined
\item Can be included in expressions; valid operators depend on return type \item Can be included in expressions; valid operators depend on return type
\end{itemize} \end{itemize}
\begin{block}{Declaration syntax}
\verb+@#define +\textit{function\_signature}\verb+ = +\textit{expression}
\end{block}
\begin{block}{Example}
If we declare the following function:
\begin{verbatim}
@#define distance(x, y) = sqrt(x^2 + y^2)
\end{verbatim}
Then \texttt{distance(3, 4)} will be equivalent to \texttt{5}.
\end{block}
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Define directive} \frametitle{Defining macro-variables (1/2)}
The value of a macro-variable can be defined with the \verb+@#define+ directive. The value of a macro-variable can be defined with the \verb+@#define+
directive.
The macro processor has its own list of variables, which are different from model variables and MATLAB/Octave variables
\begin{block}{Syntax} \begin{block}{Syntax}
\verb+@#define +\textit{variable\_name}\verb+ = +\textit{expression} \verb+@#define +\textit{variable\_name}\verb+ = +\textit{expression}
...@@ -331,13 +332,34 @@ ...@@ -331,13 +332,34 @@
@#define v = [ 1, 2, 4 ] // Real array @#define v = [ 1, 2, 4 ] // Real array
@#define w = [ "US", "EA" ] // String array @#define w = [ "US", "EA" ] // String array
@#define z = 3 + v[2] // Equals 5 @#define z = 3 + v[2] // Equals 5
@#define t = ("US" in w) // Equals 1 (true) @#define t = ("US" in w) // Equals true
@#define f(x) = " " + x + y // Function f with argument x
\end{verbatim} \end{verbatim}
\end{block} \end{block}
NB: You can define macro variables on the dynare command line by using the \texttt{-D} option
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Defining macro-variables (2/2)}
Macro variables can also be defined on the Dynare command line by using the
\texttt{-D} option, for easily switching between different flavours of a model.
\begin{block}{Example 1}
\begin{verbatim}
dynare myfile.mod -Dx=5
\end{verbatim}
The macro-variable \texttt{x} will be equal to \texttt{5} when running \texttt{myfile.mod}.
\end{block}
\begin{block}{Example 2}
Use single quotes around the \texttt{-D} option when there are spaces or
special characters in the variable definition.
\begin{verbatim}
dynare myfile.mod '-DA=[ i in [1,2,3] when i > 1 ]'
\end{verbatim}
The macro-variable \texttt{A} will be equal to \texttt{[2,3]} when running \texttt{myfile.mod}.
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Expression substitution} \frametitle{Expression substitution}
\framesubtitle{Dummy example} \framesubtitle{Dummy example}
...@@ -394,23 +416,23 @@ end; ...@@ -394,23 +416,23 @@ end;
\item Files to include are searched for in the current directory. Other directories can \item Files to include are searched for in the current directory. Other directories can
be added with the be added with the
\verb+@#includepath+ directive, the \texttt{-I} command line option, or the \verb+@#includepath+ directive, the \texttt{-I} command line option, or the
\texttt{[paths]} section in config file. \texttt{[paths]} section in config files.
\end{itemize} \end{itemize}
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Loop directive (1/2)} \frametitle{Loop directive (1/4)}
\begin{block}{Syntax 1} \begin{block}{Syntax 1: Simple iteration over one variable}
\verb+@#for +\textit{variable\_name}\verb+ in +\textit{array\_expr} \\ \verb+@#for +\textit{variable\_name}\verb+ in +\textit{array\_expr} \\
\verb+ +\textit{loop\_body} \\ \verb+ +\textit{loop\_body} \\
\verb+@#endfor+ \verb+@#endfor+
\end{block} \end{block}
\begin{block}{Syntax 2} \begin{block}{Syntax 2: Iteration over several variables at the same time}
\verb+@#for +\textit{tuple}\verb+ in +\textit{array\_expr} \\ \verb+@#for +\textit{tuple}\verb+ in +\textit{array\_expr} \\
\verb+ +\textit{loop\_body} \\ \verb+ +\textit{loop\_body} \\
\verb+@#endfor+ \verb+@#endfor+
\end{block} \end{block}
\begin{block}{Syntax 3} \begin{block}{Syntax 3: Iteration with some values excluded}
\verb+@#for +\textit{tuple\_or\_variable}\verb+ in +\textit{array\_expr} \verb+ when +\textit{expr}\\ \verb+@#for +\textit{tuple\_or\_variable}\verb+ in +\textit{array\_expr} \verb+ when +\textit{expr}\\
\verb+ +\textit{loop\_body} \\ \verb+ +\textit{loop\_body} \\
\verb+@#endfor+ \verb+@#endfor+
...@@ -418,7 +440,7 @@ end; ...@@ -418,7 +440,7 @@ end;
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Loop directive (2/2)} \frametitle{Loop directive (2/4)}
\begin{block}{Example: before macro processing} \begin{block}{Example: before macro processing}
\small \small
\begin{verbatim} \begin{verbatim}
...@@ -443,6 +465,44 @@ end; ...@@ -443,6 +465,44 @@ end;
\end{block} \end{block}
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Loop directive (3/4)}
\begin{block}{Example: loop over several variables}
\small
\begin{verbatim}
@#define A = [ "X", "Y", "Z"]
@#define B = [ 1, 2, 3]
model;
@#for (i,j) in A*B
e_@{i}_@{j} = …
@#endfor
end;
\end{verbatim}
\normalsize
This will loop over \texttt{e\_X\_1}, \texttt{e\_X\_2}, …, \texttt{e\_Z\_3} (9
variables in total)
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Loop directive (4/4)}
\begin{block}{Example: loop over several variables with filtering}
\small
\begin{verbatim}
model;
@#for (i,j,k) in (1:10)^3 when i^2+j^2==k^2
e_@{i}_@{j}_@{k} = …
@#endfor
end;
\end{verbatim}
\normalsize
This loop will iterate over only 4 triplets: \texttt{(3,4,5)},
\texttt{(4,3,5)}, \texttt{(6,8,10)}, \texttt{(8,6,10)}.
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Conditional directives (1/3)} \frametitle{Conditional directives (1/3)}
...@@ -468,6 +528,7 @@ end; ...@@ -468,6 +528,7 @@ end;
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Conditional directives (2/3)} \frametitle{Conditional directives (2/3)}
\begin{block}{Syntax 3} \begin{block}{Syntax 3}
\scriptsize
\verb+@#if +\textit{bool\_or\_real\_expr1} \\ \verb+@#if +\textit{bool\_or\_real\_expr1} \\
\verb+ +\textit{body included if expr1 is true (or != 0)} \\ \verb+ +\textit{body included if expr1 is true (or != 0)} \\
\verb+@#elseif +\textit{bool\_or\_real\_expr2} \\ \verb+@#elseif +\textit{bool\_or\_real\_expr2} \\
...@@ -517,26 +578,27 @@ end; ...@@ -517,26 +578,27 @@ end;
\end{columns} \end{columns}
\bigskip \bigskip
\begin{itemize}
There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+ \item There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
(\textit{i.e.} it tests whether a variable is \emph{not} defined). NB: There is (\textit{i.e.} it tests whether a variable is \emph{not} defined).
\item NB: There is
\emph{no} \verb+@#elseifdef+ or \verb+@#elseifndef+ directive; use \emph{no} \verb+@#elseifdef+ or \verb+@#elseifndef+ directive; use
\verb+elseif defined(variable_name)+ to achieve the desired objective. \verb+elseif defined(variable_name)+ to achieve the desired objective.
\end{itemize}
\end{frame} \end{frame}
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Echo and error directives} \frametitle{Echo directives}
\begin{itemize} \begin{itemize}
\item The echo directive will simply display a message on standard output \item The echo directive will simply display a message on standard output
\item The error directive will display the message and make Dynare stop (only makes sense inside a conditional directive)
\item The echomacrovars directive will display all of the macro variables (or \item The echomacrovars directive will display all of the macro variables (or
those specified) and their values, optionally saving them those specified) and their values
\item The \texttt{save} option allows saving this information to \texttt{options\_.macrovars\_line\_x}, where \texttt{x} denotes the line number where the statement was encountered
\end{itemize} \end{itemize}
\begin{block}{Syntax} \begin{block}{Syntax}
\verb+@#echo +\textit{string\_expr} \\ \verb+@#echo +\textit{string\_expr} \\
\verb+@#error +\textit{string\_expr} \\
\verb+@#echomacrovars +\\ \verb+@#echomacrovars +\\
\verb+@#echomacrovars +\textit{list\_of\_variables}\\ \verb+@#echomacrovars +\textit{list\_of\_variables}\\
\verb+@#echomacrovars(save)+\\ \verb+@#echomacrovars(save)+\\
...@@ -546,6 +608,23 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+ ...@@ -546,6 +608,23 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
\begin{block}{Examples} \begin{block}{Examples}
\begin{verbatim} \begin{verbatim}
@#echo "Information message." @#echo "Information message."
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Error directive}
\begin{itemize}
\item The error directive will display the message and make Dynare stop (only makes sense inside a conditional directive)
\end{itemize}
\begin{block}{Syntax}
\verb+@#error +\textit{string\_expr} \\
\end{block}
\begin{block}{Example}
\begin{verbatim}
@#error "Error message!" @#error "Error message!"
\end{verbatim} \end{verbatim}
\end{block} \end{block}
...@@ -554,9 +633,9 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+ ...@@ -554,9 +633,9 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
\begin{frame} \begin{frame}
\frametitle{Macro-related command line options} \frametitle{Macro-related command line options}
\begin{itemize} \begin{itemize}
\item \texttt{savemacro}: Useful for debugging or learning purposes, saves the output of the macro processor. If your \texttt{.mod} file is called \texttt{file.mod}, the output is saved to \texttt{file-macroexp.mod}. \item \texttt{savemacro}: Useful for debugging or learning purposes, saves the output of the macro processor. If your \texttt{.mod} file is called \texttt{file.mod}, the output is saved to \texttt{file\_macroexp.mod}.
\item \texttt{nolinemacro}: In the output of \texttt{savemacro}, don't print line numbers where the macro directives were placed. \item NB: \texttt{savemacro=filename} allows a user-defined file name
\item \texttt{noemptylinemacro}: Remove empty lines in the output of \texttt{savemacro}. \item \texttt{linemacro}: In the output of \texttt{savemacro}, print line numbers where the macro directives were placed.
\item \texttt{onlymacro}: Stops processing after the macro processing step. \item \texttt{onlymacro}: Stops processing after the macro processing step.
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -569,13 +648,13 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+ ...@@ -569,13 +648,13 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
\item The \verb+@#include+ directive can be used to split \texttt{.mod} files into several modular components \item The \verb+@#include+ directive can be used to split \texttt{.mod} files into several modular components
\item Example setup: \item Example setup:
\begin{description} \begin{description}
\item[\texttt{modeldesc.mod}:] contains variable declarations, model equations and shocks declarations \item[\texttt{modeldesc.mod}:] contains variable declarations, model equations, and shock declarations
\item[\texttt{simulate.mod}:] includes \texttt{modeldesc.mod}, calibrates parameters and runs stochastic simulations \item[\texttt{simulate.mod}:] includes \texttt{modeldesc.mod}, calibrates parameters, and runs stochastic simulations
\item[\texttt{estim.mod}:] includes \texttt{modeldesc.mod}, declares priors on parameters and runs bayesian estimation \item[\texttt{estim.mod}:] includes \texttt{modeldesc.mod}, declares priors on parameters, and runs Bayesian estimation
\end{description} \end{description}
\item Dynare can be called on \texttt{simulate.mod} and \texttt{estim.mod} \item Dynare can be called on \texttt{simulate.mod} and \texttt{estim.mod}
\item But it makes no sense to run it on \texttt{modeldesc.mod} \item But it makes no sense to run it on \texttt{modeldesc.mod}
\item Advantage: no need to manually copy/paste the whole model (at the beginning) or changes to the model (during development) \item Advantage: no need to manually copy/paste the whole model (during initial development) or port model changes (during development)
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -654,18 +733,18 @@ end; ...@@ -654,18 +733,18 @@ end;
\begin{frame} \begin{frame}
\frametitle{Endogeneizing parameters (1/4)} \frametitle{Endogeneizing parameters (1/4)}
\begin{itemize} \begin{itemize}
\item When calibrating the model it may be useful to consider a parameter as an endogenous (and vice-versa) \item When calibrating the model, it may be useful to pin down parameters by targeting endogenous objects
\item Example: \item Example:
\begin{gather*} \begin{gather*}
y = \left(\alpha^{\frac{1}{\xi}} \ell^{1-\frac{1}{\xi}} + (1-\alpha)^{\frac{1}{\xi}}k^{1-\frac{1}{\xi}}\right)^{\frac{\xi}{\xi - 1}} \\ y_t = \left(\alpha^{\frac{1}{\xi}} \ell_t^{1-\frac{1}{\xi}} + (1-\alpha)^{\frac{1}{\xi}}k_t^{1-\frac{1}{\xi}}\right)^{\frac{\xi}{\xi - 1}} \\
lab\_rat = \frac{w \ell}{p y} lab\_rat_t = \frac{w_t \ell_t}{p_t y_t}
\end{gather*} \end{gather*}
\item In the model, $\alpha$ is a (share) parameter, and $lab\_rat$ is an endogenous variable \item In the model, $\alpha$ is a (share) parameter, and $lab\_rat_t$ is an endogenous variable
\item We observe that: \item We observe that:
\begin{itemize} \begin{itemize}
\item calibrating $\alpha$ is not straigthforward! \item setting a value for $\alpha$ is not straightforward!
\item on the contrary, we have real world data for $lab\_rat$ \item but we have real world data for $lab\_rat_t$
\item it is clear that these two variables are economically linked \item it is clear that these two objects are economically linked
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -673,13 +752,13 @@ end; ...@@ -673,13 +752,13 @@ end;
\begin{frame}[fragile=singleslide] \begin{frame}[fragile=singleslide]
\frametitle{Endogeneizing parameters (2/4)} \frametitle{Endogeneizing parameters (2/4)}
\begin{itemize} \begin{itemize}
\item Therefore, when computing the steady state: \item Therefore, when computing the steady state by solving the static model:
\begin{itemize} \begin{itemize}
\item we make $\alpha$ an endogenous variable and $lab\_rat$ a parameter \item we make $\alpha$ a variable and the steady state value $lab\_rat$ of the dynamic variable $lab\_rat_t$ a parameter
\item we impose an economically relevant value for $lab\_rat$ \item we impose an economically sensible value for $lab\_rat$
\item the solution algorithm deduces the implied value for $\alpha$ \item the solution algorithm deduces the implied value for $\alpha$
\end{itemize} \end{itemize}
\item We call this method ``variable flipping'' \item We call this method ``variable flipping'', because it treats $\alpha$ as a variable and $lab\_rat$ as a parameter for the purpose of the static model
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -714,16 +793,16 @@ end; ...@@ -714,16 +793,16 @@ end;
\item File \texttt{steadystate.mod}: \item File \texttt{steadystate.mod}:
\begin{itemize} \begin{itemize}
\item begins with \verb+@#define steady = true+ \item begins with \verb+@#define steady = true+
\item then with \verb+@#include "modeqs.mod"+ \item followed by \verb+@#include "modeqs.mod"+
\item initializes parameters (including \texttt{lab\_rat}, excluding \texttt{alpha}) \item initializes parameters (including \texttt{lab\_rat}, excluding \texttt{alpha})
\item computes steady state (using guess values for endogenous, including \texttt{alpha}) \item computes steady state (using guess values for endogenous, including \texttt{alpha})
\item saves values of parameters and endogenous at steady-state in a file, using the \texttt{save\_params\_and\_steady\_state} command \item saves values of parameters and variables at steady-state in a file, using the \texttt{save\_params\_and\_steady\_state} command
\end{itemize} \end{itemize}
\item File \texttt{simulate.mod}: \item File \texttt{simulate.mod}:
\begin{itemize} \begin{itemize}
\item begins with \verb+@#define steady = false+ \item begins with \verb+@#define steady = false+
\item then with \verb+@#include "modeqs.mod"+ \item followed by \verb+@#include "modeqs.mod"+
\item loads values of parameters and endogenous at steady-state from file, using the \texttt{load\_params\_and\_steady\_state} command \item loads values of parameters and variables at steady-state from file, using the \texttt{load\_params\_and\_steady\_state} command
\item computes simulations \item computes simulations
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
...@@ -738,14 +817,18 @@ end; ...@@ -738,14 +817,18 @@ end;
\begin{verbatim} \begin{verbatim}
rhos = [ 0.8, 0.9, 1]; rhos = [ 0.8, 0.9, 1];
for i = 1:length(rhos) for i = 1:length(rhos)
rho = rhos(i); set_param_value('rho',rhos(i));
stoch_simul(order=1); stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
end end
\end{verbatim} \end{verbatim}
\end{block} \end{block}
\begin{itemize} \begin{itemize}
\item The loop is not unrolled \item The loop is not unrolled
\item MATLAB/Octave manages the iterations \item MATLAB/Octave manages the iterations
\item NB: always check whether the error flag \texttt{info(1)==0} to prevent erroneously relying on stale results from previous iterations
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -755,8 +838,11 @@ end ...@@ -755,8 +838,11 @@ end
\begin{verbatim} \begin{verbatim}
rhos = [ 0.8, 0.9, 1]; rhos = [ 0.8, 0.9, 1];
@#for i in 1:3 @#for i in 1:3
rho = rhos(@{i}); set_param_value('rho',rhos(@{i}));
stoch_simul(order=1); stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
@#endfor @#endfor
\end{verbatim} \end{verbatim}
\end{block} \end{block}
...@@ -772,8 +858,11 @@ rhos = [ 0.8, 0.9, 1]; ...@@ -772,8 +858,11 @@ rhos = [ 0.8, 0.9, 1];
\begin{block}{With a macro processor loop (case 2)} \begin{block}{With a macro processor loop (case 2)}
\begin{verbatim} \begin{verbatim}
@#for rho_val in [ 0.8, 0.9, 1] @#for rho_val in [ 0.8, 0.9, 1]
rho = @{rho_val}; set_param_value('rho',@{rho_val});
stoch_simul(order=1); stoch_simul(order=1);
if info(1)~=0
error('Simulation failed for parameter draw')
end
@#endfor @#endfor
\end{verbatim} \end{verbatim}
\end{block} \end{block}
...@@ -783,26 +872,26 @@ rhos = [ 0.8, 0.9, 1]; ...@@ -783,26 +872,26 @@ rhos = [ 0.8, 0.9, 1];
\end{itemize} \end{itemize}
\end{frame} \end{frame}
% \begin{frame}[fragile=singleslide]
% \frametitle{Possible future developments}
% \begin{itemize}
% \item Find a nicer syntax for indexed sums/products
% \item Implement other control structures: \texttt{elsif}, \texttt{switch/case}, \texttt{while/until} loops
% \item Implement macro-functions (or templates), with a syntax like:
% \small
% \verb+@#define QUADRATIC_COST(x, x_ss, phi) = phi/2*(x/x_ss-1)^2+
% \normalsize
% \end{itemize}
% \end{frame}
\begin{frame} \begin{frame}
\begin{center} \begin{center}
\vfill {\LARGE Thanks for your attention!} \vfill \vfill {\LARGE Thanks for your attention! \\
{\LARGE Questions?} Questions?}
\vfill
{\LARGE My email: \texttt{sebastien@dynare.org}}
\vfill \vfill
\end{center} \end{center}
\vfill \vfill
\end{frame} \begin{columns}[T]
\column{0.2\textwidth}
\column{0.09\textwidth}
\ccbysa
\column{0.71\textwidth}
\tiny
Copyright © 2008-2024 Dynare Team \\
License: \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative
Commons Attribution-ShareAlike 4.0}
\end{columns}
\end{frame}
\end{document} \end{document}
latexmk_exe = find_program('latexmk', required : false, disabler : true)
# We have to set TEXINPUTS because the current directory is not the source
# directory when latexmk is invoked (and using the -cd option in combination
# with -outdir/-auxdir does not work in all cases because @OUTDIR@ and
# @PRIVATE_DIR@ can be relative paths)
# Without the -g flag, latexmk remembers a previous build failure and will refuse
# to recompile even if the error has been fixed in the TeX source
latexmk_command = [ latexmk_exe, '-pdf', '-g', '-outdir=@OUTDIR@', '-auxdir=@PRIVATE_DIR@', '@INPUT@']
# The \graphicspath{} command does not compute directories relative to TEXINPUTS,
# so add these manually
logos_dir = meson.current_source_dir() / 'logos'
macroprocessor_pdf = custom_target('macroprocessor.pdf',
output : 'macroprocessor.pdf',
input : 'macroprocessor/macroprocessor.tex',
command : latexmk_command,
env : { 'TEXINPUTS': meson.current_source_dir()
+ '/macroprocessor:' + logos_dir + ':' },
depend_files : [ 'macroprocessor/new-design.pdf',
'logos/dlogo.png' ],
build_by_default : false,
install : true,
install_dir : 'share/doc/dynare')
preprocessor_pdf = custom_target('preprocessor.pdf',
output : 'preprocessor.pdf',
input : 'preprocessor/preprocessor.tex',
command : latexmk_command,
env : { 'TEXINPUTS': meson.current_source_dir() + '/preprocessor:'
+ logos_dir + ':' },
depend_files : [ 'preprocessor/expr.png',
'preprocessor/expr-sharing.png',
'preprocessor/json-preprocessor.png',
'preprocessor/matrices.png',
'preprocessor/overview.png', 'logos/dlogo.png' ],
build_by_default : false,
install : true,
install_dir : 'share/doc/dynare')
if ENABLE_DOC
pdf-local: preprocessor.pdf
endif
SRC = preprocessor.tex expr.png expr-sharing.png matrices.png overview.png json-preprocessor.png
EXTRA_DIST = $(SRC)
preprocessor.pdf: $(SRC)
$(PDFLATEX) preprocessor
$(PDFLATEX) preprocessor
clean-local:
rm -f *.pdf *.toc *.aux *.log *.nav *.snm *.vrb *.out *~
\documentclass{beamer} \documentclass[aspectratio=169]{beamer}
\usepackage[utf8]{inputenc} \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} \usepackage[T1]{fontenc}
\usepackage{lmodern} \usepackage{lmodern}
...@@ -9,14 +9,18 @@ ...@@ -9,14 +9,18 @@
\usepackage[english]{babel} \usepackage[english]{babel}
\usepackage[utf8]{inputenc} \usepackage[utf8]{inputenc}
\newenvironment{witemize}{\itemize\addtolength{\itemsep}{8pt}}{\enditemize}
\newenvironment{wenumerate}{\enumerate\addtolength{\itemsep}{8pt}}{\enditemize}
\titlegraphic{\includegraphics{../logos/dlogo.png}} \graphicspath{{../logos}}
\titlegraphic{\includegraphics{dlogo.png}}
\title{The Dynare Preprocessor} \title{The Dynare Preprocessor}
\author[S. Villemot, H.Bastani]{Sébastien Villemot \and Houtan Bastani} \author[S. Villemot, H.Bastani]{Sébastien Villemot \and Houtan Bastani}
\institute[CEPREMAP]{\includegraphics[scale=0.15]{../logos/cepremap.jpg}} \institute[CEPREMAP]{\includegraphics[scale=0.15]{cepremap.jpg}}
\date{1 February 2017} \date{1 February 2017}
...@@ -67,7 +71,7 @@ ...@@ -67,7 +71,7 @@
\ccbysa \ccbysa
\column{0.71\textwidth} \column{0.71\textwidth}
\tiny \tiny
Copyright © 2007--2017 Dynare Team \\ Copyright © 2007--2023 Dynare Team \\
Licence: \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative Licence: \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative
Commons Attribution-ShareAlike 4.0} Commons Attribution-ShareAlike 4.0}
\end{columns} \end{columns}
...@@ -88,35 +92,106 @@ ...@@ -88,35 +92,106 @@
\begin{frame} \begin{frame}
\frametitle{Calling Dynare} \frametitle{Calling Dynare}
\begin{itemize} \begin{witemize}
\item Dynare is called from the host language platform with the syntax \texttt{dynare <<filename>>.mod} \item Dynare is called from the host language platform with the syntax \texttt{dynare <<filename>>.mod}
\item This call can be followed by certain options: \item This call can be followed by certain options:
\begin{itemize} \begin{itemize}
\item Some of these options impact host language platform functionality, \textit{e.g.} \texttt{nograph} prevents graphs from being displayed in MATLAB \item Some of these options impact host language platform functionality\\
\item Some cause differences in the output created by default, \textit{e.g.} \texttt{notmpterms} prevents temporary terms from being written to the static/dynamic files $\rightarrow$ \textit{e.g.} \texttt{nograph} prevents graphs from being displayed in MATLAB
\item While others impact the functionality of the macroprocessor or the preprocessor, \textit{e.g.} \texttt{nostrict} shuts off certain checks that the preprocessor does by defalut \item Some cause differences in the output created by default\\
$\rightarrow$ \texttt{notmpterms} prevents temporary terms from being written to the static/dynamic files
\item While others impact the functionality of the macroprocessor or the preprocessor\\
$\rightarrow$ \textit{e.g.} \texttt{nostrict} shuts off certain checks that the preprocessor does by default
\end{itemize} \end{itemize}
\item MATLAB command line supports syntax completion since Dynare 6.x
\end{witemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Command line options in the mod-file}
\begin{witemize}
\item Command line options can alternatively be defined in the first line of the .mod file
\item Avoids to always have to invoke an option at the command line\\
$\rightarrow$ particularly useful for the \texttt{nostrict} option during the development phase of a model
\item Definition must be
\begin{itemize}
\item a one-line Dynare comment, i.e. begin //
\item the options must be enclosed in \texttt{----+ options:} and \texttt{+----} and must be whitespace separated
\item As in the command line, if an option admits a value, the equal symbol must not be surrounded by spaces
\end{itemize} \end{itemize}
\begin{block}{Example}
\begin{verbatim}
// --+ options: json=compute, stochastic, nostrict +--
\end{verbatim}
\end{block}
\end{witemize}
\end{frame}
\section{Macro processing}
\begin{frame}
\frametitle{Macro processing}
\begin{witemize}
\item The Dynare macro language provides a set of macro commands that can be used in \texttt{mod} files
\item The macro processor employs text expansions/inclusions to transform a \texttt{mod} file with macro commands into a \texttt{mod} file without macro commands\\
$\rightarrow$ result can be stored using \texttt{savemacro} option
\item The result is fed to the parser\\
$\rightarrow$ use \texttt{onlymacro} to stop after macro processing before parsing
\item Attention: the macro processor only does text substitution; objects computed in later steps are not available yet and cannot be conditioned on for that reason
\end{witemize}
\end{frame} \end{frame}
\section{Parsing} \section{Parsing}
\begin{frame} \begin{frame}
\frametitle{Parsing overview} \frametitle{Parsing overview}
\begin{itemize} \begin{witemize}
\item Parsing is the action of transforming an input text (a \texttt{mod} file in our case) into a data structure suitable for computation \item Parsing is the action of transforming an input text (a \texttt{mod} file in our case) into a data structure suitable for computation
\item The parser consists of three components: \item The parser consists of three components:
\begin{itemize} \begin{wenumerate}
\item the \alert{lexical analyzer}, which recognizes the ``words'' of the \texttt{mod} file (analog to the \textit{vocabulary} of a language) \item the \alert{lexical analyzer}, which recognizes the ``words'' of the \texttt{mod} file (analog to the \textit{vocabulary} of a language)
\item the \alert{syntax analyzer}, which recognizes the ``sentences'' of the \texttt{mod} file (analog to the \textit{grammar} of a language) \item the \alert{syntax analyzer}, which recognizes the ``sentences'' of the \texttt{mod} file (analog to the \textit{grammar} of a language)
\item the \alert{parsing driver}, which coordinates the whole process and constructs the data structure using the results of the lexical and syntax analyses \item the \alert{parsing driver}, which coordinates the whole process and constructs the data structure using the results of the lexical and syntax analyses
\end{itemize} \end{wenumerate}
\end{itemize} \end{witemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Undesired Parsing}
\begin{witemize}
\item Dynare will try to parse all tokens it recognizes
\item Code not recognized by the parser is directly passed to the preprocessor output\\
$\rightarrow$ allows using MATLAB/Octave commands directly in the mod-file
\item Causes problems when one wants to invoke commands containing recognized tokens
\end{witemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Bypassing the parsing}
\begin{witemize}
\item The \texttt{verbatim} block instructs Dynare not to parse text contained in it
\item In the following example, \texttt{stoch\_simul} would otherwise be recognized as a Dynare command during parsing
\end{witemize}
\begin{block}{Verbatim example}
\begin{verbatim}
verbatim;
rhos = [ 0.8, 0.9, 1];
for iter = 1:length(rhos)
set_param_value('rho',rhos(iter));
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_)
if info(1)~=0
error('Simulation failed for parameter draw')
end
end
end;
\end{verbatim}
\end{block}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Lexical analysis} \frametitle{1.\ Lexical analysis}
\begin{itemize} \begin{witemize}
\item The lexical analyzer recognizes the ``words'' (or \alert{lexemes}) of the language \item The lexical analyzer recognizes the ``words'' (or \alert{lexemes}) of the language
\item Defined in \texttt{DynareFlex.ll}, it is transformed into C++ source code by the program \texttt{flex} \item Defined in \texttt{DynareFlex.ll}, it is transformed into C++ source code by the program \texttt{flex}
\item This file details the list of known lexemes (described by regular expressions) and the associated \alert{token} for each of them \item This file details the list of known lexemes (described by regular expressions) and the associated \alert{token} for each of them
...@@ -124,7 +199,7 @@ ...@@ -124,7 +199,7 @@
\item For variable names or numbers, the token also contains the associated string for further processing \item For variable names or numbers, the token also contains the associated string for further processing
%\item \textit{Note:} the list of tokens can be found at the beginning of \texttt{DynareBison.yy} %\item \textit{Note:} the list of tokens can be found at the beginning of \texttt{DynareBison.yy}
\item When invoked, the lexical analyzer reads the next characters of the input, tries to recognize a lexeme, and either produces an error or returns the associated token \item When invoked, the lexical analyzer reads the next characters of the input, tries to recognize a lexeme, and either produces an error or returns the associated token
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
...@@ -159,7 +234,7 @@ SEMICOLON ...@@ -159,7 +234,7 @@ SEMICOLON
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Syntax analysis} \frametitle{2.\ Syntax analysis}
\framesubtitle{In Dynare} \framesubtitle{In Dynare}
\begin{itemize} \begin{itemize}
\item The \texttt{mod} file grammar is described in \texttt{DynareBison.yy}, which is transformed into C++ source code by the program \texttt{bison} \item The \texttt{mod} file grammar is described in \texttt{DynareBison.yy}, which is transformed into C++ source code by the program \texttt{bison}
...@@ -201,13 +276,13 @@ expression := expression PLUS expression ...@@ -201,13 +276,13 @@ expression := expression PLUS expression
\begin{frame} \begin{frame}
\frametitle{Semantic actions} \frametitle{Semantic actions}
\begin{itemize} \begin{witemize}
\item So far we have only described how to accept valid \texttt{mod} files and to reject others \item So far we have only described how to accept valid \texttt{mod} files and reject others
\item But validating is not enough: one needs to do something with the parsed \texttt{mod} file \item But validating is not enough: one needs to do something with the parsed \texttt{mod} file
\item Every grammar rule can have a \alert{semantic action} associated with it: C/C++ code enclosed by curly braces \item Every grammar rule can have a \alert{semantic action} associated with it: C/C++ code enclosed by curly braces
\item Every rule can return a semantic value (referenced by \texttt{\$\$} in the action) \item Every rule can return a semantic value (referenced by \texttt{\$\$} in the action)
\item In the action, it is possible to refer to semantic values returned by components of the rule (using \texttt{\$1}, \texttt{\$2}, \ldots) \item In the action, it is possible to refer to semantic values returned by components of the rule (using \texttt{\$1}, \texttt{\$2}, \ldots)
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
...@@ -238,15 +313,15 @@ expression := expression PLUS expression ...@@ -238,15 +313,15 @@ expression := expression PLUS expression
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Parsing driver} \frametitle{3.\ Parsing driver}
The class \texttt{ParsingDriver} has the following roles: The class \texttt{ParsingDriver} has the following roles:
\begin{itemize} \begin{witemize}
\item It opens the \texttt{mod} file and launches the lexical and syntaxic analyzers on it \item It opens the \texttt{mod} file and launches the lexical and syntaxic analyzers on it
\item It implements most of the semantic actions of the grammar \item It implements most of the semantic actions of the grammar
\item By doing so, it creates an object of type \texttt{ModFile}, which is the data structure representing the \texttt{mod} file \item By doing so, it creates an object of type \texttt{ModFile}, which is the data structure representing the \texttt{mod} file
\item Or, if there is a parsing error (unknown keyword, undeclared symbol, syntax error), it displays the line and column numbers where the error occurred and exits \item Or, if there is a parsing error (unknown keyword, undeclared symbol, syntax error), it displays the line and column numbers where the error occurred and exits
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\section{Data structure representing a \texttt{mod} file} \section{Data structure representing a \texttt{mod} file}
...@@ -270,7 +345,7 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -270,7 +345,7 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame} \begin{frame}
\frametitle{The symbol table (1/3)} \frametitle{The symbol table (1/3)}
\begin{itemize} \begin{witemize}
\item A \alert{symbol} is simply the name of a variable (endogenous, exogenous, local, auxiliary, etc), parameter, external function, \ldots basically everything that is not recognized as a Dynare keyword \item A \alert{symbol} is simply the name of a variable (endogenous, exogenous, local, auxiliary, etc), parameter, external function, \ldots basically everything that is not recognized as a Dynare keyword
\item \alert{SymbolTable} is a simple class used to maintain the list of the symbols used in the \texttt{mod} file \item \alert{SymbolTable} is a simple class used to maintain the list of the symbols used in the \texttt{mod} file
\item For each symbol, it stores: \item For each symbol, it stores:
...@@ -279,7 +354,7 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -279,7 +354,7 @@ The class \texttt{ParsingDriver} has the following roles:
\item its type (an enumerator defined in \texttt{CodeInterpreter.hh}) \item its type (an enumerator defined in \texttt{CodeInterpreter.hh})
\item a unique integer identifier (also has a unique identifier by type) \item a unique integer identifier (also has a unique identifier by type)
\end{itemize} \end{itemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
...@@ -301,20 +376,20 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -301,20 +376,20 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame} \begin{frame}
\frametitle{The symbol table (3/3)} \frametitle{The symbol table (3/3)}
\begin{itemize} \begin{witemize}
\item Symbol table filled in: \item Symbol table filled in:
\begin{itemize} \begin{witemize}
\item using the \texttt{var}, \texttt{varexo}, \texttt{varexo\_det}, \texttt{parameter}, \texttt{external\_function}, \texttt{trend\_var}, and \texttt{log\_trend\_var} declarations \item using the \texttt{var}, \texttt{varexo}, \texttt{varexo\_det}, \texttt{parameter}, \texttt{external\_function}, \texttt{trend\_var}, and \texttt{log\_trend\_var} declarations
\item using pound sign (\#) constructions in the model block \item using pound sign (\#) constructions (``model-local variables'') in the model block
\item on the fly during parsing: local variables outside models or unknown functions when an undeclared symbol is encountered \item on the fly during parsing: local variables outside models or unknown functions when an undeclared symbol is encountered
\item during the creation of auxiliary variables in the transform pass \item during the creation of auxiliary variables in the transform pass
\end{itemize} \end{witemize}
\item Roles of the symbol table: \item Roles of the symbol table:
\begin{itemize} \begin{witemize}
\item permits parcimonious and more efficient representation of expressions (no need to duplicate or compare strings, only handle a pair of integers) \item permits parsimonious and more efficient representation of expressions (no need to duplicate or compare strings, only handle a pair of integers)
\item ensures that a given symbol is used with only one type \item ensures that a given symbol is used with only one type
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
...@@ -333,30 +408,30 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -333,30 +408,30 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame} \begin{frame}
\frametitle{Expression trees (2/3)} \frametitle{Expression trees (2/3)}
\begin{itemize} \begin{witemize}
\item A tree node is represented by an instance of the abstract class \texttt{ExprNode} \item A tree node is represented by an instance of the abstract class \texttt{ExprNode}
\item This class has 5 sub-classes, corresponding to the 5 types of non-external-function nodes: \item This class has 5 sub-classes, corresponding to the 5 types of non-external-function nodes:
\begin{itemize} \begin{wenumerate}
\item \texttt{NumConstNode} for constant nodes: contains the identifier of the numerical constants it represents \item \texttt{NumConstNode} for constant nodes: contains the identifier of the numerical constants it represents
\item \texttt{VariableNode} for variable/parameters nodes: contains the identifier of the variable or parameter it represents \item \texttt{VariableNode} for variable/parameters nodes: contains the identifier of the variable or parameter it represents
\item \texttt{UnaryOpNode} for unary operators (\textit{e.g.} unary minus, $\log$, $\sin$): contains an enumerator representing the operator, and a pointer to its child \item \texttt{UnaryOpNode} for unary operators (\textit{e.g.} unary minus, $\log$, $\sin$): contains an enumerator representing the operator, and a pointer to its child
\item \texttt{BinaryOpNode} for binary operators (\textit{e.g.} $+$, $*$, pow): contains an enumerator representing the operator, and pointers to its two children \item \texttt{BinaryOpNode} for binary operators (\textit{e.g.} $+$, $*$, pow): contains an enumerator representing the operator, and pointers to its two children
\item \texttt{TrinaryOpNode} for trinary operators (\textit{e.g.} $normcdf$, $normpdf$): contains an enumerator representing the operator and pointers to its three children \item \texttt{TrinaryOpNode} for trinary operators (\textit{e.g.} $normcdf$, $normpdf$): contains an enumerator representing the operator and pointers to its three children
\end{itemize} \end{wenumerate}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Expression trees (3/3)} \frametitle{Expression trees (3/3)}
\begin{itemize} \begin{witemize}
\item The abstract class \texttt{ExprNode} has an abstract sub-class called \texttt{AbstractExternalFunctionNode} \item The abstract class \texttt{ExprNode} has an abstract sub-class called \texttt{AbstractExternalFunctionNode}
\item This abstract sub-class has 3 sub-classes, corresponding to the 3 types of external function nodes: \item This abstract sub-class has 3 sub-classes, corresponding to the 3 types of external function nodes:
\begin{itemize} \begin{wenumerate}
\item \texttt{ExternalFunctionNode} for external functions. Contains the identifier of the external function and a vector of its arguments \item \texttt{ExternalFunctionNode} for external functions. Contains the identifier of the external function and a vector of its arguments
\item \texttt{FirstDerivExternalFunctionNode} for the first derivative of an external function. In addition to the information contained in \texttt{ExternalFunctionNode}, contains the index w.r.t. which this node is the derivative. \item \texttt{FirstDerivExternalFunctionNode} for the first derivative of an external function. In addition to the information contained in \texttt{ExternalFunctionNode}, contains the index w.r.t. which this node is the derivative.
\item \texttt{SecondDerivExternalFunctionNode} for the second derivative of an external function. In addition to the information contained in \texttt{FirstDerivExternalFunctionNode}, contains the index w.r.t. which this node is the second derivative. \item \texttt{SecondDerivExternalFunctionNode} for the second derivative of an external function. In addition to the information contained in \texttt{FirstDerivExternalFunctionNode}, contains the index w.r.t. which this node is the second derivative.
\end{itemize} \end{wenumerate}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
...@@ -383,28 +458,28 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -383,28 +458,28 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame} \begin{frame}
\frametitle{Constructing expression trees} \frametitle{Constructing expression trees}
\begin{itemize} \begin{witemize}
\item Class \texttt{DataTree} contains a set of methods for constructing expression trees \item Class \texttt{DataTree} contains a set of methods for constructing expression trees
\item Construction is done bottom-up, node by node: \item Construction is done bottom-up, node by node:
\begin{itemize} \begin{witemize}
\item one method for adding a constant node (\texttt{AddPossiblyNegativeConstant(double)}) \item one method for adding a constant node (\texttt{AddPossiblyNegativeConstant(double)})
\item one method for a log node (\texttt{AddLog(arg)}) \item one method for a log node (\texttt{AddLog(arg)})
\item one method for a plus node (\texttt{AddPlus(arg1, arg2)}) \item one method for a plus node (\texttt{AddPlus(arg1, arg2)})
\end{itemize} \end{witemize}
\item These methods take pointers to \texttt{ExprNode}, allocate the memory for the node, construct it, and return its pointer \item These methods take pointers to \texttt{ExprNode}, allocate the memory for the node, construct it, and return its pointer
\item These methods are called: \item These methods are called:
\begin{itemize} \begin{witemize}
\item from \texttt{ParsingDriver} in the semantic actions associated to the parsing of expressions \item from \texttt{ParsingDriver} in the semantic actions associated to the parsing of expressions
\item during symbolic derivation, to create derivatives expressions \item during symbolic derivation to create derivatives expressions
\item when creating the static model from the dynamic model \item when creating the static model from the dynamic model
\item \ldots \item \ldots
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Reduction of constants and symbolic simplifications} \frametitle{Reduction of constants and symbolic simplifications}
\begin{itemize} \begin{witemize}
\item The construction methods compute constants whenever possible \item The construction methods compute constants whenever possible
\begin{itemize} \begin{itemize}
\item Suppose you ask to construct the node $1+1$ \item Suppose you ask to construct the node $1+1$
...@@ -421,19 +496,20 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -421,19 +496,20 @@ The class \texttt{ParsingDriver} has the following roles:
\item $x^0 = 1$ \item $x^0 = 1$
\end{itemize} \end{itemize}
\item When a simplification rule applies, no new node is created \item When a simplification rule applies, no new node is created
\end{itemize} \item Attention: this may cause the program to detect issues not directly visible to users like a division by 0
\end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Sub-expression sharing (1/2)} \frametitle{Sub-expression sharing (1/2)}
\begin{itemize} \begin{witemize}
\item Consider the two following expressions: $(1+z)*\log(y)$ and $2^{(1+z)}$ \item Consider the two following expressions: $(1+z)*\log(y)$ and $2^{(1+z)}$
\item Expressions share a common sub-expression: $1+z$ \item Expressions share a common sub-expression: $1+z$
\item The internal representation of these expressions is: \item The internal representation of these expressions is:
\begin{center} \begin{center}
\includegraphics[width=7cm]{expr-sharing.png} \includegraphics[width=7cm]{expr-sharing.png}
\end{center} \end{center}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
...@@ -454,107 +530,107 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -454,107 +530,107 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame} \begin{frame}
\frametitle{Final remarks about expressions} \frametitle{Final remarks about expressions}
\begin{itemize} \begin{witemize}
\item Storage of negative constants \item Storage of negative constants
\begin{itemize} \begin{witemize}
\item class \texttt{NumConstNode} only accepts positive constants \item class \texttt{NumConstNode} only accepts positive constants
\item a negative constant is stored as a unary minus applied to a positive constant \item a negative constant is stored as a unary minus applied to a positive constant
\item this is a kind of identification constraint to avoid having two ways of representing negative constants: $(-2)$ and $-(2)$ \item this is a kind of identification constraint to avoid having two ways of representing negative constants: $(-2)$ and $-(2)$
\end{itemize} \end{witemize}
\item Widely used constants \item Widely used constants
\begin{itemize} \begin{witemize}
\item class \texttt{DataTree} has attributes containing pointers to constants: $0$, $1$, $2$, $-1$, \texttt{NaN}, $\infty$, $-\infty$, and $\pi$ \item class \texttt{DataTree} has attributes containing pointers to constants: $0$, $1$, $2$, $-1$, \texttt{NaN}, $\infty$, $-\infty$, and $\pi$
\item these constants are used in many places (in simplification rules, in derivation algorithm\ldots) \item these constants are used in many places (in simplification rules, in derivation algorithm\ldots)
\item sub-expression sharing algorithm ensures that these constants will never be duplicated \item sub-expression sharing algorithm ensures that these constants will never be duplicated
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{List of statements} \frametitle{List of statements}
\begin{itemize} \begin{witemize}
\item A statement is represented by an instance of a subclass of the abstract class \texttt{Statement} \item A statement is represented by an instance of a subclass of the abstract class \texttt{Statement}
\item Three groups of statements: \item Three groups of statements:
\begin{itemize} \begin{itemize}
\item initialization statements (parameter initialization with $p = \ldots$, \texttt{initval}, \texttt{histval}, or \texttt{endval} block) \item initialization statements (parameter initialization with $p = \ldots$, \texttt{initval}, \texttt{histval}, or \texttt{endval} block)
\item shocks blocks (\texttt{shocks}, \texttt{mshocks}, \ldots) \item shocks blocks (\texttt{shocks}, \texttt{mshocks}, \ldots)
\item computing tasks (\texttt{steady}, \texttt{check}, \texttt{simul}, \ldots) \item computing tasks (\texttt{steady}, \texttt{check}, \texttt{perfect\_foresight\_solver}, \ldots)
\end{itemize} \end{itemize}
\item Each type of statement has its own class (\textit{e.g.} \texttt{InitValStatement}, \texttt{SimulStatement}, \ldots) \item Each type of statement has its own class (\textit{e.g.} \texttt{InitValStatement}, \texttt{PerfectForesightSolverStatement}, \ldots)
\item The class \texttt{ModFile} stores a list of pointers of type \texttt{Statement*}, corresponding to the statements of the \texttt{mod} file, in their order of declaration \item The class \texttt{ModFile} stores a list of pointers of type \texttt{Statement*}, corresponding to the statements of the \texttt{mod} file, in their order of declaration
\item Heavy use of polymorphism in the check pass, computing pass, and when writing outputs: abstract class \texttt{Statement} provides a virtual method for these 3 actions \item Heavy use of polymorphism in the check pass, computing pass, and when writing outputs: abstract class \texttt{Statement} provides a virtual method for these 3 actions
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Evaluation context} \frametitle{Evaluation context}
\begin{itemize} \begin{witemize}
\item The \texttt{ModFile} class contains an \alert{evaluation context} \item The \texttt{ModFile} class contains an \alert{evaluation context}
\item It is a map associating a numerical value to some symbols \item It is a map associating a numerical value to some symbols
\item Filled in with \texttt{initval} block values and parameter initializations \item Filled in with \texttt{initval} block values and parameter initializations
\item Used during equation normalization (in the block decomposition), for finding non-zero entries in the jacobian \item Used during equation normalization (in the block decomposition), for finding non-zero entries in the Jacobian
\item Used in testing that trends are compatible with a balanced growth path, for finding non-zero cross partials of equations with respect to trend variables and endogenous varibales \item Used in testing that trends are compatible with a balanced growth path, for finding non-zero cross partials of equations with respect to trend variables and endogenous variables
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\section{Check pass} \section{Check pass}
\begin{frame} \begin{frame}
\frametitle{Error checking during parsing} \frametitle{Error checking during parsing}
\begin{itemize} \begin{witemize}
\item Some errors in the \texttt{mod} file can be detected during parsing: \item Some errors in the \texttt{mod} file can be detected during parsing:
\begin{itemize} \begin{witemize}
\item syntax errors \item syntax errors
\item use of undeclared symbols in model block, initval block\ldots \item use of undeclared symbols in model block, initval block\ldots
\item use of a symbol incompatible with its type (\textit{e.g.} parameter in initval, local variable used both in model and outside model) \item use of a symbol incompatible with its type (\textit{e.g.} parameter in initval, local variable used both in model and outside model)
\item multiple shock declarations for the same variable \item multiple shock declarations for the same variable
\end{itemize} \end{witemize}
\item But some other checks can only be done when parsing is completed\ldots \item But some other checks can only be done when parsing is completed\ldots
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Check pass} \frametitle{Check pass}
\begin{itemize} \begin{witemize}
\item The check pass is implemented through the method \texttt{ModFile::checkPass()} \item The check pass is implemented through the method \texttt{ModFile::checkPass()}
\item Performs many checks. Examples include: \item Performs many checks. Examples include:
\begin{itemize} \begin{witemize}
\item check there is at least one equation in the model (except if doing a standalone BVAR estimation) \item check there is at least one equation in the model (except if doing a standalone BVAR estimation)
\item checks for coherence in statements (\textit{e.g.} options passed to statements do not conflict with each other, required options have been passed) \item checks for coherence in statements (\textit{e.g.} options passed to statements do not conflict with each other, required options have been passed)
\item checks for coherence among statements (\textit{e.g.} if \texttt{osr} statement is present, ensure \texttt{osr\_params} and \texttt{optim\_weights} statements are present) \item checks for coherence among statements (\textit{e.g.} if \texttt{osr} statement is present, ensure \texttt{osr\_params} and \texttt{optim\_weights} statements are present)
\item checks for coherence between statements and attributes of \texttt{mod} file (\textit{e.g.} \texttt{use\_dll} is not used with \texttt{block} or \texttt{bytecode}) \item checks for coherence between statements and attributes of \texttt{mod} file (\textit{e.g.} \texttt{use\_dll} is not used with \texttt{block} or \texttt{bytecode})
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\section{Transform pass} \section{Transform pass}
\begin{frame} \begin{frame}
\frametitle{Transform pass (1/2)} \frametitle{Transform pass (1/2)}
\begin{itemize} \begin{witemize}
\item The transform pass is implemented through the method \texttt{ModFile::transformPass(bool nostrict)} \item The transform pass is implemented through the method \texttt{ModFile::transformPass(bool nostrict)}
\item It makes necessary transformations (notably to the dynamic model, symbol table, and statements list) preparing the \texttt{ModFile} object for the computing pass. Examples of transformations include: \item It makes necessary transformations (notably to the dynamic model, symbol table, and statements list), preparing the \texttt{ModFile} object for the computing pass. Examples of transformations include:
\begin{itemize} \begin{witemize}
\item creation of auxiliary variables and equations for leads, lags, expectation operator, differentiated forward variables, etc. \item creation of auxiliary variables and equations for leads, lags, expectation operator, differentiated forward variables, etc.
\item detrending of model equations if nonstationary variables are present \item detrending of model equations if nonstationary variables are present
\item decreasing leads/lags of predetermined variables by one period \item decreasing leads/lags of predetermined variables by one period
\item addition of FOCs of Langrangian for Ramsey problem \item addition of FOCs of Lagrangian for Ramsey problem
\item addition of \texttt{dsge\_prior\_weight} initialization before all other statements if estimating a DSGE-VAR where the weight of the DSGE prior of the VAR is calibrated \item addition of \texttt{dsge\_prior\_weight} initialization before all other statements if estimating a DSGE-VAR where the weight of the DSGE prior of the VAR is calibrated
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Transform pass (2/2)} \frametitle{Transform pass (2/2)}
\begin{itemize} \begin{witemize}
\item It then freezes the symbol table, meaning that no more symbols can be created on the \texttt{ModFile} object \item It then freezes the symbol table, meaning that no more symbols can be created on the \texttt{ModFile} object
\item Finally checks are performed on the transformed model. Examples include: \item Finally, checks are performed on the transformed model. Examples include:
\begin{itemize} \begin{witemize}
\item same number of endogenous varibables as equations (not done in certain situations, \textit{e.g.} Ramsey, discretionary policy, etc.) \item same number of endogenous variables as equations (not done in certain situations, \textit{e.g.} Ramsey, discretionary policy, where checks are done in MATLAB)
\item correspondence among variables and statements, \textit{e.g.} Ramsey policy, identification, perfect foresight solver, and simul are incompatible with deterministic exogenous variables \item correspondence among variables and statements, \textit{e.g.} Ramsey policy, identification, perfect foresight solver, and perfect foresight solver are incompatible with deterministic exogenous variables
\item correspondence among statements, \textit{e.g.} for DSGE-VAR without \texttt{bayesian\_irf} option, the number of shocks must be greater than or equal to the number of observed variables \item correspondence among statements, \textit{e.g.} for DSGE-VAR with \texttt{bayesian\_irf} option, the number of shocks must be equal to the number of observed variables
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
...@@ -564,9 +640,9 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -564,9 +640,9 @@ The class \texttt{ParsingDriver} has the following roles:
\frametitle{Overview of the computing pass} \frametitle{Overview of the computing pass}
\begin{itemize} \begin{itemize}
\item Computing pass implemented in \texttt{ModFile::computingPass()} \item Computing pass implemented in \texttt{ModFile::computingPass()}
\item Creates Static model from Dynamic (by removing leads/lags) \item Creates static model from dynamic one (by removing leads/lags)
\item Determines which derivatives to compute \item Determines which derivatives to compute
\item Then calls \texttt{DynamicModel::computingPass()} which computes: \item Then calls \texttt{DynamicModel::computingPass()}, which computes:
\begin{itemize} \begin{itemize}
\item leag/lag variable incidence matrix \item leag/lag variable incidence matrix
\item symbolic derivatives w.r.t. endogenous, exogenous, and parameters, if needed \item symbolic derivatives w.r.t. endogenous, exogenous, and parameters, if needed
...@@ -574,34 +650,34 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -574,34 +650,34 @@ The class \texttt{ParsingDriver} has the following roles:
\item temporary terms \item temporary terms
\item computes equation cross references, if desired \item computes equation cross references, if desired
\end{itemize} \end{itemize}
\item NB: analagous operations for Static model are performed by \texttt{StaticModel::computingPass()} \item NB: analogous operations for static model are performed by \texttt{StaticModel::computingPass()}
\item Asserts that equations declared linear are indeed linear (by checking that Hessian == 0) \item Asserts that equations declared \texttt{linear} are indeed linear (by checking that Hessian == 0)
\item Finally, calls \texttt{Statement::computingPass()} on all statements \item Finally, calls \texttt{Statement::computingPass()} on all statements
\end{itemize} \end{itemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Model Variables} \frametitle{Model Variables}
\begin{itemize} \begin{witemize}
\item In the context of class \texttt{ModelTree}, a \alert{variable} is a pair (symbol, lag) \item In the context of class \texttt{ModelTree}, a \alert{variable} is a pair (symbol, lag)
\item The symbol must correspond to a variable of type endogenous, exogenous, deterministic exogenous variable, or parameter \item The symbol must correspond to a variable of type endogenous, exogenous, deterministic exogenous variable, or parameter
\item The \texttt{SymbolTable} class keeps track of valid symbols while the \texttt{variable\_node\_map} keeps track of model variables (symbol, lag pairs stored in \texttt{VariableNode} objects) \item The \texttt{SymbolTable} class keeps track of valid symbols, while the \texttt{variable\_node\_map} keeps track of model variables (symbol, lag pairs stored in \texttt{VariableNode} objects)
\item After the computing pass, the \texttt{DynamicModel} class writes the leag/lag incidence matrix: \item After the computing pass, the \texttt{DynamicModel} class writes the leag/lag incidence matrix:
\begin{itemize} \begin{witemize}
\item three rows: the first row indicates $t-1$, the second row $t$, and the third row $t+1$ \item \texttt{max\_lag + max\_lead + 1} rows (usually 3): the first row indicates $t-1$ (if applicable), the second row $t$, and the third row $t+1$ (if applicable)
\item one column for every endogenous symbol in order of declaration; NB: includes endogenous auxiliary variables created during the transform pass \item one column for every endogenous symbol in order of declaration; NB: includes endogenous auxiliary variables created during the transform pass
\item elements of the matrix are either 0 (if the variable does not appear in the model) or correspond to the variable's column in the Jacobian of the dynamic model \item elements of the matrix are either 0 (if the variable does not appear in the model) or correspond to the variable's column in the Jacobian of the dynamic model
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Static versus dynamic model} \frametitle{Static versus dynamic model}
\begin{itemize} \begin{witemize}
\item The static model is simply the dynamic model without leads and lags \item The static model is simply the dynamic model without leads and lags
\item Static model used to characterize the steady state \item Static model used to characterize the steady state
\item The jacobian of the static model is used in the (MATLAB) solver for determining the steady state \item The Jacobian of the static model is used in the (MATLAB) solver for determining the steady state
\end{itemize} \end{witemize}
\begin{block}{Example} \begin{block}{Example}
\begin{itemize} \begin{itemize}
\item suppose dynamic model is $2x_t \cdot x_{t-1} = 0$ \item suppose dynamic model is $2x_t \cdot x_{t-1} = 0$
...@@ -614,41 +690,41 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -614,41 +690,41 @@ The class \texttt{ParsingDriver} has the following roles:
\begin{frame} \begin{frame}
\frametitle{Which derivatives to compute?} \frametitle{Which derivatives to compute?}
\begin{itemize} \begin{witemize}
\item In deterministic mode: \item In deterministic mode:
\begin{itemize} \begin{itemize}
\item static jacobian w.r.t. endogenous variables only \item static Jacobian w.r.t. endogenous variables only
\item dynamic jacobian w.r.t. endogenous variables only \item dynamic Jacobian w.r.t. endogenous variables only
\end{itemize} \end{itemize}
\item In stochastic mode: \item In stochastic mode:
\begin{itemize} \begin{itemize}
\item static jacobian w.r.t. endogenous variables only \item static Jacobian w.r.t. endogenous variables only
\item dynamic jacobian w.r.t. endogenous, exogenous, and deterministic exogenous variables \item dynamic Jacobian w.r.t. endogenous, exogenous, and deterministic exogenous variables
\item dynamic hessian w.r.t. endogenous, exogenous, and deterministic exogenous variables \item dynamic Hessian w.r.t. endogenous, exogenous, and deterministic exogenous variables
\item possibly dynamic 3rd derivatives (if \texttt{order} option $\geq 3$) \item possibly dynamic 3rd derivatives (if \texttt{order} option $\geq 3$)
\item possibly dynamic jacobian and/or hessian w.r.t. parameters (if \texttt{identification} or analytic derivs needed for \texttt{estimation} and \texttt{params\_derivs\_order} $>0$) \item possibly dynamic Jacobian and/or Hessian w.r.t. parameters (if \texttt{identification} or analytic derivs needed for \texttt{estimation} and \texttt{params\_derivs\_order} $>0$)
\end{itemize} \end{itemize}
\item For Ramsey policy: the same as above, but with one further order of derivation than declared by the user with \texttt{order} option (the derivation order is determined in the check pass, see \texttt{RamseyPolicyStatement::checkPass()}) \item For Ramsey policy: the same as above, but with one further order of derivation than declared by the user with \texttt{order} option (the derivation order is determined in the check pass, see \texttt{RamseyPolicyStatement::checkPass()})
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Derivation algorithm (1/2)} \frametitle{Derivation algorithm (1/2)}
\begin{itemize} \begin{witemize}
\item Derivation of the model implemented in \texttt{ModelTree::computeJacobian()}, \texttt{ModelTree::computeHessian()}, \texttt{ModelTree::computeThirdDerivatives()}, and \texttt{ModelTree::computeParamsDerivatives()} \item Derivation of the model implemented in \texttt{ModelTree::computeJacobian()}, \texttt{ModelTree::computeHessian()}, \texttt{ModelTree::computeThirdDerivatives()}, and \texttt{ModelTree::computeParamsDerivatives()}
\item Simply call \texttt{ExprNode::getDerivative(deriv\_id)} on each equation node \item Simply call \texttt{ExprNode::getDerivative(deriv\_id)} on each equation node
\item Use of polymorphism: \item Use of polymorphism:
\begin{itemize} \begin{witemize}
\item for a constant or variable node, derivative is straightforward ($0$ or $1$) \item for a constant or variable node, derivative is straightforward ($0$ or $1$)
\item for a unary, binary, trinary op nodes and external function nodes, recursively calls method \texttt{computeDerivative()} on children to construct derivative \item for a unary, binary, trinary op nodes and external function nodes, recursively calls method \texttt{computeDerivative()} on children to construct derivative
\end{itemize} \end{witemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{Derivation algorithm (2/2)} \frametitle{Derivation algorithm (2/2)}
\framesubtitle{Optimizations} \framesubtitle{Optimizations}
\begin{itemize} \begin{witemize}
\item Caching of derivation results \item Caching of derivation results
\begin{itemize} \begin{itemize}
\item method \texttt{ExprNode::getDerivative(deriv\_id)} memorizes its result in a member attribute (\texttt{derivatives}) the first time it is called \item method \texttt{ExprNode::getDerivative(deriv\_id)} memorizes its result in a member attribute (\texttt{derivatives}) the first time it is called
...@@ -658,12 +734,12 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -658,12 +734,12 @@ The class \texttt{ParsingDriver} has the following roles:
\item Efficiently finds symbolic derivatives equal to $0$ \item Efficiently finds symbolic derivatives equal to $0$
\begin{itemize} \begin{itemize}
\item consider the expression $x+y^2$ \item consider the expression $x+y^2$
\item without any computation, you know its derivative w.r.t. $z$ is zero \item without any computation, you know its derivative w.r.t.\ $z$ is zero
\item each node stores in an attribute (\texttt{non\_null\_derivatives}) the set of variables which appear in the expression it represents ($\{x,y\}$ in the example) \item each node stores in an attribute (\texttt{non\_null\_derivatives}) the set of variables which appear in the expression it represents ($\{x,y\}$ in the example)
\item this set is computed in \texttt{prepareForDerivation()} \item this set is computed in \texttt{prepareForDerivation()}
\item when \texttt{getDerivative(deriv\_id)} is called, immediately returns zero if \texttt{deriv\_id} is not in that set \item when \texttt{getDerivative(deriv\_id)} is called, immediately returns zero if \texttt{deriv\_id} is not in that set
\end{itemize} \end{itemize}
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\begin{frame}[fragile] \begin{frame}[fragile]
...@@ -672,7 +748,7 @@ The class \texttt{ParsingDriver} has the following roles: ...@@ -672,7 +748,7 @@ The class \texttt{ParsingDriver} has the following roles:
\item When the preprocessor writes equations and derivatives in its outputs, it takes advantage of sub-expression sharing \item When the preprocessor writes equations and derivatives in its outputs, it takes advantage of sub-expression sharing
\item In MATLAB static and dynamic output files, equations are preceded by a list of \alert{temporary terms} \item In MATLAB static and dynamic output files, equations are preceded by a list of \alert{temporary terms}
\item These terms are variables containing expressions shared by several equations or derivatives \item These terms are variables containing expressions shared by several equations or derivatives
\item Using these terms greatly enhances the computing speed of the model residual, jacobian, hessian, or third derivative \item Using these terms greatly enhances the computing speed of the model residual, Jacobian, Hessian, or third derivative
\end{itemize} \end{itemize}
\begin{block}{Example} \begin{block}{Example}
\begin{columns}[t] \begin{columns}[t]
...@@ -697,26 +773,27 @@ residual(1)=3*T1+1; ...@@ -697,26 +773,27 @@ residual(1)=3*T1+1;
\begin{frame} \begin{frame}
\frametitle{Temporary terms (2/2)} \frametitle{Temporary terms (2/2)}
\begin{itemize} \begin{witemize}
\item Expression storage in the preprocessor implements maximal sharing but this is not optimal for the MATLAB output files, because creating a temporary variable also has a cost (in terms of CPU and of memory) \item Expression storage in the preprocessor implements maximal sharing, but this is not optimal for the MATLAB output files, because creating a temporary variable also has a cost (in terms of CPU and of memory)
\item Computation of temporary terms implements a trade-off between: \item Computation of temporary terms implements a trade-off between:
\begin{itemize} \begin{witemize}
\item cost of duplicating sub-expressions \item cost of duplicating sub-expressions
\item cost of creating new variables \item cost of creating new variables
\end{itemize} \end{witemize}
\item Algorithm uses a recursive cost calculation, which marks some nodes as being ``temporary'' \item Algorithm uses a recursive cost calculation, which marks some nodes as being ``temporary''
\item \textit{Problem}: redundant with optimizations done by the C/C++ compiler (when Dynare is in DLL mode) $\Rightarrow$ compilation very slow on big models \item \textit{Problem}: redundant with optimizations done by the C/C++ compiler (when Dynare is in DLL mode)\\
\end{itemize} $\Rightarrow$ compilation very slow on big models
\end{witemize}
\end{frame} \end{frame}
\begin{frame} \begin{frame}
\frametitle{The special case of Ramsey policy} \frametitle{The special case of Ramsey model}
\begin{itemize} \begin{witemize}
\item For most statements, the method \texttt{computingPass()} is a no-op\ldots \item For most statements, the method \texttt{computingPass()} is a no-op\ldots
\item \ldots except for \texttt{planner\_objective} statement, which serves to declare planner objective when doing optimal policy under commitment \item \ldots except for \texttt{planner\_objective} statement, which serves to declare planner objective when doing optimal policy under commitment
\item Class \texttt{PlannerObjectiveStatement} contains an instance of \texttt{ModelTree}, which stores the objective function (\texttt{i.e.} only one equation in the tree) \item Class \texttt{PlannerObjectiveStatement} contains an instance of \texttt{ModelTree} which stores the objective function (\texttt{i.e.} only one equation in the tree)
\item During the computing pass, triggers the computation of the first and second order (static) derivatives of the objective \item During the computing pass, triggers the computation of the first and second order (static) derivatives of the objective
\end{itemize} \end{witemize}
\end{frame} \end{frame}
\section{Writing outputs} \section{Writing outputs}
...@@ -725,8 +802,8 @@ residual(1)=3*T1+1; ...@@ -725,8 +802,8 @@ residual(1)=3*T1+1;
\frametitle{Output overview} \frametitle{Output overview}
\begin{itemize} \begin{itemize}
\item Implemented in \texttt{ModFile::writeOutputFiles()} \item Implemented in \texttt{ModFile::writeOutputFiles()}
\item If \texttt{mod} file is \texttt{model.mod}, all created filenames will begin with \texttt{model} \item If \texttt{mod} file is \texttt{mymodel.mod}, all created filenames will begin with \texttt{mymodel}
\item Main output file is \texttt{model.m}, containing: \item Main output file is \texttt{mymodel.driver}, containing:
\begin{itemize} \begin{itemize}
\item general initialization commands \item general initialization commands
\item symbol table output (from \texttt{SymbolTable::writeOutput()}) \item symbol table output (from \texttt{SymbolTable::writeOutput()})
...@@ -735,11 +812,12 @@ residual(1)=3*T1+1; ...@@ -735,11 +812,12 @@ residual(1)=3*T1+1;
\end{itemize} \end{itemize}
\item Subsidiary output files: \item Subsidiary output files:
\begin{itemize} \begin{itemize}
\item one for the static model \item for the static model (residuals, temporary terms, derivatives)
\item one for the dynamic model \item for the dynamic model (residuals, temporary terms, derivatives)
\item one for the auxiliary variables \item one for the auxiliary variables in the dynamic model (if relevant)
\item one for the steady state file (if relevant) \item one for the steady state file (if relevant)
\item one for the planner objective (if relevant) \item for the planner objective and Lagrange multipliers (static residuals and derivatives, if relevant)
\item one each for the static and dynamic parameter derivatives (if required)
\end{itemize} \end{itemize}
\end{itemize} \end{itemize}
\end{frame} \end{frame}
...@@ -829,7 +907,7 @@ residual(1)=3*T1+1; ...@@ -829,7 +907,7 @@ residual(1)=3*T1+1;
\item No divergence of codebase: don't need to repeat code (checks, transformations, etc.) across platforms \item No divergence of codebase: don't need to repeat code (checks, transformations, etc.) across platforms
\item Creates \texttt{mod} files that can be used on other host language platforms \item Creates \texttt{mod} files that can be used on other host language platforms
\item Adds one more HLP library to distribute \item Adds one more HLP library to distribute
\item Need to design/implement classes that will store processed dynare \texttt{mod} file in various HLPs \item Need to design/implement classes that will store processed Dynare \texttt{mod} file in various HLPs
\end{itemize} \end{itemize}
\end{frame} \end{frame}
......
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Dynare-preprocessor
Upstream-Contact: Dynare Team, whose members in 2019 are:
Stéphane Adjemian <stephane.adjemian@univ-lemans.fr>
Houtan Bastani <houtan@dynare.org>
Michel Juillard <michel.juillard@mjui.fr>
Frédéric Karamé <frederic.karame@univ-lemans.fr>
Junior Maih <junior.maih@gmail.com>
Ferhat Mihoubi <fmihoubi@univ-evry.fr>
Johannes Pfeifer <jpfeifer@gmx.de>
Marco Ratto <marco.ratto@ec.europa.eu>
Sébastien Villemot <sebastien@dynare.org>
Source: https://www.dynare.org
Files: *
Copyright: 1996-2019 Dynare Team
License: GPL-3+
Files: m4/ax_boost_base.m4
m4/ax_boost_system.m4
m4/ax_boost_filesystem.m4
Copyright: 2008-2009 Thomas Porschberg <thomas@randspringer.de>
2009 Peter Adolphs
2008-2009 Michael Tindal
2008 Daniel Casimiro <dan.casimiro@gmail.com>
2009 Roman Rybalko <libtorrent@romanr.info>
License: FSFAP
Files: m4/ax_cxx_compile_stdcxx.m4
m4/ax_cxx_compile_stdcxx_17.m4
Copyright: 2008 Benjamin Kosnik <bkoz@redhat.com>
2012 Zack Weinberg <zackw@panix.com>
2013 Roy Stogner <roystgnr@ices.utexas.edu>
2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
2015 Paul Norman <penorman@mac.com>
2015 Moritz Klammler <moritz@klammler.eu>
2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
2019 Enji Cooper <yaneurabeya@gmail.com>
License: FSFAP
Files: m4/ax_latex_class.m4 m4/ax_tex_test.m4
Copyright: 2008 Boretti Mathieu <boretti@eig.unige.ch>
2009 Dynare Team
License: LGPL-2.1+
License: GPL-3+
Dynare is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
Dynare is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with Dynare. If not, see <http://www.gnu.org/licenses/>.
License: GPL-3+ with Autoconf exception
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
.
You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
.
As a special exception, the respective Autoconf Macro's copyright owner
gives unlimited permission to copy, distribute and modify the configure
scripts that are the output of Autoconf when processing the Macro. You
need not follow the terms of the GNU General Public License when using
or distributing such scripts, even though portions of the text of the
Macro appear in them. The GNU General Public License (GPL) does govern
all other use of the material that constitutes the Autoconf Macro.
.
This special exception to the GPL applies to versions of the Autoconf
Macro released by the Autoconf Archive. When you make and distribute a
modified version of the Autoconf Macro, you may extend this special
exception to the GPL to apply to your modified version as well.
License: LGPL-2.1+
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
License: LGPL-3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
License: FSFAP
Copying and distribution of this file, with or without modification, are
permitted in any medium without royalty provided the copyright notice
and this notice are preserved. This file is offered as-is, without any
warranty.
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_boost_base.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
#
# DESCRIPTION
#
# Test for the Boost C++ libraries of a particular version (or newer)
#
# If no path to the installed boost library is given the macro searchs
# under /usr, /usr/local, /opt and /opt/local and evaluates the
# $BOOST_ROOT environment variable. Further documentation is available at
# <http://randspringer.de/boost/index.html>.
#
# This macro calls:
#
# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
#
# And sets:
#
# HAVE_BOOST
#
# LICENSE
#
# Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
# Copyright (c) 2009 Peter Adolphs
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 43
# example boost program (need to pass version)
m4_define([_AX_BOOST_BASE_PROGRAM],
[AC_LANG_PROGRAM([[
#include <boost/version.hpp>
]],[[
(void) ((void)sizeof(char[1 - 2*!!((BOOST_VERSION) < ($1))]));
]])])
AC_DEFUN([AX_BOOST_BASE],
[
AC_ARG_WITH([boost],
[AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
[use Boost library from a standard location (ARG=yes),
from the specified location (ARG=<path>),
or disable it (ARG=no)
@<:@ARG=yes@:>@ ])],
[
AS_CASE([$withval],
[no],[want_boost="no";_AX_BOOST_BASE_boost_path=""],
[yes],[want_boost="yes";_AX_BOOST_BASE_boost_path=""],
[want_boost="yes";_AX_BOOST_BASE_boost_path="$withval"])
],
[want_boost="yes"])
AC_ARG_WITH([boost-libdir],
[AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
[Force given directory for boost libraries.
Note that this will override library path detection,
so use this parameter only if default library detection fails
and you know exactly where your boost libraries are located.])],
[
AS_IF([test -d "$withval"],
[_AX_BOOST_BASE_boost_lib_path="$withval"],
[AC_MSG_ERROR([--with-boost-libdir expected directory name])])
],
[_AX_BOOST_BASE_boost_lib_path=""])
BOOST_LDFLAGS=""
BOOST_CPPFLAGS=""
AS_IF([test "x$want_boost" = "xyes"],
[_AX_BOOST_BASE_RUNDETECT([$1],[$2],[$3])])
AC_SUBST(BOOST_CPPFLAGS)
AC_SUBST(BOOST_LDFLAGS)
])
# convert a version string in $2 to numeric and affect to polymorphic var $1
AC_DEFUN([_AX_BOOST_BASE_TONUMERICVERSION],[
AS_IF([test "x$2" = "x"],[_AX_BOOST_BASE_TONUMERICVERSION_req="1.20.0"],[_AX_BOOST_BASE_TONUMERICVERSION_req="$2"])
_AX_BOOST_BASE_TONUMERICVERSION_req_shorten=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\.[[0-9]]*\)'`
_AX_BOOST_BASE_TONUMERICVERSION_req_major=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([[0-9]]*\)'`
AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_major" = "x"],
[AC_MSG_ERROR([You should at least specify libboost major version])])
_AX_BOOST_BASE_TONUMERICVERSION_req_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.\([[0-9]]*\)'`
AS_IF([test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_minor" = "x"],
[_AX_BOOST_BASE_TONUMERICVERSION_req_minor="0"])
_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
AS_IF([test "X$_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor" = "X"],
[_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor="0"])
_AX_BOOST_BASE_TONUMERICVERSION_RET=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req_major \* 100000 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_minor \* 100 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor`
AS_VAR_SET($1,$_AX_BOOST_BASE_TONUMERICVERSION_RET)
])
dnl Run the detection of boost should be run only if $want_boost
AC_DEFUN([_AX_BOOST_BASE_RUNDETECT],[
_AX_BOOST_BASE_TONUMERICVERSION(WANT_BOOST_VERSION,[$1])
succeeded=no
AC_REQUIRE([AC_CANONICAL_HOST])
dnl On 64-bit systems check for system libraries in both lib64 and lib.
dnl The former is specified by FHS, but e.g. Debian does not adhere to
dnl this (as it rises problems for generic multi-arch support).
dnl The last entry in the list is chosen by default when no libraries
dnl are found, e.g. when only header-only libraries are installed!
AS_CASE([${host_cpu}],
[x86_64],[libsubdirs="lib64 libx32 lib lib64"],
[ppc64|s390x|sparc64|aarch64|ppc64le],[libsubdirs="lib64 lib lib64"],
[libsubdirs="lib"]
)
dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give
dnl them priority over the other paths since, if libs are found there, they
dnl are almost assuredly the ones desired.
AS_CASE([${host_cpu}],
[i?86],[multiarch_libsubdir="lib/i386-${host_os}"],
[multiarch_libsubdir="lib/${host_cpu}-${host_os}"]
)
dnl first we check the system location for boost libraries
dnl this location ist chosen if boost libraries are installed with the --layout=system option
dnl or if you install boost with RPM
AS_IF([test "x$_AX_BOOST_BASE_boost_path" != "x"],[
AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) includes in "$_AX_BOOST_BASE_boost_path/include"])
AS_IF([test -d "$_AX_BOOST_BASE_boost_path/include" && test -r "$_AX_BOOST_BASE_boost_path/include"],[
AC_MSG_RESULT([yes])
BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include"
for _AX_BOOST_BASE_boost_path_tmp in $multiarch_libsubdir $libsubdirs; do
AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION) lib path in "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"])
AS_IF([test -d "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" && test -r "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" ],[
AC_MSG_RESULT([yes])
BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp";
break;
],
[AC_MSG_RESULT([no])])
done],[
AC_MSG_RESULT([no])])
],[
if test X"$cross_compiling" = Xyes; then
search_libsubdirs=$multiarch_libsubdir
else
search_libsubdirs="$multiarch_libsubdir $libsubdirs"
fi
for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then
for libsubdir in $search_libsubdirs ; do
if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path_tmp/$libsubdir"
BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path_tmp/include"
break;
fi
done
])
dnl overwrite ld flags if we have required special directory with
dnl --with-boost-libdir parameter
AS_IF([test "x$_AX_BOOST_BASE_boost_lib_path" != "x"],
[BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_lib_path"])
AC_MSG_CHECKING([for boostlib >= $1 ($WANT_BOOST_VERSION)])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_REQUIRE([AC_PROG_CXX])
AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[
AC_MSG_RESULT(yes)
succeeded=yes
found_system=yes
],[
])
AC_LANG_POP([C++])
dnl if we found no boost with system layout we search for boost libraries
dnl built and installed without the --layout=system option or for a staged(not installed) version
if test "x$succeeded" != "xyes" ; then
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
BOOST_CPPFLAGS=
if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
BOOST_LDFLAGS=
fi
_version=0
if test -n "$_AX_BOOST_BASE_boost_path" ; then
if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path"; then
for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do
_version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
V_CHECK=`expr $_version_tmp \> $_version`
if test "x$V_CHECK" = "x1" ; then
_version=$_version_tmp
fi
VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include/boost-$VERSION_UNDERSCORE"
done
dnl if nothing found search for layout used in Windows distributions
if test -z "$BOOST_CPPFLAGS"; then
if test -d "$_AX_BOOST_BASE_boost_path/boost" && test -r "$_AX_BOOST_BASE_boost_path/boost"; then
BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path"
fi
fi
dnl if we found something and BOOST_LDFLAGS was unset before
dnl (because "$_AX_BOOST_BASE_boost_lib_path" = ""), set it here.
if test -n "$BOOST_CPPFLAGS" && test -z "$BOOST_LDFLAGS"; then
for libsubdir in $libsubdirs ; do
if ls "$_AX_BOOST_BASE_boost_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$libsubdir"
fi
fi
else
if test "x$cross_compiling" != "xyes" ; then
for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local ; do
if test -d "$_AX_BOOST_BASE_boost_path" && test -r "$_AX_BOOST_BASE_boost_path" ; then
for i in `ls -d $_AX_BOOST_BASE_boost_path/include/boost-* 2>/dev/null`; do
_version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
V_CHECK=`expr $_version_tmp \> $_version`
if test "x$V_CHECK" = "x1" ; then
_version=$_version_tmp
best_path=$_AX_BOOST_BASE_boost_path
fi
done
fi
done
VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
for libsubdir in $libsubdirs ; do
if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
BOOST_LDFLAGS="-L$best_path/$libsubdir"
fi
fi
if test -n "$BOOST_ROOT" ; then
for libsubdir in $libsubdirs ; do
if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
done
if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
V_CHECK=`expr $stage_version_shorten \>\= $_version`
if test "x$V_CHECK" = "x1" && test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
BOOST_CPPFLAGS="-I$BOOST_ROOT"
BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
fi
fi
fi
fi
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_LANG_PUSH(C++)
AC_COMPILE_IFELSE([_AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)],[
AC_MSG_RESULT(yes)
succeeded=yes
found_system=yes
],[
])
AC_LANG_POP([C++])
fi
if test "x$succeeded" != "xyes" ; then
if test "x$_version" = "x0" ; then
AC_MSG_NOTICE([[We could not detect the boost libraries (version $1 or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.]])
else
AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
fi
# execute ACTION-IF-NOT-FOUND (if present):
ifelse([$3], , :, [$3])
else
AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
# execute ACTION-IF-FOUND (if present):
ifelse([$2], , :, [$2])
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
])
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the specified
# version of the C++ standard. If necessary, add switches to CXX and
# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
# or '14' (for the C++14 standard).
#
# The second argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
# preference for an extended mode.
#
# The third argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline support for the specified C++ standard is
# required and that the macro should error out if no mode with that
# support is found. If specified 'optional', then configuration proceeds
# regardless, after defining HAVE_CXX${VERSION} if and only if a
# supporting mode is found.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 11
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
dnl (serial version number 13).
AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
[$1], [14], [ax_cxx_compile_alternatives="14 1y"],
[$1], [17], [ax_cxx_compile_alternatives="17 1z"],
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
[$2], [noext], [],
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true],
[$3], [mandatory], [ax_cxx_compile_cxx$1_required=true],
[$3], [optional], [ax_cxx_compile_cxx$1_required=false],
[m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
AC_LANG_PUSH([C++])dnl
ac_success=no
m4_if([$2], [noext], [], [dnl
if test x$ac_success = xno; then
for alternative in ${ax_cxx_compile_alternatives}; do
switch="-std=gnu++${alternative}"
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXX="$CXX"
CXX="$CXX $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXX="$ac_save_CXX"])
if eval test x\$$cachevar = xyes; then
CXX="$CXX $switch"
if test -n "$CXXCPP" ; then
CXXCPP="$CXXCPP $switch"
fi
ac_success=yes
break
fi
done
fi])
m4_if([$2], [ext], [], [dnl
if test x$ac_success = xno; then
dnl HP's aCC needs +std=c++11 according to:
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
dnl Cray's crayCC needs "-h std=c++11"
for alternative in ${ax_cxx_compile_alternatives}; do
for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
[ac_save_CXX="$CXX"
CXX="$CXX $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXX="$ac_save_CXX"])
if eval test x\$$cachevar = xyes; then
CXX="$CXX $switch"
if test -n "$CXXCPP" ; then
CXXCPP="$CXXCPP $switch"
fi
ac_success=yes
break
fi
done
if test x$ac_success = xyes; then
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$ax_cxx_compile_cxx$1_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
fi
fi
if test x$ac_success = xno; then
HAVE_CXX$1=0
AC_MSG_NOTICE([No compiler with C++$1 support was found])
else
HAVE_CXX$1=1
AC_DEFINE(HAVE_CXX$1,1,
[define if the compiler supports basic C++$1 syntax])
fi
AC_SUBST(HAVE_CXX$1)
])
dnl Test body for checking C++11 support
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
)
dnl Test body for checking C++14 support
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
)
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
)
dnl Tests for new features in C++11
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
// If the compiler admits that it is not ready for C++11, why torture it?
// Hopefully, this will speed up the test.
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201103L
#error "This is not a C++11 compiler"
#else
namespace cxx11
{
namespace test_static_assert
{
template <typename T>
struct check
{
static_assert(sizeof(int) <= sizeof(T), "not big enough");
};
}
namespace test_final_override
{
struct Base
{
virtual ~Base() {}
virtual void f() {}
};
struct Derived : public Base
{
virtual ~Derived() override {}
virtual void f() override {}
};
}
namespace test_double_right_angle_brackets
{
template < typename T >
struct check {};
typedef check<void> single_type;
typedef check<check<void>> double_type;
typedef check<check<check<void>>> triple_type;
typedef check<check<check<check<void>>>> quadruple_type;
}
namespace test_decltype
{
int
f()
{
int a = 1;
decltype(a) b = 2;
return a + b;
}
}
namespace test_type_deduction
{
template < typename T1, typename T2 >
struct is_same
{
static const bool value = false;
};
template < typename T >
struct is_same<T, T>
{
static const bool value = true;
};
template < typename T1, typename T2 >
auto
add(T1 a1, T2 a2) -> decltype(a1 + a2)
{
return a1 + a2;
}
int
test(const int c, volatile int v)
{
static_assert(is_same<int, decltype(0)>::value == true, "");
static_assert(is_same<int, decltype(c)>::value == false, "");
static_assert(is_same<int, decltype(v)>::value == false, "");
auto ac = c;
auto av = v;
auto sumi = ac + av + 'x';
auto sumf = ac + av + 1.0;
static_assert(is_same<int, decltype(ac)>::value == true, "");
static_assert(is_same<int, decltype(av)>::value == true, "");
static_assert(is_same<int, decltype(sumi)>::value == true, "");
static_assert(is_same<int, decltype(sumf)>::value == false, "");
static_assert(is_same<int, decltype(add(c, v))>::value == true, "");
return (sumf > 0.0) ? sumi : add(c, v);
}
}
namespace test_noexcept
{
int f() { return 0; }
int g() noexcept { return 0; }
static_assert(noexcept(f()) == false, "");
static_assert(noexcept(g()) == true, "");
}
namespace test_constexpr
{
template < typename CharT >
unsigned long constexpr
strlen_c_r(const CharT *const s, const unsigned long acc) noexcept
{
return *s ? strlen_c_r(s + 1, acc + 1) : acc;
}
template < typename CharT >
unsigned long constexpr
strlen_c(const CharT *const s) noexcept
{
return strlen_c_r(s, 0UL);
}
static_assert(strlen_c("") == 0UL, "");
static_assert(strlen_c("1") == 1UL, "");
static_assert(strlen_c("example") == 7UL, "");
static_assert(strlen_c("another\0example") == 7UL, "");
}
namespace test_rvalue_references
{
template < int N >
struct answer
{
static constexpr int value = N;
};
answer<1> f(int&) { return answer<1>(); }
answer<2> f(const int&) { return answer<2>(); }
answer<3> f(int&&) { return answer<3>(); }
void
test()
{
int i = 0;
const int c = 0;
static_assert(decltype(f(i))::value == 1, "");
static_assert(decltype(f(c))::value == 2, "");
static_assert(decltype(f(0))::value == 3, "");
}
}
namespace test_uniform_initialization
{
struct test
{
static const int zero {};
static const int one {1};
};
static_assert(test::zero == 0, "");
static_assert(test::one == 1, "");
}
namespace test_lambdas
{
void
test1()
{
auto lambda1 = [](){};
auto lambda2 = lambda1;
lambda1();
lambda2();
}
int
test2()
{
auto a = [](int i, int j){ return i + j; }(1, 2);
auto b = []() -> int { return '0'; }();
auto c = [=](){ return a + b; }();
auto d = [&](){ return c; }();
auto e = [a, &b](int x) mutable {
const auto identity = [](int y){ return y; };
for (auto i = 0; i < a; ++i)
a += b--;
return x + identity(a + b);
}(0);
return a + b + c + d + e;
}
int
test3()
{
const auto nullary = [](){ return 0; };
const auto unary = [](int x){ return x; };
using nullary_t = decltype(nullary);
using unary_t = decltype(unary);
const auto higher1st = [](nullary_t f){ return f(); };
const auto higher2nd = [unary](nullary_t f1){
return [unary, f1](unary_t f2){ return f2(unary(f1())); };
};
return higher1st(nullary) + higher2nd(nullary)(unary);
}
}
namespace test_variadic_templates
{
template <int...>
struct sum;
template <int N0, int... N1toN>
struct sum<N0, N1toN...>
{
static constexpr auto value = N0 + sum<N1toN...>::value;
};
template <>
struct sum<>
{
static constexpr auto value = 0;
};
static_assert(sum<>::value == 0, "");
static_assert(sum<1>::value == 1, "");
static_assert(sum<23>::value == 23, "");
static_assert(sum<1, 2>::value == 3, "");
static_assert(sum<5, 5, 11>::value == 21, "");
static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, "");
}
// http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
// Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function
// because of this.
namespace test_template_alias_sfinae
{
struct foo {};
template<typename T>
using member = typename T::member_type;
template<typename T>
void func(...) {}
template<typename T>
void func(member<T>*) {}
void test();
void test() { func<foo>(0); }
}
} // namespace cxx11
#endif // __cplusplus >= 201103L
]])
dnl Tests for new features in C++14
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
// If the compiler admits that it is not ready for C++14, why torture it?
// Hopefully, this will speed up the test.
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201402L
#error "This is not a C++14 compiler"
#else
namespace cxx14
{
namespace test_polymorphic_lambdas
{
int
test()
{
const auto lambda = [](auto&&... args){
const auto istiny = [](auto x){
return (sizeof(x) == 1UL) ? 1 : 0;
};
const int aretiny[] = { istiny(args)... };
return aretiny[0];
};
return lambda(1, 1L, 1.0f, '1');
}
}
namespace test_binary_literals
{
constexpr auto ivii = 0b0000000000101010;
static_assert(ivii == 42, "wrong value");
}
namespace test_generalized_constexpr
{
template < typename CharT >
constexpr unsigned long
strlen_c(const CharT *const s) noexcept
{
auto length = 0UL;
for (auto p = s; *p; ++p)
++length;
return length;
}
static_assert(strlen_c("") == 0UL, "");
static_assert(strlen_c("x") == 1UL, "");
static_assert(strlen_c("test") == 4UL, "");
static_assert(strlen_c("another\0test") == 7UL, "");
}
namespace test_lambda_init_capture
{
int
test()
{
auto x = 0;
const auto lambda1 = [a = x](int b){ return a + b; };
const auto lambda2 = [a = lambda1(x)](){ return a; };
return lambda2();
}
}
namespace test_digit_separators
{
constexpr auto ten_million = 100'000'000;
static_assert(ten_million == 100000000, "");
}
namespace test_return_type_deduction
{
auto f(int& x) { return x; }
decltype(auto) g(int& x) { return x; }
template < typename T1, typename T2 >
struct is_same
{
static constexpr auto value = false;
};
template < typename T >
struct is_same<T, T>
{
static constexpr auto value = true;
};
int
test()
{
auto x = 0;
static_assert(is_same<int, decltype(f(x))>::value, "");
static_assert(is_same<int&, decltype(g(x))>::value, "");
return x;
}
}
} // namespace cxx14
#endif // __cplusplus >= 201402L
]])
dnl Tests for new features in C++17
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
// If the compiler admits that it is not ready for C++17, why torture it?
// Hopefully, this will speed up the test.
#ifndef __cplusplus
#error "This is not a C++ compiler"
#elif __cplusplus < 201703L
#error "This is not a C++17 compiler"
#else
#include <initializer_list>
#include <utility>
#include <type_traits>
namespace cxx17
{
namespace test_constexpr_lambdas
{
constexpr int foo = [](){return 42;}();
}
namespace test::nested_namespace::definitions
{
}
namespace test_fold_expression
{
template<typename... Args>
int multiply(Args... args)
{
return (args * ... * 1);
}
template<typename... Args>
bool all(Args... args)
{
return (args && ...);
}
}
namespace test_extended_static_assert
{
static_assert (true);
}
namespace test_auto_brace_init_list
{
auto foo = {5};
auto bar {5};
static_assert(std::is_same<std::initializer_list<int>, decltype(foo)>::value);
static_assert(std::is_same<int, decltype(bar)>::value);
}
namespace test_typename_in_template_template_parameter
{
template<template<typename> typename X> struct D;
}
namespace test_fallthrough_nodiscard_maybe_unused_attributes
{
int f1()
{
return 42;
}
[[nodiscard]] int f2()
{
[[maybe_unused]] auto unused = f1();
switch (f1())
{
case 17:
f1();
[[fallthrough]];
case 42:
f1();
}
return f1();
}
}
namespace test_extended_aggregate_initialization
{
struct base1
{
int b1, b2 = 42;
};
struct base2
{
base2() {
b3 = 42;
}
int b3;
};
struct derived : base1, base2
{
int d;
};
derived d1 {{1, 2}, {}, 4}; // full initialization
derived d2 {{}, {}, 4}; // value-initialized bases
}
namespace test_general_range_based_for_loop
{
struct iter
{
int i;
int& operator* ()
{
return i;
}
const int& operator* () const
{
return i;
}
iter& operator++()
{
++i;
return *this;
}
};
struct sentinel
{
int i;
};
bool operator== (const iter& i, const sentinel& s)
{
return i.i == s.i;
}
bool operator!= (const iter& i, const sentinel& s)
{
return !(i == s);
}
struct range
{
iter begin() const
{
return {0};
}
sentinel end() const
{
return {5};
}
};
void f()
{
range r {};
for (auto i : r)
{
[[maybe_unused]] auto v = i;
}
}
}
namespace test_lambda_capture_asterisk_this_by_value
{
struct t
{
int i;
int foo()
{
return [*this]()
{
return i;
}();
}
};
}
namespace test_enum_class_construction
{
enum class byte : unsigned char
{};
byte foo {42};
}
namespace test_constexpr_if
{
template <bool cond>
int f ()
{
if constexpr(cond)
{
return 13;
}
else
{
return 42;
}
}
}
namespace test_selection_statement_with_initializer
{
int f()
{
return 13;
}
int f2()
{
if (auto i = f(); i > 0)
{
return 3;
}
switch (auto i = f(); i + 4)
{
case 17:
return 2;
default:
return 1;
}
}
}
namespace test_template_argument_deduction_for_class_templates
{
template <typename T1, typename T2>
struct pair
{
pair (T1 p1, T2 p2)
: m1 {p1},
m2 {p2}
{}
T1 m1;
T2 m2;
};
void f()
{
[[maybe_unused]] auto p = pair{13, 42u};
}
}
namespace test_non_type_auto_template_parameters
{
template <auto n>
struct B
{};
B<5> b1;
B<'a'> b2;
}
namespace test_structured_bindings
{
int arr[2] = { 1, 2 };
std::pair<int, int> pr = { 1, 2 };
auto f1() -> int(&)[2]
{
return arr;
}
auto f2() -> std::pair<int, int>&
{
return pr;
}
struct S
{
int x1 : 2;
volatile double y1;
};
S f3()
{
return {};
}
auto [ x1, y1 ] = f1();
auto& [ xr1, yr1 ] = f1();
auto [ x2, y2 ] = f2();
auto& [ xr2, yr2 ] = f2();
const auto [ x3, y3 ] = f3();
}
namespace test_exception_spec_type_system
{
struct Good {};
struct Bad {};
void g1() noexcept;
void g2();
template<typename T>
Bad
f(T*, T*);
template<typename T1, typename T2>
Good
f(T1*, T2*);
static_assert (std::is_same_v<Good, decltype(f(g1, g2))>);
}
namespace test_inline_variables
{
template<class T> void f(T)
{}
template<class T> inline T g(T)
{
return T{};
}
template<> inline void f<>(int)
{}
template<> int g<>(int)
{
return 5;
}
}
} // namespace cxx17
#endif // __cplusplus < 201703L
]])
# =============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html
# =============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++17
# standard; if necessary, add switches to CXX and CXXCPP to enable
# support.
#
# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
# macro with the version set to C++17. The two optional arguments are
# forwarded literally as the second and third argument respectively.
# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for
# more information. If you want to use this macro, you also need to
# download the ax_cxx_compile_stdcxx.m4 file.
#
# LICENSE
#
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
# Copyright (c) 2016 Krzesimir Nowak <qdlacz@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 2
AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])])
# ===========================================================================
# http://www.nongnu.org/autoconf-archive/ax_latex_class.html
# ===========================================================================
#
# OBSOLETE MACRO
#
# Deprecated because of licensing issues. The Lesser GPL imposes licensing
# restrictions on the generated configure script unless it is augmented
# with an Autoconf Exception clause.
#
# SYNOPSIS
#
# AX_LATEX_CLASS(CLASSNAME,VARIABLETOSET[,ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
#
# DESCRIPTION
#
# This macros test is class CLASSNAME exists and work and set
# VARIABLETOSET to yes or no If ACTION-IF-FOUND (and ACTION-IF-NOT-FOUND)
# are set, do the correct action
#
# LICENSE
#
# Copyright © 2008 Boretti Mathieu <boretti@eig.unige.ch>
# Copyright © 2009 Dynare Team
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or (at
# your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
AC_DEFUN([AX_LATEX_CLASS],[
AC_CACHE_CHECK([for usability of class $1],[ac_cv_latex_class_]translit($1,[-],[_]),[
AX_LATEX_TEST([\documentclass{$1}
\begin{document}
\end{document}],[ac_cv_latex_class_]translit($1,[-],[_]))
])
$2=$[ac_cv_latex_class_]translit($1,[-],[_]) ; export $2;
AC_SUBST($2)
ifelse($#,2,[],$#,3,[
if test "[$]$2" = "yes" ;
then
$3
fi
],$#,4,[
ifelse($3,[],[
if test "[$]$2" = "no" ;
then
$4
fi
],[
if test "[$]$2" = "yes" ;
then
$3
else
$4
fi
])
])
])