Skip to content

Commit

Permalink
PHP 8.3 Support: Arbitrary static variable initializers (Part 1)
Browse files Browse the repository at this point in the history
- apache#6701
- apache#8073
- https://wiki.php.net/rfc/arbitrary_static_variable_initializers
- Fix the grammar file (parser)
- Add unit tests for the parser

Example:
```php
class Example {
    private int $field = 1;

    public function method(): int {
        return 1;
    }

    public function run(int $param1) : void {
        static $example1 = rand();
        static $example2 = $param1;
        static $example3 = $this->field;
        static $example4 = $this->method();
        static $example5 = new class() {};
        static $example6 = new stdClass(...[0]);
        static $example6 = new stdClass($param1);
        static $example7 = new (Test);
        static $example8 = new static;
        static $example9 = $param1 <= 100 ? run($param1 + 1) : "Test $param1";
        static $example10 = rand(), $example11 = rand();
    }
}

$variable = 1;
static $example1 = rand();
static $example2 = $variable;
```
  • Loading branch information
junichi11 committed Dec 19, 2024
1 parent 22172a9 commit d0f037d
Show file tree
Hide file tree
Showing 27 changed files with 2,227 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
// Tue May 14 21:41:03 NOVT 2024
// Thu Dec 19 14:22:13 JST 2024
//----------------------------------------------------

package org.netbeans.modules.php.editor.parser;
Expand All @@ -30,7 +30,7 @@
import org.openide.util.Pair;

/** CUP v0.11a beta 20060608 generated parser.
* @version Tue May 14 21:41:03 NOVT 2024
* @version Thu Dec 19 14:22:13 JST 2024
*/
@org.netbeans.api.annotations.common.SuppressWarnings({"EI_EXPOSE_REP", "MS_PKGPROTECT", "BC_BAD_CAST_TO_CONCRETE_COLLECTION"})
public class ASTPHP5Parser extends java_cup.runtime.lr_parser {
Expand Down Expand Up @@ -2343,67 +2343,75 @@ public class ASTPHP5Parser extends java_cup.runtime.lr_parser {
"\324\u038f\327\u038e\001\001\000\002\001\001\000\002\001" +
"\001\000\002\001\001\000\002\001\001\000\002\001\001" +
"\000\002\001\001\000\002\001\001\000\002\001\001\000" +
"\002\001\001\000\002\001\001\000\002\001\001\000\032" +
"\004\346\074\336\075\u0625\077\335\101\352\167\354\177" +
"\333\200\337\307\344\311\334\312\341\315\356\001\001" +
"\000\002\001\001\000\034\004\346\074\336\076\u0627\077" +
"\u024a\100\u024b\101\352\167\354\177\333\200\337\307\344" +
"\311\334\312\341\315\356\001\001\000\002\001\001\000" +
"\004\150\u0629\001\001\000\002\001\001\000\024\043\u062b" +
"\046\u0221\047\u0223\210\u0225\272\u0224\274\u021f\323\135\324" +
"\u0220\333\u0222\001\001\000\002\001\001\000\004\255\u062d" +
"\001\001\000\002\001\001\000\004\017\u062f\001\001\000" +
"\156\004\125\016\u038c\020\u038a\021\144\066\151\067\133" +
"\070\013\071\064\074\042\102\132\106\110\110\166\113" +
"\130\114\101\115\124\116\213\123\136\124\211\125\117" +
"\126\226\137\222\147\023\151\057\167\054\170\041\171" +
"\146\172\131\173\100\174\060\175\066\177\172\200\051" +
"\216\016\217\070\220\046\231\203\232\076\233\040\234" +
"\010\235\175\256\105\260\163\261\021\263\157\266\043" +
"\277\221\300\216\302\031\303\075\304\074\316\165\323" +
"\135\324\u038f\327\u038e\001\001\000\002\001\001\000\136" +
"\004\125\050\u0632\051\u020f\052\u01fb\053\u0203\066\u0211\067" +
"\133\070\013\071\064\074\042\102\132\106\u01ad\115\124" +
"\116\213\123\136\124\211\125\117\126\226\137\222\147" +
"\023\150\u0201\167\054\170\041\171\146\172\131\173\100" +
"\174\060\175\066\177\172\200\051\202\u019c\203\u01fc\220" +
"\u01ff\256\105\260\163\261\021\263\157\266\043\277\221" +
"\300\216\302\031\303\075\304\074\316\165\323\135\324" +
"\u01ab\001\001\000\002\001\001\000\002\001\001\000\002" +
"\001\001\000\002\001\001\000\004\104\u0638\001\001\000" +
"\010\177\u0635\200\337\325\u063a\001\001\000\002\001\001" +
"\000\002\001\001\000\002\001\001\000\136\004\125\050" +
"\u063c\051\u020f\052\u01fb\053\u0203\066\u0211\067\133\070\013" +
"\071\064\074\042\102\132\106\u01ad\115\124\116\213\123" +
"\136\124\211\125\117\126\226\137\222\147\023\150\u0201" +
"\167\054\170\041\171\146\172\131\173\100\174\060\175" +
"\066\177\172\200\051\202\u019c\203\u01fc\220\u01ff\256\105" +
"\260\163\261\021\263\157\266\043\277\221\300\216\302" +
"\031\303\075\304\074\316\165\323\135\324\u01ab\001\001" +
"\000\002\001\001\000\002\001\001\000\002\001\001\000" +
"\002\001\001\000\056\070\013\071\064\123\u026a\124\211" +
"\125\117\126\226\137\222\170\041\173\u0266\174\060\177" +
"\172\200\051\220\u0643\256\u0642\261\021\263\157\266\043" +
"\300\u0267\302\031\303\075\304\074\316\165\001\001\000" +
"\002\001\001\000\002\001\001\000\002\001\001\000\120" +
"\004\125\066\151\067\133\070\013\071\064\074\042\102" +
"\132\106\u0645\115\124\116\213\123\136\124\211\125\117" +
"\132\106\u0625\115\124\116\213\123\136\124\211\125\117" +
"\126\226\137\222\147\023\167\054\170\041\171\146\172" +
"\131\173\100\174\060\175\066\177\172\200\051\220\046" +
"\256\105\260\163\261\021\263\157\266\043\277\221\300" +
"\216\302\031\303\075\304\074\316\165\323\135\324\u01ab" +
"\001\001\000\002\001\001\000\002\001\001\000\004\055" +
"\u0649\001\001\000\002\001\001\000\002\001\001\000\006" +
"\145\u0543\266\u0542\001\001\000\002\001\001\000\136\004" +
"\125\050\u064d\051\u020f\052\u01fb\053\u0203\066\u0211\067\133" +
"\001\001\000\002\001\001\000\120\004\125\066\151\067" +
"\133\070\013\071\064\074\042\102\132\106\u0627\115\124" +
"\116\213\123\136\124\211\125\117\126\226\137\222\147" +
"\023\167\054\170\041\171\146\172\131\173\100\174\060" +
"\175\066\177\172\200\051\220\046\256\105\260\163\261" +
"\021\263\157\266\043\277\221\300\216\302\031\303\075" +
"\304\074\316\165\323\135\324\u01ab\001\001\000\002\001" +
"\001\000\004\150\u0629\001\001\000\002\001\001\000\024" +
"\043\u062b\046\u0221\047\u0223\210\u0225\272\u0224\274\u021f\323" +
"\135\324\u0220\333\u0222\001\001\000\002\001\001\000\004" +
"\255\u062d\001\001\000\002\001\001\000\004\017\u062f\001" +
"\001\000\156\004\125\016\u038c\020\u038a\021\144\066\151" +
"\067\133\070\013\071\064\074\042\102\132\106\110\110" +
"\166\113\130\114\101\115\124\116\213\123\136\124\211" +
"\125\117\126\226\137\222\147\023\151\057\167\054\170" +
"\041\171\146\172\131\173\100\174\060\175\066\177\172" +
"\200\051\216\016\217\070\220\046\231\203\232\076\233" +
"\040\234\010\235\175\256\105\260\163\261\021\263\157" +
"\266\043\277\221\300\216\302\031\303\075\304\074\316" +
"\165\323\135\324\u038f\327\u038e\001\001\000\002\001\001" +
"\000\136\004\125\050\u0632\051\u020f\052\u01fb\053\u0203\066" +
"\u0211\067\133\070\013\071\064\074\042\102\132\106\u01ad" +
"\115\124\116\213\123\136\124\211\125\117\126\226\137" +
"\222\147\023\150\u0201\167\054\170\041\171\146\172\131" +
"\173\100\174\060\175\066\177\172\200\051\202\u019c\203" +
"\u01fc\220\u01ff\256\105\260\163\261\021\263\157\266\043" +
"\277\221\300\216\302\031\303\075\304\074\316\165\323" +
"\135\324\u01ab\001\001\000\002\001\001\000\002\001\001" +
"\000\002\001\001\000\002\001\001\000\004\104\u0638\001" +
"\001\000\010\177\u0635\200\337\325\u063a\001\001\000\002" +
"\001\001\000\002\001\001\000\002\001\001\000\136\004" +
"\125\050\u063c\051\u020f\052\u01fb\053\u0203\066\u0211\067\133" +
"\070\013\071\064\074\042\102\132\106\u01ad\115\124\116" +
"\213\123\136\124\211\125\117\126\226\137\222\147\023" +
"\150\u0201\167\054\170\041\171\146\172\131\173\100\174" +
"\060\175\066\177\172\200\051\202\u019c\203\u01fc\220\u01ff" +
"\256\105\260\163\261\021\263\157\266\043\277\221\300" +
"\216\302\031\303\075\304\074\316\165\323\135\324\u01ab" +
"\001\001\000\002\001\001\000\002\001\001\000\002\001" +
"\001\000\002\001\001\000\002\001\001" });
"\001\000\002\001\001\000\056\070\013\071\064\123\u026a" +
"\124\211\125\117\126\226\137\222\170\041\173\u0266\174" +
"\060\177\172\200\051\220\u0643\256\u0642\261\021\263\157" +
"\266\043\300\u0267\302\031\303\075\304\074\316\165\001" +
"\001\000\002\001\001\000\002\001\001\000\002\001\001" +
"\000\120\004\125\066\151\067\133\070\013\071\064\074" +
"\042\102\132\106\u0645\115\124\116\213\123\136\124\211" +
"\125\117\126\226\137\222\147\023\167\054\170\041\171" +
"\146\172\131\173\100\174\060\175\066\177\172\200\051" +
"\220\046\256\105\260\163\261\021\263\157\266\043\277" +
"\221\300\216\302\031\303\075\304\074\316\165\323\135" +
"\324\u01ab\001\001\000\002\001\001\000\002\001\001\000" +
"\004\055\u0649\001\001\000\002\001\001\000\002\001\001" +
"\000\006\145\u0543\266\u0542\001\001\000\002\001\001\000" +
"\136\004\125\050\u064d\051\u020f\052\u01fb\053\u0203\066\u0211" +
"\067\133\070\013\071\064\074\042\102\132\106\u01ad\115" +
"\124\116\213\123\136\124\211\125\117\126\226\137\222" +
"\147\023\150\u0201\167\054\170\041\171\146\172\131\173" +
"\100\174\060\175\066\177\172\200\051\202\u019c\203\u01fc" +
"\220\u01ff\256\105\260\163\261\021\263\157\266\043\277" +
"\221\300\216\302\031\303\075\304\074\316\165\323\135" +
"\324\u01ab\001\001\000\002\001\001\000\002\001\001\000" +
"\002\001\001\000\002\001\001\000\002\001\001" });

/** Access to <code>reduce_goto</code> table. */
public short[][] reduce_table() {return _reduce_table;}
Expand Down Expand Up @@ -8361,7 +8369,7 @@ public final java_cup.runtime.Symbol fakeMethod300to399(
return CUP$ASTPHP5Parser$result;

/*. . . . . . . . . . . . . . . . . . . .*/
case 325: // static_var_list ::= static_var_list T_COMMA T_VARIABLE T_EQUAL static_scalar
case 325: // static_var_list ::= static_var_list T_COMMA T_VARIABLE T_EQUAL expr
{
List RESULT =null;
int listleft = ((java_cup.runtime.Symbol)CUP$ASTPHP5Parser$stack.elementAt(CUP$ASTPHP5Parser$top-4)).left;
Expand Down Expand Up @@ -8401,7 +8409,7 @@ public final java_cup.runtime.Symbol fakeMethod300to399(
return CUP$ASTPHP5Parser$result;

/*. . . . . . . . . . . . . . . . . . . .*/
case 327: // static_var_list ::= T_VARIABLE T_EQUAL static_scalar_with_class_instance
case 327: // static_var_list ::= T_VARIABLE T_EQUAL expr
{
List RESULT =null;
int varleft = ((java_cup.runtime.Symbol)CUP$ASTPHP5Parser$stack.elementAt(CUP$ASTPHP5Parser$top-2)).left;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
// Tue May 14 21:41:03 NOVT 2024
// Thu Dec 19 14:22:13 JST 2024
//----------------------------------------------------

package org.netbeans.modules.php.editor.parser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public String getTableData() {
protected EncodedActionTable10() {
sb = new StringBuilder();
sb.append("\uff62");
sb.append("\015");
sb.append("\uff62");
sb.append("\016");
sb.append("\uff62");
sb.append("\017");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable10() {
sb.append("\175");
sb.append("\u01c8");
sb.append("\176");
sb.append("\u01b8");
sb.append("\201");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public String getTableData() {
}
protected EncodedActionTable11() {
sb = new StringBuilder();
sb.append("\u01b8");
sb.append("\201");
sb.append("\u01bd");
sb.append("\215");
sb.append("\ufe21");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable11() {
sb.append("\112");
sb.append("\u0437");
sb.append("\121");
sb.append("\u0439");
sb.append("\222");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public String getTableData() {
}
protected EncodedActionTable12() {
sb = new StringBuilder();
sb.append("\u0439");
sb.append("\222");
sb.append("\333");
sb.append("\253");
sb.append("\240");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable12() {
sb.append("\166");
sb.append("\u01c0");
sb.append("\167");
sb.append("\u01d0");
sb.append("\170");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public String getTableData() {
}
protected EncodedActionTable13() {
sb = new StringBuilder();
sb.append("\u01d0");
sb.append("\170");
sb.append("\u01cb");
sb.append("\171");
sb.append("\u01c6");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable13() {
sb.append("\125");
sb.append("\115");
sb.append("\126");
sb.append("\130");
sb.append("\127");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public String getTableData() {
}
protected EncodedActionTable14() {
sb = new StringBuilder();
sb.append("\130");
sb.append("\127");
sb.append("\ufcfd");
sb.append("\133");
sb.append("\020");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable14() {
sb.append("\236");
sb.append("\uff02");
sb.append("\240");
sb.append("\uff02");
sb.append("\247");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public String getTableData() {
protected EncodedActionTable15() {
sb = new StringBuilder();
sb.append("\uff02");
sb.append("\247");
sb.append("\uff02");
sb.append("\250");
sb.append("\uff02");
sb.append("\252");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable15() {
sb.append("\027");
sb.append("\uff7c");
sb.append("\032");
sb.append("\uff7c");
sb.append("\034");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public String getTableData() {
protected EncodedActionTable16() {
sb = new StringBuilder();
sb.append("\uff7c");
sb.append("\034");
sb.append("\uff7c");
sb.append("\036");
sb.append("\uff7c");
sb.append("\041");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable16() {
sb.append("\052");
sb.append("\056");
sb.append("\054");
sb.append("\026");
sb.append("\056");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public String getTableData() {
}
protected EncodedActionTable17() {
sb = new StringBuilder();
sb.append("\026");
sb.append("\056");
sb.append("\u038e");
sb.append("\057");
sb.append("\016");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable17() {
sb.append("\066");
sb.append("\uff3d");
sb.append("\074");
sb.append("\uff3d");
sb.append("\075");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public String getTableData() {
protected EncodedActionTable18() {
sb = new StringBuilder();
sb.append("\uff3d");
sb.append("\075");
sb.append("\uff3d");
sb.append("\077");
sb.append("\uff3d");
sb.append("\100");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable18() {
sb.append("\212");
sb.append("\062");
sb.append("\213");
sb.append("\073");
sb.append("\214");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public String getTableData() {
}
protected EncodedActionTable19() {
sb = new StringBuilder();
sb.append("\073");
sb.append("\214");
sb.append("\113");
sb.append("\216");
sb.append("\100");
Expand Down Expand Up @@ -4528,5 +4526,7 @@ protected EncodedActionTable19() {
sb.append("\122");
sb.append("\013");
sb.append("\123");
sb.append("\064");
sb.append("\124");
}
}
Loading

0 comments on commit d0f037d

Please sign in to comment.