From d5ec637eeb61badaaed664b78f694d22266bd8ba Mon Sep 17 00:00:00 2001 From: Mikhail Kornaukhov <66915223+mkornaukhov03@users.noreply.github.com> Date: Mon, 20 Jan 2025 13:09:54 +0300 Subject: [PATCH] Support CompileTimeLocation in K2 (#1213) --- .../kphp-light/unsupported/misc.txt | 5 ++- .../diagnostics/compile-time-location.h | 34 +++++++++++++++++++ .../exception-functions.h | 0 tests/phpt/array/027_explode.php | 2 +- tests/phpt/cl/197_compile_time_location.php | 2 +- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 runtime-light/stdlib/diagnostics/compile-time-location.h rename runtime-light/stdlib/{exception => diagnostics}/exception-functions.h (100%) diff --git a/builtin-functions/kphp-light/unsupported/misc.txt b/builtin-functions/kphp-light/unsupported/misc.txt index 64f2080653..4b3fb277c3 100644 --- a/builtin-functions/kphp-light/unsupported/misc.txt +++ b/builtin-functions/kphp-light/unsupported/misc.txt @@ -41,7 +41,6 @@ function ctype_digit(mixed $text): bool; function ctype_xdigit(mixed $text): bool; /** - * @kphp-generate-stub-class * @kphp-immutable-class */ class CompileTimeLocation { @@ -49,9 +48,9 @@ class CompileTimeLocation { public string $function; public int $line; - /** @kphp-extern-func-info generate-stub */ + /** @kphp-extern-func-info */ public function __construct($file ::: string, $function ::: string, $line ::: int) ::: CompileTimeLocation; - /** @kphp-extern-func-info generate-stub */ + /** @kphp-extern-func-info */ static public function calculate(?CompileTimeLocation $passed) ::: CompileTimeLocation; } diff --git a/runtime-light/stdlib/diagnostics/compile-time-location.h b/runtime-light/stdlib/diagnostics/compile-time-location.h new file mode 100644 index 0000000000..d220fe384b --- /dev/null +++ b/runtime-light/stdlib/diagnostics/compile-time-location.h @@ -0,0 +1,34 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2024 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#include "runtime-common/stdlib/visitors/common-visitors-methods.h" + +struct C$CompileTimeLocation : public refcountable_php_classes, private CommonDefaultVisitorMethods { + string $file; + string $function; + int64_t $line; + + ~C$CompileTimeLocation() = default; + + const char *get_class() const noexcept { + return "CompileTimeLocation"; + } + + using CommonDefaultVisitorMethods::accept; +}; + +using CompileTimeLocation = class_instance; + +inline CompileTimeLocation f$CompileTimeLocation$$__construct(const CompileTimeLocation &v$this, const string &file, const string &function, int64_t line) { + v$this->$file = file; + v$this->$function = function; + v$this->$line = line; + return v$this; +} + +inline CompileTimeLocation f$CompileTimeLocation$$calculate(const CompileTimeLocation &v$passed) { + return v$passed; +} diff --git a/runtime-light/stdlib/exception/exception-functions.h b/runtime-light/stdlib/diagnostics/exception-functions.h similarity index 100% rename from runtime-light/stdlib/exception/exception-functions.h rename to runtime-light/stdlib/diagnostics/exception-functions.h diff --git a/tests/phpt/array/027_explode.php b/tests/phpt/array/027_explode.php index 0e39999797..9e3b9bbddf 100644 --- a/tests/phpt/array/027_explode.php +++ b/tests/phpt/array/027_explode.php @@ -1,4 +1,4 @@ -@ok k2_skip +@ok