Skip to content

Commit

Permalink
Support CompileTimeLocation in K2 (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkornaukhov03 authored Jan 20, 2025
1 parent 1964df3 commit d5ec637
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
5 changes: 2 additions & 3 deletions builtin-functions/kphp-light/unsupported/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ function ctype_digit(mixed $text): bool;
function ctype_xdigit(mixed $text): bool;

/**
* @kphp-generate-stub-class
* @kphp-immutable-class
*/
class CompileTimeLocation {
public string $file;
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;
}

34 changes: 34 additions & 0 deletions runtime-light/stdlib/diagnostics/compile-time-location.h
Original file line number Diff line number Diff line change
@@ -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<C$CompileTimeLocation>, 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<C$CompileTimeLocation>;

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;
}
2 changes: 1 addition & 1 deletion tests/phpt/array/027_explode.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@ok k2_skip
@ok
<?php

require_once 'kphp_tester_include.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/phpt/cl/197_compile_time_location.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@ok k2_skip
@ok
<?php

require_once 'kphp_tester_include.php';
Expand Down

0 comments on commit d5ec637

Please sign in to comment.