| 1 |
/*{ AutoGen5 template -*- C++ -*- |
| 2 |
h |
| 3 |
(use-modules (srfi srfi-1)) |
| 4 |
}*/ |
| 5 |
// Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 6 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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. |
| 21 |
|
| 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/>. |
| 26 |
|
| 27 |
/*{ (dne "// ") }*/ |
| 28 |
|
| 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 |
*/ |
| 33 |
|
| 34 |
// Usage guide: |
| 35 |
// |
| 36 |
// In your usual header, do something like: |
| 37 |
// |
| 38 |
// #define __glibcxx_want_ranges |
| 39 |
// #define __glibcxx_want_concepts |
| 40 |
// #include <bits/version.h> |
| 41 |
// |
| 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. |
| 46 |
|
| 47 |
#ifdef _GLIBCXX_SYSHDR |
| 48 |
#pragma GCC system_header |
| 49 |
#endif |
| 50 |
|
| 51 |
#include <bits/c++config.h> |
| 52 |
/*{ |
| 53 |
|
| 54 |
;; Helper for dealing with autogens redefined (error) |
| 55 |
(define (ferror msg . args) |
| 56 |
(error (apply format (cons* #f msg args)))) |
| 57 |
|
| 58 |
;; Helper function that, in the context of a single FTM value, generates the |
| 59 |
;; condition expression that fulfills the specification of this value. See the |
| 60 |
;; comment block in version.def for an explanation of the format this |
| 61 |
;; function parses. |
| 62 |
(define (generate-cond) |
| 63 |
(define c++min #f) |
| 64 |
(define gnu++min #f) |
| 65 |
(define gthread #f) |
| 66 |
(define hosted #f) |
| 67 |
(define c++11-abi #f) |
| 68 |
(define extra-cond (get "extra_cond")) |
| 69 |
|
| 70 |
(define conds '()) |
| 71 |
(define (prepend x) |
| 72 |
(if x (set! conds (cons x conds)))) |
| 73 |
|
| 74 |
(if (string-null? extra-cond) |
| 75 |
(set! extra-cond #f)) |
| 76 |
|
| 77 |
(let ((cxxmin (get "cxxmin")) |
| 78 |
(gnuxxmin (get "gnuxxmin")) |
| 79 |
(getstdcond |
| 80 |
(lambda (var) |
| 81 |
(let ((ver (get var))) |
| 82 |
(if (not (string-null? ver)) |
| 83 |
(let ((std-cond (get (format #f "stds[~a]" ver)))) |
| 84 |
(if (string-null? std-cond) |
| 85 |
(ferror "Standard ~s invalid." ver)) |
| 86 |
std-cond) |
| 87 |
#f))))) |
| 88 |
(set! c++min (getstdcond "cxxmin")) |
| 89 |
(set! gnu++min (getstdcond "gnuxxmin"))) |
| 90 |
|
| 91 |
(let ((process-tristate |
| 92 |
(lambda (name) |
| 93 |
(let ((val (get name))) |
| 94 |
(cond |
| 95 |
((equal? val "") #f) ; Don't test |
| 96 |
((equal? val "yes") "") ; Test directly |
| 97 |
((equal? val "no") "!") ; Invert |
| 98 |
(else (ferror "Bad ~a value ~a." name val))))))) |
| 99 |
(set! gthread (process-tristate "gthread")) |
| 100 |
(set! c++11-abi (process-tristate "cxx11abi")) |
| 101 |
(set! hosted (process-tristate "hosted"))) |
| 102 |
|
| 103 |
(prepend (if extra-cond (format #f "(~a)" extra-cond) #f)) |
| 104 |
(prepend (if hosted (format #f "~a~a" hosted "_GLIBCXX_HOSTED") #f)) |
| 105 |
(prepend (if gthread (format #f "~a~a" gthread "defined(_GLIBCXX_HAS_GTHREADS)") #f)) |
| 106 |
(prepend (if c++11-abi (format #f "~a~a" c++11-abi "_GLIBCXX_USE_CXX11_ABI") #f)) |
| 107 |
|
| 108 |
(prepend |
| 109 |
(let ((strict "defined(__STRICT_ANSI__)") |
| 110 |
(c++ "__cplusplus")) |
| 111 |
(cond |
| 112 |
((or (and (equal? c++min gnu++min) c++min) |
| 113 |
(and (not gnu++min) c++min)) |
| 114 |
;; If we have both values, and they are equal, or we only have gnu++min, |
| 115 |
;; we want to output a simple check. |
| 116 |
(format #f "(~a ~a)" c++ c++min)) |
| 117 |
((and gnu++min c++min) |
| 118 |
;; We have differing cases for strict and non-strict modes. |
| 119 |
(format #f "((~a && ~a ~a) || (!~a && ~a ~a))" |
| 120 |
strict c++ c++min |
| 121 |
strict c++ gnu++min)) |
| 122 |
((and gnu++min (not c++min)) |
| 123 |
(format #f "(!~a && (~a ~a))" strict c++ gnu++min)) |
| 124 |
(else #f)))) |
| 125 |
(string-join conds " && " 'strict-infix)) |
| 126 |
|
| 127 |
|
| 128 |
}*/ |
| 129 |
/*{ FOR ftms |
| 130 |
}*/#if !defined(__cpp_lib_/*{name}*/) |
| 131 |
/*{ FOR values }*//*{ # |
| 132 |
|
| 133 |
This macro block defines two versions of each FTM: |
| 134 |
|
| 135 |
1. __glibcxx_NAME, which is defined unconditionally, and |
| 136 |
2. __cpp_lib_NAME, which is defined only if marked as wanted. |
| 137 |
|
| 138 |
This allows FTMs to depend on eachother in their definitions without messing |
| 139 |
with the exported values. |
| 140 |
|
| 141 |
This can also be used by bits that do not want to expose FTMs that they can't |
| 142 |
implement. |
| 143 |
|
| 144 |
}*/# /*{(unless (first-for?) "el")}*/if /*{(generate-cond)}*/ |
| 145 |
# define __glibcxx_/*{name}*/ /*{v}*/L |
| 146 |
# if defined(__glibcxx_want_all) || defined(__glibcxx_want_/*{name}*/)/*{ |
| 147 |
IF (not (exist? "no_stdname")) }*/ |
| 148 |
# define /*{ |
| 149 |
;; Compute the name for this FTM based on stdname/name. |
| 150 |
(if (exist? "stdname") |
| 151 |
(get "stdname") |
| 152 |
(format #f "__cpp_lib_~a" (get "name"))) |
| 153 |
}*/ /*{v}*/L/*{ |
| 154 |
ENDIF no_std_name }*/ |
| 155 |
# endif |
| 156 |
/*{ ENDFOR values |
| 157 |
}*/# endif |
| 158 |
#endif /* !defined(__cpp_lib_/*{name}*/) && defined(__glibcxx_want_/*{name}*/) */ |
| 159 |
#undef __glibcxx_want_/*{name |
| 160 |
}*//*{ (unless (last-for?) "\n\n" "\n")}*/ |
| 161 |
/*{ ENDFOR ftms }*//*{ |
| 162 |
|
| 163 |
;; Helper that generates [LO, HI]. |
| 164 |
(define (closed-int-set lo hi) |
| 165 |
(iota (+ (- hi lo) 1) lo)) |
| 166 |
|
| 167 |
;; Sanity checking for duplicates and for value order. |
| 168 |
(let ((ht (make-hash-table (count "ftms")))) |
| 169 |
(for-each |
| 170 |
(lambda (idx) |
| 171 |
(let ((name (get (format #f "ftms[~a].name" idx)))) |
| 172 |
(if (string-null? name) (ferror "No name for FTM ~a" idx)) |
| 173 |
(let ((cur (cdr (or (hash-get-handle ht name) '(1 . 0))))) |
| 174 |
(hash-set! ht name (+ cur 1))))) |
| 175 |
(closed-int-set (low-lim "ftms") (high-lim "ftms"))) |
| 176 |
(if (hash-fold |
| 177 |
(lambda (name count prior) |
| 178 |
(if (= 1 count) |
| 179 |
prior |
| 180 |
(begin |
| 181 |
(printf "FTM %s appears %d times.\n" name count) |
| 182 |
#t))) |
| 183 |
#f ht) |
| 184 |
(error "Duplicates found."))) |
| 185 |
|
| 186 |
(define (check-value-order ftm key order) |
| 187 |
(let ((valmin 999999)) ; TODO(arsen): bump before year 10000 |
| 188 |
(for-each |
| 189 |
(lambda (vidx) |
| 190 |
(let* ((sval (get (format #f "values[~a].~a" vidx key))) |
| 191 |
(val (string->number sval))) |
| 192 |
(unless (string-null? sval) |
| 193 |
(unless val (ferror "Bad value in FTM ~a" ftm)) |
| 194 |
(if (order val valmin) |
| 195 |
(ferror "Found inverted ~s value in FTM ~a: ~a" key ftm sval)) |
| 196 |
(set! valmin val)))) |
| 197 |
(closed-int-set (low-lim "values") (high-lim "values"))))) |
| 198 |
|
| 199 |
}*//*{ FOR ftms }*//*{# |
| 200 |
Check for values that are in ascending order. Because it is generally the |
| 201 |
case that FTMs increase as the values of tests they probe for do, we check |
| 202 |
them to prevent simple, silly errors. |
| 203 |
|
| 204 |
We're iterating in a separate FOR block rather than in pure Guile since, for |
| 205 |
some reason, high-lim and low-lim do not work with complex names that include |
| 206 |
periods and indices (whereas exist? and others do). |
| 207 |
}*//*{ |
| 208 |
(let ((ftm (get "name"))) |
| 209 |
(check-value-order (get "name") "v" >) |
| 210 |
(check-value-order (get "name") "cxxmin" >) |
| 211 |
(check-value-order (get "name") "gnuxxmin" >)) |
| 212 |
}*//*{ ENDFOR ftms }*/ |
| 213 |
#undef __glibcxx_want_all |