use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class ASMExpressionTest method testSimple.
@Test
public void testSimple() {
ExprStmtToken expression = getASMExpression("1 + 2").getResult();
Assert.assertEquals(3, expression.getTokens().size());
Assert.assertEquals("12+", expression.getWord());
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class ASMExpressionTest method getASMExpression.
private ASMExpression getASMExpression(String expr) {
environment.scope.setLangMode(LangMode.DEFAULT);
Tokenizer tokenizer = null;
try {
tokenizer = new Tokenizer(context = new Context(expr + ";"));
} catch (IOException e) {
throw new RuntimeException(e);
}
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
Assert.assertTrue(analyzer.getTree().size() == 1);
Assert.assertTrue(analyzer.getTree().get(0) instanceof ExprStmtToken);
return new ASMExpression(null, context, (ExprStmtToken) analyzer.getTree().get(0));
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class ListCompiler method write.
public void write(ListExprToken list, boolean returnValue, boolean writeValue) {
if (writeValue) {
expr.writeExpression(list.getValue(), true, false);
expr.writePopBoxing();
}
int i, length = list.getVariables().size();
for (i = length - 1; i >= 0; i--) {
// desc order as in PHP
ListExprToken.Variable v = list.getVariables().get(i);
expr.writePushDup();
if (v.indexes != null) {
for (int index : v.indexes) {
expr.writePushConstLong(index);
expr.writeSysStaticCall(MemoryUtils.class, "valueForList", Memory.class, Memory.class, expr.stackPeek().type.toClass());
//expr.writeSysDynamicCall(Memory.class, "valueOfIndex", Memory.class, expr.stackPeek().type.toClass());
}
}
expr.writePushConstLong(v.index);
expr.writeSysStaticCall(MemoryUtils.class, "valueForList", Memory.class, Memory.class, expr.stackPeek().type.toClass());
if (v.isVariable()) {
LocalVariable variable = method.getLocalVariable(v.getVariableName());
expr.writeVarAssign(variable, (VariableExprToken) v.var.getSingle(), false, true);
} else if (v.isArray() || v.isStaticProperty() || v.isArrayPush()) {
expr.writeExpression(v.var, true, false);
if (expr.stackPeek().immutable || expr.stackPeek().isConstant())
expr.unexpectedToken(v.var.getSingle());
expr.writeSysStaticCall(Memory.class, "assignRight", Memory.class, Memory.class, Memory.class);
expr.writePopAll(1);
} else if (v.isDynamicProperty()) {
DynamicAccessExprToken dynamic = (DynamicAccessExprToken) v.var.getLast();
ExprStmtToken var = new ExprStmtToken(this.env, this.compiler.getContext(), v.var.getTokens());
var.getTokens().remove(var.getTokens().size() - 1);
var.updateAsmExpr(this.env, this.compiler.getContext());
expr.writeDynamicAccessInfo(dynamic, false);
expr.writeExpression(var, true, false);
expr.writePopBoxing(false);
expr.writeGetStatic("$CALL_PROP_CACHE", PropertyCallCache.class);
expr.writePushConstInt(method.clazz.getAndIncCallPropCount());
expr.writeSysStaticCall(ObjectInvokeHelper.class, "assignPropertyRight", Memory.class, Memory.class, String.class, Environment.class, TraceInfo.class, Memory.class, PropertyCallCache.class, int.class);
expr.writePopAll(1);
}
}
if (!returnValue)
expr.writePopAll(1);
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class NamespaceSyntaxTest method testSimple.
@Test
public void testSimple() {
List<Token> tree = getSyntaxTree("namespace; 123;");
Assert.assertTrue(tree.size() == 2);
Assert.assertTrue(tree.get(0) instanceof NamespaceStmtToken);
Assert.assertTrue(tree.get(1) instanceof ExprStmtToken);
NamespaceStmtToken token = (NamespaceStmtToken) tree.get(0);
Assert.assertNull(token.getTree());
Assert.assertNull(token.getName());
}
use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.
the class SimpleExprTest method testSimpleCall.
@Test
public void testSimpleCall() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("myCall(1 * 2, func(3, 2), 4);"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
List<Token> tokens = analyzer.getTree();
Assert.assertTrue(tokens.size() == 1);
Assert.assertTrue(tokens.get(0) instanceof ExprStmtToken);
ExprStmtToken expr = (ExprStmtToken) tokens.get(0);
tokens = expr.getTokens();
Assert.assertTrue(tokens.size() == 1);
Assert.assertTrue(tokens.get(0) instanceof CallExprToken);
CallExprToken call = (CallExprToken) expr.getTokens().get(0);
Assert.assertTrue(call.getName() instanceof NameToken);
Assert.assertEquals("myCall", ((NameToken) call.getName()).getName());
Assert.assertTrue(call.getParameters().size() == 3);
Assert.assertTrue(call.getParameters().get(0).getTokens().size() == 3);
Assert.assertTrue(call.getParameters().get(2).getTokens().size() == 1);
ExprStmtToken param = call.getParameters().get(1);
Assert.assertTrue(param.getTokens().size() == 1);
Assert.assertTrue(param.getTokens().get(0) instanceof CallExprToken);
CallExprToken subCall = (CallExprToken) param.getTokens().get(0);
Assert.assertTrue(subCall.getParameters().size() == 2);
}
Aggregations