From 0b140c854851b59a26cb0f7e09052b15effacd38 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 16 Oct 2024 10:17:21 -0400 Subject: [PATCH] Make use of JSON Schema validation from the new Blaze project (#178) Signed-off-by: Juan Cruz Viotti --- .github/workflows/test.yml | 2 +- CMakeLists.txt | 1 + DEPENDENCIES | 11 +- cmake/FindBlaze.cmake | 5 + src/CMakeLists.txt | 7 + src/command_compile.cc | 14 +- src/command_frame.cc | 3 +- src/command_identify.cc | 11 +- src/command_metaschema.cc | 17 +- src/command_test.cc | 18 +- src/command_validate.cc | 30 +- src/utils.cc | 22 +- src/utils.h | 7 +- test/compile/pass_1.sh | 2 +- test/validate/fail_2019_09.sh | 3 - test/validate/fail_2020_12.sh | 3 - vendor/alterschema/src/engine/rule.cc | 12 +- .../noa/cmake/noa/compiler/options.cmake | 24 +- .../vendor/noa/cmake/noa/library.cmake | 36 +- vendor/blaze/CMakeLists.txt | 98 + vendor/blaze/LICENSE | 661 +++++++ vendor/blaze/LICENSE-COMMERCIAL | 2 + vendor/blaze/cmake/FindGoogleBenchmark.cmake | 5 + vendor/blaze/cmake/FindGoogleTest.cmake | 6 + vendor/blaze/cmake/FindJSONToolkit.cmake | 10 + vendor/blaze/config.cmake.in | 25 + vendor/blaze/src/compiler/CMakeLists.txt | 26 + vendor/blaze/src/compiler/compile.cc | 354 ++++ .../src/compiler}/compile_describe.cc | 291 ++- .../src/compiler}/compile_helpers.h | 75 +- vendor/blaze/src/compiler/compile_json.cc | 344 ++++ .../src/compiler}/default_compiler.cc | 32 +- .../src/compiler}/default_compiler_2019_09.h | 233 +-- .../src/compiler/default_compiler_2020_12.h | 77 + .../src/compiler}/default_compiler_draft4.h | 895 +++++---- .../src/compiler/default_compiler_draft6.h | 235 +++ .../src/compiler}/default_compiler_draft7.h | 51 +- .../include/sourcemeta/blaze/compiler.h} | 211 ++- .../include/sourcemeta/blaze/compiler_error.h | 59 + vendor/blaze/src/evaluator/CMakeLists.txt | 19 + .../src/evaluator/context.cc | 172 +- .../src/evaluator/evaluator.cc | 818 ++++---- .../include/sourcemeta/blaze}/evaluator.h | 95 +- .../sourcemeta/blaze/evaluator_context.h | 151 ++ .../sourcemeta/blaze}/evaluator_error.h | 16 +- .../sourcemeta/blaze/evaluator_template.h | 495 +++++ .../sourcemeta/blaze}/evaluator_value.h | 61 +- .../src/evaluator/trace.h | 8 +- vendor/blaze/vendor/noa/LICENSE | 661 +++++++ vendor/blaze/vendor/noa/cmake/noa.cmake | 13 + .../noa/cmake/noa/commands/copy-file.cmake | 17 + .../noa/cmake/noa/compiler/options.cmake | 109 ++ .../noa/cmake/noa/compiler/sanitizer.cmake | 40 + .../blaze/vendor/noa/cmake/noa/defaults.cmake | 94 + .../blaze/vendor/noa/cmake/noa/library.cmake | 159 ++ .../vendor/noa/cmake/noa/options/enum.cmake | 32 + vendor/blaze/vendor/noa/cmake/noa/shim.cmake | 5 + .../noa/cmake/noa/targets/clang-format.cmake | 48 + .../noa/cmake/noa/targets/clang-format.config | 3 + .../noa/cmake/noa/targets/clang-tidy.cmake | 58 + .../noa/cmake/noa/targets/clang-tidy.config | 7 + .../noa/cmake/noa/targets/doxygen.cmake | 26 + .../noa/cmake/noa/targets/shellcheck.cmake | 34 + .../vendor/noa/cmake/noa/variables.cmake | 12 + vendor/hydra/CMakeLists.txt | 16 +- vendor/hydra/cmake/CompilerOptions.cmake | 66 - vendor/hydra/cmake/FindCURL.cmake | 4 + vendor/hydra/config.cmake.in | 10 +- vendor/hydra/src/bucket/CMakeLists.txt | 3 +- vendor/hydra/src/bucket/aws_sigv4.cc | 115 +- vendor/hydra/src/bucket/bucket.cc | 10 +- .../sourcemeta/hydra/bucket_aws_sigv4.h | 34 +- vendor/hydra/src/crypto/CMakeLists.txt | 9 + vendor/hydra/src/crypto/base64.cc | 52 + vendor/hydra/src/crypto/bearssl.h | 24 + .../crypto/include/sourcemeta/hydra/crypto.h | 100 + vendor/hydra/src/crypto/md5.cc | 26 + vendor/hydra/src/crypto/sha256.cc | 40 + vendor/hydra/src/crypto/uuid.cc | 32 + vendor/hydra/src/http/CMakeLists.txt | 6 +- .../src/http/include/sourcemeta/hydra/http.h | 1 + .../include/sourcemeta/hydra/http_method.h | 5 +- .../http/include/sourcemeta/hydra/http_mime.h | 30 + .../include/sourcemeta/hydra/http_status.h | 5 +- vendor/hydra/src/http/mime.cc | 36 + vendor/hydra/src/httpclient/CMakeLists.txt | 1 - vendor/hydra/src/httpclient/request.cc | 4 +- vendor/hydra/src/httpclient/stream_curl.cc | 28 +- vendor/hydra/src/httpserver/CMakeLists.txt | 4 +- vendor/hydra/src/httpserver/httpserver.cc | 14 +- .../include/sourcemeta/hydra/httpserver.h | 36 +- .../sourcemeta/hydra/httpserver_response.h | 46 +- vendor/hydra/src/httpserver/logger.cc | 34 +- vendor/hydra/src/httpserver/request.cc | 5 +- vendor/hydra/src/httpserver/response.cc | 51 +- vendor/hydra/src/httpserver/static.cc | 63 + vendor/hydra/src/httpserver/uwebsockets.h | 2 + vendor/hydra/vendor/curl.mask | 7 + vendor/hydra/vendor/curl/include/curl/curl.h | 151 +- .../hydra/vendor/curl/include/curl/curlver.h | 10 +- vendor/hydra/vendor/curl/include/curl/easy.h | 2 +- .../hydra/vendor/curl/include/curl/mprintf.h | 11 +- vendor/hydra/vendor/curl/include/curl/multi.h | 16 +- .../hydra/vendor/curl/include/curl/system.h | 6 +- .../vendor/curl/include/curl/typecheck-gcc.h | 10 +- .../hydra/vendor/curl/include/curl/urlapi.h | 5 +- vendor/hydra/vendor/curl/lib/altsvc.c | 68 +- vendor/hydra/vendor/curl/lib/altsvc.h | 4 +- vendor/hydra/vendor/curl/lib/amigaos.c | 2 +- vendor/hydra/vendor/curl/lib/arpa_telnet.h | 2 +- vendor/hydra/vendor/curl/lib/asyn-ares.c | 92 +- vendor/hydra/vendor/curl/lib/asyn-thread.c | 281 +-- vendor/hydra/vendor/curl/lib/asyn.h | 16 +- vendor/hydra/vendor/curl/lib/bufq.c | 69 + vendor/hydra/vendor/curl/lib/bufq.h | 6 + vendor/hydra/vendor/curl/lib/bufref.c | 2 +- vendor/hydra/vendor/curl/lib/c-hyper.c | 330 ++-- vendor/hydra/vendor/curl/lib/cf-h1-proxy.c | 35 +- vendor/hydra/vendor/curl/lib/cf-h2-proxy.c | 266 ++- vendor/hydra/vendor/curl/lib/cf-haproxy.c | 37 +- .../hydra/vendor/curl/lib/cf-https-connect.c | 98 +- vendor/hydra/vendor/curl/lib/cf-socket.c | 698 ++++--- vendor/hydra/vendor/curl/lib/cf-socket.h | 9 +- vendor/hydra/vendor/curl/lib/cfilters.c | 187 +- vendor/hydra/vendor/curl/lib/cfilters.h | 80 +- vendor/hydra/vendor/curl/lib/config-mac.h | 2 +- vendor/hydra/vendor/curl/lib/config-os400.h | 8 +- vendor/hydra/vendor/curl/lib/config-plan9.h | 1 - vendor/hydra/vendor/curl/lib/config-riscos.h | 13 - vendor/hydra/vendor/curl/lib/config-win32ce.h | 4 +- vendor/hydra/vendor/curl/lib/conncache.c | 1435 ++++++++++---- vendor/hydra/vendor/curl/lib/conncache.h | 241 ++- vendor/hydra/vendor/curl/lib/connect.c | 263 ++- vendor/hydra/vendor/curl/lib/connect.h | 27 +- .../hydra/vendor/curl/lib/content_encoding.c | 63 +- vendor/hydra/vendor/curl/lib/cookie.c | 86 +- vendor/hydra/vendor/curl/lib/cookie.h | 2 +- vendor/hydra/vendor/curl/lib/curl_addrinfo.c | 20 +- vendor/hydra/vendor/curl/lib/curl_addrinfo.h | 6 +- vendor/hydra/vendor/curl/lib/curl_des.c | 10 +- vendor/hydra/vendor/curl/lib/curl_des.h | 8 +- vendor/hydra/vendor/curl/lib/curl_endian.c | 6 +- vendor/hydra/vendor/curl/lib/curl_fnmatch.c | 2 +- vendor/hydra/vendor/curl/lib/curl_fnmatch.h | 2 +- .../hydra/vendor/curl/lib/curl_gethostname.c | 25 +- vendor/hydra/vendor/curl/lib/curl_memrchr.c | 4 + vendor/hydra/vendor/curl/lib/curl_memrchr.h | 4 + vendor/hydra/vendor/curl/lib/curl_multibyte.h | 13 +- vendor/hydra/vendor/curl/lib/curl_ntlm_core.c | 62 +- vendor/hydra/vendor/curl/lib/curl_ntlm_core.h | 7 - vendor/hydra/vendor/curl/lib/curl_printf.h | 5 +- vendor/hydra/vendor/curl/lib/curl_range.c | 15 +- vendor/hydra/vendor/curl/lib/curl_rtmp.c | 9 +- vendor/hydra/vendor/curl/lib/curl_sasl.c | 2 +- vendor/hydra/vendor/curl/lib/curl_setup.h | 107 +- .../hydra/vendor/curl/lib/curl_setup_once.h | 14 +- vendor/hydra/vendor/curl/lib/curl_sha256.h | 9 +- .../hydra/vendor/curl/lib/curl_sha512_256.c | 93 +- .../hydra/vendor/curl/lib/curl_sha512_256.h | 2 +- vendor/hydra/vendor/curl/lib/curl_sspi.c | 28 +- vendor/hydra/vendor/curl/lib/curl_sspi.h | 4 +- vendor/hydra/vendor/curl/lib/curl_threads.c | 15 +- vendor/hydra/vendor/curl/lib/curl_threads.h | 9 +- vendor/hydra/vendor/curl/lib/curl_trc.c | 205 +- vendor/hydra/vendor/curl/lib/curl_trc.h | 32 + vendor/hydra/vendor/curl/lib/curlx.h | 43 +- vendor/hydra/vendor/curl/lib/cw-out.c | 4 +- vendor/hydra/vendor/curl/lib/dict.c | 8 +- vendor/hydra/vendor/curl/lib/doh.c | 624 +++--- vendor/hydra/vendor/curl/lib/doh.h | 70 +- vendor/hydra/vendor/curl/lib/dynbuf.c | 4 +- vendor/hydra/vendor/curl/lib/dynhds.c | 2 +- vendor/hydra/vendor/curl/lib/dynhds.h | 36 +- vendor/hydra/vendor/curl/lib/easy.c | 188 +- vendor/hydra/vendor/curl/lib/easygetopt.c | 2 +- vendor/hydra/vendor/curl/lib/easyif.h | 2 +- vendor/hydra/vendor/curl/lib/easyoptions.c | 3 +- vendor/hydra/vendor/curl/lib/escape.c | 19 +- vendor/hydra/vendor/curl/lib/file.c | 63 +- vendor/hydra/vendor/curl/lib/fileinfo.h | 2 +- vendor/hydra/vendor/curl/lib/fopen.c | 8 +- vendor/hydra/vendor/curl/lib/formdata.c | 26 +- vendor/hydra/vendor/curl/lib/formdata.h | 4 +- vendor/hydra/vendor/curl/lib/ftp.c | 290 +-- vendor/hydra/vendor/curl/lib/ftp.h | 6 +- vendor/hydra/vendor/curl/lib/getenv.c | 6 +- vendor/hydra/vendor/curl/lib/getinfo.c | 62 +- vendor/hydra/vendor/curl/lib/gopher.c | 10 +- vendor/hydra/vendor/curl/lib/hash.c | 118 +- vendor/hydra/vendor/curl/lib/hash.h | 21 +- vendor/hydra/vendor/curl/lib/headers.c | 50 +- vendor/hydra/vendor/curl/lib/headers.h | 2 +- vendor/hydra/vendor/curl/lib/hmac.c | 2 +- vendor/hydra/vendor/curl/lib/hostasyn.c | 2 +- vendor/hydra/vendor/curl/lib/hostip.c | 137 +- vendor/hydra/vendor/curl/lib/hostip.h | 29 +- vendor/hydra/vendor/curl/lib/hostip4.c | 26 +- vendor/hydra/vendor/curl/lib/hostip6.c | 2 +- vendor/hydra/vendor/curl/lib/hsts.c | 54 +- vendor/hydra/vendor/curl/lib/hsts.h | 6 +- vendor/hydra/vendor/curl/lib/http.c | 363 ++-- vendor/hydra/vendor/curl/lib/http.h | 11 +- vendor/hydra/vendor/curl/lib/http1.c | 2 +- vendor/hydra/vendor/curl/lib/http2.c | 773 ++++---- vendor/hydra/vendor/curl/lib/http_aws_sigv4.c | 266 ++- vendor/hydra/vendor/curl/lib/http_chunks.c | 15 +- vendor/hydra/vendor/curl/lib/http_chunks.h | 10 +- vendor/hydra/vendor/curl/lib/http_negotiate.c | 21 +- vendor/hydra/vendor/curl/lib/http_ntlm.c | 8 +- vendor/hydra/vendor/curl/lib/http_ntlm.h | 4 +- vendor/hydra/vendor/curl/lib/http_proxy.c | 1 + vendor/hydra/vendor/curl/lib/idn.c | 125 +- vendor/hydra/vendor/curl/lib/if2ip.c | 8 + vendor/hydra/vendor/curl/lib/imap.c | 26 +- vendor/hydra/vendor/curl/lib/inet_ntop.c | 17 +- vendor/hydra/vendor/curl/lib/inet_ntop.h | 7 +- vendor/hydra/vendor/curl/lib/inet_pton.c | 16 +- vendor/hydra/vendor/curl/lib/krb5.c | 41 +- vendor/hydra/vendor/curl/lib/ldap.c | 34 +- vendor/hydra/vendor/curl/lib/llist.c | 200 +- vendor/hydra/vendor/curl/lib/llist.h | 67 +- vendor/hydra/vendor/curl/lib/macos.c | 28 +- vendor/hydra/vendor/curl/lib/md4.c | 148 +- vendor/hydra/vendor/curl/lib/md5.c | 179 +- vendor/hydra/vendor/curl/lib/memdebug.c | 24 +- vendor/hydra/vendor/curl/lib/memdebug.h | 17 +- vendor/hydra/vendor/curl/lib/mime.c | 81 +- vendor/hydra/vendor/curl/lib/mime.h | 4 +- vendor/hydra/vendor/curl/lib/mprintf.c | 9 +- vendor/hydra/vendor/curl/lib/mqtt.c | 24 +- vendor/hydra/vendor/curl/lib/multi.c | 1662 ++++++++-------- vendor/hydra/vendor/curl/lib/multihandle.h | 48 +- vendor/hydra/vendor/curl/lib/multiif.h | 28 +- vendor/hydra/vendor/curl/lib/netrc.c | 8 +- vendor/hydra/vendor/curl/lib/netrc.h | 2 +- vendor/hydra/vendor/curl/lib/nonblock.c | 19 +- vendor/hydra/vendor/curl/lib/noproxy.c | 35 +- vendor/hydra/vendor/curl/lib/noproxy.h | 6 +- vendor/hydra/vendor/curl/lib/openldap.c | 6 +- vendor/hydra/vendor/curl/lib/parsedate.c | 14 +- vendor/hydra/vendor/curl/lib/pingpong.c | 160 +- vendor/hydra/vendor/curl/lib/pingpong.h | 6 +- vendor/hydra/vendor/curl/lib/pop3.c | 104 +- vendor/hydra/vendor/curl/lib/pop3.h | 5 - vendor/hydra/vendor/curl/lib/progress.c | 282 +-- vendor/hydra/vendor/curl/lib/progress.h | 8 +- vendor/hydra/vendor/curl/lib/rand.c | 155 +- vendor/hydra/vendor/curl/lib/rand.h | 12 +- vendor/hydra/vendor/curl/lib/rename.c | 2 +- vendor/hydra/vendor/curl/lib/request.c | 163 +- vendor/hydra/vendor/curl/lib/request.h | 35 +- vendor/hydra/vendor/curl/lib/rtsp.c | 19 +- vendor/hydra/vendor/curl/lib/rtsp.h | 10 - vendor/hydra/vendor/curl/lib/select.c | 176 +- vendor/hydra/vendor/curl/lib/select.h | 33 + vendor/hydra/vendor/curl/lib/sendf.c | 115 +- vendor/hydra/vendor/curl/lib/sendf.h | 8 + vendor/hydra/vendor/curl/lib/setopt.c | 210 +- vendor/hydra/vendor/curl/lib/setup-os400.h | 13 + vendor/hydra/vendor/curl/lib/setup-vms.h | 4 +- vendor/hydra/vendor/curl/lib/setup-win32.h | 10 +- vendor/hydra/vendor/curl/lib/sha256.c | 38 +- vendor/hydra/vendor/curl/lib/share.c | 19 +- vendor/hydra/vendor/curl/lib/share.h | 7 +- vendor/hydra/vendor/curl/lib/sigpipe.h | 19 + vendor/hydra/vendor/curl/lib/smb.c | 39 +- vendor/hydra/vendor/curl/lib/smtp.c | 111 +- vendor/hydra/vendor/curl/lib/socketpair.c | 73 +- vendor/hydra/vendor/curl/lib/socketpair.h | 54 +- vendor/hydra/vendor/curl/lib/socks.c | 37 +- vendor/hydra/vendor/curl/lib/socks_gssapi.c | 25 +- vendor/hydra/vendor/curl/lib/socks_sspi.c | 181 +- vendor/hydra/vendor/curl/lib/splay.c | 43 +- vendor/hydra/vendor/curl/lib/splay.h | 12 +- vendor/hydra/vendor/curl/lib/strcase.c | 12 +- vendor/hydra/vendor/curl/lib/strerror.c | 43 +- vendor/hydra/vendor/curl/lib/strtok.c | 2 +- vendor/hydra/vendor/curl/lib/strtoofft.c | 16 +- vendor/hydra/vendor/curl/lib/strtoofft.h | 2 +- vendor/hydra/vendor/curl/lib/system_win32.c | 45 +- vendor/hydra/vendor/curl/lib/system_win32.h | 32 +- vendor/hydra/vendor/curl/lib/telnet.c | 32 +- vendor/hydra/vendor/curl/lib/tftp.c | 79 +- vendor/hydra/vendor/curl/lib/timediff.h | 4 +- vendor/hydra/vendor/curl/lib/timeval.c | 16 +- vendor/hydra/vendor/curl/lib/transfer.c | 426 ++--- vendor/hydra/vendor/curl/lib/transfer.h | 64 +- vendor/hydra/vendor/curl/lib/url.c | 1379 +++++++------- vendor/hydra/vendor/curl/lib/url.h | 20 +- vendor/hydra/vendor/curl/lib/urlapi-int.h | 6 +- vendor/hydra/vendor/curl/lib/urlapi.c | 118 +- vendor/hydra/vendor/curl/lib/urldata.h | 249 ++- .../hydra/vendor/curl/lib/vauth/cleartext.c | 8 +- vendor/hydra/vendor/curl/lib/vauth/cram.c | 2 +- vendor/hydra/vendor/curl/lib/vauth/digest.c | 26 +- .../hydra/vendor/curl/lib/vauth/digest_sspi.c | 68 +- .../hydra/vendor/curl/lib/vauth/krb5_gssapi.c | 6 +- .../hydra/vendor/curl/lib/vauth/krb5_sspi.c | 34 +- vendor/hydra/vendor/curl/lib/vauth/ntlm.c | 44 +- .../hydra/vendor/curl/lib/vauth/ntlm_sspi.c | 30 +- vendor/hydra/vendor/curl/lib/vauth/oauth2.c | 6 +- .../vendor/curl/lib/vauth/spnego_gssapi.c | 20 +- .../hydra/vendor/curl/lib/vauth/spnego_sspi.c | 59 +- vendor/hydra/vendor/curl/lib/vauth/vauth.c | 8 +- vendor/hydra/vendor/curl/lib/version.c | 21 +- vendor/hydra/vendor/curl/lib/version_win32.c | 16 +- vendor/hydra/vendor/curl/lib/version_win32.h | 2 +- .../hydra/vendor/curl/lib/vquic/curl_msh3.c | 77 +- .../hydra/vendor/curl/lib/vquic/curl_ngtcp2.c | 390 ++-- .../hydra/vendor/curl/lib/vquic/curl_osslq.c | 321 ++-- .../hydra/vendor/curl/lib/vquic/curl_quiche.c | 410 ++-- .../hydra/vendor/curl/lib/vquic/vquic-tls.c | 79 +- .../hydra/vendor/curl/lib/vquic/vquic-tls.h | 5 +- vendor/hydra/vendor/curl/lib/vquic/vquic.c | 106 +- vendor/hydra/vendor/curl/lib/vssh/libssh.c | 172 +- vendor/hydra/vendor/curl/lib/vssh/libssh2.c | 139 +- vendor/hydra/vendor/curl/lib/vssh/ssh.h | 8 +- vendor/hydra/vendor/curl/lib/vssh/wolfssh.c | 37 +- vendor/hydra/vendor/curl/lib/vtls/bearssl.c | 216 ++- .../hydra/vendor/curl/lib/vtls/cipher_suite.c | 257 ++- .../hydra/vendor/curl/lib/vtls/cipher_suite.h | 6 +- vendor/hydra/vendor/curl/lib/vtls/gtls.c | 719 ++++--- vendor/hydra/vendor/curl/lib/vtls/gtls.h | 18 +- vendor/hydra/vendor/curl/lib/vtls/hostcheck.c | 2 +- vendor/hydra/vendor/curl/lib/vtls/hostcheck.h | 2 +- vendor/hydra/vendor/curl/lib/vtls/mbedtls.c | 643 ++++--- vendor/hydra/vendor/curl/lib/vtls/openssl.c | 1061 ++++++----- vendor/hydra/vendor/curl/lib/vtls/openssl.h | 16 +- vendor/hydra/vendor/curl/lib/vtls/rustls.c | 476 ++++- vendor/hydra/vendor/curl/lib/vtls/schannel.c | 394 ++-- .../hydra/vendor/curl/lib/vtls/schannel_int.h | 15 +- .../vendor/curl/lib/vtls/schannel_verify.c | 27 +- vendor/hydra/vendor/curl/lib/vtls/sectransp.c | 1681 +++++------------ vendor/hydra/vendor/curl/lib/vtls/vtls.c | 416 ++-- vendor/hydra/vendor/curl/lib/vtls/vtls.h | 31 +- vendor/hydra/vendor/curl/lib/vtls/vtls_int.h | 65 +- vendor/hydra/vendor/curl/lib/vtls/wolfssl.c | 1050 +++++++--- vendor/hydra/vendor/curl/lib/vtls/wolfssl.h | 19 + vendor/hydra/vendor/curl/lib/vtls/x509asn1.c | 97 +- vendor/hydra/vendor/curl/lib/vtls/x509asn1.h | 14 +- vendor/hydra/vendor/curl/lib/ws.c | 265 ++- vendor/hydra/vendor/curl/lib/ws.h | 2 +- vendor/hydra/vendor/noa/LICENSE | 862 +++++++-- vendor/hydra/vendor/noa/cmake/noa.cmake | 3 +- .../noa/cmake/noa/compiler/options.cmake | 109 ++ .../hydra/vendor/noa/cmake/noa/defaults.cmake | 23 + .../hydra/vendor/noa/cmake/noa/library.cmake | 45 +- vendor/hydra/vendor/uwebsockets/src/App.h | 182 +- .../vendor/uwebsockets/src/AsyncSocket.h | 6 +- .../vendor/uwebsockets/src/BloomFilter.h | 2 +- .../hydra/vendor/uwebsockets/src/CachingApp.h | 113 ++ .../vendor/uwebsockets/src/HttpContext.h | 8 +- .../vendor/uwebsockets/src/HttpContextData.h | 6 +- .../hydra/vendor/uwebsockets/src/HttpParser.h | 18 +- .../vendor/uwebsockets/src/HttpResponse.h | 2 +- .../vendor/uwebsockets/src/LocalCluster.h | 2 +- .../hydra/vendor/uwebsockets/src/LoopData.h | 7 +- .../hydra/vendor/uwebsockets/src/WebSocket.h | 5 +- .../vendor/uwebsockets/src/WebSocketContext.h | 10 +- .../uwebsockets/src/WebSocketProtocol.h | 21 +- .../vendor/uwebsockets/uSockets/src/context.c | 2 +- .../uSockets/src/internal/internal.h | 2 +- .../uwebsockets/uSockets/src/libusockets.h | 2 +- .../vendor/uwebsockets/uSockets/src/loop.c | 2 +- .../vendor/uwebsockets/uSockets/src/quic.c | 4 +- vendor/jsonbinpack/src/compiler/encoding.h | 13 +- .../noa/cmake/noa/compiler/options.cmake | 24 +- .../vendor/noa/cmake/noa/library.cmake | 36 +- vendor/jsontoolkit/CMakeLists.txt | 22 +- .../cmake/FindGoogleBenchmark.cmake | 4 +- vendor/jsontoolkit/cmake/FindUriParser.cmake | 68 +- vendor/jsontoolkit/config.cmake.in | 16 - .../jsontoolkit/src/evaluator/CMakeLists.txt | 19 - .../jsontoolkit/evaluator_context.h | 138 -- .../jsontoolkit/evaluator_template.h | 516 ----- .../include/sourcemeta/jsontoolkit/json.h | 2 + .../sourcemeta/jsontoolkit/json_error.h | 2 + .../sourcemeta/jsontoolkit/json_value.h | 2 + .../include/sourcemeta/jsontoolkit/jsonl.h | 2 + .../sourcemeta/jsontoolkit/jsonl_iterator.h | 2 + .../sourcemeta/jsontoolkit/jsonpointer.h | 2 + .../jsontoolkit/jsonpointer_error.h | 2 + .../jsontoolkit/src/jsonschema/CMakeLists.txt | 24 +- vendor/jsontoolkit/src/jsonschema/anchor.cc | 9 +- vendor/jsontoolkit/src/jsonschema/bundle.cc | 15 +- vendor/jsontoolkit/src/jsonschema/compile.cc | 283 --- .../src/jsonschema/compile_json.cc | 335 ---- .../src/jsonschema/default_compiler_2020_12.h | 76 - .../src/jsonschema/default_compiler_draft6.h | 224 --- .../sourcemeta/jsontoolkit/jsonschema.h | 22 +- .../jsontoolkit/jsonschema_anchor.h | 7 +- .../jsontoolkit/jsonschema_bundle.h | 27 +- .../sourcemeta/jsontoolkit/jsonschema_error.h | 29 +- .../jsontoolkit/jsonschema_reference.h | 12 +- .../jsontoolkit/jsonschema_resolver.h | 13 +- .../jsontoolkit/jsonschema_walker.h | 4 +- .../jsontoolkit/src/jsonschema/jsonschema.cc | 111 +- .../src/jsonschema/official_resolver.in.cc | 205 +- .../jsontoolkit/src/jsonschema/reference.cc | 7 +- vendor/jsontoolkit/src/jsonschema/resolver.cc | 18 +- vendor/jsontoolkit/src/jsonschema/walker.cc | 18 +- .../uri/include/sourcemeta/jsontoolkit/uri.h | 2 + .../sourcemeta/jsontoolkit/uri_error.h | 2 + .../vendor/jsonschema-test-suite.mask | 18 - .../noa/cmake/noa/compiler/options.cmake | 2 + .../vendor/noa/cmake/noa/library.cmake | 36 +- .../vendor/uriparser/CMakeLists.txt | 505 ----- .../vendor/uriparser/cmake/.gitignore | 3 - .../uriparser/cmake/uriparser-config.cmake.in | 57 - .../vendor/uriparser/liburiparser.pc.in | 12 - vendor/noa/cmake/noa/compiler/options.cmake | 24 +- vendor/noa/cmake/noa/library.cmake | 36 +- 412 files changed, 22701 insertions(+), 15694 deletions(-) create mode 100644 cmake/FindBlaze.cmake create mode 100644 vendor/blaze/CMakeLists.txt create mode 100644 vendor/blaze/LICENSE create mode 100644 vendor/blaze/LICENSE-COMMERCIAL create mode 100644 vendor/blaze/cmake/FindGoogleBenchmark.cmake create mode 100644 vendor/blaze/cmake/FindGoogleTest.cmake create mode 100644 vendor/blaze/cmake/FindJSONToolkit.cmake create mode 100644 vendor/blaze/config.cmake.in create mode 100644 vendor/blaze/src/compiler/CMakeLists.txt create mode 100644 vendor/blaze/src/compiler/compile.cc rename vendor/{jsontoolkit/src/jsonschema => blaze/src/compiler}/compile_describe.cc (85%) rename vendor/{jsontoolkit/src/jsonschema => blaze/src/compiler}/compile_helpers.h (50%) create mode 100644 vendor/blaze/src/compiler/compile_json.cc rename vendor/{jsontoolkit/src/jsonschema => blaze/src/compiler}/default_compiler.cc (97%) rename vendor/{jsontoolkit/src/jsonschema => blaze/src/compiler}/default_compiler_2019_09.h (51%) create mode 100644 vendor/blaze/src/compiler/default_compiler_2020_12.h rename vendor/{jsontoolkit/src/jsonschema => blaze/src/compiler}/default_compiler_draft4.h (57%) create mode 100644 vendor/blaze/src/compiler/default_compiler_draft6.h rename vendor/{jsontoolkit/src/jsonschema => blaze/src/compiler}/default_compiler_draft7.h (51%) rename vendor/{jsontoolkit/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_compile.h => blaze/src/compiler/include/sourcemeta/blaze/compiler.h} (55%) create mode 100644 vendor/blaze/src/compiler/include/sourcemeta/blaze/compiler_error.h create mode 100644 vendor/blaze/src/evaluator/CMakeLists.txt rename vendor/{jsontoolkit => blaze}/src/evaluator/context.cc (62%) rename vendor/{jsontoolkit => blaze}/src/evaluator/evaluator.cc (58%) rename vendor/{jsontoolkit/src/evaluator/include/sourcemeta/jsontoolkit => blaze/src/evaluator/include/sourcemeta/blaze}/evaluator.h (63%) create mode 100644 vendor/blaze/src/evaluator/include/sourcemeta/blaze/evaluator_context.h rename vendor/{jsontoolkit/src/evaluator/include/sourcemeta/jsontoolkit => blaze/src/evaluator/include/sourcemeta/blaze}/evaluator_error.h (68%) create mode 100644 vendor/blaze/src/evaluator/include/sourcemeta/blaze/evaluator_template.h rename vendor/{jsontoolkit/src/evaluator/include/sourcemeta/jsontoolkit => blaze/src/evaluator/include/sourcemeta/blaze}/evaluator_value.h (56%) rename vendor/{jsontoolkit => blaze}/src/evaluator/trace.h (78%) create mode 100644 vendor/blaze/vendor/noa/LICENSE create mode 100644 vendor/blaze/vendor/noa/cmake/noa.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/commands/copy-file.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/compiler/options.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/compiler/sanitizer.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/defaults.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/library.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/options/enum.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/shim.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/targets/clang-format.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/targets/clang-format.config create mode 100644 vendor/blaze/vendor/noa/cmake/noa/targets/clang-tidy.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/targets/clang-tidy.config create mode 100644 vendor/blaze/vendor/noa/cmake/noa/targets/doxygen.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/targets/shellcheck.cmake create mode 100644 vendor/blaze/vendor/noa/cmake/noa/variables.cmake delete mode 100644 vendor/hydra/cmake/CompilerOptions.cmake create mode 100644 vendor/hydra/src/crypto/CMakeLists.txt create mode 100644 vendor/hydra/src/crypto/base64.cc create mode 100644 vendor/hydra/src/crypto/bearssl.h create mode 100644 vendor/hydra/src/crypto/include/sourcemeta/hydra/crypto.h create mode 100644 vendor/hydra/src/crypto/md5.cc create mode 100644 vendor/hydra/src/crypto/sha256.cc create mode 100644 vendor/hydra/src/crypto/uuid.cc create mode 100644 vendor/hydra/src/http/include/sourcemeta/hydra/http_mime.h create mode 100644 vendor/hydra/src/http/mime.cc create mode 100644 vendor/hydra/src/httpserver/static.cc create mode 100644 vendor/hydra/vendor/noa/cmake/noa/compiler/options.cmake create mode 100644 vendor/hydra/vendor/uwebsockets/src/CachingApp.h delete mode 100644 vendor/jsontoolkit/src/evaluator/CMakeLists.txt delete mode 100644 vendor/jsontoolkit/src/evaluator/include/sourcemeta/jsontoolkit/evaluator_context.h delete mode 100644 vendor/jsontoolkit/src/evaluator/include/sourcemeta/jsontoolkit/evaluator_template.h delete mode 100644 vendor/jsontoolkit/src/jsonschema/compile.cc delete mode 100644 vendor/jsontoolkit/src/jsonschema/compile_json.cc delete mode 100644 vendor/jsontoolkit/src/jsonschema/default_compiler_2020_12.h delete mode 100644 vendor/jsontoolkit/src/jsonschema/default_compiler_draft6.h delete mode 100644 vendor/jsontoolkit/vendor/jsonschema-test-suite.mask delete mode 100644 vendor/jsontoolkit/vendor/uriparser/CMakeLists.txt delete mode 100644 vendor/jsontoolkit/vendor/uriparser/cmake/.gitignore delete mode 100644 vendor/jsontoolkit/vendor/uriparser/cmake/uriparser-config.cmake.in delete mode 100644 vendor/jsontoolkit/vendor/uriparser/liburiparser.pc.in diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6176872..098f052 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: CXX: ${{ matrix.platform.cxx }} steps: - name: Install ClangFormat - run: pip install clang-format==19.1.0 + run: pipx install clang-format==19.1.0 - uses: actions/checkout@v4 - name: Install dependencies (macOS) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffdb356..50ebc31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ option(JSONSCHEMA_CONTINUOUS "Perform a continuous JSON Schema CLI release" ON) find_package(JSONToolkit REQUIRED) find_package(AlterSchema REQUIRED) +find_package(Blaze REQUIRED) find_package(JSONBinPack REQUIRED) find_package(Hydra REQUIRED) add_subdirectory(src) diff --git a/DEPENDENCIES b/DEPENDENCIES index 15e8bb3..e9d67a4 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,6 +1,7 @@ vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4 -noa https://github.com/sourcemeta/noa 517e88aef5981b88ac6bb8caff15d17dffcb4320 -jsontoolkit https://github.com/sourcemeta/jsontoolkit 9abbaee71e9e00e95632858d29c7ebe5c2a723b0 -hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc -alterschema https://github.com/sourcemeta/alterschema 358df64771979da64e043a416cf340d83a5382ca -jsonbinpack https://github.com/sourcemeta/jsonbinpack b25d54363f5a88cd23c1af41e4c6025b9c94d0d6 +noa https://github.com/sourcemeta/noa 837e1ff981f8df45d9e2977a50f5da61d8affed4 +jsontoolkit https://github.com/sourcemeta/jsontoolkit 9685d29e2e633d71319c64b1ab2fbceab865dbf3 +hydra https://github.com/sourcemeta/hydra c0d2f53dc52d8febd3092ce873847729b9f447fb +alterschema https://github.com/sourcemeta/alterschema 36dc1933bbbdbf1f2574c309e41f510f58874838 +jsonbinpack https://github.com/sourcemeta/jsonbinpack b09b7948f90a9e9c30a2c38441f44d1c4b93b45a +blaze https://github.com/sourcemeta/blaze 43cac42dc486be24addbc2cd0aa646d18e2000f5 diff --git a/cmake/FindBlaze.cmake b/cmake/FindBlaze.cmake new file mode 100644 index 0000000..c4602f4 --- /dev/null +++ b/cmake/FindBlaze.cmake @@ -0,0 +1,5 @@ +if(NOT Blaze_FOUND) + set(BLAZE_INSTALL OFF CACHE BOOL "disable installation") + add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/blaze") + set(Blaze_FOUND ON) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd00bc9..b370fa5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,13 @@ target_link_libraries(jsonschema_cli PRIVATE sourcemeta::alterschema::linter) target_link_libraries(jsonschema_cli PRIVATE sourcemeta::hydra::httpclient) target_link_libraries(jsonschema_cli PRIVATE sourcemeta::jsonbinpack::compiler) target_link_libraries(jsonschema_cli PRIVATE sourcemeta::jsonbinpack::runtime) +target_link_libraries(jsonschema_cli PRIVATE sourcemeta::blaze::compiler) +target_link_libraries(jsonschema_cli PRIVATE sourcemeta::blaze::evaluator) + +# TODO: This is hack to disambiguate between JSON BinPack's "compiler" module +# and Blaze's "compiler" module, where both will try to include "compiler_export.h" +# We should fix these cases properly in Noa. +target_compile_definitions(jsonschema_cli PRIVATE SOURCEMETA_BLAZE_COMPILER_EXPORT=) configure_file(configure.h.in configure.h @ONLY) target_include_directories(jsonschema_cli PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/src/command_compile.cc b/src/command_compile.cc index a06ef86..e7dc59a 100644 --- a/src/command_compile.cc +++ b/src/command_compile.cc @@ -1,6 +1,9 @@ #include #include +#include +#include + #include // EXIT_SUCCESS #include // std::cout, std::endl @@ -20,16 +23,15 @@ auto sourcemeta::jsonschema::cli::compile( const auto schema{sourcemeta::jsontoolkit::from_file(options.at("").front())}; - const auto compiled_schema{sourcemeta::jsontoolkit::compile( + const auto compiled_schema{sourcemeta::blaze::compile( schema, sourcemeta::jsontoolkit::default_schema_walker, resolver(options, options.contains("h") || options.contains("http")), - sourcemeta::jsontoolkit::default_schema_compiler)}; + sourcemeta::blaze::default_schema_compiler)}; const sourcemeta::jsontoolkit::JSON result{ - sourcemeta::jsontoolkit::to_json(compiled_schema)}; - sourcemeta::jsontoolkit::prettify( - result, std::cout, - sourcemeta::jsontoolkit::compiler_template_format_compare); + sourcemeta::blaze::to_json(compiled_schema)}; + sourcemeta::jsontoolkit::prettify(result, std::cout, + sourcemeta::blaze::template_format_compare); std::cout << std::endl; return EXIT_SUCCESS; } diff --git a/src/command_frame.cc b/src/command_frame.cc index b9dd1c7..43b6fd2 100644 --- a/src/command_frame.cc +++ b/src/command_frame.cc @@ -40,8 +40,7 @@ auto sourcemeta::jsonschema::cli::frame( sourcemeta::jsontoolkit::ReferenceMap references; sourcemeta::jsontoolkit::frame(schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, - resolver(options)) - .wait(); + resolver(options)); const auto output_json = options.contains("json") || options.contains("j"); if (output_json) { diff --git a/src/command_identify.cc b/src/command_identify.cc index c493576..ec0c5cc 100644 --- a/src/command_identify.cc +++ b/src/command_identify.cc @@ -35,10 +35,8 @@ auto sourcemeta::jsonschema::cli::identify( // Just to print a nice warning try { - const auto base_dialect{ - sourcemeta::jsontoolkit::base_dialect( - schema, sourcemeta::jsontoolkit::official_resolver) - .get()}; + const auto base_dialect{sourcemeta::jsontoolkit::base_dialect( + schema, sourcemeta::jsontoolkit::official_resolver)}; if (!base_dialect.has_value()) { std::cerr << "warning: Cannot determine the base dialect of the schema, " "but will attempt to guess\n"; @@ -52,9 +50,8 @@ auto sourcemeta::jsonschema::cli::identify( try { identifier = sourcemeta::jsontoolkit::identify( - schema, sourcemeta::jsontoolkit::official_resolver, - sourcemeta::jsontoolkit::IdentificationStrategy::Loose) - .get(); + schema, sourcemeta::jsontoolkit::official_resolver, + sourcemeta::jsontoolkit::IdentificationStrategy::Loose); } catch (const sourcemeta::jsontoolkit::SchemaError &error) { std::cerr << "error: " << error.what() << "\n " diff --git a/src/command_metaschema.cc b/src/command_metaschema.cc index 1ff2861..9c19f43 100644 --- a/src/command_metaschema.cc +++ b/src/command_metaschema.cc @@ -1,6 +1,9 @@ #include #include +#include +#include + #include // EXIT_SUCCESS, EXIT_FAILURE #include // std::cerr #include // std::map @@ -18,7 +21,7 @@ auto sourcemeta::jsonschema::cli::metaschema( resolver(options, options.contains("h") || options.contains("http"))}; bool result{true}; - std::map cache; + std::map cache; for (const auto &entry : for_each_json(options.at(""), parse_ignore(options), parse_extensions(options))) { @@ -35,17 +38,15 @@ auto sourcemeta::jsonschema::cli::metaschema( const auto metaschema{ sourcemeta::jsontoolkit::metaschema(entry.second, custom_resolver)}; if (!cache.contains(dialect.value())) { - const auto metaschema_template{sourcemeta::jsontoolkit::compile( + const auto metaschema_template{sourcemeta::blaze::compile( metaschema, sourcemeta::jsontoolkit::default_schema_walker, - custom_resolver, sourcemeta::jsontoolkit::default_schema_compiler)}; + custom_resolver, sourcemeta::blaze::default_schema_compiler)}; cache.insert({dialect.value(), metaschema_template}); } - sourcemeta::jsontoolkit::SchemaCompilerErrorTraceOutput output{metaschema}; - if (sourcemeta::jsontoolkit::evaluate( - cache.at(dialect.value()), entry.second, - sourcemeta::jsontoolkit::SchemaCompilerEvaluationMode::Fast, - std::ref(output))) { + sourcemeta::blaze::ErrorTraceOutput output{metaschema}; + if (sourcemeta::blaze::evaluate(cache.at(dialect.value()), entry.second, + std::ref(output))) { log_verbose(options) << "ok: " << std::filesystem::weakly_canonical(entry.first).string() << "\n matches " << dialect.value() << "\n"; diff --git a/src/command_test.cc b/src/command_test.cc index 5da1dec..b533001 100644 --- a/src/command_test.cc +++ b/src/command_test.cc @@ -2,6 +2,9 @@ #include #include +#include +#include + #include // EXIT_SUCCESS, EXIT_FAILURE #include // std::filesystem #include // std::cerr, std::cout @@ -13,7 +16,7 @@ static auto get_schema_object(const sourcemeta::jsontoolkit::URI &identifier, const sourcemeta::jsontoolkit::SchemaResolver &resolver) -> std::optional { - const auto schema{resolver(identifier.recompose()).get()}; + const auto schema{resolver(identifier.recompose())}; if (schema.has_value()) { return schema; } @@ -137,12 +140,12 @@ auto sourcemeta::jsonschema::cli::test( continue; } - sourcemeta::jsontoolkit::SchemaCompilerTemplate schema_template; + sourcemeta::blaze::Template schema_template; try { - schema_template = sourcemeta::jsontoolkit::compile( + schema_template = sourcemeta::blaze::compile( schema.value(), sourcemeta::jsontoolkit::default_schema_walker, - test_resolver, sourcemeta::jsontoolkit::default_schema_compiler); + test_resolver, sourcemeta::blaze::default_schema_compiler); } catch (const sourcemeta::jsontoolkit::SchemaReferenceError &error) { if (error.location() == sourcemeta::jsontoolkit::Pointer{"$ref"} && error.id() == schema_uri.recompose()) { @@ -239,12 +242,11 @@ auto sourcemeta::jsonschema::cli::test( } const std::string ref{"$ref"}; - sourcemeta::jsontoolkit::SchemaCompilerErrorTraceOutput output{ - schema.value(), {std::cref(ref)}}; - const auto case_result{sourcemeta::jsontoolkit::evaluate( + sourcemeta::blaze::ErrorTraceOutput output{schema.value(), + {std::cref(ref)}}; + const auto case_result{sourcemeta::blaze::evaluate( schema_template, get_data(test_case, entry.first.parent_path(), verbose), - sourcemeta::jsontoolkit::SchemaCompilerEvaluationMode::Fast, std::ref(output))}; std::ostringstream test_case_description; diff --git a/src/command_validate.cc b/src/command_validate.cc index 6d314f4..3001370 100644 --- a/src/command_validate.cc +++ b/src/command_validate.cc @@ -2,6 +2,9 @@ #include #include +#include +#include + #include // std::chrono #include // EXIT_SUCCESS, EXIT_FAILURE #include // std::cerr @@ -48,9 +51,9 @@ auto sourcemeta::jsonschema::cli::validate( } const auto benchmark{options.contains("b") || options.contains("benchmark")}; - const auto schema_template{sourcemeta::jsontoolkit::compile( + const auto schema_template{sourcemeta::blaze::compile( schema, sourcemeta::jsontoolkit::default_schema_walker, custom_resolver, - sourcemeta::jsontoolkit::default_schema_compiler)}; + sourcemeta::blaze::default_schema_compiler)}; bool result{true}; @@ -69,14 +72,12 @@ auto sourcemeta::jsonschema::cli::validate( for (const auto &instance : sourcemeta::jsontoolkit::JSONL{stream}) { index += 1; std::ostringstream error; - sourcemeta::jsontoolkit::SchemaCompilerErrorTraceOutput output{ - instance}; + sourcemeta::blaze::ErrorTraceOutput output{instance}; bool subresult = true; if (benchmark) { const auto timestamp_start{ std::chrono::high_resolution_clock::now()}; - subresult = - sourcemeta::jsontoolkit::evaluate(schema_template, instance); + subresult = sourcemeta::blaze::evaluate(schema_template, instance); const auto timestamp_end{std::chrono::high_resolution_clock::now()}; const auto duration_us{ std::chrono::duration_cast( @@ -87,10 +88,8 @@ auto sourcemeta::jsonschema::cli::validate( error << "error: Schema validation failure\n"; } } else { - subresult = sourcemeta::jsontoolkit::evaluate( - schema_template, instance, - sourcemeta::jsontoolkit::SchemaCompilerEvaluationMode::Fast, - std::ref(output)); + subresult = sourcemeta::blaze::evaluate(schema_template, instance, + std::ref(output)); } if (subresult) { @@ -125,12 +124,11 @@ auto sourcemeta::jsonschema::cli::validate( } else { const auto instance{sourcemeta::jsontoolkit::from_file(instance_path)}; std::ostringstream error; - sourcemeta::jsontoolkit::SchemaCompilerErrorTraceOutput output{instance}; + sourcemeta::blaze::ErrorTraceOutput output{instance}; bool subresult{true}; if (benchmark) { const auto timestamp_start{std::chrono::high_resolution_clock::now()}; - subresult = - sourcemeta::jsontoolkit::evaluate(schema_template, instance); + subresult = sourcemeta::blaze::evaluate(schema_template, instance); const auto timestamp_end{std::chrono::high_resolution_clock::now()}; const auto duration_us{ std::chrono::duration_cast( @@ -142,10 +140,8 @@ auto sourcemeta::jsonschema::cli::validate( result = false; } } else { - subresult = sourcemeta::jsontoolkit::evaluate( - schema_template, instance, - sourcemeta::jsontoolkit::SchemaCompilerEvaluationMode::Fast, - std::ref(output)); + subresult = sourcemeta::blaze::evaluate(schema_template, instance, + std::ref(output)); } if (subresult) { diff --git a/src/utils.cc b/src/utils.cc index 2fac99f..865dd46 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -175,9 +175,8 @@ auto parse_options(const std::span &arguments, return options; } -auto print( - const sourcemeta::jsontoolkit::SchemaCompilerErrorTraceOutput &output, - std::ostream &stream) -> void { +auto print(const sourcemeta::blaze::ErrorTraceOutput &output, + std::ostream &stream) -> void { stream << "error: Schema validation failure\n"; for (const auto &entry : output) { stream << " " << entry.message << "\n"; @@ -193,13 +192,10 @@ auto print( static auto fallback_resolver( const std::map> &options, std::string_view identifier) - -> std::future> { - auto official_result{ - sourcemeta::jsontoolkit::official_resolver(identifier).get()}; + -> std::optional { + auto official_result{sourcemeta::jsontoolkit::official_resolver(identifier)}; if (official_result.has_value()) { - std::promise> promise; - promise.set_value(std::move(official_result)); - return promise.get_future(); + return official_result; } // If the URI is not an HTTP URL, then abort @@ -207,9 +203,7 @@ static auto fallback_resolver( const auto maybe_scheme{uri.scheme()}; if (uri.is_urn() || !maybe_scheme.has_value() || (maybe_scheme.value() != "https" && maybe_scheme.value() != "http")) { - std::promise> promise; - promise.set_value(std::nullopt); - return promise.get_future(); + return std::nullopt; } log_verbose(options) << "Resolving over HTTP: " << identifier << "\n"; @@ -222,9 +216,7 @@ static auto fallback_resolver( throw std::runtime_error(error.str()); } - std::promise> promise; - promise.set_value(sourcemeta::jsontoolkit::parse(response.body())); - return promise.get_future(); + return sourcemeta::jsontoolkit::parse(response.body()); } auto resolver(const std::map> &options, diff --git a/src/utils.h b/src/utils.h index 9041f0b..27fda5a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -5,6 +5,8 @@ #include #include +#include + #include // std::filesystem #include // std::map #include // std::ostream @@ -27,9 +29,8 @@ auto for_each_json(const std::vector &arguments, -> std::vector< std::pair>; -auto print( - const sourcemeta::jsontoolkit::SchemaCompilerErrorTraceOutput &output, - std::ostream &stream) -> void; +auto print(const sourcemeta::blaze::ErrorTraceOutput &output, + std::ostream &stream) -> void; auto resolver(const std::map> &options, const bool remote = false) diff --git a/test/compile/pass_1.sh b/test/compile/pass_1.sh index dcc1554..3087055 100755 --- a/test/compile/pass_1.sh +++ b/test/compile/pass_1.sh @@ -28,7 +28,7 @@ cat << 'EOF' > "$TMP/expected.json" "type": "type", "value": "string" }, - "schemaResource": "", + "schemaResource": 0, "absoluteKeywordLocation": "#/properties/foo/type", "relativeSchemaLocation": "/properties/foo/type", "relativeInstanceLocation": "/foo", diff --git a/test/validate/fail_2019_09.sh b/test/validate/fail_2019_09.sh index 182b4ce..54d9983 100755 --- a/test/validate/fail_2019_09.sh +++ b/test/validate/fail_2019_09.sh @@ -33,9 +33,6 @@ error: Schema validation failure The value was expected to be of type string but it was of type integer at instance location "/foo" at evaluate path "/properties/foo/type" - The object value was expected to validate against the single defined property subschema - at instance location "" - at evaluate path "/properties" EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/validate/fail_2020_12.sh b/test/validate/fail_2020_12.sh index 61a2160..c9a7c81 100755 --- a/test/validate/fail_2020_12.sh +++ b/test/validate/fail_2020_12.sh @@ -33,9 +33,6 @@ error: Schema validation failure The value was expected to be of type string but it was of type integer at instance location "/foo" at evaluate path "/properties/foo/type" - The object value was expected to validate against the single defined property subschema - at instance location "" - at evaluate path "/properties" EOF diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/vendor/alterschema/src/engine/rule.cc b/vendor/alterschema/src/engine/rule.cc index 669d3a5..3e45c65 100644 --- a/vendor/alterschema/src/engine/rule.cc +++ b/vendor/alterschema/src/engine/rule.cc @@ -48,9 +48,9 @@ auto sourcemeta::alterschema::Rule::apply( "Could not determine the schema dialect"); } - const auto vocabularies{vocabularies_to_set( - sourcemeta::jsontoolkit::vocabularies(schema, resolver, default_dialect) - .get())}; + const auto vocabularies{ + vocabularies_to_set(sourcemeta::jsontoolkit::vocabularies( + schema, resolver, default_dialect))}; if (!this->condition(schema, dialect.value(), vocabularies, pointer)) { return {}; } @@ -83,8 +83,8 @@ auto sourcemeta::alterschema::Rule::check( "Could not determine the schema dialect"); } - const auto vocabularies{vocabularies_to_set( - sourcemeta::jsontoolkit::vocabularies(schema, resolver, default_dialect) - .get())}; + const auto vocabularies{ + vocabularies_to_set(sourcemeta::jsontoolkit::vocabularies( + schema, resolver, default_dialect))}; return this->condition(schema, dialect.value(), vocabularies, pointer); } diff --git a/vendor/alterschema/vendor/noa/cmake/noa/compiler/options.cmake b/vendor/alterschema/vendor/noa/cmake/noa/compiler/options.cmake index b1fc6e5..dde90f2 100644 --- a/vendor/alterschema/vendor/noa/cmake/noa/compiler/options.cmake +++ b/vendor/alterschema/vendor/noa/cmake/noa/compiler/options.cmake @@ -42,6 +42,10 @@ function(noa_add_default_options visibility target) -Winvalid-offsetof -funroll-loops -fstrict-aliasing + -ftree-vectorize + + # To improve how much GCC/Clang will vectorize + -fno-math-errno # Assume that signed arithmetic overflow of addition, subtraction and # multiplication wraps around using twos-complement representation @@ -78,10 +82,28 @@ function(noa_add_default_options visibility target) -fslp-vectorize) elseif(NOA_COMPILER_GCC) target_compile_options("${target}" ${visibility} + -fno-trapping-math # Newer versions of GCC (i.e. 14) seem to print a lot of false-positives here -Wno-dangling-reference - + # GCC seems to print a lot of false-positives here + -Wno-free-nonheap-object # Disables runtime type information -fno-rtti) endif() endfunction() + +# For studying failed vectorization results +# - On Clang , seems to only take effect on release shared builds +# - On GCC, seems to only take effect on release shared builds +function(noa_add_vectorization_diagnostics target) + if(NOA_COMPILER_LLVM) + # See https://llvm.org/docs/Vectorizers.html#id6 + target_compile_options("${target}" PRIVATE + -Rpass-analysis=loop-vectorize + -Rpass-missed=loop-vectorize) + elseif(NOA_COMPILER_GCC) + target_compile_options("${target}" PRIVATE + -fopt-info-vec-missed + -fopt-info-loop-missed) + endif() +endfunction() diff --git a/vendor/alterschema/vendor/noa/cmake/noa/library.cmake b/vendor/alterschema/vendor/noa/cmake/noa/library.cmake index 05d5774..9868714 100644 --- a/vendor/alterschema/vendor/noa/cmake/noa/library.cmake +++ b/vendor/alterschema/vendor/noa/cmake/noa/library.cmake @@ -1,6 +1,6 @@ function(noa_library) cmake_parse_arguments(NOA_LIBRARY "" - "NAMESPACE;PROJECT;NAME;FOLDER" "PRIVATE_HEADERS;SOURCES" ${ARGN}) + "NAMESPACE;PROJECT;NAME;FOLDER;VARIANT" "PRIVATE_HEADERS;SOURCES" ${ARGN}) if(NOT NOA_LIBRARY_PROJECT) message(FATAL_ERROR "You must pass the project name using the PROJECT option") @@ -18,7 +18,11 @@ function(noa_library) set(INCLUDE_PREFIX "include/${NOA_LIBRARY_PROJECT}") endif() - set(PUBLIC_HEADER "${INCLUDE_PREFIX}/${NOA_LIBRARY_NAME}.h") + if(NOT NOA_LIBRARY_VARIANT) + set(PUBLIC_HEADER "${INCLUDE_PREFIX}/${NOA_LIBRARY_NAME}.h") + else() + set(PUBLIC_HEADER "../${INCLUDE_PREFIX}/${NOA_LIBRARY_NAME}.h") + endif() if(NOA_LIBRARY_SOURCES) set(ABSOLUTE_PRIVATE_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/${NOA_LIBRARY_NAME}_export.h") @@ -38,6 +42,11 @@ function(noa_library) set(ALIAS_NAME "${NOA_LIBRARY_PROJECT}::${NOA_LIBRARY_NAME}") endif() + if(NOA_LIBRARY_VARIANT) + set(TARGET_NAME "${TARGET_NAME}_${NOA_LIBRARY_VARIANT}") + set(ALIAS_NAME "${ALIAS_NAME}::${NOA_LIBRARY_VARIANT}") + endif() + if(NOA_LIBRARY_SOURCES) add_library(${TARGET_NAME} ${PUBLIC_HEADER} ${ABSOLUTE_PRIVATE_HEADERS} ${NOA_LIBRARY_SOURCES}) @@ -50,23 +59,34 @@ function(noa_library) add_library(${ALIAS_NAME} ALIAS ${TARGET_NAME}) + if(NOT NOA_LIBRARY_VARIANT) + set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}/include") + else() + set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}/../include") + endif() if(NOA_LIBRARY_SOURCES) target_include_directories(${TARGET_NAME} PUBLIC - "$" + "$" "$") else() target_include_directories(${TARGET_NAME} INTERFACE - "$" + "$" "$") endif() if(NOA_LIBRARY_SOURCES) + if(NOA_LIBRARY_VARIANT) + set(export_name "${NOA_LIBRARY_PROJECT}::${NOA_LIBRARY_NAME}::${NOA_LIBRARY_VARIANT}") + else() + set(export_name "${NOA_LIBRARY_PROJECT}::${NOA_LIBRARY_NAME}") + endif() + set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME} PUBLIC_HEADER "${PUBLIC_HEADER}" PRIVATE_HEADER "${ABSOLUTE_PRIVATE_HEADERS}" - EXPORT_NAME "${NOA_LIBRARY_PROJECT}::${NOA_LIBRARY_NAME}" + EXPORT_NAME "${export_name}" FOLDER "${NOA_LIBRARY_FOLDER}") else() set_target_properties(${TARGET_NAME} @@ -93,7 +113,7 @@ function(noa_library) endfunction() function(noa_library_install) - cmake_parse_arguments(NOA_LIBRARY "" "NAMESPACE;PROJECT;NAME" "" ${ARGN}) + cmake_parse_arguments(NOA_LIBRARY "" "NAMESPACE;PROJECT;NAME;VARIANT" "" ${ARGN}) if(NOT NOA_LIBRARY_PROJECT) message(FATAL_ERROR "You must pass the project name using the PROJECT option") @@ -114,6 +134,10 @@ function(noa_library_install) set(NAMESPACE_PREFIX "") endif() + if(NOA_LIBRARY_VARIANT) + set(TARGET_NAME "${TARGET_NAME}_${NOA_LIBRARY_VARIANT}") + endif() + include(GNUInstallDirs) install(TARGETS ${TARGET_NAME} EXPORT ${TARGET_NAME} diff --git a/vendor/blaze/CMakeLists.txt b/vendor/blaze/CMakeLists.txt new file mode 100644 index 0000000..2920780 --- /dev/null +++ b/vendor/blaze/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required(VERSION 3.16) +project(blaze VERSION 0.0.1 LANGUAGES CXX + DESCRIPTION "The ultra high-performance JSON Schema evaluator" + HOMEPAGE_URL "https://github.com/sourcemeta/blaze") +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +include(vendor/noa/cmake/noa.cmake) + +# Options +option(BLAZE_COMPILER "Build the Blaze compiler library" ON) +option(BLAZE_EVALUATOR "Build the Blaze evaluator library" ON) +option(BLAZE_TESTS "Build the Blaze tests" OFF) +option(BLAZE_BENCHMARK "Build the Blaze benchmarks" OFF) +option(BLAZE_CONTRIB "Build the Blaze contrib programs" OFF) +option(BLAZE_DOCS "Build the Blaze docs" OFF) +option(BLAZE_INSTALL "Install the Blaze library" ON) +option(BLAZE_ADDRESS_SANITIZER "Build Blaze with an address sanitizer" OFF) +option(BLAZE_UNDEFINED_SANITIZER "Build Blaze with an undefined behavior sanitizer" OFF) + +if(BLAZE_INSTALL) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + configure_package_config_file( + config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + COMPATIBILITY SameMajorVersion) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + COMPONENT sourcemeta_blaze_dev) +endif() + +if(BLAZE_COMPILER OR BLAZE_EVALUATOR) + find_package(JSONToolkit REQUIRED) +endif() + +if(BLAZE_COMPILER) + add_subdirectory(src/compiler) +endif() + +if(BLAZE_EVALUATOR) + add_subdirectory(src/evaluator) +endif() + +if(BLAZE_CONTRIB) + add_subdirectory(contrib) +endif() + +if(BLAZE_ADDRESS_SANITIZER) + noa_sanitizer(TYPE address) +elseif(BLAZE_UNDEFINED_SANITIZER) + noa_sanitizer(TYPE undefined) +endif() + +if(BLAZE_DOCS) + noa_target_doxygen(CONFIG "${PROJECT_SOURCE_DIR}/doxygen/Doxyfile.in" + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/website") +endif() + +if(PROJECT_IS_TOP_LEVEL) + noa_target_clang_format(SOURCES + bindings/*.cc contrib/*.cc + src/*.h src/*.cc + benchmark/*.h benchmark/*.cc + test/*.h test/*.cc) + noa_target_clang_tidy(SOURCES + src/*.h src/*.cc) +endif() + +# Testing +if(BLAZE_TESTS) + find_package(GoogleTest REQUIRED) + enable_testing() + + if(BLAZE_COMPILER) + add_subdirectory(test/compiler) + endif() + + if(BLAZE_EVALUATOR) + add_subdirectory(test/evaluator) + endif() + + if(PROJECT_IS_TOP_LEVEL) + # Otherwise we need the child project to link + # against the sanitizers too. + if(NOT BLAZE_ADDRESS_SANITIZER AND NOT BLAZE_UNDEFINED_SANITIZER) + add_subdirectory(test/packaging) + endif() + endif() + + if(BLAZE_BENCHMARK) + find_package(GoogleBenchmark REQUIRED) + add_subdirectory(benchmark) + endif() +endif() diff --git a/vendor/blaze/LICENSE b/vendor/blaze/LICENSE new file mode 100644 index 0000000..0be6f02 --- /dev/null +++ b/vendor/blaze/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + JSON Toolkit - The swiss army knife for JSON applications + Copyright (C) 2022 Juan Cruz Viotti + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + 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. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/vendor/blaze/LICENSE-COMMERCIAL b/vendor/blaze/LICENSE-COMMERCIAL new file mode 100644 index 0000000..2b3c48a --- /dev/null +++ b/vendor/blaze/LICENSE-COMMERCIAL @@ -0,0 +1,2 @@ +Refer to https://www.sourcemeta.com/licensing/ for learning more about +obtaining a commercial license. diff --git a/vendor/blaze/cmake/FindGoogleBenchmark.cmake b/vendor/blaze/cmake/FindGoogleBenchmark.cmake new file mode 100644 index 0000000..da442f6 --- /dev/null +++ b/vendor/blaze/cmake/FindGoogleBenchmark.cmake @@ -0,0 +1,5 @@ +if(NOT Benchmark_FOUND) + set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable testing of the benchmark library.") + add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/googlebenchmark") + set(Benchmark_FOUND ON) +endif() diff --git a/vendor/blaze/cmake/FindGoogleTest.cmake b/vendor/blaze/cmake/FindGoogleTest.cmake new file mode 100644 index 0000000..5202b12 --- /dev/null +++ b/vendor/blaze/cmake/FindGoogleTest.cmake @@ -0,0 +1,6 @@ +if(NOT GoogleTest_FOUND) + set(BUILD_GMOCK OFF CACHE BOOL "disable googlemock") + set(INSTALL_GTEST OFF CACHE BOOL "disable installation") + add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/googletest") + set(GoogleTest_FOUND ON) +endif() diff --git a/vendor/blaze/cmake/FindJSONToolkit.cmake b/vendor/blaze/cmake/FindJSONToolkit.cmake new file mode 100644 index 0000000..d860b95 --- /dev/null +++ b/vendor/blaze/cmake/FindJSONToolkit.cmake @@ -0,0 +1,10 @@ +if(NOT JSONToolkit_FOUND) + if(BLAZE_INSTALL) + set(JSONTOOLKIT_INSTALL ON CACHE BOOL "enable JSON Toolkit installation") + else() + set(JSONTOOLKIT_INSTALL OFF CACHE BOOL "disable JSON Toolkit installation") + endif() + + add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/jsontoolkit") + set(JSONToolkit_FOUND ON) +endif() diff --git a/vendor/blaze/config.cmake.in b/vendor/blaze/config.cmake.in new file mode 100644 index 0000000..7a5a0bb --- /dev/null +++ b/vendor/blaze/config.cmake.in @@ -0,0 +1,25 @@ +@PACKAGE_INIT@ + +# Support both casing styles +list(APPEND BLAZE_COMPONENTS ${Blaze_FIND_COMPONENTS}) +list(APPEND BLAZE_COMPONENTS ${blaze_FIND_COMPONENTS}) +if(NOT BLAZE_COMPONENTS) + list(APPEND BLAZE_COMPONENTS compiler) + list(APPEND BLAZE_COMPONENTS evaluator) +endif() + +include(CMakeFindDependencyMacro) +find_dependency(JSONToolkit COMPONENTS uri json jsonpointer jsonschema) + +foreach(component ${BLAZE_COMPONENTS}) + if(component STREQUAL "compiler") + include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_blaze_evaluator.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_blaze_compiler.cmake") + elseif(component STREQUAL "evaluator") + include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_blaze_evaluator.cmake") + else() + message(FATAL_ERROR "Unknown Blaze component: ${component}") + endif() +endforeach() + +check_required_components("@PROJECT_NAME@") diff --git a/vendor/blaze/src/compiler/CMakeLists.txt b/vendor/blaze/src/compiler/CMakeLists.txt new file mode 100644 index 0000000..845b01a --- /dev/null +++ b/vendor/blaze/src/compiler/CMakeLists.txt @@ -0,0 +1,26 @@ +noa_library(NAMESPACE sourcemeta PROJECT blaze NAME compiler + FOLDER "Blaze/Compiler" + PRIVATE_HEADERS error.h + SOURCES + compile.cc compile_json.cc compile_describe.cc + compile_helpers.h default_compiler.cc + default_compiler_2020_12.h + default_compiler_2019_09.h + default_compiler_draft7.h + default_compiler_draft6.h + default_compiler_draft4.h) + +if(BLAZE_INSTALL) + noa_library_install(NAMESPACE sourcemeta PROJECT blaze NAME compiler) +endif() + +target_link_libraries(sourcemeta_blaze_compiler PUBLIC + sourcemeta::jsontoolkit::json) +target_link_libraries(sourcemeta_blaze_compiler PUBLIC + sourcemeta::jsontoolkit::jsonpointer) +target_link_libraries(sourcemeta_blaze_compiler PRIVATE + sourcemeta::jsontoolkit::uri) +target_link_libraries(sourcemeta_blaze_compiler PUBLIC + sourcemeta::jsontoolkit::jsonschema) +target_link_libraries(sourcemeta_blaze_compiler PUBLIC + sourcemeta::blaze::evaluator) diff --git a/vendor/blaze/src/compiler/compile.cc b/vendor/blaze/src/compiler/compile.cc new file mode 100644 index 0000000..ce1e63a --- /dev/null +++ b/vendor/blaze/src/compiler/compile.cc @@ -0,0 +1,354 @@ +#include +#include + +#include + +#include // std::move, std::any_of, std::sort, std::unique +#include // assert +#include // std::back_inserter +#include // std::move + +#include "compile_helpers.h" + +namespace { + +auto compile_subschema(const sourcemeta::blaze::Context &context, + const sourcemeta::blaze::SchemaContext &schema_context, + const sourcemeta::blaze::DynamicContext &dynamic_context, + const std::optional &default_dialect) + -> sourcemeta::blaze::Template { + using namespace sourcemeta::blaze; + assert(is_schema(schema_context.schema)); + + // Handle boolean schemas earlier on, as nobody should be able to + // override what these mean. + if (schema_context.schema.is_boolean()) { + if (schema_context.schema.to_boolean()) { + return {}; + } else { + return {make(true, context, schema_context, + dynamic_context, ValueNone{})}; + } + } + + Template steps; + for (const auto &entry : sourcemeta::jsontoolkit::SchemaKeywordIterator{ + schema_context.schema, context.walker, context.resolver, + default_dialect}) { + assert(entry.pointer.back().is_property()); + const auto &keyword{entry.pointer.back().to_property()}; + // Bases must not contain fragments + assert(!schema_context.base.fragment().has_value()); + for (auto &&step : context.compiler( + context, + {schema_context.relative_pointer.concat({keyword}), + schema_context.schema, entry.vocabularies, schema_context.base, + // TODO: This represents a copy + schema_context.labels, schema_context.references}, + {keyword, dynamic_context.base_schema_location, + dynamic_context.base_instance_location})) { + // Just a sanity check to ensure every keyword location is indeed valid + assert(context.frame.contains( + {sourcemeta::jsontoolkit::ReferenceType::Static, + std::visit([](const auto &value) { return value.keyword_location; }, + step)})); + steps.push_back(std::move(step)); + } + } + + return steps; +} + +} // namespace + +namespace sourcemeta::blaze { + +auto compile(const sourcemeta::jsontoolkit::JSON &schema, + const sourcemeta::jsontoolkit::SchemaWalker &walker, + const sourcemeta::jsontoolkit::SchemaResolver &resolver, + const Compiler &compiler, const Mode mode, + const std::optional &default_dialect) -> Template { + assert(is_schema(schema)); + + // Make sure the input schema is bundled, otherwise we won't be able to + // resolve remote references here + const sourcemeta::jsontoolkit::JSON result{sourcemeta::jsontoolkit::bundle( + schema, walker, resolver, sourcemeta::jsontoolkit::BundleOptions::Default, + default_dialect)}; + + // Perform framing to resolve references later on + sourcemeta::jsontoolkit::ReferenceFrame frame; + sourcemeta::jsontoolkit::ReferenceMap references; + sourcemeta::jsontoolkit::frame(result, frame, references, walker, resolver, + default_dialect); + + const std::string base{sourcemeta::jsontoolkit::URI{ + sourcemeta::jsontoolkit::identify( + schema, resolver, + sourcemeta::jsontoolkit::IdentificationStrategy::Strict, + default_dialect) + .value_or("")} + .canonicalize() + .recompose()}; + + assert( + frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, base})); + const auto root_frame_entry{ + frame.at({sourcemeta::jsontoolkit::ReferenceType::Static, base})}; + + // Check whether dynamic referencing takes places in this schema. If not, + // we can avoid the overhead of keeping track of dynamics scopes, etc + bool uses_dynamic_scopes{false}; + for (const auto &reference : references) { + if (reference.first.first == + sourcemeta::jsontoolkit::ReferenceType::Dynamic) { + uses_dynamic_scopes = true; + break; + } + } + + SchemaContext schema_context{ + sourcemeta::jsontoolkit::empty_pointer, + result, + vocabularies(schema, resolver, root_frame_entry.dialect), + sourcemeta::jsontoolkit::URI{root_frame_entry.base} + .canonicalize() + .recompose(), + {}, + {}}; + + bool uses_unevaluated_properties{false}; + bool uses_unevaluated_items{false}; + if (schema_context.vocabularies.contains( + "https://json-schema.org/draft/2019-09/vocab/core") || + schema_context.vocabularies.contains( + "https://json-schema.org/draft/2020-12/vocab/core")) { + for (const auto &entry : sourcemeta::jsontoolkit::SchemaIterator{ + result, walker, resolver, default_dialect}) { + if (!entry.vocabularies.contains( + "https://json-schema.org/draft/2019-09/vocab/applicator") && + !entry.vocabularies.contains( + "https://json-schema.org/draft/2020-12/vocab/unevaluated")) { + continue; + } + + const auto &subschema{ + sourcemeta::jsontoolkit::get(result, entry.pointer)}; + if (!subschema.is_object()) { + continue; + } + + if (!uses_unevaluated_properties && + subschema.defines("unevaluatedProperties") && + sourcemeta::jsontoolkit::is_schema( + subschema.at("unevaluatedProperties"))) { + uses_unevaluated_properties = true; + } + + if (!uses_unevaluated_items && subschema.defines("unevaluatedItems") && + sourcemeta::jsontoolkit::is_schema( + subschema.at("unevaluatedItems"))) { + uses_unevaluated_items = true; + } + } + } + + std::vector resources; + for (const auto &entry : frame) { + if (entry.second.type == + sourcemeta::jsontoolkit::ReferenceEntryType::Resource) { + resources.push_back(entry.first.second); + } + } + + // Rule out any duplicates as we will use this list as the + // source for a perfect hash function on schema resources. + std::sort(resources.begin(), resources.end()); + resources.erase(std::unique(resources.begin(), resources.end()), + resources.end()); + assert(resources.size() == + std::set(resources.cbegin(), resources.cend()).size()); + + const Context context{result, + frame, + references, + std::move(resources), + walker, + resolver, + compiler, + mode, + uses_dynamic_scopes, + uses_unevaluated_properties, + uses_unevaluated_items}; + const DynamicContext dynamic_context{relative_dynamic_context}; + Template compiler_template; + + if (uses_dynamic_scopes && + (schema_context.vocabularies.contains( + "https://json-schema.org/draft/2019-09/vocab/core") || + schema_context.vocabularies.contains( + "https://json-schema.org/draft/2020-12/vocab/core"))) { + for (const auto &entry : frame) { + // We are only trying to find dynamic anchors + if (entry.second.type != + sourcemeta::jsontoolkit::ReferenceEntryType::Anchor || + entry.first.first != + sourcemeta::jsontoolkit::ReferenceType::Dynamic) { + continue; + } + + const sourcemeta::jsontoolkit::URI anchor_uri{entry.first.second}; + const auto label{EvaluationContext{}.hash( + schema_resource_id( + context, anchor_uri.recompose_without_fragment().value_or("")), + std::string{anchor_uri.fragment().value_or("")})}; + schema_context.labels.insert(label); + + // Configure a schema context that corresponds to the + // schema resource that we are precompiling + auto subschema{get(result, entry.second.pointer)}; + auto nested_vocabularies{ + vocabularies(subschema, resolver, entry.second.dialect)}; + const SchemaContext nested_schema_context{entry.second.relative_pointer, + std::move(subschema), + std::move(nested_vocabularies), + entry.second.base, + {}, + {}}; + + compiler_template.push_back(make( + true, context, nested_schema_context, dynamic_context, + ValueUnsignedInteger{label}, + compile(context, nested_schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer, entry.first.second))); + } + } + + auto children{compile_subschema(context, schema_context, dynamic_context, + root_frame_entry.dialect)}; + if (compiler_template.empty()) { + return children; + } else { + compiler_template.reserve(compiler_template.size() + children.size()); + std::move(children.begin(), children.end(), + std::back_inserter(compiler_template)); + return compiler_template; + } +} + +auto compile(const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context, + const sourcemeta::jsontoolkit::Pointer &schema_suffix, + const sourcemeta::jsontoolkit::Pointer &instance_suffix, + const std::optional &uri) -> Template { + // Determine URI of the destination after recursion + const std::string destination{ + uri.has_value() + ? sourcemeta::jsontoolkit::URI{uri.value()}.canonicalize().recompose() + : to_uri(schema_context.relative_pointer.concat(schema_suffix), + schema_context.base) + .canonicalize() + .recompose()}; + + // Otherwise the recursion attempt is non-sense + if (!context.frame.contains( + {sourcemeta::jsontoolkit::ReferenceType::Static, destination})) { + throw sourcemeta::jsontoolkit::SchemaReferenceError( + destination, schema_context.relative_pointer, + "The target of the reference does not exist in the schema"); + } + + const auto &entry{context.frame.at( + {sourcemeta::jsontoolkit::ReferenceType::Static, destination})}; + const auto &new_schema{get(context.root, entry.pointer)}; + + if (!is_schema(new_schema)) { + throw sourcemeta::jsontoolkit::SchemaReferenceError( + destination, schema_context.relative_pointer, + "The target of the reference is not a valid schema"); + } + + const sourcemeta::jsontoolkit::Pointer destination_pointer{ + dynamic_context.keyword.empty() + ? dynamic_context.base_schema_location.concat(schema_suffix) + : dynamic_context.base_schema_location + .concat({dynamic_context.keyword}) + .concat(schema_suffix)}; + + return compile_subschema( + context, + {entry.relative_pointer, new_schema, + vocabularies(new_schema, context.resolver, entry.dialect), + sourcemeta::jsontoolkit::URI{entry.base} + .recompose_without_fragment() + .value_or(""), + // TODO: This represents a copy + schema_context.labels, schema_context.references}, + {dynamic_context.keyword, destination_pointer, + dynamic_context.base_instance_location.concat(instance_suffix)}, + entry.dialect); +} + +ErrorTraceOutput::ErrorTraceOutput( + const sourcemeta::jsontoolkit::JSON &instance, + const sourcemeta::jsontoolkit::WeakPointer &base) + : instance_{instance}, base_{base} {} + +auto ErrorTraceOutput::begin() const -> const_iterator { + return this->output.begin(); +} + +auto ErrorTraceOutput::end() const -> const_iterator { + return this->output.end(); +} + +auto ErrorTraceOutput::cbegin() const -> const_iterator { + return this->output.cbegin(); +} + +auto ErrorTraceOutput::cend() const -> const_iterator { + return this->output.cend(); +} + +auto ErrorTraceOutput::operator()( + const EvaluationType type, const bool result, + const Template::value_type &step, + const sourcemeta::jsontoolkit::WeakPointer &evaluate_path, + const sourcemeta::jsontoolkit::WeakPointer &instance_location, + const sourcemeta::jsontoolkit::JSON &annotation) -> void { + assert(!evaluate_path.empty()); + assert(evaluate_path.back().is_property()); + + if (type == EvaluationType::Pre) { + assert(result); + const auto &keyword{evaluate_path.back().to_property()}; + // To ease the output + if (keyword == "oneOf" || keyword == "not") { + this->mask.insert(evaluate_path); + } + } else if (type == EvaluationType::Post && + this->mask.contains(evaluate_path)) { + this->mask.erase(evaluate_path); + } + + // Ignore successful or masked steps + if (result || std::any_of(this->mask.cbegin(), this->mask.cend(), + [&evaluate_path](const auto &entry) { + return evaluate_path.starts_with(entry); + })) { + return; + } + + auto effective_evaluate_path{evaluate_path.resolve_from(this->base_)}; + if (effective_evaluate_path.empty()) { + return; + } + + this->output.push_back( + {describe(result, step, evaluate_path, instance_location, this->instance_, + annotation), + instance_location, std::move(effective_evaluate_path)}); +} + +} // namespace sourcemeta::blaze diff --git a/vendor/jsontoolkit/src/jsonschema/compile_describe.cc b/vendor/blaze/src/compiler/compile_describe.cc similarity index 85% rename from vendor/jsontoolkit/src/jsonschema/compile_describe.cc rename to vendor/blaze/src/compiler/compile_describe.cc index a65f49d..6206063 100644 --- a/vendor/jsontoolkit/src/jsonschema/compile_describe.cc +++ b/vendor/blaze/src/compiler/compile_describe.cc @@ -1,4 +1,4 @@ -#include +#include #include // std::any_of #include // assert @@ -6,7 +6,7 @@ #include // std::visit namespace { -using namespace sourcemeta::jsontoolkit; +using namespace sourcemeta::blaze; template auto step_value(const T &step) -> decltype(auto) { if constexpr (requires { step.value; }) { @@ -16,10 +16,10 @@ template auto step_value(const T &step) -> decltype(auto) { } } -auto to_string(const JSON::Type type) -> std::string { +auto to_string(const sourcemeta::jsontoolkit::JSON::Type type) -> std::string { // Otherwise the type "real" might not make a lot // of sense to JSON Schema users - if (type == JSON::Type::Real) { + if (type == sourcemeta::jsontoolkit::JSON::Type::Real) { return "number"; } else { std::ostringstream result; @@ -44,9 +44,10 @@ auto escape_string(const std::string &input) -> std::string { return result.str(); } -auto describe_type_check(const bool valid, const JSON::Type current, - const JSON::Type expected, std::ostringstream &message) - -> void { +auto describe_type_check(const bool valid, + const sourcemeta::jsontoolkit::JSON::Type current, + const sourcemeta::jsontoolkit::JSON::Type expected, + std::ostringstream &message) -> void { message << "The value was expected to be of type "; message << to_string(expected); if (!valid) { @@ -55,16 +56,18 @@ auto describe_type_check(const bool valid, const JSON::Type current, } } -auto describe_types_check(const bool valid, const JSON::Type current, - const std::vector &expected, - std::ostringstream &message) -> void { +auto describe_types_check( + const bool valid, const sourcemeta::jsontoolkit::JSON::Type current, + const std::vector &expected, + std::ostringstream &message) -> void { assert(expected.size() > 1); auto copy = expected; - const auto match_real{ - std::find(copy.cbegin(), copy.cend(), JSON::Type::Real)}; + const auto match_real{std::find(copy.cbegin(), copy.cend(), + sourcemeta::jsontoolkit::JSON::Type::Real)}; const auto match_integer{ - std::find(copy.cbegin(), copy.cend(), JSON::Type::Integer)}; + std::find(copy.cbegin(), copy.cend(), + sourcemeta::jsontoolkit::JSON::Type::Integer)}; if (match_real != copy.cend() && match_integer != copy.cend()) { copy.erase(match_integer); } @@ -89,15 +92,17 @@ auto describe_types_check(const bool valid, const JSON::Type current, message << " but it was of type "; } - if (valid && current == JSON::Type::Integer && - std::find(copy.cbegin(), copy.cend(), JSON::Type::Real) != copy.cend()) { + if (valid && current == sourcemeta::jsontoolkit::JSON::Type::Integer && + std::find(copy.cbegin(), copy.cend(), + sourcemeta::jsontoolkit::JSON::Type::Real) != copy.cend()) { message << "number"; } else { message << to_string(current); } } -auto describe_reference(const JSON &target) -> std::string { +auto describe_reference(const sourcemeta::jsontoolkit::JSON &target) + -> std::string { std::ostringstream message; message << "The " << to_string(target.type()) << " value was expected to validate against the statically " @@ -105,8 +110,9 @@ auto describe_reference(const JSON &target) -> std::string { return message.str(); } -auto is_within_keyword(const WeakPointer &evaluate_path, - const std::string &keyword) -> bool { +auto is_within_keyword( + const sourcemeta::jsontoolkit::WeakPointer &evaluate_path, + const std::string &keyword) -> bool { return std::any_of(evaluate_path.cbegin(), evaluate_path.cend(), [&keyword](const auto &token) { return token.is_property() && @@ -122,13 +128,13 @@ auto unknown() -> std::string { struct DescribeVisitor { const bool valid; - const WeakPointer &evaluate_path; + const sourcemeta::jsontoolkit::WeakPointer &evaluate_path; const std::string &keyword; - const WeakPointer &instance_location; - const JSON ⌖ - const JSON &annotation; + const sourcemeta::jsontoolkit::WeakPointer &instance_location; + const sourcemeta::jsontoolkit::JSON ⌖ + const sourcemeta::jsontoolkit::JSON &annotation; - auto operator()(const SchemaCompilerAssertionFail &) const -> std::string { + auto operator()(const AssertionFail &) const -> std::string { if (this->keyword == "contains") { return "The constraints declared for this keyword were not satisfiable"; } @@ -147,7 +153,7 @@ struct DescribeVisitor { return "No instance is expected to succeed against the false schema"; } - auto operator()(const SchemaCompilerLogicalOr &step) const -> std::string { + auto operator()(const LogicalOr &step) const -> std::string { assert(!step.children.empty()); std::ostringstream message; message << "The " << to_string(this->target.type()) @@ -162,7 +168,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLogicalAnd &step) const -> std::string { + auto operator()(const LogicalAnd &step) const -> std::string { if (this->keyword == "allOf") { assert(!step.children.empty()); std::ostringstream message; @@ -201,7 +207,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerLogicalXor &step) const -> std::string { + auto operator()(const LogicalXor &step) const -> std::string { assert(!step.children.empty()); std::ostringstream message; message << "The " << to_string(this->target.type()) @@ -216,11 +222,11 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLogicalCondition &) const -> std::string { + auto operator()(const LogicalCondition &) const -> std::string { return unknown(); } - auto operator()(const SchemaCompilerLogicalNot &) const -> std::string { + auto operator()(const LogicalNot &) const -> std::string { std::ostringstream message; message << "The " << to_string(this->target.type()) @@ -232,20 +238,31 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerControlLabel &) const -> std::string { + auto operator()(const AnnotationNot &) const -> std::string { + std::ostringstream message; + message + << "The " << to_string(this->target.type()) + << " value was expected to not validate against the given subschema"; + if (!this->valid) { + message << ", but it did"; + } + + return message.str(); + } + + auto operator()(const ControlLabel &) const -> std::string { return describe_reference(this->target); } - auto operator()(const SchemaCompilerControlMark &) const -> std::string { + auto operator()(const ControlMark &) const -> std::string { return describe_reference(this->target); } - auto operator()(const SchemaCompilerControlJump &) const -> std::string { + auto operator()(const ControlJump &) const -> std::string { return describe_reference(this->target); } - auto operator()(const SchemaCompilerControlDynamicAnchorJump &step) const - -> std::string { + auto operator()(const ControlDynamicAnchorJump &step) const -> std::string { if (this->keyword == "$dynamicRef") { const auto &value{step_value(step)}; std::ostringstream message; @@ -264,7 +281,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAnnotationEmit &) const -> std::string { + auto operator()(const AnnotationEmit &) const -> std::string { if (this->keyword == "properties") { assert(this->annotation.is_string()); std::ostringstream message; @@ -473,8 +490,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAnnotationWhenArraySizeEqual &) const - -> std::string { + auto operator()(const AnnotationWhenArraySizeEqual &) const -> std::string { if (this->keyword == "items" && this->annotation.is_boolean() && this->annotation.to_boolean()) { assert(this->target.is_array()); @@ -496,8 +512,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAnnotationWhenArraySizeGreater &) const - -> std::string { + auto operator()(const AnnotationWhenArraySizeGreater &) const -> std::string { if ((this->keyword == "prefixItems" || this->keyword == "items") && this->annotation.is_integer()) { assert(this->target.is_array()); @@ -520,8 +535,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAnnotationToParent &) const - -> std::string { + auto operator()(const AnnotationToParent &) const -> std::string { if (this->keyword == "unevaluatedItems" && this->annotation.is_boolean() && this->annotation.to_boolean()) { assert(this->target.is_array()); @@ -534,8 +548,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAnnotationBasenameToParent &) const - -> std::string { + auto operator()(const AnnotationBasenameToParent &) const -> std::string { if (this->keyword == "patternProperties") { assert(this->annotation.is_string()); std::ostringstream message; @@ -579,13 +592,11 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerLoopProperties &step) const - -> std::string { + auto operator()(const LoopProperties &step) const -> std::string { assert(this->keyword == "additionalProperties"); std::ostringstream message; if (step.children.size() == 1 && - std::holds_alternative( - step.children.front())) { + std::holds_alternative(step.children.front())) { message << "The object value was not expected to define additional " "properties"; } else { @@ -596,13 +607,12 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLoopPropertiesNoAnnotation &step) const + auto operator()(const AnnotationLoopPropertiesUnevaluated &step) const -> std::string { if (this->keyword == "unevaluatedProperties") { std::ostringstream message; if (!step.children.empty() && - std::holds_alternative( - step.children.front())) { + std::holds_alternative(step.children.front())) { message << "The object value was not expected to define unevaluated " "properties"; } else { @@ -616,13 +626,11 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerLoopPropertiesExcept &step) const - -> std::string { + auto operator()(const LoopPropertiesExcept &step) const -> std::string { assert(this->keyword == "additionalProperties"); std::ostringstream message; if (step.children.size() == 1 && - std::holds_alternative( - step.children.front())) { + std::holds_alternative(step.children.front())) { message << "The object value was not expected to define additional " "properties"; } else { @@ -633,23 +641,21 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLoopPropertiesType &step) const - -> std::string { + auto operator()(const LoopPropertiesType &step) const -> std::string { std::ostringstream message; message << "The object properties were expected to be of type " << to_string(step.value); return message.str(); } - auto operator()(const SchemaCompilerLoopPropertiesTypeStrict &step) const - -> std::string { + auto operator()(const LoopPropertiesTypeStrict &step) const -> std::string { std::ostringstream message; message << "The object properties were expected to be of type " << to_string(step.value); return message.str(); } - auto operator()(const SchemaCompilerLoopKeys &) const -> std::string { + auto operator()(const LoopKeys &) const -> std::string { assert(this->keyword == "propertyNames"); assert(this->target.is_object()); std::ostringstream message; @@ -679,7 +685,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLoopItems &step) const -> std::string { + auto operator()(const LoopItems &step) const -> std::string { assert(this->target.is_array()); const auto &value{step_value(step)}; std::ostringstream message; @@ -694,12 +700,11 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLoopItemsUnmarked &) const - -> std::string { + auto operator()(const AnnotationLoopItemsUnmarked &) const -> std::string { return unknown(); } - auto operator()(const SchemaCompilerLoopItemsUnevaluated &step) const + auto operator()(const AnnotationLoopItemsUnevaluated &step) const -> std::string { assert(this->keyword == "unevaluatedItems"); const auto &value{step_value(step)}; @@ -710,7 +715,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLoopContains &step) const -> std::string { + auto operator()(const LoopContains &step) const -> std::string { assert(this->target.is_array()); std::ostringstream message; const auto &value{step_value(step)}; @@ -754,16 +759,14 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionDefines &step) const - -> std::string { + auto operator()(const AssertionDefines &step) const -> std::string { std::ostringstream message; message << "The object value was expected to define the property " << escape_string(step_value(step)); return message.str(); } - auto operator()(const SchemaCompilerAssertionDefinesAll &step) const - -> std::string { + auto operator()(const AssertionDefinesAll &step) const -> std::string { const auto &value{step_value(step)}; assert(value.size() > 1); std::ostringstream message; @@ -807,24 +810,24 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionType &step) const - -> std::string { + auto operator()(const AssertionType &step) const -> std::string { std::ostringstream message; describe_type_check(this->valid, this->target.type(), step_value(step), message); return message.str(); } - auto operator()(const SchemaCompilerAssertionTypeStrict &step) const - -> std::string { + auto operator()(const AssertionTypeStrict &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; - if (!this->valid && value == JSON::Type::Real && - this->target.type() == JSON::Type::Integer) { + if (!this->valid && value == sourcemeta::jsontoolkit::JSON::Type::Real && + this->target.type() == sourcemeta::jsontoolkit::JSON::Type::Integer) { message << "The value was expected to be a real number but it was an integer"; - } else if (!this->valid && value == JSON::Type::Integer && - this->target.type() == JSON::Type::Real) { + } else if (!this->valid && + value == sourcemeta::jsontoolkit::JSON::Type::Integer && + this->target.type() == + sourcemeta::jsontoolkit::JSON::Type::Real) { message << "The value was expected to be an integer but it was a real number"; } else { @@ -834,24 +837,21 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionTypeAny &step) const - -> std::string { + auto operator()(const AssertionTypeAny &step) const -> std::string { std::ostringstream message; describe_types_check(this->valid, this->target.type(), step_value(step), message); return message.str(); } - auto operator()(const SchemaCompilerAssertionTypeStrictAny &step) const - -> std::string { + auto operator()(const AssertionTypeStrictAny &step) const -> std::string { std::ostringstream message; describe_types_check(this->valid, this->target.type(), step_value(step), message); return message.str(); } - auto operator()(const SchemaCompilerAssertionTypeStringBounded &step) const - -> std::string { + auto operator()(const AssertionTypeStringBounded &step) const -> std::string { std::ostringstream message; const auto minimum{std::get<0>(step.value)}; @@ -872,8 +872,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionTypeArrayBounded &step) const - -> std::string { + auto operator()(const AssertionTypeArrayBounded &step) const -> std::string { std::ostringstream message; const auto minimum{std::get<0>(step.value)}; @@ -893,8 +892,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionTypeObjectBounded &step) const - -> std::string { + auto operator()(const AssertionTypeObjectBounded &step) const -> std::string { std::ostringstream message; const auto minimum{std::get<0>(step.value)}; @@ -915,8 +913,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionRegex &step) const - -> std::string { + auto operator()(const AssertionRegex &step) const -> std::string { assert(this->target.is_string()); std::ostringstream message; message << "The string value " << escape_string(this->target.to_string()) @@ -925,8 +922,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionStringSizeLess &step) const - -> std::string { + auto operator()(const AssertionStringSizeLess &step) const -> std::string { if (this->keyword == "maxLength") { std::ostringstream message; const auto maximum{step_value(step) - 1}; @@ -967,8 +963,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAssertionStringSizeGreater &step) const - -> std::string { + auto operator()(const AssertionStringSizeGreater &step) const -> std::string { if (this->keyword == "minLength") { std::ostringstream message; const auto minimum{step_value(step) + 1}; @@ -1009,8 +1004,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAssertionArraySizeLess &step) const - -> std::string { + auto operator()(const AssertionArraySizeLess &step) const -> std::string { if (this->keyword == "maxItems") { assert(this->target.is_array()); std::ostringstream message; @@ -1042,8 +1036,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAssertionArraySizeGreater &step) const - -> std::string { + auto operator()(const AssertionArraySizeGreater &step) const -> std::string { if (this->keyword == "minItems") { assert(this->target.is_array()); std::ostringstream message; @@ -1075,8 +1068,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAssertionObjectSizeLess &step) const - -> std::string { + auto operator()(const AssertionObjectSizeLess &step) const -> std::string { if (this->keyword == "maxProperties") { assert(this->target.is_object()); std::ostringstream message; @@ -1124,8 +1116,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAssertionObjectSizeGreater &step) const - -> std::string { + auto operator()(const AssertionObjectSizeGreater &step) const -> std::string { if (this->keyword == "minProperties") { assert(this->target.is_object()); std::ostringstream message; @@ -1173,8 +1164,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAssertionEqual &step) const - -> std::string { + auto operator()(const AssertionEqual &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; message << "The " << to_string(this->target.type()) << " value "; @@ -1185,7 +1175,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionGreaterEqual &step) const { + auto operator()(const AssertionGreaterEqual &step) const { std::ostringstream message; const auto &value{step_value(step)}; message << "The " << to_string(this->target.type()) << " value "; @@ -1196,8 +1186,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionLessEqual &step) const - -> std::string { + auto operator()(const AssertionLessEqual &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; message << "The " << to_string(this->target.type()) << " value "; @@ -1208,8 +1197,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionGreater &step) const - -> std::string { + auto operator()(const AssertionGreater &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; message << "The " << to_string(this->target.type()) << " value "; @@ -1224,8 +1212,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionLess &step) const - -> std::string { + auto operator()(const AssertionLess &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; message << "The " << to_string(this->target.type()) << " value "; @@ -1240,14 +1227,14 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionUnique &) const -> std::string { + auto operator()(const AssertionUnique &) const -> std::string { assert(this->target.is_array()); auto array{this->target.as_array()}; std::ostringstream message; if (this->valid) { message << "The array value was expected to not contain duplicate items"; } else { - std::set duplicates; + std::set duplicates; for (auto iterator = array.cbegin(); iterator != array.cend(); ++iterator) { for (auto subiterator = std::next(iterator); @@ -1281,8 +1268,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionDivisible &step) const - -> std::string { + auto operator()(const AssertionDivisible &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; message << "The " << to_string(this->target.type()) << " value "; @@ -1293,8 +1279,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionEqualsAny &step) const - -> std::string { + auto operator()(const AssertionEqualsAny &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; message << "The " << to_string(this->target.type()) << " value "; @@ -1327,14 +1312,13 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionStringType &step) const - -> std::string { + auto operator()(const AssertionStringType &step) const -> std::string { assert(this->target.is_string()); std::ostringstream message; message << "The string value " << escape_string(this->target.to_string()) << " was expected to represent a valid"; switch (step_value(step)) { - case SchemaCompilerValueStringType::URI: + case ValueStringType::URI: message << " URI"; break; default: @@ -1344,16 +1328,17 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionPropertyType &step) const - -> std::string { + auto operator()(const AssertionPropertyType &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; - if (!this->valid && value == JSON::Type::Real && - this->target.type() == JSON::Type::Integer) { + if (!this->valid && value == sourcemeta::jsontoolkit::JSON::Type::Real && + this->target.type() == sourcemeta::jsontoolkit::JSON::Type::Integer) { message << "The value was expected to be a real number but it was an integer"; - } else if (!this->valid && value == JSON::Type::Integer && - this->target.type() == JSON::Type::Real) { + } else if (!this->valid && + value == sourcemeta::jsontoolkit::JSON::Type::Integer && + this->target.type() == + sourcemeta::jsontoolkit::JSON::Type::Real) { message << "The value was expected to be an integer but it was a real number"; } else { @@ -1363,16 +1348,18 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerAssertionPropertyTypeStrict &step) const + auto operator()(const AssertionPropertyTypeStrict &step) const -> std::string { std::ostringstream message; const auto &value{step_value(step)}; - if (!this->valid && value == JSON::Type::Real && - this->target.type() == JSON::Type::Integer) { + if (!this->valid && value == sourcemeta::jsontoolkit::JSON::Type::Real && + this->target.type() == sourcemeta::jsontoolkit::JSON::Type::Integer) { message << "The value was expected to be a real number but it was an integer"; - } else if (!this->valid && value == JSON::Type::Integer && - this->target.type() == JSON::Type::Real) { + } else if (!this->valid && + value == sourcemeta::jsontoolkit::JSON::Type::Integer && + this->target.type() == + sourcemeta::jsontoolkit::JSON::Type::Real) { message << "The value was expected to be an integer but it was a real number"; } else { @@ -1382,8 +1369,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLoopPropertiesMatch &step) const - -> std::string { + auto operator()(const LoopPropertiesMatch &step) const -> std::string { assert(!step.children.empty()); assert(this->target.is_object()); std::ostringstream message; @@ -1397,8 +1383,7 @@ struct DescribeVisitor { return message.str(); } - auto operator()(const SchemaCompilerLogicalWhenType &step) const - -> std::string { + auto operator()(const LogicalWhenType &step) const -> std::string { if (this->keyword == "patternProperties") { assert(!step.children.empty()); assert(this->target.is_object()); @@ -1441,9 +1426,8 @@ struct DescribeVisitor { for (const auto &child : step.children) { // Schema - if (std::holds_alternative(child)) { - const auto &substep{ - std::get(child)}; + if (std::holds_alternative(child)) { + const auto &substep{std::get(child)}; const auto &property{step_value(substep)}; all_dependencies.insert(property); if (!this->target.defines(property)) { @@ -1455,10 +1439,8 @@ struct DescribeVisitor { // Properties } else { - assert(std::holds_alternative< - SchemaCompilerAssertionPropertyDependencies>(child)); - const auto &substep{ - std::get(child)}; + assert(std::holds_alternative(child)); + const auto &substep{std::get(child)}; for (const auto &[property, dependencies] : substep.value) { all_dependencies.insert(property); @@ -1566,8 +1548,8 @@ struct DescribeVisitor { std::set present; std::set all_dependencies; for (const auto &child : step.children) { - assert(std::holds_alternative(child)); - const auto &substep{std::get(child)}; + assert(std::holds_alternative(child)); + const auto &substep{std::get(child)}; const auto &property{step_value(substep)}; all_dependencies.insert(property); if (!this->target.defines(property)) { @@ -1625,7 +1607,7 @@ struct DescribeVisitor { return unknown(); } - auto operator()(const SchemaCompilerAssertionPropertyDependencies &step) const + auto operator()(const AssertionPropertyDependencies &step) const -> std::string { if (this->keyword == "dependentRequired") { assert(this->target.is_object()); @@ -1706,34 +1688,31 @@ struct DescribeVisitor { // These steps are never described, at least not right now - auto operator()(const SchemaCompilerLogicalWhenArraySizeGreater &) const - -> std::string { + auto operator()(const LogicalWhenArraySizeGreater &) const -> std::string { return unknown(); } - auto operator()(const SchemaCompilerLogicalWhenArraySizeEqual &) const - -> std::string { + auto operator()(const LogicalWhenArraySizeEqual &) const -> std::string { return unknown(); } - auto operator()(const SchemaCompilerLogicalWhenDefines &) const - -> std::string { + auto operator()(const LogicalWhenDefines &) const -> std::string { return unknown(); } - auto operator()(const SchemaCompilerLoopPropertiesRegex &) const - -> std::string { + auto operator()(const LoopPropertiesRegex &) const -> std::string { return unknown(); } }; } // namespace -namespace sourcemeta::jsontoolkit { +namespace sourcemeta::blaze { // TODO: What will unlock even better error messages is being able to // get the subschema being evaluated along with the keyword -auto describe(const bool valid, const SchemaCompilerTemplate::value_type &step, - const WeakPointer &evaluate_path, - const WeakPointer &instance_location, const JSON &instance, - const JSON &annotation) -> std::string { +auto describe(const bool valid, const Template::value_type &step, + const sourcemeta::jsontoolkit::WeakPointer &evaluate_path, + const sourcemeta::jsontoolkit::WeakPointer &instance_location, + const sourcemeta::jsontoolkit::JSON &instance, + const sourcemeta::jsontoolkit::JSON &annotation) -> std::string { assert(evaluate_path.empty() || evaluate_path.back().is_property()); return std::visit( DescribeVisitor{ @@ -1743,4 +1722,4 @@ auto describe(const bool valid, const SchemaCompilerTemplate::value_type &step, step); } -} // namespace sourcemeta::jsontoolkit +} // namespace sourcemeta::blaze diff --git a/vendor/jsontoolkit/src/jsonschema/compile_helpers.h b/vendor/blaze/src/compiler/compile_helpers.h similarity index 50% rename from vendor/jsontoolkit/src/jsonschema/compile_helpers.h rename to vendor/blaze/src/compiler/compile_helpers.h index e0d6625..8f0ad4f 100644 --- a/vendor/jsontoolkit/src/jsonschema/compile_helpers.h +++ b/vendor/blaze/src/compiler/compile_helpers.h @@ -1,21 +1,39 @@ -#ifndef SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_COMPILE_HELPERS_H_ -#define SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_COMPILE_HELPERS_H_ +#ifndef SOURCEMETA_BLAZE_COMPILER_COMPILE_HELPERS_H_ +#define SOURCEMETA_BLAZE_COMPILER_COMPILE_HELPERS_H_ -#include +#include +#include -#include // assert -#include // std::declval, std::move +#include // std::find +#include // assert +#include // std::distance +#include // std::declval, std::move -namespace sourcemeta::jsontoolkit { +namespace sourcemeta::blaze { -static const SchemaCompilerDynamicContext relative_dynamic_context{ - "", empty_pointer, empty_pointer}; +static const DynamicContext relative_dynamic_context{ + "", sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer}; + +inline auto schema_resource_id(const Context &context, + const std::string &resource) -> std::size_t { + const auto iterator{std::find( + context.resources.cbegin(), context.resources.cend(), + sourcemeta::jsontoolkit::URI{resource}.canonicalize().recompose())}; + if (iterator == context.resources.cend()) { + assert(resource.empty()); + return 0; + } + + return 1 + static_cast( + std::distance(context.resources.cbegin(), iterator)); +} // Instantiate a value-oriented step template -auto make(const bool report, const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, +auto make(const bool report, const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context, // Take the value type from the "type" property of the step struct const decltype(std::declval().value) &value) -> Step { return { @@ -25,7 +43,7 @@ auto make(const bool report, const SchemaCompilerContext &context, {dynamic_context.keyword}), dynamic_context.base_instance_location, to_uri(schema_context.relative_pointer, schema_context.base).recompose(), - schema_context.base.recompose(), + schema_resource_id(context, schema_context.base.recompose()), context.uses_dynamic_scopes, report, value}; @@ -33,12 +51,12 @@ auto make(const bool report, const SchemaCompilerContext &context, // Instantiate an applicator step template -auto make(const bool report, const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, +auto make(const bool report, const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context, // Take the value type from the "value" property of the step struct - decltype(std::declval().value) &&value, - SchemaCompilerTemplate &&children) -> Step { + decltype(std::declval().value) &&value, Template &&children) + -> Step { return { dynamic_context.keyword.empty() ? dynamic_context.base_schema_location @@ -46,7 +64,7 @@ auto make(const bool report, const SchemaCompilerContext &context, {dynamic_context.keyword}), dynamic_context.base_instance_location, to_uri(schema_context.relative_pointer, schema_context.base).recompose(), - schema_context.base.recompose(), + schema_resource_id(context, schema_context.base.recompose()), context.uses_dynamic_scopes, report, std::move(value), @@ -54,9 +72,9 @@ auto make(const bool report, const SchemaCompilerContext &context, } template -auto unroll(const SchemaCompilerDynamicContext &dynamic_context, - const Step &step, - const Pointer &base_instance_location = empty_pointer) -> Type { +auto unroll(const DynamicContext &dynamic_context, const Step &step, + const sourcemeta::jsontoolkit::Pointer &base_instance_location = + sourcemeta::jsontoolkit::empty_pointer) -> Type { assert(std::holds_alternative(step)); return {dynamic_context.keyword.empty() ? std::get(step).relative_schema_location @@ -72,8 +90,9 @@ auto unroll(const SchemaCompilerDynamicContext &dynamic_context, std::get(step).value}; } -inline auto unsigned_integer_property(const JSON &document, - const JSON::String &property) +inline auto +unsigned_integer_property(const sourcemeta::jsontoolkit::JSON &document, + const sourcemeta::jsontoolkit::JSON::String &property) -> std::optional { if (document.defines(property) && document.at(property).is_integer()) { const auto value{document.at(property).to_integer()}; @@ -84,13 +103,13 @@ inline auto unsigned_integer_property(const JSON &document, return std::nullopt; } -inline auto unsigned_integer_property(const JSON &document, - const JSON::String &property, - const std::size_t otherwise) - -> std::size_t { +inline auto +unsigned_integer_property(const sourcemeta::jsontoolkit::JSON &document, + const sourcemeta::jsontoolkit::JSON::String &property, + const std::size_t otherwise) -> std::size_t { return unsigned_integer_property(document, property).value_or(otherwise); } -} // namespace sourcemeta::jsontoolkit +} // namespace sourcemeta::blaze #endif diff --git a/vendor/blaze/src/compiler/compile_json.cc b/vendor/blaze/src/compiler/compile_json.cc new file mode 100644 index 0000000..0bb5fac --- /dev/null +++ b/vendor/blaze/src/compiler/compile_json.cc @@ -0,0 +1,344 @@ +#include + +#include // assert +#include // std::less +#include // std::map +#include // std::ostringstream +#include // std::string_view +#include // std::is_same_v +#include // std::move + +namespace { + +template +auto value_to_json(const T &value) -> sourcemeta::jsontoolkit::JSON { + using namespace sourcemeta::blaze; + sourcemeta::jsontoolkit::JSON result{ + sourcemeta::jsontoolkit::JSON::make_object()}; + result.assign("category", sourcemeta::jsontoolkit::JSON{"value"}); + if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"json"}); + result.assign("value", sourcemeta::jsontoolkit::JSON{value}); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"boolean"}); + result.assign("value", sourcemeta::jsontoolkit::JSON{value}); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"regex"}); + result.assign("value", sourcemeta::jsontoolkit::JSON{value.second}); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"type"}); + std::ostringstream type_string; + type_string << value; + result.assign("value", sourcemeta::jsontoolkit::JSON{type_string.str()}); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"types"}); + sourcemeta::jsontoolkit::JSON types{ + sourcemeta::jsontoolkit::JSON::make_array()}; + for (const auto type : value) { + std::ostringstream type_string; + type_string << type; + types.push_back(sourcemeta::jsontoolkit::JSON{type_string.str()}); + } + + result.assign("value", std::move(types)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"string"}); + result.assign("value", sourcemeta::jsontoolkit::JSON{value}); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"strings"}); + sourcemeta::jsontoolkit::JSON items{ + sourcemeta::jsontoolkit::JSON::make_array()}; + for (const auto &item : value) { + items.push_back(sourcemeta::jsontoolkit::JSON{item}); + } + + result.assign("value", std::move(items)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"array"}); + sourcemeta::jsontoolkit::JSON items{ + sourcemeta::jsontoolkit::JSON::make_array()}; + for (const auto &item : value) { + items.push_back(item); + } + + result.assign("value", std::move(items)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"unsigned-integer"}); + result.assign("value", sourcemeta::jsontoolkit::JSON{value}); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"range"}); + sourcemeta::jsontoolkit::JSON values{ + sourcemeta::jsontoolkit::JSON::make_array()}; + const auto &range{value}; + values.push_back(sourcemeta::jsontoolkit::JSON{std::get<0>(range)}); + values.push_back( + std::get<1>(range).has_value() + ? sourcemeta::jsontoolkit::JSON{std::get<1>(range).value()} + : sourcemeta::jsontoolkit::JSON{nullptr}); + values.push_back(sourcemeta::jsontoolkit::JSON{std::get<2>(range)}); + result.assign("value", std::move(values)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"named-indexes"}); + sourcemeta::jsontoolkit::JSON values{ + sourcemeta::jsontoolkit::JSON::make_object()}; + for (const auto &[name, index] : value) { + values.assign(name, sourcemeta::jsontoolkit::JSON{index}); + } + + result.assign("value", std::move(values)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"string-map"}); + sourcemeta::jsontoolkit::JSON map{ + sourcemeta::jsontoolkit::JSON::make_object()}; + for (const auto &[string, strings] : value) { + sourcemeta::jsontoolkit::JSON dependencies{ + sourcemeta::jsontoolkit::JSON::make_array()}; + for (const auto &substring : strings) { + dependencies.push_back(sourcemeta::jsontoolkit::JSON{substring}); + } + + map.assign(string, std::move(dependencies)); + } + + result.assign("value", std::move(map)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", + sourcemeta::jsontoolkit::JSON{"items-annotation-keywords"}); + sourcemeta::jsontoolkit::JSON data{ + sourcemeta::jsontoolkit::JSON::make_object()}; + data.assign("index", sourcemeta::jsontoolkit::JSON{value.index}); + + sourcemeta::jsontoolkit::JSON mask{ + sourcemeta::jsontoolkit::JSON::make_array()}; + for (const auto &keyword : value.mask) { + mask.push_back(sourcemeta::jsontoolkit::JSON{keyword}); + } + data.assign("mask", std::move(mask)); + + sourcemeta::jsontoolkit::JSON filter{ + sourcemeta::jsontoolkit::JSON::make_array()}; + for (const auto &keyword : value.filter) { + filter.push_back(sourcemeta::jsontoolkit::JSON{keyword}); + } + data.assign("filter", std::move(filter)); + + result.assign("value", std::move(data)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"indexed-json"}); + sourcemeta::jsontoolkit::JSON data{ + sourcemeta::jsontoolkit::JSON::make_object()}; + data.assign("index", sourcemeta::jsontoolkit::JSON{value.first}); + data.assign("value", value.second); + result.assign("value", std::move(data)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"property-filter"}); + sourcemeta::jsontoolkit::JSON data{ + sourcemeta::jsontoolkit::JSON::make_object()}; + data.assign("names", sourcemeta::jsontoolkit::JSON::make_array()); + data.assign("patterns", sourcemeta::jsontoolkit::JSON::make_array()); + + for (const auto &name : value.first) { + data.at("names").push_back(sourcemeta::jsontoolkit::JSON{name}); + } + + for (const auto &pattern : value.second) { + data.at("patterns") + .push_back(sourcemeta::jsontoolkit::JSON{pattern.second}); + } + + result.assign("value", std::move(data)); + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"string-type"}); + switch (value) { + case ValueStringType::URI: + result.assign("value", sourcemeta::jsontoolkit::JSON{"uri"}); + break; + default: + // We should never get here + assert(false); + } + + return result; + } else if constexpr (std::is_same_v) { + result.assign("type", sourcemeta::jsontoolkit::JSON{"index-pair"}); + sourcemeta::jsontoolkit::JSON data{ + sourcemeta::jsontoolkit::JSON::make_array()}; + data.push_back(sourcemeta::jsontoolkit::JSON{value.first}); + data.push_back(sourcemeta::jsontoolkit::JSON{value.second}); + result.assign("value", std::move(data)); + return result; + } else { + static_assert(std::is_same_v); + return sourcemeta::jsontoolkit::JSON{nullptr}; + } +} + +template +auto step_to_json(const sourcemeta::blaze::Template::value_type &step) + -> sourcemeta::jsontoolkit::JSON { + static V visitor; + return std::visit(visitor, step); +} + +template +auto encode_step(const std::string_view category, const std::string_view type, + const T &step) -> sourcemeta::jsontoolkit::JSON { + sourcemeta::jsontoolkit::JSON result{ + sourcemeta::jsontoolkit::JSON::make_object()}; + result.assign("category", sourcemeta::jsontoolkit::JSON{category}); + result.assign("type", sourcemeta::jsontoolkit::JSON{type}); + result.assign( + "relativeSchemaLocation", + sourcemeta::jsontoolkit::JSON{to_string(step.relative_schema_location)}); + result.assign("relativeInstanceLocation", + sourcemeta::jsontoolkit::JSON{ + to_string(step.relative_instance_location)}); + result.assign("absoluteKeywordLocation", + sourcemeta::jsontoolkit::JSON{step.keyword_location}); + result.assign("schemaResource", + sourcemeta::jsontoolkit::JSON{step.schema_resource}); + result.assign("dynamic", sourcemeta::jsontoolkit::JSON{step.dynamic}); + result.assign("report", sourcemeta::jsontoolkit::JSON{step.report}); + result.assign("value", value_to_json(step.value)); + + if constexpr (requires { step.children; }) { + result.assign("children", sourcemeta::jsontoolkit::JSON::make_array()); + for (const auto &child : step.children) { + result.at("children").push_back(step_to_json(child)); + } + } + + return result; +} + +struct StepVisitor { +#define HANDLE_STEP(category, type, name) \ + auto operator()(const sourcemeta::blaze::name &step) \ + const->sourcemeta::jsontoolkit::JSON { \ + return encode_step(category, type, step); \ + } + + HANDLE_STEP("assertion", "fail", AssertionFail) + HANDLE_STEP("assertion", "defines", AssertionDefines) + HANDLE_STEP("assertion", "defines-all", AssertionDefinesAll) + HANDLE_STEP("assertion", "property-dependencies", + AssertionPropertyDependencies) + HANDLE_STEP("assertion", "type", AssertionType) + HANDLE_STEP("assertion", "type-any", AssertionTypeAny) + HANDLE_STEP("assertion", "type-strict", AssertionTypeStrict) + HANDLE_STEP("assertion", "type-strict-any", AssertionTypeStrictAny) + HANDLE_STEP("assertion", "type-string-bounded", AssertionTypeStringBounded) + HANDLE_STEP("assertion", "type-array-bounded", AssertionTypeArrayBounded) + HANDLE_STEP("assertion", "type-object-bounded", AssertionTypeObjectBounded) + HANDLE_STEP("assertion", "regex", AssertionRegex) + HANDLE_STEP("assertion", "string-size-less", AssertionStringSizeLess) + HANDLE_STEP("assertion", "string-size-greater", AssertionStringSizeGreater) + HANDLE_STEP("assertion", "array-size-less", AssertionArraySizeLess) + HANDLE_STEP("assertion", "array-size-greater", AssertionArraySizeGreater) + HANDLE_STEP("assertion", "object-size-less", AssertionObjectSizeLess) + HANDLE_STEP("assertion", "object-size-greater", AssertionObjectSizeGreater) + HANDLE_STEP("assertion", "equal", AssertionEqual) + HANDLE_STEP("assertion", "greater-equal", AssertionGreaterEqual) + HANDLE_STEP("assertion", "less-equal", AssertionLessEqual) + HANDLE_STEP("assertion", "greater", AssertionGreater) + HANDLE_STEP("assertion", "less", AssertionLess) + HANDLE_STEP("assertion", "unique", AssertionUnique) + HANDLE_STEP("assertion", "divisible", AssertionDivisible) + HANDLE_STEP("assertion", "string-type", AssertionStringType) + HANDLE_STEP("assertion", "property-type", AssertionPropertyType) + HANDLE_STEP("assertion", "property-type-strict", AssertionPropertyTypeStrict) + HANDLE_STEP("assertion", "equals-any", AssertionEqualsAny) + HANDLE_STEP("annotation", "emit", AnnotationEmit) + HANDLE_STEP("annotation", "when-array-size-equal", + AnnotationWhenArraySizeEqual) + HANDLE_STEP("annotation", "when-array-size-greater", + AnnotationWhenArraySizeGreater) + HANDLE_STEP("annotation", "to-parent", AnnotationToParent) + HANDLE_STEP("annotation", "basename-to-parent", AnnotationBasenameToParent) + HANDLE_STEP("annotation", "loop-properties-unevaluated", + AnnotationLoopPropertiesUnevaluated) + HANDLE_STEP("annotation", "loop-items-unmarked", AnnotationLoopItemsUnmarked) + HANDLE_STEP("annotation", "loop-items-unevaluated", + AnnotationLoopItemsUnevaluated) + HANDLE_STEP("annotation", "not", AnnotationNot) + HANDLE_STEP("logical", "not", LogicalNot) + HANDLE_STEP("logical", "or", LogicalOr) + HANDLE_STEP("logical", "and", LogicalAnd) + HANDLE_STEP("logical", "xor", LogicalXor) + HANDLE_STEP("logical", "condition", LogicalCondition) + HANDLE_STEP("logical", "when-type", LogicalWhenType) + HANDLE_STEP("logical", "when-defines", LogicalWhenDefines) + HANDLE_STEP("logical", "when-array-size-greater", LogicalWhenArraySizeGreater) + HANDLE_STEP("logical", "when-array-size-equal", LogicalWhenArraySizeEqual) + HANDLE_STEP("loop", "properties-match", LoopPropertiesMatch) + HANDLE_STEP("loop", "properties", LoopProperties) + HANDLE_STEP("loop", "properties-regex", LoopPropertiesRegex) + HANDLE_STEP("loop", "properties-except", LoopPropertiesExcept) + HANDLE_STEP("loop", "properties-type", LoopPropertiesType) + HANDLE_STEP("loop", "properties-type-strict", LoopPropertiesTypeStrict) + HANDLE_STEP("loop", "keys", LoopKeys) + HANDLE_STEP("loop", "items", LoopItems) + HANDLE_STEP("loop", "contains", LoopContains) + HANDLE_STEP("control", "label", ControlLabel) + HANDLE_STEP("control", "mark", ControlMark) + HANDLE_STEP("control", "jump", ControlJump) + HANDLE_STEP("control", "dynamic-anchor-jump", ControlDynamicAnchorJump) + +#undef HANDLE_STEP +}; + +} // namespace + +namespace sourcemeta::blaze { + +auto to_json(const Template &steps) -> sourcemeta::jsontoolkit::JSON { + sourcemeta::jsontoolkit::JSON result{ + sourcemeta::jsontoolkit::JSON::make_array()}; + for (const auto &step : steps) { + result.push_back(step_to_json(step)); + } + + return result; +} + +auto template_format_compare(const sourcemeta::jsontoolkit::JSON::String &left, + const sourcemeta::jsontoolkit::JSON::String &right) + -> bool { + using Rank = std::map< + sourcemeta::jsontoolkit::JSON::String, std::uint64_t, + std::less, + sourcemeta::jsontoolkit::JSON::Allocator>>; + static Rank rank{{"category", 0}, + {"type", 1}, + {"value", 2}, + {"schemaResource", 3}, + {"absoluteKeywordLocation", 4}, + {"relativeSchemaLocation", 5}, + {"relativeInstanceLocation", 6}, + {"report", 7}, + {"dynamic", 8}, + {"children", 9}}; + + constexpr std::uint64_t DEFAULT_RANK{999}; + const auto left_rank{rank.contains(left) ? rank.at(left) : DEFAULT_RANK}; + const auto right_rank{rank.contains(right) ? rank.at(right) : DEFAULT_RANK}; + return left_rank < right_rank; +} + +} // namespace sourcemeta::blaze diff --git a/vendor/jsontoolkit/src/jsonschema/default_compiler.cc b/vendor/blaze/src/compiler/default_compiler.cc similarity index 97% rename from vendor/jsontoolkit/src/jsonschema/default_compiler.cc rename to vendor/blaze/src/compiler/default_compiler.cc index 443804b..1c77ece 100644 --- a/vendor/jsontoolkit/src/jsonschema/default_compiler.cc +++ b/vendor/blaze/src/compiler/default_compiler.cc @@ -1,5 +1,4 @@ -#include -#include +#include #include "default_compiler_2019_09.h" #include "default_compiler_2020_12.h" @@ -11,12 +10,11 @@ #include // std::set #include // std::string -// TODO: Support every keyword -auto sourcemeta::jsontoolkit::default_schema_compiler( - const sourcemeta::jsontoolkit::SchemaCompilerContext &context, - const sourcemeta::jsontoolkit::SchemaCompilerSchemaContext &schema_context, - const sourcemeta::jsontoolkit::SchemaCompilerDynamicContext - &dynamic_context) -> sourcemeta::jsontoolkit::SchemaCompilerTemplate { +auto sourcemeta::blaze::default_schema_compiler( + const sourcemeta::blaze::Context &context, + const sourcemeta::blaze::SchemaContext &schema_context, + const sourcemeta::blaze::DynamicContext &dynamic_context) + -> sourcemeta::blaze::Template { assert(!dynamic_context.keyword.empty()); static std::set SUPPORTED_VOCABULARIES{ @@ -39,12 +37,12 @@ auto sourcemeta::jsontoolkit::default_schema_compiler( for (const auto &vocabulary : schema_context.vocabularies) { if (!SUPPORTED_VOCABULARIES.contains(vocabulary.first) && vocabulary.second) { - throw SchemaVocabularyError(vocabulary.first, - "Cannot compile unsupported vocabulary"); + throw sourcemeta::jsontoolkit::SchemaVocabularyError( + vocabulary.first, "Cannot compile unsupported vocabulary"); } } - using namespace sourcemeta::jsontoolkit; + using namespace sourcemeta::blaze; #define COMPILE(vocabulary, _keyword, handler) \ if (schema_context.vocabularies.contains(vocabulary) && \ @@ -87,8 +85,6 @@ auto sourcemeta::jsontoolkit::default_schema_compiler( COMPILE("https://json-schema.org/draft/2020-12/vocab/applicator", "additionalProperties", compiler_2019_09_applicator_additionalproperties); - COMPILE("https://json-schema.org/draft/2020-12/vocab/applicator", "anyOf", - compiler_2019_09_applicator_anyof); COMPILE("https://json-schema.org/draft/2020-12/vocab/unevaluated", "unevaluatedProperties", compiler_2019_09_applicator_unevaluatedproperties); @@ -129,6 +125,8 @@ auto sourcemeta::jsontoolkit::default_schema_compiler( COMPILE("https://json-schema.org/draft/2020-12/vocab/applicator", "allOf", compiler_draft4_applicator_allof); + COMPILE("https://json-schema.org/draft/2020-12/vocab/applicator", "anyOf", + compiler_draft4_applicator_anyof); COMPILE("https://json-schema.org/draft/2020-12/vocab/applicator", "oneOf", compiler_draft4_applicator_oneof); COMPILE("https://json-schema.org/draft/2020-12/vocab/applicator", "not", @@ -182,8 +180,6 @@ auto sourcemeta::jsontoolkit::default_schema_compiler( compiler_2019_09_applicator_items); COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", "additionalItems", compiler_2019_09_applicator_additionalitems); - COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", "anyOf", - compiler_2019_09_applicator_anyof); COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", "properties", compiler_2019_09_applicator_properties); COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", @@ -225,6 +221,8 @@ auto sourcemeta::jsontoolkit::default_schema_compiler( COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", "allOf", compiler_draft4_applicator_allof); + COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", "anyOf", + compiler_draft4_applicator_anyof); COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", "oneOf", compiler_draft4_applicator_oneof); COMPILE("https://json-schema.org/draft/2019-09/vocab/applicator", "not", @@ -512,6 +510,10 @@ auto sourcemeta::jsontoolkit::default_schema_compiler( return {}; } + if (context.mode == Mode::FastValidation) { + return {}; + } + return internal::compiler_2019_09_core_annotation(context, schema_context, dynamic_context); } diff --git a/vendor/jsontoolkit/src/jsonschema/default_compiler_2019_09.h b/vendor/blaze/src/compiler/default_compiler_2019_09.h similarity index 51% rename from vendor/jsontoolkit/src/jsonschema/default_compiler_2019_09.h rename to vendor/blaze/src/compiler/default_compiler_2019_09.h index 36c4957..9de486e 100644 --- a/vendor/jsontoolkit/src/jsonschema/default_compiler_2019_09.h +++ b/vendor/blaze/src/compiler/default_compiler_2019_09.h @@ -1,20 +1,17 @@ -#ifndef SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_DEFAULT_COMPILER_2019_09_H_ -#define SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_DEFAULT_COMPILER_2019_09_H_ +#ifndef SOURCEMETA_BLAZE_COMPILER_DEFAULT_COMPILER_2019_09_H_ +#define SOURCEMETA_BLAZE_COMPILER_DEFAULT_COMPILER_2019_09_H_ -#include -#include +#include #include "compile_helpers.h" #include "default_compiler_draft4.h" namespace internal { -using namespace sourcemeta::jsontoolkit; +using namespace sourcemeta::blaze; auto compiler_2019_09_applicator_dependentschemas( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_object()); if (schema_context.schema.defines("type") && @@ -23,7 +20,7 @@ auto compiler_2019_09_applicator_dependentschemas( return {}; } - SchemaCompilerTemplate children; + Template children; // To guarantee order std::vector dependents; @@ -41,24 +38,22 @@ auto compiler_2019_09_applicator_dependentschemas( } if (!dependency.is_boolean() || !dependency.to_boolean()) { - children.push_back(make( + children.push_back(make( false, context, schema_context, relative_dynamic_context, - SchemaCompilerValueString{dependent}, + ValueString{dependent}, compile(context, schema_context, relative_dynamic_context, - {dependent}, empty_pointer))); + {dependent}, sourcemeta::jsontoolkit::empty_pointer))); } } - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Object, - std::move(children))}; + return {make(true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Object, + std::move(children))}; } auto compiler_2019_09_validation_dependentrequired( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { if (!schema_context.schema.at(dynamic_context.keyword).is_object()) { return {}; } @@ -69,14 +64,14 @@ auto compiler_2019_09_validation_dependentrequired( return {}; } - SchemaCompilerValueStringMap dependencies; + ValueStringMap dependencies; for (const auto &entry : schema_context.schema.at(dynamic_context.keyword).as_object()) { if (!entry.second.is_array()) { continue; } - std::vector properties; + std::vector properties; for (const auto &property : entry.second.as_array()) { assert(property.is_string()); properties.push_back(property.to_string()); @@ -91,25 +86,23 @@ auto compiler_2019_09_validation_dependentrequired( return {}; } - return {make( + return {make( true, context, schema_context, dynamic_context, std::move(dependencies))}; } -auto compiler_2019_09_core_annotation( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { - return {make( +auto compiler_2019_09_core_annotation(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { + return {make( true, context, schema_context, dynamic_context, - JSON{schema_context.schema.at(dynamic_context.keyword)})}; + sourcemeta::jsontoolkit::JSON{ + schema_context.schema.at(dynamic_context.keyword)})}; } auto compiler_2019_09_applicator_contains_conditional_annotate( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, const bool annotate) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context, const bool annotate) -> Template { if (schema_context.schema.defines("type") && schema_context.schema.at("type").is_string() && schema_context.schema.at("type").to_string() != "array") { @@ -141,23 +134,21 @@ auto compiler_2019_09_applicator_contains_conditional_annotate( } if (maximum.has_value() && minimum > maximum.value()) { - return {make(true, context, schema_context, - dynamic_context, - SchemaCompilerValueNone{})}; + return {make(true, context, schema_context, dynamic_context, + ValueNone{})}; } if (minimum == 0 && !maximum.has_value()) { return {}; } - SchemaCompilerTemplate children{compile(context, schema_context, - relative_dynamic_context, - empty_pointer, empty_pointer)}; + Template children{compile(context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer)}; if (annotate) { - children.push_back(make( - true, context, schema_context, relative_dynamic_context, - SchemaCompilerValueNone{})); + children.push_back(make( + true, context, schema_context, relative_dynamic_context, ValueNone{})); // TODO: If after emitting the above annotation, the number of annotations // for the current schema location + instance location is equal to the @@ -165,105 +156,98 @@ auto compiler_2019_09_applicator_contains_conditional_annotate( // an annotation "true" } - return {make( + return {make( true, context, schema_context, dynamic_context, - SchemaCompilerValueRange{ - minimum, maximum, - // TODO: We only need to be exhaustive here if `unevaluatedItems` is - // in use on the schema. Can we pre-determine that and speed things up - // if not? - annotate}, + ValueRange{minimum, maximum, + // TODO: We only need to be exhaustive here if + // `unevaluatedItems` is in use on the schema. Can we + // pre-determine that and speed things up if not? + annotate}, std::move(children))}; } -auto compiler_2019_09_applicator_contains( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_2019_09_applicator_contains(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { return compiler_2019_09_applicator_contains_conditional_annotate( context, schema_context, dynamic_context, false); } auto compiler_2019_09_applicator_additionalproperties( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { return compiler_draft4_applicator_additionalproperties_conditional_annotation( - context, schema_context, dynamic_context, true); + context, schema_context, dynamic_context, + context.uses_unevaluated_properties || context.mode == Mode::Exhaustive); } -auto compiler_2019_09_applicator_items( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_2019_09_applicator_items(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { return compiler_draft4_applicator_items_conditional_annotation( - context, schema_context, dynamic_context, true); + context, schema_context, dynamic_context, + context.uses_unevaluated_items || context.mode == Mode::Exhaustive); } auto compiler_2019_09_applicator_additionalitems( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { return compiler_draft4_applicator_additionalitems_conditional_annotation( - context, schema_context, dynamic_context, true); + context, schema_context, dynamic_context, + context.uses_unevaluated_items || context.mode == Mode::Exhaustive); } auto compiler_2019_09_applicator_unevaluateditems( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { if (schema_context.schema.defines("type") && schema_context.schema.at("type").is_string() && schema_context.schema.at("type").to_string() != "array") { return {}; } - SchemaCompilerTemplate children{compile(context, schema_context, - relative_dynamic_context, - empty_pointer, empty_pointer)}; - children.push_back(make( - true, context, schema_context, relative_dynamic_context, JSON{true})); + Template children{compile(context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer)}; + children.push_back(make( + true, context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::JSON{true})); if (schema_context.vocabularies.contains( "https://json-schema.org/draft/2019-09/vocab/applicator")) { - return {make( + return {make( true, context, schema_context, dynamic_context, - SchemaCompilerValueItemsAnnotationKeywords{ + ValueItemsAnnotationKeywords{ "items", {}, {"items", "additionalItems", "unevaluatedItems"}}, std::move(children))}; } else if (schema_context.vocabularies.contains( "https://json-schema.org/draft/2020-12/vocab/applicator")) { - return {make( + return {make( true, context, schema_context, dynamic_context, - SchemaCompilerValueItemsAnnotationKeywords{ + ValueItemsAnnotationKeywords{ "prefixItems", {"contains"}, {"prefixItems", "items", "contains", "unevaluatedItems"}}, std::move(children))}; } else { - return {make( + return {make( true, context, schema_context, dynamic_context, - SchemaCompilerValueStrings{"unevaluatedItems"}, std::move(children))}; + ValueString{"unevaluatedItems"}, std::move(children))}; } } auto compiler_2019_09_applicator_unevaluatedproperties( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { if (schema_context.schema.defines("type") && schema_context.schema.at("type").is_string() && schema_context.schema.at("type").to_string() != "object") { return {}; } - SchemaCompilerValueStrings dependencies{"unevaluatedProperties"}; + ValueStrings dependencies{"unevaluatedProperties"}; if (schema_context.vocabularies.contains( "https://json-schema.org/draft/2019-09/vocab/applicator")) { @@ -279,66 +263,51 @@ auto compiler_2019_09_applicator_unevaluatedproperties( dependencies.push_back("additionalProperties"); } - SchemaCompilerTemplate children{compile(context, schema_context, - relative_dynamic_context, - empty_pointer, empty_pointer)}; - children.push_back(make( - true, context, schema_context, relative_dynamic_context, - SchemaCompilerValueNone{})); + Template children{compile(context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer)}; + children.push_back(make( + true, context, schema_context, relative_dynamic_context, ValueNone{})); - return {make( + return {make( true, context, schema_context, dynamic_context, std::move(dependencies), std::move(children))}; } -auto compiler_2019_09_core_recursiveref( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_2019_09_core_recursiveref(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { const auto current{ to_uri(schema_context.relative_pointer, schema_context.base).recompose()}; - assert(context.frame.contains({ReferenceType::Static, current})); - const auto &entry{context.frame.at({ReferenceType::Static, current})}; + assert(context.frame.contains( + {sourcemeta::jsontoolkit::ReferenceType::Static, current})); + const auto &entry{context.frame.at( + {sourcemeta::jsontoolkit::ReferenceType::Static, current})}; // In this case, just behave as a normal static reference - if (!context.references.contains({ReferenceType::Dynamic, entry.pointer})) { + if (!context.references.contains( + {sourcemeta::jsontoolkit::ReferenceType::Dynamic, entry.pointer})) { return compiler_draft4_core_ref(context, schema_context, dynamic_context); } - return {make( - true, context, schema_context, dynamic_context, "")}; -} - -auto compiler_2019_09_applicator_anyof( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { - return compiler_draft4_applicator_anyof_conditional_exhaustive( - context, schema_context, dynamic_context, - // TODO: This set to true means that every disjunction of `anyOf` - // is always evaluated. In fact, we only need to enable this if - // the schema makes any use of `unevaluatedItems` or - // `unevaluatedProperties` - true); + return {make(true, context, schema_context, + dynamic_context, "")}; } auto compiler_2019_09_applicator_properties( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { return compiler_draft4_applicator_properties_conditional_annotation( - context, schema_context, dynamic_context, true); + context, schema_context, dynamic_context, + context.uses_unevaluated_properties || context.mode == Mode::Exhaustive); } auto compiler_2019_09_applicator_patternproperties( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { return compiler_draft4_applicator_patternproperties_conditional_annotation( - context, schema_context, dynamic_context, true); + context, schema_context, dynamic_context, + context.uses_unevaluated_properties || context.mode == Mode::Exhaustive); } } // namespace internal diff --git a/vendor/blaze/src/compiler/default_compiler_2020_12.h b/vendor/blaze/src/compiler/default_compiler_2020_12.h new file mode 100644 index 0000000..0781094 --- /dev/null +++ b/vendor/blaze/src/compiler/default_compiler_2020_12.h @@ -0,0 +1,77 @@ +#ifndef SOURCEMETA_BLAZE_COMPILER_DEFAULT_COMPILER_2020_12_H_ +#define SOURCEMETA_BLAZE_COMPILER_DEFAULT_COMPILER_2020_12_H_ + +#include +#include + +#include "compile_helpers.h" +#include "default_compiler_draft4.h" + +namespace internal { +using namespace sourcemeta::blaze; + +auto compiler_2020_12_applicator_prefixitems( + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { + return compiler_draft4_applicator_items_array( + context, schema_context, dynamic_context, + context.uses_unevaluated_items || context.mode == Mode::Exhaustive); +} + +auto compiler_2020_12_applicator_items(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { + const auto cursor{(schema_context.schema.defines("prefixItems") && + schema_context.schema.at("prefixItems").is_array()) + ? schema_context.schema.at("prefixItems").size() + : 0}; + + return compiler_draft4_applicator_additionalitems_from_cursor( + context, schema_context, dynamic_context, cursor, + context.uses_unevaluated_items || context.mode == Mode::Exhaustive); +} + +auto compiler_2020_12_applicator_contains(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { + return compiler_2019_09_applicator_contains_conditional_annotate( + context, schema_context, dynamic_context, + context.uses_unevaluated_items || context.mode == Mode::Exhaustive); +} + +auto compiler_2020_12_core_dynamicref(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { + const auto current{ + to_uri(schema_context.relative_pointer, schema_context.base).recompose()}; + assert(context.frame.contains( + {sourcemeta::jsontoolkit::ReferenceType::Static, current})); + const auto &entry{context.frame.at( + {sourcemeta::jsontoolkit::ReferenceType::Static, current})}; + // In this case, just behave as a normal static reference + if (!context.references.contains( + {sourcemeta::jsontoolkit::ReferenceType::Dynamic, entry.pointer})) { + return compiler_draft4_core_ref(context, schema_context, dynamic_context); + } + + assert(schema_context.schema.at(dynamic_context.keyword).is_string()); + sourcemeta::jsontoolkit::URI reference{ + schema_context.schema.at(dynamic_context.keyword).to_string()}; + reference.resolve_from_if_absolute(schema_context.base); + reference.canonicalize(); + // We handle the non-anchor variant by not treating it as a dynamic reference + assert(reference.fragment().has_value()); + + // Note we don't need to even care about the static part of the dynamic + // reference (if any), as even if we jump first there, we will still + // look for the oldest dynamic anchor in the schema resource chain. + return {make( + true, context, schema_context, dynamic_context, + std::string{reference.fragment().value()})}; +} + +} // namespace internal +#endif diff --git a/vendor/jsontoolkit/src/jsonschema/default_compiler_draft4.h b/vendor/blaze/src/compiler/default_compiler_draft4.h similarity index 57% rename from vendor/jsontoolkit/src/jsonschema/default_compiler_draft4.h rename to vendor/blaze/src/compiler/default_compiler_draft4.h index df2c31d..f0e7c62 100644 --- a/vendor/jsontoolkit/src/jsonschema/default_compiler_draft4.h +++ b/vendor/blaze/src/compiler/default_compiler_draft4.h @@ -1,8 +1,8 @@ -#ifndef SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_DEFAULT_COMPILER_DRAFT4_H_ -#define SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_DEFAULT_COMPILER_DRAFT4_H_ +#ifndef SOURCEMETA_BLAZE_COMPILER_DEFAULT_COMPILER_DRAFT4_H_ +#define SOURCEMETA_BLAZE_COMPILER_DEFAULT_COMPILER_DRAFT4_H_ -#include -#include +#include +#include #include // std::sort, std::any_of #include // assert @@ -22,40 +22,40 @@ static auto parse_regex(const std::string &pattern, } catch (const std::regex_error &) { std::ostringstream message; message << "Invalid regular expression: " << pattern; - throw sourcemeta::jsontoolkit::SchemaCompilationError(base, schema_location, - message.str()); + throw sourcemeta::blaze::CompilerError(base, schema_location, + message.str()); } } namespace internal { -using namespace sourcemeta::jsontoolkit; +using namespace sourcemeta::blaze; -auto compiler_draft4_core_ref( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_draft4_core_ref(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { // Determine the label - const auto type{ReferenceType::Static}; + const auto type{sourcemeta::jsontoolkit::ReferenceType::Static}; const auto current{ to_uri(schema_context.relative_pointer, schema_context.base).recompose()}; assert(context.frame.contains({type, current})); const auto &entry{context.frame.at({type, current})}; if (!context.references.contains({type, entry.pointer})) { assert(schema_context.schema.at(dynamic_context.keyword).is_string()); - throw SchemaReferenceError( + throw sourcemeta::jsontoolkit::SchemaReferenceError( schema_context.schema.at(dynamic_context.keyword).to_string(), entry.pointer, "The schema location is inside of an unknown keyword"); } const auto &reference{context.references.at({type, entry.pointer})}; - const auto label{std::hash{}(reference.destination)}; + const auto label{EvaluationContext{}.hash( + schema_resource_id(context, reference.base.value_or("")), + reference.fragment.value_or(""))}; // The label is already registered, so just jump to it if (schema_context.labels.contains(label)) { - return {make( - true, context, schema_context, dynamic_context, - SchemaCompilerValueUnsignedInteger{label})}; + return {make(true, context, schema_context, dynamic_context, + ValueUnsignedInteger{label})}; } auto new_schema_context{schema_context}; @@ -83,21 +83,22 @@ auto compiler_draft4_core_ref( schema_context.references.contains(reference.destination)}; if (!is_recursive && direct_children_references <= 5) { - // TODO: Enable this optimization for 2019-09 on-wards - if (schema_context.vocabularies.contains( - "http://json-schema.org/draft-04/schema#") || - schema_context.vocabularies.contains( - "http://json-schema.org/draft-06/schema#") || - schema_context.vocabularies.contains( - "http://json-schema.org/draft-07/schema#")) { + if (context.mode == Mode::FastValidation && + // Expanding references inline when dynamic scoping is required + // may not work, as we might omit the instruction that introduces + // one of the necessary schema resources to the evaluator + !context.uses_dynamic_scopes) { return compile(context, new_schema_context, dynamic_context, - empty_pointer, empty_pointer, reference.destination); + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer, + reference.destination); } else { - return {make( - true, context, schema_context, dynamic_context, - SchemaCompilerValueNone{}, + return {make( + true, context, schema_context, dynamic_context, ValueNone{}, compile(context, new_schema_context, relative_dynamic_context, - empty_pointer, empty_pointer, reference.destination))}; + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer, + reference.destination))}; } } @@ -108,73 +109,84 @@ auto compiler_draft4_core_ref( // handler, without having to add logic to every single keyword to check // whether something points to them and add the "checkpoint" themselves. new_schema_context.labels.insert(label); - return {make( + return {make( true, context, schema_context, dynamic_context, - SchemaCompilerValueUnsignedInteger{label}, + ValueUnsignedInteger{label}, compile(context, new_schema_context, relative_dynamic_context, - empty_pointer, empty_pointer, reference.destination))}; + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer, reference.destination))}; } -auto compiler_draft4_validation_type( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_draft4_validation_type(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { if (schema_context.schema.at(dynamic_context.keyword).is_string()) { const auto &type{ schema_context.schema.at(dynamic_context.keyword).to_string()}; if (type == "null") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Null)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Null)}; } else if (type == "boolean") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Boolean)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Boolean)}; } else if (type == "object") { const auto minimum{ unsigned_integer_property(schema_context.schema, "minProperties", 0)}; const auto maximum{ unsigned_integer_property(schema_context.schema, "maxProperties")}; - if (minimum > 0 || maximum.has_value()) { - return {make( - true, context, schema_context, dynamic_context, - {minimum, maximum, false})}; + if (context.mode == Mode::FastValidation && + (minimum > 0 || maximum.has_value())) { + return {make(true, context, schema_context, + dynamic_context, + {minimum, maximum, false})}; } - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Object)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Object)}; } else if (type == "array") { const auto minimum{ unsigned_integer_property(schema_context.schema, "minItems", 0)}; const auto maximum{ unsigned_integer_property(schema_context.schema, "maxItems")}; - if (minimum > 0 || maximum.has_value()) { - return {make( - true, context, schema_context, dynamic_context, - {minimum, maximum, false})}; + if (context.mode == Mode::FastValidation && + (minimum > 0 || maximum.has_value())) { + return {make(true, context, schema_context, + dynamic_context, + {minimum, maximum, false})}; } - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Array)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Array)}; } else if (type == "number") { - return {make( + return {make( true, context, schema_context, dynamic_context, - std::vector{JSON::Type::Real, JSON::Type::Integer})}; + std::vector{ + sourcemeta::jsontoolkit::JSON::Type::Real, + sourcemeta::jsontoolkit::JSON::Type::Integer})}; } else if (type == "integer") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Integer)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Integer)}; } else if (type == "string") { const auto minimum{ unsigned_integer_property(schema_context.schema, "minLength", 0)}; const auto maximum{ unsigned_integer_property(schema_context.schema, "maxLength")}; - if (minimum > 0 || maximum.has_value()) { - return {make( - true, context, schema_context, dynamic_context, - {minimum, maximum, false})}; + if (context.mode == Mode::FastValidation && + (minimum > 0 || maximum.has_value())) { + return {make(true, context, schema_context, + dynamic_context, + {minimum, maximum, false})}; } - return {make( - true, context, schema_context, dynamic_context, JSON::Type::String)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::String)}; } else { return {}; } @@ -186,68 +198,75 @@ auto compiler_draft4_validation_type( const auto &type{ schema_context.schema.at(dynamic_context.keyword).front().to_string()}; if (type == "null") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Null)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Null)}; } else if (type == "boolean") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Boolean)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Boolean)}; } else if (type == "object") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Object)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Object)}; } else if (type == "array") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Array)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Array)}; } else if (type == "number") { - return {make( + return {make( true, context, schema_context, dynamic_context, - std::vector{JSON::Type::Real, JSON::Type::Integer})}; + std::vector{ + sourcemeta::jsontoolkit::JSON::Type::Real, + sourcemeta::jsontoolkit::JSON::Type::Integer})}; } else if (type == "integer") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Integer)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Integer)}; } else if (type == "string") { - return {make( - true, context, schema_context, dynamic_context, JSON::Type::String)}; + return {make( + true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::String)}; } else { return {}; } } else if (schema_context.schema.at(dynamic_context.keyword).is_array()) { - std::vector types; + std::vector types; for (const auto &type : schema_context.schema.at(dynamic_context.keyword).as_array()) { assert(type.is_string()); const auto &type_string{type.to_string()}; if (type_string == "null") { - types.push_back(JSON::Type::Null); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::Null); } else if (type_string == "boolean") { - types.push_back(JSON::Type::Boolean); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::Boolean); } else if (type_string == "object") { - types.push_back(JSON::Type::Object); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::Object); } else if (type_string == "array") { - types.push_back(JSON::Type::Array); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::Array); } else if (type_string == "number") { - types.push_back(JSON::Type::Integer); - types.push_back(JSON::Type::Real); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::Integer); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::Real); } else if (type_string == "integer") { - types.push_back(JSON::Type::Integer); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::Integer); } else if (type_string == "string") { - types.push_back(JSON::Type::String); + types.push_back(sourcemeta::jsontoolkit::JSON::Type::String); } } assert(types.size() >= schema_context.schema.at(dynamic_context.keyword).size()); - return {make( - true, context, schema_context, dynamic_context, std::move(types))}; + return {make(true, context, schema_context, + dynamic_context, std::move(types))}; } return {}; } -auto compiler_draft4_validation_required( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_draft4_validation_required(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_array()); if (schema_context.schema.defines("type") && @@ -259,7 +278,7 @@ auto compiler_draft4_validation_required( if (schema_context.schema.at(dynamic_context.keyword).empty()) { return {}; } else if (schema_context.schema.at(dynamic_context.keyword).size() > 1) { - std::vector properties; + std::vector properties; for (const auto &property : schema_context.schema.at(dynamic_context.keyword).as_array()) { assert(property.is_string()); @@ -267,112 +286,105 @@ auto compiler_draft4_validation_required( } if (properties.size() == 1) { - return {make( - true, context, schema_context, dynamic_context, - SchemaCompilerValueString{*(properties.cbegin())})}; + return {make(true, context, schema_context, + dynamic_context, + ValueString{*(properties.cbegin())})}; } else { - return {make( - true, context, schema_context, dynamic_context, - std::move(properties))}; + return {make(true, context, schema_context, + dynamic_context, + std::move(properties))}; } } else { assert( schema_context.schema.at(dynamic_context.keyword).front().is_string()); - return {make( + return {make( true, context, schema_context, dynamic_context, - SchemaCompilerValueString{ - schema_context.schema.at(dynamic_context.keyword) - .front() - .to_string()})}; + ValueString{schema_context.schema.at(dynamic_context.keyword) + .front() + .to_string()})}; } } -auto compiler_draft4_applicator_allof( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_draft4_applicator_allof(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_array()); assert(!schema_context.schema.at(dynamic_context.keyword).empty()); - SchemaCompilerTemplate children; + Template children; for (std::uint64_t index = 0; index < schema_context.schema.at(dynamic_context.keyword).size(); index++) { for (auto &&step : compile(context, schema_context, relative_dynamic_context, - {static_cast(index)})) { + {static_cast( + index)})) { children.push_back(std::move(step)); } } - return {make( - true, context, schema_context, dynamic_context, SchemaCompilerValueNone{}, - std::move(children))}; + return {make(true, context, schema_context, dynamic_context, + ValueNone{}, std::move(children))}; } -auto compiler_draft4_applicator_anyof_conditional_exhaustive( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, const bool exhaustive) - -> SchemaCompilerTemplate { +auto compiler_draft4_applicator_anyof(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_array()); assert(!schema_context.schema.at(dynamic_context.keyword).empty()); - SchemaCompilerTemplate disjunctors; + Template disjunctors; for (std::uint64_t index = 0; index < schema_context.schema.at(dynamic_context.keyword).size(); index++) { - disjunctors.push_back(make( - false, context, schema_context, relative_dynamic_context, - SchemaCompilerValueNone{}, + disjunctors.push_back(make( + false, context, schema_context, relative_dynamic_context, ValueNone{}, compile(context, schema_context, relative_dynamic_context, - {static_cast(index)}))); + {static_cast( + index)}))); } - return {make( - true, context, schema_context, dynamic_context, - SchemaCompilerValueBoolean{exhaustive}, std::move(disjunctors))}; -} + const auto requires_exhaustive{context.mode == Mode::Exhaustive || + context.uses_unevaluated_properties || + context.uses_unevaluated_items}; -auto compiler_draft4_applicator_anyof( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { - return compiler_draft4_applicator_anyof_conditional_exhaustive( - context, schema_context, dynamic_context, false); + return {make(true, context, schema_context, dynamic_context, + ValueBoolean{requires_exhaustive}, + std::move(disjunctors))}; } -auto compiler_draft4_applicator_oneof( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_draft4_applicator_oneof(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_array()); assert(!schema_context.schema.at(dynamic_context.keyword).empty()); - SchemaCompilerTemplate disjunctors; + Template disjunctors; for (std::uint64_t index = 0; index < schema_context.schema.at(dynamic_context.keyword).size(); index++) { - disjunctors.push_back(make( - false, context, schema_context, relative_dynamic_context, - SchemaCompilerValueNone{}, + disjunctors.push_back(make( + false, context, schema_context, relative_dynamic_context, ValueNone{}, compile(context, schema_context, relative_dynamic_context, - {static_cast(index)}))); + {static_cast( + index)}))); } - return {make( - true, context, schema_context, dynamic_context, SchemaCompilerValueNone{}, - std::move(disjunctors))}; + const auto requires_exhaustive{context.mode == Mode::Exhaustive || + context.uses_unevaluated_properties || + context.uses_unevaluated_items}; + + return {make(true, context, schema_context, dynamic_context, + ValueBoolean{requires_exhaustive}, + std::move(disjunctors))}; } auto compiler_draft4_applicator_properties_conditional_annotation( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, const bool annotate) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context, const bool annotate) -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_object()); if (schema_context.schema.at(dynamic_context.keyword).empty()) { return {}; @@ -412,7 +424,7 @@ auto compiler_draft4_applicator_properties_conditional_annotation( } std::size_t is_required = 0; - std::vector> properties; + std::vector> properties; for (const auto &entry : schema_context.schema.at(dynamic_context.keyword).as_object()) { properties.push_back( @@ -462,36 +474,37 @@ auto compiler_draft4_applicator_properties_conditional_annotation( !is_directly_inside_oneof}; if (prefer_loop_over_instance) { - SchemaCompilerValueNamedIndexes indexes; - SchemaCompilerTemplate children; + ValueNamedIndexes indexes; + Template children; std::size_t cursor = 0; for (auto &&[name, substeps] : properties) { indexes.emplace(name, cursor); if (annotate) { - substeps.push_back(make( + substeps.push_back(make( true, context, schema_context, relative_dynamic_context, - JSON{name})); + sourcemeta::jsontoolkit::JSON{name})); } // Note that the evaluator completely ignores this wrapper anyway - children.push_back(make( - false, context, schema_context, relative_dynamic_context, - SchemaCompilerValueNone{}, std::move(substeps))); + children.push_back(make(false, context, schema_context, + relative_dynamic_context, ValueNone{}, + std::move(substeps))); cursor += 1; } - return {make( - true, context, schema_context, dynamic_context, std::move(indexes), - std::move(children))}; + return {make(true, context, schema_context, + dynamic_context, std::move(indexes), + std::move(children))}; } - SchemaCompilerTemplate children; + Template children; for (auto &&[name, substeps] : properties) { if (annotate) { - substeps.push_back(make( - true, context, schema_context, relative_dynamic_context, JSON{name})); + substeps.push_back(make( + true, context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::JSON{name})); } const auto assume_object{imports_validation_vocabulary && @@ -504,7 +517,8 @@ auto compiler_draft4_applicator_properties_conditional_annotation( if (imports_validation_vocabulary && assume_object && schema_context.schema.defines("required") && schema_context.schema.at("required").is_array() && - schema_context.schema.at("required").contains(JSON{name})) { + schema_context.schema.at("required") + .contains(sourcemeta::jsontoolkit::JSON{name})) { // We can avoid the container too and just inline these steps for (auto &&substep : substeps) { children.push_back(std::move(substep)); @@ -513,76 +527,65 @@ auto compiler_draft4_applicator_properties_conditional_annotation( // Optimize `properties` where its subschemas just include a type check, // as that's a very common pattern - } else if (substeps.size() == 1 && - std::holds_alternative( - substeps.front())) { - const auto &type_step{ - std::get(substeps.front())}; - children.push_back(SchemaCompilerAssertionPropertyTypeStrict{ + } else if (context.mode == Mode::FastValidation && substeps.size() == 1 && + std::holds_alternative(substeps.front())) { + const auto &type_step{std::get(substeps.front())}; + children.push_back(AssertionPropertyTypeStrict{ type_step.relative_schema_location, dynamic_context.base_instance_location.concat( type_step.relative_instance_location), type_step.keyword_location, type_step.schema_resource, type_step.dynamic, type_step.report, type_step.value}); - } else if (substeps.size() == 1 && - std::holds_alternative( - substeps.front())) { - const auto &type_step{ - std::get(substeps.front())}; - children.push_back(SchemaCompilerAssertionPropertyType{ + } else if (context.mode == Mode::FastValidation && substeps.size() == 1 && + std::holds_alternative(substeps.front())) { + const auto &type_step{std::get(substeps.front())}; + children.push_back(AssertionPropertyType{ type_step.relative_schema_location, dynamic_context.base_instance_location.concat( type_step.relative_instance_location), type_step.keyword_location, type_step.schema_resource, type_step.dynamic, type_step.report, type_step.value}); - } else if (substeps.size() == 1 && - std::holds_alternative< - SchemaCompilerAssertionPropertyTypeStrict>( + } else if (context.mode == Mode::FastValidation && substeps.size() == 1 && + std::holds_alternative( substeps.front())) { - children.push_back(unroll( + children.push_back(unroll( relative_dynamic_context, substeps.front(), dynamic_context.base_instance_location)); - } else if (substeps.size() == 1 && - std::holds_alternative( + } else if (context.mode == Mode::FastValidation && substeps.size() == 1 && + std::holds_alternative( substeps.front())) { - children.push_back(unroll( + children.push_back(unroll( relative_dynamic_context, substeps.front(), dynamic_context.base_instance_location)); } else { - children.push_back(make( + children.push_back(make( false, context, schema_context, relative_dynamic_context, - SchemaCompilerValueString{name}, std::move(substeps))); + ValueString{name}, std::move(substeps))); } } // Optimize away the wrapper when emitting a single instruction - if (children.size() == 1 && - std::holds_alternative( - children.front())) { - return {unroll( - dynamic_context, children.front())}; + if (context.mode == Mode::FastValidation && children.size() == 1 && + std::holds_alternative(children.front())) { + return { + unroll(dynamic_context, children.front())}; } - return {make( - true, context, schema_context, dynamic_context, SchemaCompilerValueNone{}, - std::move(children))}; + return {make(true, context, schema_context, dynamic_context, + ValueNone{}, std::move(children))}; } auto compiler_draft4_applicator_properties( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { return compiler_draft4_applicator_properties_conditional_annotation( context, schema_context, dynamic_context, false); } auto compiler_draft4_applicator_patternproperties_conditional_annotation( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, const bool annotate) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context, const bool annotate) -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_object()); if (schema_context.schema.at(dynamic_context.keyword).empty()) { return {}; @@ -594,7 +597,7 @@ auto compiler_draft4_applicator_patternproperties_conditional_annotation( return {}; } - SchemaCompilerTemplate children; + Template children; // To guarantee ordering std::vector patterns; @@ -614,21 +617,21 @@ auto compiler_draft4_applicator_patternproperties_conditional_annotation( // The evaluator will make sure the same annotation is not reported twice. // For example, if the same property matches more than one subschema in // `patternProperties` - substeps.push_back(make( + substeps.push_back(make( true, context, schema_context, relative_dynamic_context, - SchemaCompilerValueNone{})); + ValueNone{})); } // If the `patternProperties` subschema for the given pattern does // nothing, then we can avoid generating an entire loop for it if (!substeps.empty()) { // Loop over the instance properties - children.push_back(make( + children.push_back(make( // Treat this as an internal step false, context, schema_context, relative_dynamic_context, - SchemaCompilerValueRegex{parse_regex(pattern, schema_context.base, - schema_context.relative_pointer), - pattern}, + ValueRegex{parse_regex(pattern, schema_context.base, + schema_context.relative_pointer), + pattern}, std::move(substeps))); } } @@ -638,48 +641,43 @@ auto compiler_draft4_applicator_patternproperties_conditional_annotation( } // If the instance is an object... - return {make( - true, context, schema_context, dynamic_context, JSON::Type::Object, - std::move(children))}; + return {make(true, context, schema_context, dynamic_context, + sourcemeta::jsontoolkit::JSON::Type::Object, + std::move(children))}; } auto compiler_draft4_applicator_patternproperties( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { return compiler_draft4_applicator_patternproperties_conditional_annotation( context, schema_context, dynamic_context, false); } auto compiler_draft4_applicator_additionalproperties_conditional_annotation( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, const bool annotate) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context, const bool annotate) -> Template { if (schema_context.schema.defines("type") && schema_context.schema.at("type").is_string() && schema_context.schema.at("type").to_string() != "object") { return {}; } - SchemaCompilerTemplate children{compile(context, schema_context, - relative_dynamic_context, - empty_pointer, empty_pointer)}; + Template children{compile(context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer)}; if (annotate) { - children.push_back(make( - true, context, schema_context, relative_dynamic_context, - SchemaCompilerValueNone{})); + children.push_back(make( + true, context, schema_context, relative_dynamic_context, ValueNone{})); } - SchemaCompilerValuePropertyFilter filter; + ValuePropertyFilter filter; if (schema_context.schema.defines("properties") && schema_context.schema.at("properties").is_object()) { for (const auto &entry : schema_context.schema.at("properties").as_object()) { - filter.first.insert(entry.first); + filter.first.push_back(entry.first); } } @@ -695,49 +693,47 @@ auto compiler_draft4_applicator_additionalproperties_conditional_annotation( } } + // For performance, if a schema sets `additionalProperties: true` (or its + // variants), we don't need to do anything + if (children.empty()) { + return {}; + } + if (!filter.first.empty() || !filter.second.empty()) { - return {make( - true, context, schema_context, dynamic_context, std::move(filter), - std::move(children))}; + return {make(true, context, schema_context, + dynamic_context, std::move(filter), + std::move(children))}; } else { - if (children.size() == 1) { + if (context.mode == Mode::FastValidation && children.size() == 1) { // Optimize `additionalProperties` set to just `type`, which is a // pretty common pattern - if (std::holds_alternative( - children.front())) { - const auto &type_step{ - std::get(children.front())}; - return {make( - true, context, schema_context, dynamic_context, type_step.value)}; - } else if (std::holds_alternative( - children.front())) { - const auto &type_step{ - std::get(children.front())}; - return {make( + if (std::holds_alternative(children.front())) { + const auto &type_step{std::get(children.front())}; + return {make( true, context, schema_context, dynamic_context, type_step.value)}; + } else if (std::holds_alternative(children.front())) { + const auto &type_step{std::get(children.front())}; + return {make(true, context, schema_context, + dynamic_context, type_step.value)}; } } - return {make( - true, context, schema_context, dynamic_context, - SchemaCompilerValueNone{}, std::move(children))}; + return {make(true, context, schema_context, dynamic_context, + ValueNone{}, std::move(children))}; } } auto compiler_draft4_applicator_additionalproperties( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context) -> Template { return compiler_draft4_applicator_additionalproperties_conditional_annotation( context, schema_context, dynamic_context, false); } -auto compiler_draft4_validation_pattern( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_draft4_validation_pattern(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_string()); if (schema_context.schema.defines("type") && @@ -748,18 +744,17 @@ auto compiler_draft4_validation_pattern( const auto ®ex_string{ schema_context.schema.at(dynamic_context.keyword).to_string()}; - return {make( + return {make( true, context, schema_context, dynamic_context, - SchemaCompilerValueRegex{parse_regex(regex_string, schema_context.base, - schema_context.relative_pointer), - regex_string})}; + ValueRegex{parse_regex(regex_string, schema_context.base, + schema_context.relative_pointer), + regex_string})}; } -auto compiler_draft4_validation_format( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { +auto compiler_draft4_validation_format(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { if (!schema_context.schema.at(dynamic_context.keyword).is_string()) { return {}; } @@ -781,19 +776,17 @@ auto compiler_draft4_validation_format( schema_context.schema.at(dynamic_context.keyword).to_string()}; if (format == "uri") { - return {make( - true, context, schema_context, dynamic_context, - SchemaCompilerValueStringType::URI)}; + return {make(true, context, schema_context, + dynamic_context, ValueStringType::URI)}; } #define COMPILE_FORMAT_REGEX(name, regular_expression) \ if (format == (name)) { \ - return {make( \ + return {make( \ true, context, schema_context, dynamic_context, \ - SchemaCompilerValueRegex{parse_regex(regular_expression, \ - schema_context.base, \ - schema_context.relative_pointer), \ - (regular_expression)})}; \ + ValueRegex{parse_regex(regular_expression, schema_context.base, \ + schema_context.relative_pointer), \ + (regular_expression)})}; \ } COMPILE_FORMAT_REGEX("ipv4", FORMAT_REGEX_IPV4) @@ -803,22 +796,31 @@ auto compiler_draft4_validation_format( return {}; } -auto compiler_draft4_applicator_not( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context) - -> SchemaCompilerTemplate { - return {make( - true, context, schema_context, dynamic_context, SchemaCompilerValueNone{}, - compile(context, schema_context, relative_dynamic_context, empty_pointer, - empty_pointer))}; +auto compiler_draft4_applicator_not(const Context &context, + const SchemaContext &schema_context, + const DynamicContext &dynamic_context) + -> Template { + // Only emit a `not` instruction that keeps track of + // dropping annotations if we really need it + if (context.mode != Mode::FastValidation || + context.uses_unevaluated_properties || context.uses_unevaluated_items) { + return {make( + true, context, schema_context, dynamic_context, ValueNone{}, + compile(context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer))}; + } else { + return {make( + true, context, schema_context, dynamic_context, ValueNone{}, + compile(context, schema_context, relative_dynamic_context, + sourcemeta::jsontoolkit::empty_pointer, + sourcemeta::jsontoolkit::empty_pointer))}; + } } auto compiler_draft4_applicator_items_array( - const SchemaCompilerContext &context, - const SchemaCompilerSchemaContext &schema_context, - const SchemaCompilerDynamicContext &dynamic_context, const bool annotate) - -> SchemaCompilerTemplate { + const Context &context, const SchemaContext &schema_context, + const DynamicContext &dynamic_context, const bool annotate) -> Template { assert(schema_context.schema.at(dynamic_context.keyword).is_array()); const auto items_size{ schema_context.schema.at(dynamic_context.keyword).size()}; @@ -841,7 +843,7 @@ auto compiler_draft4_applicator_items_array( // - [ {} ] if the instance array size is == 1 // Precompile subschemas - std::vector subschemas; + std::vector