Skip to content

Commit 9fb0e9c

Browse files
committed
Fix #366, Fix #373: Cannot call in some cases. Syntax errors.
1 parent d0abc2d commit 9fb0e9c

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

jphp-core/src/org/develnext/jphp/core/compiler/jvm/statement/ExpressionStmtCompiler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ public void writeTickTrigger(Token token) {
21112111
}
21122112

21132113
public void writeTickTrigger(TraceInfo trace) {
2114-
if (compiler.getScope().isDebugMode() && method.getLocalVariable("~local") != null) {
2114+
if (/*compiler.getScope().isDebugMode() &&*/ method.getLocalVariable("~local") != null) {
21152115
int line = trace.getStartLine();
21162116

21172117
if (method.registerTickTrigger(line)) {
@@ -2805,7 +2805,8 @@ Memory writeUnaryOperator(OperatorExprToken operator, boolean returnValue, boole
28052805
stackPush(o);
28062806
writeArrayGet((ArrayGetExprToken) operator, returnValue);
28072807
} else if (operator instanceof CallOperatorToken) {
2808-
stackPush(o);
2808+
writePush(o);
2809+
writePopBoxing();
28092810

28102811
CallOperatorToken call = (CallOperatorToken) operator;
28112812

jphp-core/src/org/develnext/jphp/core/syntax/generators/ExprGenerator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.develnext.jphp.core.compiler.common.ASMExpression;
44
import org.develnext.jphp.core.tokenizer.token.expr.*;
5+
import org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken.Kind;
56
import php.runtime.common.Messages;
67
import org.develnext.jphp.core.common.Separator;
78
import php.runtime.exceptions.FatalException;
@@ -20,6 +21,7 @@
2021
import java.util.ListIterator;
2122

2223
import static org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken.Kind.ARRAY;
24+
import static org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken.Kind.SIMPLE;
2325

2426
public class ExprGenerator extends Generator<ExprStmtToken> {
2527

@@ -569,8 +571,12 @@ public void processEcho(EchoStmtToken result, ListIterator<Token> iterator){
569571
}
570572

571573
protected List<Token> processSimpleExpr(Token current, ListIterator<Token> iterator){
574+
Kind closedBraceKind = null;
575+
if (isOpenedBrace(current, SIMPLE)) closedBraceKind = SIMPLE;
576+
else if (isOpenedBrace(current, ARRAY)) closedBraceKind = ARRAY;
577+
572578
ExprStmtToken token = analyzer.generator(SimpleExprGenerator.class)
573-
.getToken(current, iterator, Separator.SEMICOLON, null);
579+
.getToken(current, iterator, Separator.SEMICOLON, closedBraceKind);
574580
return token.getTokens();
575581
}
576582

jphp-core/src/org/develnext/jphp/core/syntax/generators/manually/SimpleExprGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ public ExprStmtToken getToken(Token current, ListIterator<Token> iterator,
14101410

14111411
if (isOpenedBrace(current, SIMPLE)){
14121412
boolean isFunc = false;
1413-
if (previous instanceof NameToken && previous.getMeta().getWord().equalsIgnoreCase("array")){
1413+
if (previous instanceof NameToken && "array".equalsIgnoreCase(previous.getMeta().getWord())){
14141414
iterator.previous();
14151415
tokens.set(tokens.size() - 1, current = processNewArray(previous, iterator));
14161416
} else {
@@ -1424,6 +1424,8 @@ else if (previous instanceof StaticAccessExprToken){
14241424
isFunc = true; // !((StaticAccessExprToken)previous).isGetStaticField(); TODO check it!
14251425
} else if (previous instanceof DynamicAccessExprToken){
14261426
isFunc = true;
1427+
} else if (isClosedBrace(previous, SIMPLE)) {
1428+
isFunc = true;
14271429
}
14281430

14291431
if (isFunc){
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.develnext.jphp.core.compiler.jvm;
2+
3+
import org.junit.Assert;
4+
import org.junit.FixMethodOrder;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.junit.runners.JUnit4;
8+
import org.junit.runners.MethodSorters;
9+
import php.runtime.Memory;
10+
11+
@RunWith(JUnit4.class)
12+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
13+
public class SyntaxTest extends JvmCompilerCase {
14+
15+
@Test
16+
public void testDynamicCall() {
17+
check("syntax/dynamic_call.phpt", true);
18+
}
19+
}

jphp-core/tests/org/develnext/jphp/core/syntax/SyntaxAnalyzerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ public void testUnexpectedEnd() throws IOException {
3333
environment.scope.setLangMode(LangMode.DEFAULT);
3434
new SyntaxAnalyzer(environment, tokenizer);
3535
}
36+
3637
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Test dynamic call syntax
3+
--FILE--
4+
<?php
5+
function test($x) {
6+
var_dump($x);
7+
}
8+
9+
('test')("foo");
10+
11+
$v = 'st';
12+
("te$v")("bar");
13+
14+
(fn() => var_dump(222))();
15+
(function() { var_dump(333); })();
16+
([fn() => var_dump(444)][0])();
17+
18+
$b = function ($a) { var_dump($a); };
19+
($a ?? $b)('magic');
20+
21+
$b = function ($a) { var_dump($a); };
22+
($a ?? $b)('magic', 'param');
23+
24+
(function () { echo 'a'; })();
25+
?>
26+
--EXPECT--
27+
string(3) "foo"
28+
string(3) "bar"
29+
int(222)
30+
int(333)
31+
int(444)
32+
string(5) "magic"
33+
string(5) "magic"
34+
a

0 commit comments

Comments
 (0)