Search in sources :

Example 21 with ExprStmtToken

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

the class IfSyntaxTest method testShortly.

@Test
public void testShortly() {
    List<Token> tree = getSyntaxTree("if (true) 'string'; 123;");
    Assert.assertTrue(tree.size() == 2);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertNotNull(token.getCondition());
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Example 22 with ExprStmtToken

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

the class IfSyntaxTest method testNested.

@Test
public void testNested() {
    List<Token> tree = getSyntaxTree("if (true){ " + "'string'; " + "if(false){ " + "1234; " + "} " + "}");
    Assert.assertTrue(tree.size() == 1);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertTrue(token.getBody().getInstructions().size() == 2);
    Assert.assertTrue(token.getBody().getInstructions().get(1).getTokens().size() == 1);
    Assert.assertTrue(token.getBody().getInstructions().get(1).getTokens().get(0) instanceof IfStmtToken);
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Example 23 with ExprStmtToken

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

the class IfSyntaxTest method testAlternative.

@Test
public void testAlternative() {
    List<Token> tree = getSyntaxTree("if (true): 123; endif");
    Assert.assertTrue(tree.size() == 1);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertNotNull(token.getCondition());
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Example 24 with ExprStmtToken

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

the class IfSyntaxTest method testSimple.

@Test
public void testSimple() {
    List<Token> tree = getSyntaxTree("if (true) { } ");
    Assert.assertTrue(tree.size() == 1);
    Assert.assertTrue(tree.get(0) instanceof ExprStmtToken);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().size() == 1);
    Assert.assertTrue(((ExprStmtToken) tree.get(0)).getTokens().get(0) instanceof IfStmtToken);
    IfStmtToken token = (IfStmtToken) ((ExprStmtToken) tree.get(0)).getTokens().get(0);
    Assert.assertNotNull(token.getBody());
    Assert.assertNotNull(token.getCondition());
}
Also used : ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) IfStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.IfStmtToken) Test(org.junit.Test)

Example 25 with ExprStmtToken

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

the class NamedFunctionTest method testSimple.

@Test
public void testSimple() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("function myFunc($x, &$y, $z = 33){  } $x = 10;"));
    SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
    ListIterator<Token> iterator = analyzer.getTree().listIterator();
    Token token;
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue((token = iterator.next()) instanceof FunctionStmtToken);
    FunctionStmtToken func = (FunctionStmtToken) token;
    Assert.assertFalse(func.isReturnReference());
    List<ArgumentStmtToken> arguments = func.getArguments();
    Assert.assertTrue(arguments != null && arguments.size() == 3);
    Assert.assertFalse(arguments.get(0).isReference());
    Assert.assertTrue(arguments.get(1).isReference());
    Assert.assertNotNull(arguments.get(2).getValue());
    Assert.assertEquals("myFunc", func.getName().getName());
    Assert.assertNotNull(func.getBody());
    Assert.assertFalse(func.isInterfacable());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.next() instanceof ExprStmtToken);
    Assert.assertFalse(iterator.hasNext());
}
Also used : Context(php.runtime.env.Context) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ArgumentStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) FunctionStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken) ArgumentStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) FunctionStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

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