Skip to content

Commit dae1ca0

Browse files
committed
Adapt to AST type refactoring
See xp-framework/ast#39
1 parent ae9ceb8 commit dae1ca0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ XP records for PHP - ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 2.4.0 / 2022-12-04
7+
8+
* Adapt to AST type refactoring (xp-framework/ast#39) - @thekid
9+
610
## 2.3.0 / 2022-02-05
711

812
* Add support for `readonly` record parameters. See issue #7 - @thekid

src/main/php/lang/ast/syntax/php/Records.class.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Variable
1515
};
1616
use lang\ast\syntax\Extension;
17-
use lang\ast\types\{IsArray, IsLiteral};
17+
use lang\ast\types\{IsArray, IsLiteral, IsValue};
1818

1919
class Records implements Extension {
2020

@@ -26,30 +26,26 @@ public static function inject(&$type, $name, $signature, $body) {
2626

2727
public function setup($language, $emitter) {
2828
$language->stmt('record', function($parse, $token) {
29-
$type= $parse->scope->resolve($parse->token->value);
30-
$parse->forward();
31-
3229
$comment= $parse->comment;
33-
$parse->comment= null;
3430
$line= $parse->token->line;
31+
$parse->comment= null;
3532

33+
$type= $this->type($parse, false);
3634
$parse->expecting('(', 'record');
3735
$components= $this->parameters($parse, []);
3836
$parse->expecting(')', 'record');
3937

4038
$parent= null;
4139
if ('extends' === $parse->token->value) {
4240
$parse->forward();
43-
$parent= $parse->scope->resolve($parse->token->value);
44-
$parse->forward();
41+
$parent= $this->type($parse, false);
4542
}
4643

4744
$implements= [];
4845
if ('implements' === $parse->token->value) {
4946
$parse->forward();
5047
do {
51-
$implements[]= $parse->scope->resolve($parse->token->value);
52-
$parse->forward();
48+
$implements[]= $this->type($parse, false);
5349
if (',' === $parse->token->value) {
5450
$parse->forward();
5551
} else if ('{' === $parse->token->value) {
@@ -136,6 +132,7 @@ public function setup($language, $emitter) {
136132
self::inject($body, 'compareTo', new Signature([new Parameter('value', null)], new IsLiteral('int')), new Code(
137133
'$value instanceof self ? \\util\\Objects::compare(['.substr($object, 2).'], ['.substr($value, 2).']) : 1'
138134
));
135+
$node->implements[]= new IsValue('\\lang\\Value');
139136

140137
// Add decomposition
141138
self::inject($body, '__invoke', new Signature([new Parameter('map', new IsLiteral('callable'), new Literal('null'))], null), new Code(
@@ -146,7 +143,7 @@ public function setup($language, $emitter) {
146143
['final'],
147144
$node->name,
148145
$node->parent,
149-
array_merge(['\\lang\\Value'], $node->implements),
146+
$node->implements,
150147
$body,
151148
$node->annotations,
152149
$node->comment,

0 commit comments

Comments
 (0)