1 /*{ AutoGen5 template -*- C++ -*-
3 (use-modules (srfi srfi-1))
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)
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/>.
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}
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>
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
60 (define (generate-cond)
66 (define extra-cond (get "extra_cond"))
70 (if x (set! conds (cons x conds))))
72 (if (string-null? extra-cond)
75 (let ((cxxmin (get "cxxmin"))
76 (gnuxxmin (get "gnuxxmin"))
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))
86 (set! c++min (getstdcond "cxxmin"))
87 (set! gnu++min (getstdcond "gnuxxmin")))
89 (let ((process-tristate
91 (let ((val (get name)))
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))
107 (let ((strict "defined(__STRICT_ANSI__)")
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))"
119 strict c++ gnu++min))
120 ((and gnu++min (not c++min))
121 (format #f "(!~a && (~a ~a))" strict c++ gnu++min))
123 (string-join conds " && " 'strict-infix))
128 }*/// /*{ (def-file-line "name") }*/
129 #if !defined(__cpp_lib_/*{name}*/)
130 /*{ FOR values }*//*{ #
132 This macro block defines two versions of each FTM:
134 1. __glibcxx_NAME, which is defined unconditionally, and
135 2. __cpp_lib_NAME, which is defined only if marked as wanted.
137 This allows FTMs to depend on eachother in their definitions without messing
138 with the exported values.
140 This can also be used by bits that do not want to expose FTMs that they can't
143 }*/# /*{(unless (first-for?) "el")}*/if /*{(generate-cond)}*/
144 # define __glibcxx_/*{name}*/ /*{v}*/L
145 # if defined(__glibcxx_want_all) || defined(__glibcxx_want_/*{name}*/)
147 ;; Compute the name for this FTM based on stdname/name.
148 (if (exist? "stdname")
150 (format #f "__cpp_lib_~a" (get "name")))
155 #endif /* !defined(__cpp_lib_/*{name}*/) && defined(__glibcxx_want_/*{name}*/) */
156 #undef __glibcxx_want_/*{name
157 }*//*{ (unless (last-for?) "\n\n" "\n")}*/
158 /*{ ENDFOR ftms }*//*{
160 ;; Helper that generates [LO, HI].
161 (define (closed-int-set lo hi)
162 (iota (+ (- hi lo) 1) lo))
164 ;; Sanity checking for duplicates and for value order.
165 (let ((ht (make-hash-table (count "ftms"))))
168 (let ((name (get (format #f "ftms[~a].name" idx))))
169 (if (string-null? name) (ferror "No name for FTM ~a" idx))
170 (let ((cur (cdr (or (hash-get-handle ht name) '(1 . 0)))))
171 (hash-set! ht name (+ cur 1)))))
172 (closed-int-set (low-lim "ftms") (high-lim "ftms")))
174 (lambda (name count prior)
178 (printf "FTM %s appears %d times.\n" name count)
181 (error "Duplicates found.")))
183 (define (check-value-order ftm key order)
184 (let ((valmin 999999)) ; TODO(arsen): bump before year 10000
187 (let* ((sval (get (format #f "values[~a].~a" vidx key)))
188 (val (string->number sval)))
189 (unless (string-null? sval)
190 (unless val (ferror "Bad value in FTM ~a" ftm))
191 (if (order val valmin)
192 (ferror "Found inverted ~s value in FTM ~a: ~a" key ftm sval))
194 (closed-int-set (low-lim "values") (high-lim "values")))))
196 }*//*{ FOR ftms }*//*{#
197 Check for values that are in ascending order. Because it is generally the
198 case that FTMs increase as the values of tests they probe for do, we check
199 them to prevent simple, silly errors.
201 We're iterating in a separate FOR block rather than in pure Guile since, for
202 some reason, high-lim and low-lim do not work with complex names that include
203 periods and indices (whereas exist? and others do).
205 (let ((ftm (get "name")))
206 (check-value-order (get "name") "v" >)
207 (check-value-order (get "name") "cxxmin" >)
208 (check-value-order (get "name") "gnuxxmin" >))
209 }*//*{ ENDFOR ftms }*/
210 #undef __glibcxx_want_all