Skip to content

Commit db793cc

Browse files
committed
Index type members by name - see #10
1 parent 833257a commit db793cc

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ XP Compiler ChangeLog
33

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

6+
* Indexed type members by name; implementing feature suggested in #10
7+
(@thekid)
68
* **Heads up:** Implemented syntax for parameter annotations as stated
79
in issue #1 - alongside the parameter; no longer in its "targeted" form
810
`$param: inject` as in https://github.com/xp-framework/rfc/issues/218

src/main/php/lang/ast/Parse.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ private function body() {
996996
}
997997

998998
$member->value= [$name, $modifiers, $signature, $annotations, $statements];
999-
$body[]= $member;
999+
$body[$name.'()']= $member;
10001000
$modifiers= [];
10011001
$annotations= null;
10021002
} else if ('const' === $this->token->symbol->id) {
@@ -1012,7 +1012,7 @@ private function body() {
10121012
$this->token= $this->expect('=');
10131013

10141014
$member->value= [$name, $modifiers, $this->expression(0)];
1015-
$body[]= $member;
1015+
$body[$name]= $member;
10161016
if (',' === $this->token->symbol->id) {
10171017
$this->token= $this->expect(',');
10181018
}
@@ -1035,7 +1035,7 @@ private function body() {
10351035
$member->value= [$name, $modifiers, null, $type, $annotations];
10361036
}
10371037

1038-
$body[]= $member;
1038+
$body['$'.$name]= $member;
10391039
if (',' === $this->token->symbol->id) {
10401040
$this->token= $this->expect(',');
10411041
}

src/test/php/lang/ast/unittest/parse/CompactFunctionsTest.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function short_method() {
1515
$block= [['==>' => ['true' => 'true']]];
1616
$this->assertNodes(
1717
[['class' => ['\\A', [], null, [], [
18-
['function' => ['a', ['public'], [[], null], null, $block]]
18+
'a()' => ['function' => ['a', ['public'], [[], null], null, $block]]
1919
], []]]],
2020
$this->parse('class A { public function a() ==> true; }')
2121
);

src/test/php/lang/ast/unittest/parse/MembersTest.class.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class MembersTest extends ParseTest {
77
#[@test]
88
public function private_instance_property() {
99
$this->assertNodes(
10-
[['class' => ['\\A', [], null, [], [['(variable)' => ['a', ['private'], null, null, null]]], []]]],
10+
[['class' => ['\\A', [], null, [], ['$a' => ['(variable)' => ['a', ['private'], null, null, null]]], []]]],
1111
$this->parse('class A { private $a; }')
1212
);
1313
}
@@ -16,8 +16,8 @@ public function private_instance_property() {
1616
public function private_instance_properties() {
1717
$this->assertNodes(
1818
[['class' => ['\\A', [], null, [], [
19-
['(variable)' => ['a', ['private'], null, null, null]],
20-
['(variable)' => ['b', ['private'], null, null, null]],
19+
'$a' => ['(variable)' => ['a', ['private'], null, null, null]],
20+
'$b' => ['(variable)' => ['b', ['private'], null, null, null]],
2121
], []]]],
2222
$this->parse('class A { private $a, $b; }')
2323
);
@@ -27,7 +27,7 @@ public function private_instance_properties() {
2727
public function private_instance_method() {
2828
$this->assertNodes(
2929
[['class' => ['\\A', [], null, [], [
30-
['function' => ['a', ['private'], [[], null], null, []]]
30+
'a()' => ['function' => ['a', ['private'], [[], null], null, []]]
3131
], []]]],
3232
$this->parse('class A { private function a() { } }')
3333
);
@@ -37,7 +37,7 @@ public function private_instance_method() {
3737
public function private_static_method() {
3838
$this->assertNodes(
3939
[['class' => ['\\A', [], null, [], [
40-
['function' => ['a', ['private', 'static'], [[], null], null, []]]
40+
'a()' => ['function' => ['a', ['private', 'static'], [[], null], null, []]]
4141
], []]]],
4242
$this->parse('class A { private static function a() { } }')
4343
);
@@ -46,7 +46,7 @@ public function private_static_method() {
4646
#[@test]
4747
public function class_constant() {
4848
$this->assertNodes(
49-
[['class' => ['\\A', [], null, [], [['const' => ['T', [], ['(literal)' => '1']]]], []]]],
49+
[['class' => ['\\A', [], null, [], ['T' => ['const' => ['T', [], ['(literal)' => '1']]]], []]]],
5050
$this->parse('class A { const T = 1; }')
5151
);
5252
}
@@ -55,8 +55,8 @@ public function class_constant() {
5555
public function class_constants() {
5656
$this->assertNodes(
5757
[['class' => ['\\A', [], null, [], [
58-
['const' => ['T', [], ['(literal)' => '1']]],
59-
['const' => ['S', [], ['(literal)' => '2']]]
58+
'T' => ['const' => ['T', [], ['(literal)' => '1']]],
59+
'S' => ['const' => ['S', [], ['(literal)' => '2']]]
6060
], []]]],
6161
$this->parse('class A { const T = 1, S = 2; }')
6262
);
@@ -65,7 +65,7 @@ public function class_constants() {
6565
#[@test]
6666
public function private_class_constant() {
6767
$this->assertNodes(
68-
[['class' => ['\\A', [], null, [], [['const' => ['T', ['private'], ['(literal)' => '1']]]], []]]],
68+
[['class' => ['\\A', [], null, [], ['T' => ['const' => ['T', ['private'], ['(literal)' => '1']]]], []]]],
6969
$this->parse('class A { private const T = 1; }')
7070
);
7171
}
@@ -74,7 +74,7 @@ public function private_class_constant() {
7474
public function method_with_return_type() {
7575
$this->assertNodes(
7676
[['class' => ['\\A', [], null, [], [
77-
['function' => ['a', ['public'], [[], new Type('void')], null, []]]
77+
'a()' => ['function' => ['a', ['public'], [[], new Type('void')], null, []]]
7878
], []]]],
7979
$this->parse('class A { public function a(): void { } }')
8080
);
@@ -85,7 +85,7 @@ public function method_with_annotation() {
8585
$annotations= [['test']];
8686
$this->assertNodes(
8787
[['class' => ['\\A', [], null, [], [
88-
['function' => ['a', ['public'], [[], null], $annotations, []]]
88+
'a()' => ['function' => ['a', ['public'], [[], null], $annotations, []]]
8989
], []]]],
9090
$this->parse('class A { <<test>> public function a() { } }')
9191
);
@@ -96,7 +96,7 @@ public function method_with_annotations() {
9696
$annotations= [['test'], ['ignore', ['(literal)' => '"Not implemented"']]];
9797
$this->assertNodes(
9898
[['class' => ['\\A', [], null, [], [
99-
['function' => ['a', ['public'], [[], null], $annotations, []]]
99+
'a()' => ['function' => ['a', ['public'], [[], null], $annotations, []]]
100100
], []]]],
101101
$this->parse('class A { <<test, ignore("Not implemented")>> public function a() { } }')
102102
);

0 commit comments

Comments
 (0)