Search in sources :

Example 26 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class NamedFunctionTest method testNoArguments.

@Test
public void testNoArguments() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("function myFunc(){}"));
    SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
    Assert.assertTrue(analyzer.getTree().size() == 1);
    Assert.assertTrue(analyzer.getTree().get(0) instanceof FunctionStmtToken);
    FunctionStmtToken func = (FunctionStmtToken) analyzer.getTree().listIterator().next();
    Assert.assertTrue(func.getArguments().size() == 0);
}
Also used : Context(php.runtime.env.Context) FunctionStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 27 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class NamedFunctionTest method testInterfacable.

@Test
public void testInterfacable() throws IOException {
    Tokenizer tokenizer = new Tokenizer(new Context("function myFunc();"));
    SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
    Assert.assertTrue(analyzer.getTree().size() == 1);
    Assert.assertTrue(analyzer.getTree().get(0) instanceof FunctionStmtToken);
    FunctionStmtToken func = (FunctionStmtToken) analyzer.getTree().listIterator().next();
    Assert.assertTrue(func.isInterfacable());
}
Also used : Context(php.runtime.env.Context) FunctionStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer) Test(org.junit.Test)

Example 28 with Context

use of php.runtime.env.Context 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)

Example 29 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class JPHPScriptEngine method compile.

@Override
public CompiledScript compile(Reader reader) throws ScriptException {
    try {
        InputStream is = new ReaderInputStream(reader);
        Context context = new Context(is);
        ModuleEntity module = environment.importModule(context);
        return new JPHPCompiledScript(module, environment);
    } catch (IOException e) {
        throw new ScriptException(e);
    } catch (Throwable e) {
        throw new ScriptException(new Exception(e));
    }
}
Also used : Context(php.runtime.env.Context) ReaderInputStream(org.develnext.jphp.scripting.util.ReaderInputStream) ReaderInputStream(org.develnext.jphp.scripting.util.ReaderInputStream) ModuleEntity(php.runtime.reflection.ModuleEntity)

Example 30 with Context

use of php.runtime.env.Context in project jphp by jphp-compiler.

the class StandaloneLoader method _fetch.

protected ModuleEntity _fetch(String name, Map<String, Module> source) {
    Module module = source.get(name);
    if (module == null) {
        return null;
    }
    InputStream input = classLoader.getResourceAsStream(module.internalName + ".dump");
    if (input == null) {
        return null;
    }
    ModuleDumper moduleDumper = new ModuleDumper(new Context(new File(module.name)), env, true);
    try {
        return moduleDumper.load(input);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Context(php.runtime.env.Context) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ModuleDumper(php.runtime.loader.dump.ModuleDumper) File(java.io.File)

Aggregations

Context (php.runtime.env.Context)30 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)27 Test (org.junit.Test)23 Token (org.develnext.jphp.core.tokenizer.token.Token)10 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)8 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)8 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)4 File (java.io.File)3 IOException (java.io.IOException)3 SyntaxAnalyzer (org.develnext.jphp.core.syntax.SyntaxAnalyzer)3 FunctionStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 Environment (php.runtime.env.Environment)2 ParseException (php.runtime.exceptions.ParseException)2 Launcher (php.runtime.launcher.Launcher)2 DataInputStream (java.io.DataInputStream)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 JvmCompiler (org.develnext.jphp.core.compiler.jvm.JvmCompiler)1 MinusExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.MinusExprToken)1