use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class ThrowGenerator method getToken.
@Override
public ThrowStmtToken getToken(Token current, ListIterator<Token> iterator) {
if (current instanceof ThrowStmtToken) {
ThrowStmtToken result = (ThrowStmtToken) current;
ExprStmtToken exception = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, Separator.SEMICOLON, null);
if (exception == null)
unexpectedToken(iterator.previous());
result.setException(exception);
return result;
}
return null;
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class BodyGenerator method getToken.
@SuppressWarnings("unchecked")
public BodyStmtToken getToken(Token current, ListIterator<Token> iterator, boolean absolute, boolean returnNull, Class<? extends Token>... endTokens) {
boolean alternativeSyntax = false;
List<ExprStmtToken> instructions = new ArrayList<ExprStmtToken>();
if (isOpenedBrace(current, BraceExprToken.Kind.BLOCK)) /*|| current instanceof SemicolonToken*/
{
//if (!returnNull)
returnNull = false;
while ((current = nextToken(iterator)) != null) {
ExprStmtToken expr = analyzer.generator(ExprGenerator.class).getToken(current, iterator, BraceExprToken.class);
if (expr == null) {
break;
}
instructions.add(expr);
}
} else if (current instanceof ColonToken || (absolute && endTokens != null)) {
if (endTokens == null)
unexpectedToken(current);
if (!(current instanceof ColonToken))
iterator.previous();
else
alternativeSyntax = true;
while (iterator.hasNext()) {
current = nextToken(iterator);
ExprStmtToken expr = analyzer.generator(ExprGenerator.class).getToken(current, iterator, endTokens);
if (expr == null) {
iterator.previous();
break;
} else if (expr.getTokens().size() == 1 && expr.getTokens().get(0) instanceof SemicolonToken) {
// nop break;
} else {
instructions.add(expr);
}
}
} else {
ExprStmtToken expr = analyzer.generator(ExprGenerator.class).getToken(current, iterator);
if (expr != null) {
if (expr.getTokens().size() == 1 && expr.getTokens().get(0) instanceof SemicolonToken) {
// nop
} else {
instructions.add(expr);
}
}
}
if (instructions.isEmpty() && returnNull)
return null;
BodyStmtToken result = new BodyStmtToken(TokenMeta.of(instructions));
result.setInstructions(instructions);
result.setAlternativeSyntax(alternativeSyntax);
return result;
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class UnsetCompiler method write.
@Override
public void write(UnsetExprToken token, boolean returnValue) {
method.getEntity().setImmutable(false);
for (ExprStmtToken param : token.getParameters()) {
if (param.isSingle() && param.getSingle() instanceof VariableExprToken) {
VariableExprToken variable = (VariableExprToken) param.getSingle();
expr.checkAssignableVar(variable);
LocalVariable local = method.getLocalVariable(variable.getName());
expr.writeVarLoad(local);
expr.writePushEnv();
expr.writeSysDynamicCall(Memory.class, "manualUnset", void.class, Environment.class);
if (!local.isReference()) {
expr.writePushNull();
expr.writeVarAssign(local, null, false, false);
}
local.setValue(null);
} else if (param.isSingle() && param.getSingle() instanceof GetVarExprToken) {
expr.writeValue((ValueExprToken) param.getSingle(), true);
expr.writePushEnv();
expr.writeSysDynamicCall(Memory.class, "manualUnset", void.class, Environment.class);
} else {
expr.writeExpression(param, false, false, true);
}
}
if (returnValue)
expr.writePushNull();
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class ASMExpressionTest method testCallExpr.
@Test
public void testCallExpr() {
ExprStmtToken expression = getASMExpression("func(1 + 2, 3) * 3").getResult();
Assert.assertEquals(3, expression.getTokens().size());
Assert.assertTrue(expression.getTokens().get(0) instanceof CallExprToken);
CallExprToken call = (CallExprToken) expression.getTokens().get(0);
Assert.assertEquals(2, call.getParameters().size());
Assert.assertEquals("1+2", call.getParameters().get(0).getWord());
Assert.assertEquals("3", call.getParameters().get(1).getWord());
Assert.assertTrue(expression.getTokens().get(1) instanceof IntegerExprToken);
Assert.assertTrue(expression.getTokens().get(2) instanceof MulExprToken);
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class ASMExpressionTest method testPriorities.
@Test
public void testPriorities() {
Assert.assertEquals("123/+", getASMExpression("1 + 2 / 3").getResult().getWord());
Assert.assertEquals("123*+", getASMExpression("1 + 2 * 3").getResult().getWord());
Assert.assertEquals("123%+", getASMExpression("1 + 2 % 3").getResult().getWord());
Assert.assertEquals("12*3/", getASMExpression("1 * 2 / 3").getResult().getWord());
Assert.assertEquals("12/3%", getASMExpression("1 / 2 % 3").getResult().getWord());
Assert.assertEquals("12/3/", getASMExpression("1 / 2 / 3").getResult().getWord());
Assert.assertEquals("12-3+", getASMExpression("1 - 2 + 3").getResult().getWord());
ExprStmtToken expr = getASMExpression("1 && 2 + 3").getResult();
Assert.assertEquals("1&&", expr.getWord());
Assert.assertTrue(expr.getTokens().get(1) instanceof LogicOperatorExprToken);
Assert.assertEquals("2+3", ((LogicOperatorExprToken) expr.getTokens().get(1)).getRightValue().getWord());
Assert.assertEquals("1||", getASMExpression("1 || 2 + 3").getResult().getWord());
Assert.assertEquals("1||", getASMExpression("1 || 2 && 3").getResult().getWord());
Assert.assertEquals("1!||", getASMExpression("!1 || 2 && 3").getResult().getWord());
}
Aggregations