Search in sources :

Example 11 with ExprStmtToken

use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.

the class SimpleExprTest method testIfElse.

@Test
public void testIfElse() {
    List<Token> tokens = getSyntaxTree("call(1, true ? 1 : 2, 'foobar');");
    Assert.assertEquals(1, tokens.size());
    Assert.assertTrue(tokens.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tokens.get(0)).getLast() instanceof CallExprToken);
    CallExprToken call = (CallExprToken) ((ExprStmtToken) tokens.get(0)).getLast();
    Assert.assertEquals(3, call.getParameters().size());
    Assert.assertTrue(call.getParameters().get(0).getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(call.getParameters().get(1).getTokens().get(1) instanceof ValueIfElseToken);
    ValueIfElseToken ifElse = (ValueIfElseToken) call.getParameters().get(1).getTokens().get(1);
    Assert.assertTrue(ifElse.getValue().getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(ifElse.getAlternative().getSingle() instanceof IntegerExprToken);
    Assert.assertTrue(call.getParameters().get(2).getSingle() instanceof StringExprToken);
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ValueIfElseToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken) Token(org.develnext.jphp.core.tokenizer.token.Token) ValueIfElseToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) MinusExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken) Test(org.junit.Test)

Example 12 with ExprStmtToken

use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.

the class SyntaxAnalyzerTest method testSimple.

@Test
public void testSimple() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("foobar;"));
    SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
    Assert.assertTrue(analyzer.getTree().size() == 1);
    Assert.assertTrue(analyzer.getTree().listIterator().next() instanceof ExprStmtToken);
}
Also used : Context(php.runtime.env.Context) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 13 with ExprStmtToken

use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.

the class BodyCompiler method write.

@Override
public void write(BodyStmtToken token) {
    if (token != null) {
        for (ExprStmtToken line : token.getInstructions()) {
            expr.writeTickTrigger(line);
            expr.writeExpression(line, false, false);
        }
    }
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)

Example 14 with ExprStmtToken

use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.

the class EchoCompiler method write.

@Override
public void write(EchoStmtToken token) {
    for (ExprStmtToken argument : token.getArguments()) {
        expr.writePushEnv();
        expr.writeExpression(argument, true, false);
        expr.writePopBoxing();
        expr.writeSysDynamicCall(Environment.class, "echo", void.class, Memory.class);
    }
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)

Example 15 with ExprStmtToken

use of org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken in project jphp by jphp-compiler.

the class StringBuilderValueCompiler method writeBuilder.

public void writeBuilder(List<Token> tokens, boolean binary) {
    expr.writePushNewObject(StringBuilder.class);
    for (Token el : tokens) {
        //writePushDup();
        if (el instanceof ValueExprToken) {
            expr.writePush((ValueExprToken) el, true, false);
        } else if (el instanceof ExprStmtToken) {
            //unexpectedToken(el);
            expr.writeExpression((ExprStmtToken) el, true, false, true);
        } else
            expr.unexpectedToken(el);
        StackItem.Type peek = expr.stackPeek().type;
        if (!peek.isConstant()) {
            expr.writeSysDynamicCall(StringBuilder.class, "append", StringBuilder.class, Object.class);
        } else
            expr.writeSysDynamicCall(StringBuilder.class, "append", StringBuilder.class, peek.toClass());
    }
    expr.writeSysDynamicCall(StringBuilder.class, "toString", String.class);
    if (binary) {
        expr.writeSysStaticCall(BinaryMemory.class, "valueOf", Memory.class, String.class);
    }
}
Also used : StackItem(org.develnext.jphp.core.compiler.common.misc.StackItem) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) StringBuilderExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StringBuilderExprToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)

Aggregations

ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)25 Test (org.junit.Test)15 Token (org.develnext.jphp.core.tokenizer.token.Token)12 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)4 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)4 MinusExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken)4 ValueIfElseToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ValueIfElseToken)4 IfStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken)4 Context (php.runtime.env.Context)4 VariableExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken)3 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)2 DynamicAccessExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.DynamicAccessExprToken)2 ListExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.ListExprToken)2 BodyStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.BodyStmtToken)2 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)2 LabelNode (org.objectweb.asm.tree.LabelNode)2 Memory (php.runtime.Memory)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StackItem (org.develnext.jphp.core.compiler.common.misc.StackItem)1