[PATCH] match.pd: Fold x/sqrt(x) to sqrt(x)
[official-gcc.git] / libstdc++-v3 / include / bits / version.tpl
blob4a7d5e29c10da2652380b39893e3d07e028eba39
1 /*{ AutoGen5 template                                              -*- C++ -*-
3 (use-modules (srfi srfi-1))
4 }*/
5 // Copyright (C) 2023-2024 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library.  This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
18 // Under Section 7 of GPL version 3, you are granted additional
19 // permissions described in the GCC Runtime Library Exception, version
20 // 3.1, as published by the Free Software Foundation.
22 // You should have received a copy of the GNU General Public License and
23 // a copy of the GCC Runtime Library Exception along with this program;
24 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
25 // <http://www.gnu.org/licenses/>.
27 /*{ (dne "// ") }*/
29 /** @file bits/version.h
30  *  This is an internal header file, included by other library headers.
31  *  Do not attempt to use it directly. @headername{version}
32  */
34 // Usage guide:
36 // In your usual header, do something like:
38 //   #define __glibcxx_want_ranges
39 //   #define __glibcxx_want_concepts
40 //   #include <bits/version.h>
42 // This will generate the FTMs you named, and let you use them in your code as
43 // if it was user code.  All macros are also exposed under __glibcxx_NAME even
44 // if unwanted, to permit bits and other FTMs to depend on them for condtional
45 // computation without exposing extra FTMs to user code.
47 #pragma GCC system_header
49 #include <bits/c++config.h>
50 /*{
52 ;; Helper for dealing with autogens redefined (error)
53 (define (ferror msg . args)
54   (error (apply format (cons* #f msg args))))
56   ;; Helper function that, in the context of a single FTM value, generates the
57 ;; condition expression that fulfills the specification of this value.  See the
58 ;; comment block in version.def for an explanation of the format this
59 ;; function parses.
60 (define (generate-cond)
61   (define c++min #f)
62   (define gnu++min #f)
63   (define gthread #f)
64   (define hosted #f)
65   (define c++11-abi #f)
66   (define extra-cond (get "extra_cond"))
68   (define conds '())
69   (define (prepend x)
70     (if x (set! conds (cons x conds))))
72   (if (string-null? extra-cond)
73       (set! extra-cond #f))
75   (let ((cxxmin (get "cxxmin"))
76         (gnuxxmin (get "gnuxxmin"))
77         (getstdcond
78          (lambda (var)
79            (let ((ver (get var)))
80              (if (not (string-null? ver))
81                (let ((std-cond (get (format #f "stds[~a]" ver))))
82                  (if (string-null? std-cond)
83                      (ferror "Standard ~s invalid." ver))
84                  std-cond)
85                #f)))))
86     (set! c++min (getstdcond "cxxmin"))
87     (set! gnu++min (getstdcond "gnuxxmin")))
89   (let ((process-tristate
90          (lambda (name)
91            (let ((val (get name)))
92              (cond
93                ((equal? val "") #f)    ; Don't test
94                ((equal? val "yes") "") ; Test directly
95                ((equal? val "no") "!") ; Invert
96                (else (ferror "Bad ~a value ~a." name val)))))))
97     (set! gthread (process-tristate "gthread"))
98     (set! c++11-abi (process-tristate "cxx11abi"))
99     (set! hosted (process-tristate "hosted")))
101   (prepend (if extra-cond (format #f "(~a)" extra-cond) #f))
102   (prepend (if hosted (format #f "~a~a" hosted "_GLIBCXX_HOSTED") #f))
103   (prepend (if gthread (format #f "~a~a" gthread "defined(_GLIBCXX_HAS_GTHREADS)") #f))
104   (prepend (if c++11-abi (format #f "~a~a" c++11-abi "_GLIBCXX_USE_CXX11_ABI") #f))
106   (prepend
107    (let ((strict "defined(__STRICT_ANSI__)")
108          (c++ "__cplusplus"))
109      (cond
110       ((or (and (equal? c++min gnu++min) c++min)
111            (and (not gnu++min) c++min))
112        ;; If we have both values, and they are equal, or we only have gnu++min,
113        ;; we want to output a simple check.
114        (format #f "(~a ~a)" c++ c++min))
115       ((and gnu++min c++min)
116        ;; We have differing cases for strict and non-strict modes.
117        (format #f "((~a && ~a ~a) || (!~a && ~a ~a))"
118                strict c++ c++min
119                strict c++ gnu++min))
120       ((and gnu++min (not c++min))
121        (format #f "(!~a && (~a ~a))" strict c++ gnu++min))
122       (else #f))))
123   (string-join conds " && " 'strict-infix))
126   }*/
127 /*{ FOR ftms
128   }*/#if !defined(__cpp_lib_/*{name}*/)
129 /*{ FOR values }*//*{ #
131   This macro block defines two versions of each FTM:
133   1. __glibcxx_NAME, which is defined unconditionally, and
134   2. __cpp_lib_NAME, which is defined only if marked as wanted.
136   This allows FTMs to depend on eachother in their definitions without messing
137   with the exported values.
139   This can also be used by bits that do not want to expose FTMs that they can't
140   implement.
142 }*/# /*{(unless (first-for?) "el")}*/if /*{(generate-cond)}*/
143 #  define __glibcxx_/*{name}*/ /*{v}*/L
144 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_/*{name}*/)
145 #   define /*{
146 ;; Compute the name for this FTM based on stdname/name.
147 (if (exist? "stdname")
148     (get "stdname")
149     (format #f "__cpp_lib_~a" (get "name")))
150 }*/ /*{v}*/L
151 #  endif
152 /*{ ENDFOR values
153   }*/# endif
154 #endif /* !defined(__cpp_lib_/*{name}*/) && defined(__glibcxx_want_/*{name}*/) */
155 #undef __glibcxx_want_/*{name
156 }*//*{ (unless (last-for?) "\n\n" "\n")}*/
157 /*{ ENDFOR ftms }*//*{
159 ;; Helper that generates [LO, HI].
160 (define (closed-int-set lo hi)
161   (iota (+ (- hi lo) 1) lo))
163 ;; Sanity checking for duplicates and for value order.
164 (let ((ht (make-hash-table (count "ftms"))))
165   (for-each
166    (lambda (idx)
167      (let ((name (get (format #f "ftms[~a].name" idx))))
168        (if (string-null? name) (ferror "No name for FTM ~a" idx))
169        (let ((cur (cdr (or (hash-get-handle ht name) '(1 . 0)))))
170          (hash-set! ht name (+ cur 1)))))
171    (closed-int-set (low-lim "ftms") (high-lim "ftms")))
172   (if (hash-fold
173        (lambda (name count prior)
174          (if (= 1 count)
175              prior
176              (begin
177                (printf "FTM %s appears %d times.\n" name count)
178                #t)))
179        #f ht)
180       (error "Duplicates found.")))
182 (define (check-value-order ftm key order)
183   (let ((valmin 999999)) ; TODO(arsen): bump before year 10000
184     (for-each
185      (lambda (vidx)
186        (let* ((sval (get (format #f "values[~a].~a" vidx key)))
187               (val (string->number sval)))
188          (unless (string-null? sval)
189            (unless val (ferror "Bad value in FTM ~a" ftm))
190            (if (order val valmin)
191                (ferror "Found inverted ~s value in FTM ~a: ~a" key ftm sval))
192            (set! valmin val))))
193      (closed-int-set (low-lim "values") (high-lim "values")))))
195 }*//*{ FOR ftms }*//*{#
196   Check for values that are in ascending order.  Because it is generally the
197   case that FTMs increase as the values of tests they probe for do, we check
198   them to prevent simple, silly errors.
200   We're iterating in a separate FOR block rather than in pure Guile since, for
201   some reason, high-lim and low-lim do not work with complex names that include
202   periods and indices (whereas exist? and others do).
203 }*//*{
204 (let ((ftm (get "name")))
205   (check-value-order (get "name") "v" >)
206   (check-value-order (get "name") "cxxmin" >)
207   (check-value-order (get "name") "gnuxxmin" >))
208 }*//*{ ENDFOR ftms }*/
209 #undef __glibcxx_want_all