tpy-lang 0.3.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tpy_lang-0.3.0.dev0.dist-info/METADATA +151 -0
- tpy_lang-0.3.0.dev0.dist-info/RECORD +333 -0
- tpy_lang-0.3.0.dev0.dist-info/WHEEL +4 -0
- tpy_lang-0.3.0.dev0.dist-info/entry_points.txt +3 -0
- tpyc/__init__.py +104 -0
- tpyc/__main__.py +6 -0
- tpyc/_buildinfo.py +1 -0
- tpyc/_data/docs/LANGUAGE_FEATURES.md +6278 -0
- tpyc/_data/docs/STDLIB_ROADMAP.md +1258 -0
- tpyc/_data/docs/TPY_FOR_AGENTS.md +556 -0
- tpyc/_data/lib/tpy/_bindings/__init__.py +6 -0
- tpyc/_data/lib/tpy/_bindings/pcre2.py +173 -0
- tpyc/_data/lib/tpy/_bindings/posix_socket.py +161 -0
- tpyc/_data/lib/tpy/_functools_macros.py +80 -0
- tpyc/_data/lib/tpy/_macro_helpers.py +161 -0
- tpyc/_data/lib/tpy/argparse.py +2062 -0
- tpyc/_data/lib/tpy/asyncio/__init__.py +744 -0
- tpyc/_data/lib/tpy/asyncio/_executor.py +515 -0
- tpyc/_data/lib/tpy/base64.py +410 -0
- tpyc/_data/lib/tpy/bisect.py +39 -0
- tpyc/_data/lib/tpy/builtins.py +38 -0
- tpyc/_data/lib/tpy/dataclasses.py +354 -0
- tpyc/_data/lib/tpy/enum.py +23 -0
- tpyc/_data/lib/tpy/functools.py +33 -0
- tpyc/_data/lib/tpy/hashlib.py +206 -0
- tpyc/_data/lib/tpy/heapq.py +118 -0
- tpyc/_data/lib/tpy/io.py +395 -0
- tpyc/_data/lib/tpy/json.py +221 -0
- tpyc/_data/lib/tpy/math.py +406 -0
- tpyc/_data/lib/tpy/random.py +597 -0
- tpyc/_data/lib/tpy/re.py +467 -0
- tpyc/_data/lib/tpy/socket.py +379 -0
- tpyc/_data/lib/tpy/struct.py +178 -0
- tpyc/_data/lib/tpy/sys.py +40 -0
- tpyc/_data/lib/tpy/time.py +39 -0
- tpyc/_data/lib/tpy/tpy/__init__.py +78 -0
- tpyc/_data/lib/tpy/tpy/_bootstrap/__init__.py +10 -0
- tpyc/_data/lib/tpy/tpy/_bootstrap/_decorators.py +37 -0
- tpyc/_data/lib/tpy/tpy/_bootstrap/_extern.py +64 -0
- tpyc/_data/lib/tpy/tpy/_builtins/__init__.py +11 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_bytes.py +378 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_dict.py +151 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_exceptions.py +125 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_funcs.py +681 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_io.py +97 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_list.py +127 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_range.py +52 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_set.py +139 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_super.py +11 -0
- tpyc/_data/lib/tpy/tpy/_builtins/_types.py +661 -0
- tpyc/_data/lib/tpy/tpy/_core/__init__.py +23 -0
- tpyc/_data/lib/tpy/tpy/_core/_bytes_view.py +129 -0
- tpyc/_data/lib/tpy/tpy/_core/_containers.py +137 -0
- tpyc/_data/lib/tpy/tpy/_core/_functions.py +40 -0
- tpyc/_data/lib/tpy/tpy/_core/_types.py +2061 -0
- tpyc/_data/lib/tpy/tpy/_typing/__init__.py +77 -0
- tpyc/_data/lib/tpy/tpy/_version.py +29 -0
- tpyc/_data/lib/tpy/tpy/bits.py +28 -0
- tpyc/_data/lib/tpy/tpy/coro/__init__.py +127 -0
- tpyc/_data/lib/tpy/tpy/extern.py +8 -0
- tpyc/_data/lib/tpy/tpy/mem.py +49 -0
- tpyc/_data/lib/tpy/tpy/unsafe.py +195 -0
- tpyc/_data/lib/tpy/tpy/version.py +21 -0
- tpyc/_data/lib/tpy/typing.py +13 -0
- tpyc/_data/runtime/cpp/include/tpy/any.hpp +461 -0
- tpyc/_data/runtime/cpp/include/tpy/as_ostream.hpp +117 -0
- tpyc/_data/runtime/cpp/include/tpy/async.hpp +76 -0
- tpyc/_data/runtime/cpp/include/tpy/bigint.hpp +1343 -0
- tpyc/_data/runtime/cpp/include/tpy/builtins.hpp +400 -0
- tpyc/_data/runtime/cpp/include/tpy/bytes_ops.hpp +469 -0
- tpyc/_data/runtime/cpp/include/tpy/container_ops.hpp +487 -0
- tpyc/_data/runtime/cpp/include/tpy/copy_iter.hpp +82 -0
- tpyc/_data/runtime/cpp/include/tpy/core.hpp +558 -0
- tpyc/_data/runtime/cpp/include/tpy/dict_ops.hpp +289 -0
- tpyc/_data/runtime/cpp/include/tpy/dunder.hpp +750 -0
- tpyc/_data/runtime/cpp/include/tpy/dynamic.hpp +44 -0
- tpyc/_data/runtime/cpp/include/tpy/enum.hpp +40 -0
- tpyc/_data/runtime/cpp/include/tpy/file.hpp +245 -0
- tpyc/_data/runtime/cpp/include/tpy/fixed_int.hpp +317 -0
- tpyc/_data/runtime/cpp/include/tpy/format.hpp +954 -0
- tpyc/_data/runtime/cpp/include/tpy/frame_slot.hpp +120 -0
- tpyc/_data/runtime/cpp/include/tpy/generator.hpp +47 -0
- tpyc/_data/runtime/cpp/include/tpy/iterable_ops.hpp +122 -0
- tpyc/_data/runtime/cpp/include/tpy/itertools.hpp +749 -0
- tpyc/_data/runtime/cpp/include/tpy/next_iter.hpp +82 -0
- tpyc/_data/runtime/cpp/include/tpy/ordered_map.hpp +518 -0
- tpyc/_data/runtime/cpp/include/tpy/ordered_set.hpp +337 -0
- tpyc/_data/runtime/cpp/include/tpy/own_iter.hpp +54 -0
- tpyc/_data/runtime/cpp/include/tpy/pascal_graph_sdl.hpp +192 -0
- tpyc/_data/runtime/cpp/include/tpy/printing.hpp +302 -0
- tpyc/_data/runtime/cpp/include/tpy/protocols.hpp +61 -0
- tpyc/_data/runtime/cpp/include/tpy/range.hpp +115 -0
- tpyc/_data/runtime/cpp/include/tpy/ranges.hpp +212 -0
- tpyc/_data/runtime/cpp/include/tpy/set_ops.hpp +265 -0
- tpyc/_data/runtime/cpp/include/tpy/slice.hpp +47 -0
- tpyc/_data/runtime/cpp/include/tpy/span_iter.hpp +42 -0
- tpyc/_data/runtime/cpp/include/tpy/stdlib/math.hpp +41 -0
- tpyc/_data/runtime/cpp/include/tpy/stdlib/pcre2_h.hpp +96 -0
- tpyc/_data/runtime/cpp/include/tpy/stdlib/random.hpp +25 -0
- tpyc/_data/runtime/cpp/include/tpy/stdlib/socket_h.hpp +145 -0
- tpyc/_data/runtime/cpp/include/tpy/stdlib/time.hpp +62 -0
- tpyc/_data/runtime/cpp/include/tpy/system.hpp +121 -0
- tpyc/_data/runtime/cpp/include/tpy/throwable.hpp +55 -0
- tpyc/_data/runtime/cpp/include/tpy/tpy.hpp +156 -0
- tpyc/_data/runtime/cpp/include/tpy/type_name.hpp +77 -0
- tpyc/_data/runtime/cpp/include/tpy/type_traits.hpp +240 -0
- tpyc/_data/runtime/cpp/include/tpy/uninit_array_storage.hpp +250 -0
- tpyc/_data/runtime/cpp/include/tpy/uninit_heap_storage.hpp +277 -0
- tpyc/_data/runtime/cpp/include/tpy/varargs.hpp +174 -0
- tpyc/_data/runtime/cpp/include/tpy/variant_ref.hpp +118 -0
- tpyc/_data/runtime/cpp/src/stdlib/socket_impl.cpp +104 -0
- tpyc/_data/runtime/cpp/third_party/README.md +58 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/AUTHORS +36 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/CMakeLists.txt +1233 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/COPYING +5 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/ChangeLog +3097 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/HACKING +853 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/INSTALL +368 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/LICENCE +94 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/NEWS +492 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/NON-AUTOTOOLS-BUILD +430 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/README +956 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/cmake/COPYING-CMAKE-SCRIPTS +22 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/cmake/FindEditline.cmake +16 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/cmake/FindPackageHandleStandardArgs.cmake +58 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/cmake/FindReadline.cmake +29 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/cmake/pcre2-config-version.cmake.in +15 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/cmake/pcre2-config.cmake.in +148 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/config-cmake.h.in +56 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-16.pc.in +13 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-32.pc.in +13 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-8.pc.in +13 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/libpcre2-posix.pc.in +13 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/pcre2-config.in +121 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/config.h +483 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/config.h.generic +483 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/config.h.in +460 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2.h +1010 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2.h.generic +1010 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2.h.in +1010 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_auto_possess.c +1371 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_chartables.c +196 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_chartables.c.dist +196 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_chkdint.c +96 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_compile.c +11001 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_config.c +252 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_context.c +510 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_convert.c +1189 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_dfa_match.c +4119 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_dftables.c +297 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_error.c +345 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_extuni.c +162 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_find_bracket.c +219 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_fuzzsupport.c +792 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_internal.h +2084 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_intmodedep.h +940 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_compile.c +14972 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_match.c +200 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_misc.c +234 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_neon_inc.h +354 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_simd_inc.h +2355 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_jit_test.c +2528 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_maketables.c +165 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_match.c +7777 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_match_data.c +185 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_newline.c +243 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ord2utf.c +120 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_pattern_info.c +432 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_printint.c +886 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_script_run.c +344 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_serialize.c +286 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_string_utils.c +237 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_study.c +1915 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_substitute.c +1009 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_substring.c +550 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_tables.c +234 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ucd.c +5460 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ucp.h +396 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_ucptables.c +1533 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_valid_utf.c +398 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2_xclass.c +308 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2demo.c +497 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2grep.c +4606 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2posix.c +425 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2posix.h +187 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2posix_test.c +209 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/pcre2test.c +9708 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorApple.c +137 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorCore.c +327 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorFreeBSD.c +89 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorPosix.c +62 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitExecAllocatorWindows.c +40 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitProtExecAllocatorNetBSD.c +72 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitProtExecAllocatorPosix.c +172 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitWXExecAllocatorPosix.c +141 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/allocator_src/sljitWXExecAllocatorWindows.c +102 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitConfig.h +142 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitConfigCPU.h +188 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitConfigInternal.h +907 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitLir.c +3561 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitLir.h +2466 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeARM_32.c +4636 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeARM_64.c +3491 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeARM_T2_32.c +4302 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeLOONGARCH_64.c +3765 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeMIPS_32.c +472 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeMIPS_64.c +387 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeMIPS_common.c +4259 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativePPC_32.c +485 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativePPC_64.c +719 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativePPC_common.c +3161 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeRISCV_32.c +142 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeRISCV_64.c +222 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeRISCV_common.c +3121 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeS390X.c +4526 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeX86_32.c +1685 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeX86_64.c +1398 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitNativeX86_common.c +5001 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitSerialize.c +516 -0
- tpyc/_data/runtime/cpp/third_party/pcre2/src/sljit/sljitUtils.c +344 -0
- tpyc/_data/runtime/cpp/third_party/pcre2.sources.txt +54 -0
- tpyc/_data/runtime/cpp/third_party/pcre2.vendor.json +7 -0
- tpyc/build/__init__.py +7 -0
- tpyc/build/pcre2.py +122 -0
- tpyc/build/third_party.py +413 -0
- tpyc/cli.py +822 -0
- tpyc/codegen_cpp/__init__.py +18 -0
- tpyc/codegen_cpp/builtins.py +484 -0
- tpyc/codegen_cpp/context.py +2064 -0
- tpyc/codegen_cpp/expressions.py +5940 -0
- tpyc/codegen_cpp/functions.py +1913 -0
- tpyc/codegen_cpp/gen_async.py +3258 -0
- tpyc/codegen_cpp/gen_generators.py +657 -0
- tpyc/codegen_cpp/generator.py +2258 -0
- tpyc/codegen_cpp/match.py +1997 -0
- tpyc/codegen_cpp/param_const.py +172 -0
- tpyc/codegen_cpp/protocols.py +907 -0
- tpyc/codegen_cpp/records.py +1654 -0
- tpyc/codegen_cpp/resumable_cfg.py +1651 -0
- tpyc/codegen_cpp/statements.py +4963 -0
- tpyc/codegen_cpp/string_dispatch.py +76 -0
- tpyc/codegen_cpp/test_context.py +46 -0
- tpyc/codegen_cpp/test_param_const.py +113 -0
- tpyc/codegen_cpp/test_resumable_cfg.py +182 -0
- tpyc/codegen_cpp/type_resolution.py +53 -0
- tpyc/codegen_cpp/types.py +436 -0
- tpyc/codegen_cpp/variant_access.py +135 -0
- tpyc/coercions.py +749 -0
- tpyc/compilation_context.py +57 -0
- tpyc/compiler.py +3945 -0
- tpyc/cycle_detection.py +358 -0
- tpyc/diagnostics.py +135 -0
- tpyc/dump_types.py +353 -0
- tpyc/frontend_diagnostics.py +47 -0
- tpyc/frontend_ir/__init__.py +140 -0
- tpyc/frontend_ir/lower.py +1098 -0
- tpyc/frontend_ir/nodes.py +718 -0
- tpyc/frontend_ir/resolver_adapter.py +151 -0
- tpyc/frontend_plugin.py +209 -0
- tpyc/install_docs.py +81 -0
- tpyc/liveness.py +756 -0
- tpyc/macro_api.py +1724 -0
- tpyc/macro_loader.py +497 -0
- tpyc/module_names.py +64 -0
- tpyc/modules/__init__.py +31 -0
- tpyc/modules/defs.py +89 -0
- tpyc/modules/registry.py +36 -0
- tpyc/modules/resolver.py +192 -0
- tpyc/modules/type_resolution.py +629 -0
- tpyc/namespace.py +172 -0
- tpyc/parse/__init__.py +84 -0
- tpyc/parse/imports.py +490 -0
- tpyc/parse/nodes.py +1732 -0
- tpyc/parse/parser.py +4043 -0
- tpyc/parse/resolve_refs.py +466 -0
- tpyc/parse/type_resolver.py +1060 -0
- tpyc/prescan.py +254 -0
- tpyc/qnames.py +149 -0
- tpyc/repl.py +529 -0
- tpyc/repl_backends.py +848 -0
- tpyc/sema/__init__.py +21 -0
- tpyc/sema/analyzer.py +3625 -0
- tpyc/sema/bound_check.py +72 -0
- tpyc/sema/builder_trace.py +684 -0
- tpyc/sema/calls.py +5406 -0
- tpyc/sema/compatibility.py +2107 -0
- tpyc/sema/context.py +1243 -0
- tpyc/sema/expressions.py +3737 -0
- tpyc/sema/flow_facts.py +199 -0
- tpyc/sema/init_tracker.py +150 -0
- tpyc/sema/list_literals.py +69 -0
- tpyc/sema/literal_utils.py +27 -0
- tpyc/sema/local_deduction.py +1088 -0
- tpyc/sema/macros.py +179 -0
- tpyc/sema/match.py +1177 -0
- tpyc/sema/method_expansion.py +347 -0
- tpyc/sema/methods.py +2197 -0
- tpyc/sema/mutation_propagation.py +268 -0
- tpyc/sema/narrowing.py +857 -0
- tpyc/sema/numeric_lattice.py +160 -0
- tpyc/sema/operators.py +402 -0
- tpyc/sema/overloads.py +841 -0
- tpyc/sema/protocols.py +1209 -0
- tpyc/sema/reach_analysis.py +202 -0
- tpyc/sema/registration.py +3156 -0
- tpyc/sema/scope_tracker.py +193 -0
- tpyc/sema/statements.py +4426 -0
- tpyc/sema/type_ops.py +1879 -0
- tpyc/sema/value_range.py +181 -0
- tpyc/symbol_binding.py +259 -0
- tpyc/test_c3_mro.py +208 -0
- tpyc/test_cli_argv.py +52 -0
- tpyc/test_compiler.py +559 -0
- tpyc/test_contains_type_param.py +101 -0
- tpyc/test_cycle_detection.py +221 -0
- tpyc/test_dump_types.py +225 -0
- tpyc/test_install_docs.py +65 -0
- tpyc/test_local_cpp_form.py +135 -0
- tpyc/test_macro_loader.py +76 -0
- tpyc/test_method_expansion.py +254 -0
- tpyc/test_nominal_identity.py +182 -0
- tpyc/test_overloads.py +410 -0
- tpyc/test_parse.py +303 -0
- tpyc/test_parse_type_ref.py +506 -0
- tpyc/test_parse_version_info.py +58 -0
- tpyc/test_reach_analysis.py +72 -0
- tpyc/test_ref_type.py +216 -0
- tpyc/test_send_sync_substitution.py +276 -0
- tpyc/test_tuple_mutation_propagation.py +206 -0
- tpyc/test_type_def_registry.py +1729 -0
- tpyc/test_union_types.py +195 -0
- tpyc/type_def_registry.py +975 -0
- tpyc/typesys.py +5104 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/*************************************************
|
|
2
|
+
* Perl-Compatible Regular Expressions *
|
|
3
|
+
*************************************************/
|
|
4
|
+
|
|
5
|
+
/* PCRE is a library of functions to support regular expressions whose syntax
|
|
6
|
+
and semantics are as close as possible to those of the Perl 5 language.
|
|
7
|
+
|
|
8
|
+
Written by Philip Hazel
|
|
9
|
+
Original API code Copyright (c) 1997-2012 University of Cambridge
|
|
10
|
+
New API code Copyright (c) 2016-2021 University of Cambridge
|
|
11
|
+
|
|
12
|
+
-----------------------------------------------------------------------------
|
|
13
|
+
Redistribution and use in source and binary forms, with or without
|
|
14
|
+
modification, are permitted provided that the following conditions are met:
|
|
15
|
+
|
|
16
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer.
|
|
18
|
+
|
|
19
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
20
|
+
notice, this list of conditions and the following disclaimer in the
|
|
21
|
+
documentation and/or other materials provided with the distribution.
|
|
22
|
+
|
|
23
|
+
* Neither the name of the University of Cambridge nor the names of its
|
|
24
|
+
contributors may be used to endorse or promote products derived from
|
|
25
|
+
this software without specific prior written permission.
|
|
26
|
+
|
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
28
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
29
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
30
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
31
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
32
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
33
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
34
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
35
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
36
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
37
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
38
|
+
-----------------------------------------------------------------------------
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/* This module contains the function for checking a script run. */
|
|
42
|
+
|
|
43
|
+
#ifdef HAVE_CONFIG_H
|
|
44
|
+
#include "config.h"
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
#include "pcre2_internal.h"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/*************************************************
|
|
51
|
+
* Check script run *
|
|
52
|
+
*************************************************/
|
|
53
|
+
|
|
54
|
+
/* A script run is conceptually a sequence of characters all in the same
|
|
55
|
+
Unicode script. However, it isn't quite that simple. There are special rules
|
|
56
|
+
for scripts that are commonly used together, and also special rules for digits.
|
|
57
|
+
This function implements the appropriate checks, which is possible only when
|
|
58
|
+
PCRE2 is compiled with Unicode support. The function returns TRUE if there is
|
|
59
|
+
no Unicode support; however, it should never be called in that circumstance
|
|
60
|
+
because an error is given by pcre2_compile() if a script run is called for in a
|
|
61
|
+
version of PCRE2 compiled without Unicode support.
|
|
62
|
+
|
|
63
|
+
Arguments:
|
|
64
|
+
pgr point to the first character
|
|
65
|
+
endptr point after the last character
|
|
66
|
+
utf TRUE if in UTF mode
|
|
67
|
+
|
|
68
|
+
Returns: TRUE if this is a valid script run
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/* These are states in the checking process. */
|
|
72
|
+
|
|
73
|
+
enum { SCRIPT_UNSET, /* Requirement as yet unknown */
|
|
74
|
+
SCRIPT_MAP, /* Bitmap contains acceptable scripts */
|
|
75
|
+
SCRIPT_HANPENDING, /* Have had only Han characters */
|
|
76
|
+
SCRIPT_HANHIRAKATA, /* Expect Han or Hirikata */
|
|
77
|
+
SCRIPT_HANBOPOMOFO, /* Expect Han or Bopomofo */
|
|
78
|
+
SCRIPT_HANHANGUL /* Expect Han or Hangul */
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
#define UCD_MAPSIZE (ucp_Unknown/32 + 1)
|
|
82
|
+
#define FULL_MAPSIZE (ucp_Script_Count/32 + 1)
|
|
83
|
+
|
|
84
|
+
BOOL
|
|
85
|
+
PRIV(script_run)(PCRE2_SPTR ptr, PCRE2_SPTR endptr, BOOL utf)
|
|
86
|
+
{
|
|
87
|
+
#ifdef SUPPORT_UNICODE
|
|
88
|
+
uint32_t require_state = SCRIPT_UNSET;
|
|
89
|
+
uint32_t require_map[FULL_MAPSIZE];
|
|
90
|
+
uint32_t map[FULL_MAPSIZE];
|
|
91
|
+
uint32_t require_digitset = 0;
|
|
92
|
+
uint32_t c;
|
|
93
|
+
|
|
94
|
+
#if PCRE2_CODE_UNIT_WIDTH == 32
|
|
95
|
+
(void)utf; /* Avoid compiler warning */
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
/* Any string containing fewer than 2 characters is a valid script run. */
|
|
99
|
+
|
|
100
|
+
if (ptr >= endptr) return TRUE;
|
|
101
|
+
GETCHARINCTEST(c, ptr);
|
|
102
|
+
if (ptr >= endptr) return TRUE;
|
|
103
|
+
|
|
104
|
+
/* Initialize the require map. This is a full-size bitmap that has a bit for
|
|
105
|
+
every script, as opposed to the maps in ucd_script_sets, which only have bits
|
|
106
|
+
for scripts less than ucp_Unknown - those that appear in script extension
|
|
107
|
+
lists. */
|
|
108
|
+
|
|
109
|
+
for (int i = 0; i < FULL_MAPSIZE; i++) require_map[i] = 0;
|
|
110
|
+
|
|
111
|
+
/* Scan strings of two or more characters, checking the Unicode characteristics
|
|
112
|
+
of each code point. There is special code for scripts that can be combined with
|
|
113
|
+
characters from the Han Chinese script. This may be used in conjunction with
|
|
114
|
+
four other scripts in these combinations:
|
|
115
|
+
|
|
116
|
+
. Han with Hiragana and Katakana is allowed (for Japanese).
|
|
117
|
+
. Han with Bopomofo is allowed (for Taiwanese Mandarin).
|
|
118
|
+
. Han with Hangul is allowed (for Korean).
|
|
119
|
+
|
|
120
|
+
If the first significant character's script is one of the four, the required
|
|
121
|
+
script type is immediately known. However, if the first significant
|
|
122
|
+
character's script is Han, we have to keep checking for a non-Han character.
|
|
123
|
+
Hence the SCRIPT_HANPENDING state. */
|
|
124
|
+
|
|
125
|
+
for (;;)
|
|
126
|
+
{
|
|
127
|
+
const ucd_record *ucd = GET_UCD(c);
|
|
128
|
+
uint32_t script = ucd->script;
|
|
129
|
+
|
|
130
|
+
/* If the script is Unknown, the string is not a valid script run. Such
|
|
131
|
+
characters can only form script runs of length one (see test above). */
|
|
132
|
+
|
|
133
|
+
if (script == ucp_Unknown) return FALSE;
|
|
134
|
+
|
|
135
|
+
/* A character without any script extensions whose script is Inherited or
|
|
136
|
+
Common is always accepted with any script. If there are extensions, the
|
|
137
|
+
following processing happens for all scripts. */
|
|
138
|
+
|
|
139
|
+
if (UCD_SCRIPTX_PROP(ucd) != 0 || (script != ucp_Inherited && script != ucp_Common))
|
|
140
|
+
{
|
|
141
|
+
BOOL OK;
|
|
142
|
+
|
|
143
|
+
/* Set up a full-sized map for this character that can include bits for all
|
|
144
|
+
scripts. Copy the scriptx map for this character (which covers those
|
|
145
|
+
scripts that appear in script extension lists), set the remaining values to
|
|
146
|
+
zero, and then, except for Common or Inherited, add this script's bit to
|
|
147
|
+
the map. */
|
|
148
|
+
|
|
149
|
+
memcpy(map, PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(ucd), UCD_MAPSIZE * sizeof(uint32_t));
|
|
150
|
+
memset(map + UCD_MAPSIZE, 0, (FULL_MAPSIZE - UCD_MAPSIZE) * sizeof(uint32_t));
|
|
151
|
+
if (script != ucp_Common && script != ucp_Inherited) MAPSET(map, script);
|
|
152
|
+
|
|
153
|
+
/* Handle the different checking states */
|
|
154
|
+
|
|
155
|
+
switch(require_state)
|
|
156
|
+
{
|
|
157
|
+
/* First significant character - it might follow Common or Inherited
|
|
158
|
+
characters that do not have any script extensions. */
|
|
159
|
+
|
|
160
|
+
case SCRIPT_UNSET:
|
|
161
|
+
switch(script)
|
|
162
|
+
{
|
|
163
|
+
case ucp_Han:
|
|
164
|
+
require_state = SCRIPT_HANPENDING;
|
|
165
|
+
break;
|
|
166
|
+
|
|
167
|
+
case ucp_Hiragana:
|
|
168
|
+
case ucp_Katakana:
|
|
169
|
+
require_state = SCRIPT_HANHIRAKATA;
|
|
170
|
+
break;
|
|
171
|
+
|
|
172
|
+
case ucp_Bopomofo:
|
|
173
|
+
require_state = SCRIPT_HANBOPOMOFO;
|
|
174
|
+
break;
|
|
175
|
+
|
|
176
|
+
case ucp_Hangul:
|
|
177
|
+
require_state = SCRIPT_HANHANGUL;
|
|
178
|
+
break;
|
|
179
|
+
|
|
180
|
+
default:
|
|
181
|
+
memcpy(require_map, map, FULL_MAPSIZE * sizeof(uint32_t));
|
|
182
|
+
require_state = SCRIPT_MAP;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
|
|
187
|
+
/* The first significant character was Han. An inspection of the Unicode
|
|
188
|
+
11.0.0 files shows that there are the following types of Script Extension
|
|
189
|
+
list that involve the Han, Bopomofo, Hiragana, Katakana, and Hangul
|
|
190
|
+
scripts:
|
|
191
|
+
|
|
192
|
+
. Bopomofo + Han
|
|
193
|
+
. Han + Hiragana + Katakana
|
|
194
|
+
. Hiragana + Katakana
|
|
195
|
+
. Bopopmofo + Hangul + Han + Hiragana + Katakana
|
|
196
|
+
|
|
197
|
+
The following code tries to make sense of this. */
|
|
198
|
+
|
|
199
|
+
#define FOUND_BOPOMOFO 1
|
|
200
|
+
#define FOUND_HIRAGANA 2
|
|
201
|
+
#define FOUND_KATAKANA 4
|
|
202
|
+
#define FOUND_HANGUL 8
|
|
203
|
+
|
|
204
|
+
case SCRIPT_HANPENDING:
|
|
205
|
+
if (script != ucp_Han) /* Another Han does nothing */
|
|
206
|
+
{
|
|
207
|
+
uint32_t chspecial = 0;
|
|
208
|
+
|
|
209
|
+
if (MAPBIT(map, ucp_Bopomofo) != 0) chspecial |= FOUND_BOPOMOFO;
|
|
210
|
+
if (MAPBIT(map, ucp_Hiragana) != 0) chspecial |= FOUND_HIRAGANA;
|
|
211
|
+
if (MAPBIT(map, ucp_Katakana) != 0) chspecial |= FOUND_KATAKANA;
|
|
212
|
+
if (MAPBIT(map, ucp_Hangul) != 0) chspecial |= FOUND_HANGUL;
|
|
213
|
+
|
|
214
|
+
if (chspecial == 0) return FALSE; /* Not allowed with Han */
|
|
215
|
+
|
|
216
|
+
if (chspecial == FOUND_BOPOMOFO)
|
|
217
|
+
require_state = SCRIPT_HANBOPOMOFO;
|
|
218
|
+
else if (chspecial == (FOUND_HIRAGANA|FOUND_KATAKANA))
|
|
219
|
+
require_state = SCRIPT_HANHIRAKATA;
|
|
220
|
+
|
|
221
|
+
/* Otherwise this character must be allowed with all of them, so remain
|
|
222
|
+
in the pending state. */
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
/* Previously encountered one of the "with Han" scripts. Check that
|
|
227
|
+
this character is appropriate. */
|
|
228
|
+
|
|
229
|
+
case SCRIPT_HANHIRAKATA:
|
|
230
|
+
if (MAPBIT(map, ucp_Han) + MAPBIT(map, ucp_Hiragana) +
|
|
231
|
+
MAPBIT(map, ucp_Katakana) == 0) return FALSE;
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
case SCRIPT_HANBOPOMOFO:
|
|
235
|
+
if (MAPBIT(map, ucp_Han) + MAPBIT(map, ucp_Bopomofo) == 0) return FALSE;
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case SCRIPT_HANHANGUL:
|
|
239
|
+
if (MAPBIT(map, ucp_Han) + MAPBIT(map, ucp_Hangul) == 0) return FALSE;
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
/* Previously encountered one or more characters that are allowed with a
|
|
243
|
+
list of scripts. */
|
|
244
|
+
|
|
245
|
+
case SCRIPT_MAP:
|
|
246
|
+
OK = FALSE;
|
|
247
|
+
|
|
248
|
+
for (int i = 0; i < FULL_MAPSIZE; i++)
|
|
249
|
+
{
|
|
250
|
+
if ((require_map[i] & map[i]) != 0)
|
|
251
|
+
{
|
|
252
|
+
OK = TRUE;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!OK) return FALSE;
|
|
258
|
+
|
|
259
|
+
/* The rest of the string must be in this script, but we have to
|
|
260
|
+
allow for the Han complications. */
|
|
261
|
+
|
|
262
|
+
switch(script)
|
|
263
|
+
{
|
|
264
|
+
case ucp_Han:
|
|
265
|
+
require_state = SCRIPT_HANPENDING;
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
case ucp_Hiragana:
|
|
269
|
+
case ucp_Katakana:
|
|
270
|
+
require_state = SCRIPT_HANHIRAKATA;
|
|
271
|
+
break;
|
|
272
|
+
|
|
273
|
+
case ucp_Bopomofo:
|
|
274
|
+
require_state = SCRIPT_HANBOPOMOFO;
|
|
275
|
+
break;
|
|
276
|
+
|
|
277
|
+
case ucp_Hangul:
|
|
278
|
+
require_state = SCRIPT_HANHANGUL;
|
|
279
|
+
break;
|
|
280
|
+
|
|
281
|
+
/* Compute the intersection of the required list of scripts and the
|
|
282
|
+
allowed scripts for this character. */
|
|
283
|
+
|
|
284
|
+
default:
|
|
285
|
+
for (int i = 0; i < FULL_MAPSIZE; i++) require_map[i] &= map[i];
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
} /* End checking character's script and extensions. */
|
|
292
|
+
|
|
293
|
+
/* The character is in an acceptable script. We must now ensure that all
|
|
294
|
+
decimal digits in the string come from the same set. Some scripts (e.g.
|
|
295
|
+
Common, Arabic) have more than one set of decimal digits. This code does
|
|
296
|
+
not allow mixing sets, even within the same script. The vector called
|
|
297
|
+
PRIV(ucd_digit_sets)[] contains, in its first element, the number of
|
|
298
|
+
following elements, and then, in ascending order, the code points of the
|
|
299
|
+
'9' characters in every set of 10 digits. Each set is identified by the
|
|
300
|
+
offset in the vector of its '9' character. An initial check of the first
|
|
301
|
+
value picks up ASCII digits quickly. Otherwise, a binary chop is used. */
|
|
302
|
+
|
|
303
|
+
if (ucd->chartype == ucp_Nd)
|
|
304
|
+
{
|
|
305
|
+
uint32_t digitset;
|
|
306
|
+
|
|
307
|
+
if (c <= PRIV(ucd_digit_sets)[1]) digitset = 1; else
|
|
308
|
+
{
|
|
309
|
+
int mid;
|
|
310
|
+
int bot = 1;
|
|
311
|
+
int top = PRIV(ucd_digit_sets)[0];
|
|
312
|
+
for (;;)
|
|
313
|
+
{
|
|
314
|
+
if (top <= bot + 1) /* <= rather than == is paranoia */
|
|
315
|
+
{
|
|
316
|
+
digitset = top;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
mid = (top + bot) / 2;
|
|
320
|
+
if (c <= PRIV(ucd_digit_sets)[mid]) top = mid; else bot = mid;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/* A required value of 0 means "unset". */
|
|
325
|
+
|
|
326
|
+
if (require_digitset == 0) require_digitset = digitset;
|
|
327
|
+
else if (digitset != require_digitset) return FALSE;
|
|
328
|
+
} /* End digit handling */
|
|
329
|
+
|
|
330
|
+
/* If we haven't yet got to the end, pick up the next character. */
|
|
331
|
+
|
|
332
|
+
if (ptr >= endptr) return TRUE;
|
|
333
|
+
GETCHARINCTEST(c, ptr);
|
|
334
|
+
} /* End checking loop */
|
|
335
|
+
|
|
336
|
+
#else /* NOT SUPPORT_UNICODE */
|
|
337
|
+
(void)ptr;
|
|
338
|
+
(void)endptr;
|
|
339
|
+
(void)utf;
|
|
340
|
+
return TRUE;
|
|
341
|
+
#endif /* SUPPORT_UNICODE */
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/* End of pcre2_script_run.c */
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/*************************************************
|
|
2
|
+
* Perl-Compatible Regular Expressions *
|
|
3
|
+
*************************************************/
|
|
4
|
+
|
|
5
|
+
/* PCRE is a library of functions to support regular expressions whose syntax
|
|
6
|
+
and semantics are as close as possible to those of the Perl 5 language.
|
|
7
|
+
|
|
8
|
+
Written by Philip Hazel
|
|
9
|
+
Original API code Copyright (c) 1997-2012 University of Cambridge
|
|
10
|
+
New API code Copyright (c) 2016-2020 University of Cambridge
|
|
11
|
+
|
|
12
|
+
-----------------------------------------------------------------------------
|
|
13
|
+
Redistribution and use in source and binary forms, with or without
|
|
14
|
+
modification, are permitted provided that the following conditions are met:
|
|
15
|
+
|
|
16
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer.
|
|
18
|
+
|
|
19
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
20
|
+
notice, this list of conditions and the following disclaimer in the
|
|
21
|
+
documentation and/or other materials provided with the distribution.
|
|
22
|
+
|
|
23
|
+
* Neither the name of the University of Cambridge nor the names of its
|
|
24
|
+
contributors may be used to endorse or promote products derived from
|
|
25
|
+
this software without specific prior written permission.
|
|
26
|
+
|
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
28
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
29
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
30
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
31
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
32
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
33
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
34
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
35
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
36
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
37
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
38
|
+
-----------------------------------------------------------------------------
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/* This module contains functions for serializing and deserializing
|
|
42
|
+
a sequence of compiled codes. */
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
#ifdef HAVE_CONFIG_H
|
|
46
|
+
#include "config.h"
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
#include "pcre2_internal.h"
|
|
51
|
+
|
|
52
|
+
/* Magic number to provide a small check against being handed junk. */
|
|
53
|
+
|
|
54
|
+
#define SERIALIZED_DATA_MAGIC 0x50523253u
|
|
55
|
+
|
|
56
|
+
/* Deserialization is limited to the current PCRE version and
|
|
57
|
+
character width. */
|
|
58
|
+
|
|
59
|
+
#define SERIALIZED_DATA_VERSION \
|
|
60
|
+
((PCRE2_MAJOR) | ((PCRE2_MINOR) << 16))
|
|
61
|
+
|
|
62
|
+
#define SERIALIZED_DATA_CONFIG \
|
|
63
|
+
(sizeof(PCRE2_UCHAR) | ((sizeof(void*)) << 8) | ((sizeof(PCRE2_SIZE)) << 16))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/*************************************************
|
|
68
|
+
* Serialize compiled patterns *
|
|
69
|
+
*************************************************/
|
|
70
|
+
|
|
71
|
+
PCRE2_EXP_DEFN int32_t PCRE2_CALL_CONVENTION
|
|
72
|
+
pcre2_serialize_encode(const pcre2_code **codes, int32_t number_of_codes,
|
|
73
|
+
uint8_t **serialized_bytes, PCRE2_SIZE *serialized_size,
|
|
74
|
+
pcre2_general_context *gcontext)
|
|
75
|
+
{
|
|
76
|
+
uint8_t *bytes;
|
|
77
|
+
uint8_t *dst_bytes;
|
|
78
|
+
int32_t i;
|
|
79
|
+
PCRE2_SIZE total_size;
|
|
80
|
+
const pcre2_real_code *re;
|
|
81
|
+
const uint8_t *tables;
|
|
82
|
+
pcre2_serialized_data *data;
|
|
83
|
+
|
|
84
|
+
const pcre2_memctl *memctl = (gcontext != NULL) ?
|
|
85
|
+
&gcontext->memctl : &PRIV(default_compile_context).memctl;
|
|
86
|
+
|
|
87
|
+
if (codes == NULL || serialized_bytes == NULL || serialized_size == NULL)
|
|
88
|
+
return PCRE2_ERROR_NULL;
|
|
89
|
+
|
|
90
|
+
if (number_of_codes <= 0) return PCRE2_ERROR_BADDATA;
|
|
91
|
+
|
|
92
|
+
/* Compute total size. */
|
|
93
|
+
total_size = sizeof(pcre2_serialized_data) + TABLES_LENGTH;
|
|
94
|
+
tables = NULL;
|
|
95
|
+
|
|
96
|
+
for (i = 0; i < number_of_codes; i++)
|
|
97
|
+
{
|
|
98
|
+
if (codes[i] == NULL) return PCRE2_ERROR_NULL;
|
|
99
|
+
re = (const pcre2_real_code *)(codes[i]);
|
|
100
|
+
if (re->magic_number != MAGIC_NUMBER) return PCRE2_ERROR_BADMAGIC;
|
|
101
|
+
if (tables == NULL)
|
|
102
|
+
tables = re->tables;
|
|
103
|
+
else if (tables != re->tables)
|
|
104
|
+
return PCRE2_ERROR_MIXEDTABLES;
|
|
105
|
+
total_size += re->blocksize;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* Initialize the byte stream. */
|
|
109
|
+
bytes = memctl->malloc(total_size + sizeof(pcre2_memctl), memctl->memory_data);
|
|
110
|
+
if (bytes == NULL) return PCRE2_ERROR_NOMEMORY;
|
|
111
|
+
|
|
112
|
+
/* The controller is stored as a hidden parameter. */
|
|
113
|
+
memcpy(bytes, memctl, sizeof(pcre2_memctl));
|
|
114
|
+
bytes += sizeof(pcre2_memctl);
|
|
115
|
+
|
|
116
|
+
data = (pcre2_serialized_data *)bytes;
|
|
117
|
+
data->magic = SERIALIZED_DATA_MAGIC;
|
|
118
|
+
data->version = SERIALIZED_DATA_VERSION;
|
|
119
|
+
data->config = SERIALIZED_DATA_CONFIG;
|
|
120
|
+
data->number_of_codes = number_of_codes;
|
|
121
|
+
|
|
122
|
+
/* Copy all compiled code data. */
|
|
123
|
+
dst_bytes = bytes + sizeof(pcre2_serialized_data);
|
|
124
|
+
memcpy(dst_bytes, tables, TABLES_LENGTH);
|
|
125
|
+
dst_bytes += TABLES_LENGTH;
|
|
126
|
+
|
|
127
|
+
for (i = 0; i < number_of_codes; i++)
|
|
128
|
+
{
|
|
129
|
+
re = (const pcre2_real_code *)(codes[i]);
|
|
130
|
+
(void)memcpy(dst_bytes, (char *)re, re->blocksize);
|
|
131
|
+
|
|
132
|
+
/* Certain fields in the compiled code block are re-set during
|
|
133
|
+
deserialization. In order to ensure that the serialized data stream is always
|
|
134
|
+
the same for the same pattern, set them to zero here. We can't assume the
|
|
135
|
+
copy of the pattern is correctly aligned for accessing the fields as part of
|
|
136
|
+
a structure. Note the use of sizeof(void *) in the second of these, to
|
|
137
|
+
specify the size of a pointer. If sizeof(uint8_t *) is used (tables is a
|
|
138
|
+
pointer to uint8_t), gcc gives a warning because the first argument is also a
|
|
139
|
+
pointer to uint8_t. Casting the first argument to (void *) can stop this, but
|
|
140
|
+
it didn't stop Coverity giving the same complaint. */
|
|
141
|
+
|
|
142
|
+
(void)memset(dst_bytes + offsetof(pcre2_real_code, memctl), 0,
|
|
143
|
+
sizeof(pcre2_memctl));
|
|
144
|
+
(void)memset(dst_bytes + offsetof(pcre2_real_code, tables), 0,
|
|
145
|
+
sizeof(void *));
|
|
146
|
+
(void)memset(dst_bytes + offsetof(pcre2_real_code, executable_jit), 0,
|
|
147
|
+
sizeof(void *));
|
|
148
|
+
|
|
149
|
+
dst_bytes += re->blocksize;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
*serialized_bytes = bytes;
|
|
153
|
+
*serialized_size = total_size;
|
|
154
|
+
return number_of_codes;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/*************************************************
|
|
159
|
+
* Deserialize compiled patterns *
|
|
160
|
+
*************************************************/
|
|
161
|
+
|
|
162
|
+
PCRE2_EXP_DEFN int32_t PCRE2_CALL_CONVENTION
|
|
163
|
+
pcre2_serialize_decode(pcre2_code **codes, int32_t number_of_codes,
|
|
164
|
+
const uint8_t *bytes, pcre2_general_context *gcontext)
|
|
165
|
+
{
|
|
166
|
+
const pcre2_serialized_data *data = (const pcre2_serialized_data *)bytes;
|
|
167
|
+
const pcre2_memctl *memctl = (gcontext != NULL) ?
|
|
168
|
+
&gcontext->memctl : &PRIV(default_compile_context).memctl;
|
|
169
|
+
|
|
170
|
+
const uint8_t *src_bytes;
|
|
171
|
+
pcre2_real_code *dst_re;
|
|
172
|
+
uint8_t *tables;
|
|
173
|
+
int32_t i, j;
|
|
174
|
+
|
|
175
|
+
/* Sanity checks. */
|
|
176
|
+
|
|
177
|
+
if (data == NULL || codes == NULL) return PCRE2_ERROR_NULL;
|
|
178
|
+
if (number_of_codes <= 0) return PCRE2_ERROR_BADDATA;
|
|
179
|
+
if (data->number_of_codes <= 0) return PCRE2_ERROR_BADSERIALIZEDDATA;
|
|
180
|
+
if (data->magic != SERIALIZED_DATA_MAGIC) return PCRE2_ERROR_BADMAGIC;
|
|
181
|
+
if (data->version != SERIALIZED_DATA_VERSION) return PCRE2_ERROR_BADMODE;
|
|
182
|
+
if (data->config != SERIALIZED_DATA_CONFIG) return PCRE2_ERROR_BADMODE;
|
|
183
|
+
|
|
184
|
+
if (number_of_codes > data->number_of_codes)
|
|
185
|
+
number_of_codes = data->number_of_codes;
|
|
186
|
+
|
|
187
|
+
src_bytes = bytes + sizeof(pcre2_serialized_data);
|
|
188
|
+
|
|
189
|
+
/* Decode tables. The reference count for the tables is stored immediately
|
|
190
|
+
following them. */
|
|
191
|
+
|
|
192
|
+
tables = memctl->malloc(TABLES_LENGTH + sizeof(PCRE2_SIZE), memctl->memory_data);
|
|
193
|
+
if (tables == NULL) return PCRE2_ERROR_NOMEMORY;
|
|
194
|
+
|
|
195
|
+
memcpy(tables, src_bytes, TABLES_LENGTH);
|
|
196
|
+
*(PCRE2_SIZE *)(tables + TABLES_LENGTH) = number_of_codes;
|
|
197
|
+
src_bytes += TABLES_LENGTH;
|
|
198
|
+
|
|
199
|
+
/* Decode the byte stream. We must not try to read the size from the compiled
|
|
200
|
+
code block in the stream, because it might be unaligned, which causes errors on
|
|
201
|
+
hardware such as Sparc-64 that doesn't like unaligned memory accesses. The type
|
|
202
|
+
of the blocksize field is given its own name to ensure that it is the same here
|
|
203
|
+
as in the block. */
|
|
204
|
+
|
|
205
|
+
for (i = 0; i < number_of_codes; i++)
|
|
206
|
+
{
|
|
207
|
+
CODE_BLOCKSIZE_TYPE blocksize;
|
|
208
|
+
memcpy(&blocksize, src_bytes + offsetof(pcre2_real_code, blocksize),
|
|
209
|
+
sizeof(CODE_BLOCKSIZE_TYPE));
|
|
210
|
+
if (blocksize <= sizeof(pcre2_real_code))
|
|
211
|
+
return PCRE2_ERROR_BADSERIALIZEDDATA;
|
|
212
|
+
|
|
213
|
+
/* The allocator provided by gcontext replaces the original one. */
|
|
214
|
+
|
|
215
|
+
dst_re = (pcre2_real_code *)PRIV(memctl_malloc)(blocksize,
|
|
216
|
+
(pcre2_memctl *)gcontext);
|
|
217
|
+
if (dst_re == NULL)
|
|
218
|
+
{
|
|
219
|
+
memctl->free(tables, memctl->memory_data);
|
|
220
|
+
for (j = 0; j < i; j++)
|
|
221
|
+
{
|
|
222
|
+
memctl->free(codes[j], memctl->memory_data);
|
|
223
|
+
codes[j] = NULL;
|
|
224
|
+
}
|
|
225
|
+
return PCRE2_ERROR_NOMEMORY;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/* The new allocator must be preserved. */
|
|
229
|
+
|
|
230
|
+
memcpy(((uint8_t *)dst_re) + sizeof(pcre2_memctl),
|
|
231
|
+
src_bytes + sizeof(pcre2_memctl), blocksize - sizeof(pcre2_memctl));
|
|
232
|
+
if (dst_re->magic_number != MAGIC_NUMBER ||
|
|
233
|
+
dst_re->name_entry_size > MAX_NAME_SIZE + IMM2_SIZE + 1 ||
|
|
234
|
+
dst_re->name_count > MAX_NAME_COUNT)
|
|
235
|
+
{
|
|
236
|
+
memctl->free(dst_re, memctl->memory_data);
|
|
237
|
+
return PCRE2_ERROR_BADSERIALIZEDDATA;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* At the moment only one table is supported. */
|
|
241
|
+
|
|
242
|
+
dst_re->tables = tables;
|
|
243
|
+
dst_re->executable_jit = NULL;
|
|
244
|
+
dst_re->flags |= PCRE2_DEREF_TABLES;
|
|
245
|
+
|
|
246
|
+
codes[i] = dst_re;
|
|
247
|
+
src_bytes += blocksize;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return number_of_codes;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
/*************************************************
|
|
255
|
+
* Get the number of serialized patterns *
|
|
256
|
+
*************************************************/
|
|
257
|
+
|
|
258
|
+
PCRE2_EXP_DEFN int32_t PCRE2_CALL_CONVENTION
|
|
259
|
+
pcre2_serialize_get_number_of_codes(const uint8_t *bytes)
|
|
260
|
+
{
|
|
261
|
+
const pcre2_serialized_data *data = (const pcre2_serialized_data *)bytes;
|
|
262
|
+
|
|
263
|
+
if (data == NULL) return PCRE2_ERROR_NULL;
|
|
264
|
+
if (data->magic != SERIALIZED_DATA_MAGIC) return PCRE2_ERROR_BADMAGIC;
|
|
265
|
+
if (data->version != SERIALIZED_DATA_VERSION) return PCRE2_ERROR_BADMODE;
|
|
266
|
+
if (data->config != SERIALIZED_DATA_CONFIG) return PCRE2_ERROR_BADMODE;
|
|
267
|
+
|
|
268
|
+
return data->number_of_codes;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
/*************************************************
|
|
273
|
+
* Free the allocated stream *
|
|
274
|
+
*************************************************/
|
|
275
|
+
|
|
276
|
+
PCRE2_EXP_DEFN void PCRE2_CALL_CONVENTION
|
|
277
|
+
pcre2_serialize_free(uint8_t *bytes)
|
|
278
|
+
{
|
|
279
|
+
if (bytes != NULL)
|
|
280
|
+
{
|
|
281
|
+
pcre2_memctl *memctl = (pcre2_memctl *)(bytes - sizeof(pcre2_memctl));
|
|
282
|
+
memctl->free(memctl, memctl->memory_data);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* End of pcre2_serialize.c */
|