Search in sources :

Example 1 with ArgumentStmtToken

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

the class FunctionDescription method parse.

@Override
protected void parse() {
    arguments = new LinkedHashMap<String, ArgumentDescription>();
    annotations = new DocAnnotations(token.getDocComment() == null ? "" : token.getDocComment().getComment());
    DocAnnotations.Parameter returnParam = annotations.getParameter("return");
    if (returnParam != null) {
        this.returnParameter = new MethodReturnParameter(token.getNamespace(), returnParam.value());
    }
    DocAnnotations.Parameter throwsParam = annotations.getParameter("throws");
    if (throwsParam != null) {
        this.throwsParameters = new MethodReturnParameter[throwsParam.values().size()];
        int i = 0;
        for (String e : throwsParam.values()) {
            this.throwsParameters[i] = new MethodReturnParameter(token.getNamespace(), e);
            i++;
        }
    }
    Map<String, MethodParamParameter> paramDescription = new HashMap<String, MethodParamParameter>();
    DocAnnotations.Parameter param = annotations.getParameter("param");
    if (param != null) {
        for (String el : param.values()) {
            MethodParamParameter tmp = new MethodParamParameter(token.getNamespace(), el);
            paramDescription.put(tmp.getArgument(), tmp);
        }
    }
    for (ArgumentStmtToken el : token.getArguments()) {
        MethodParamParameter desc = paramDescription.get(el.getName().getName());
        arguments.put(el.getName().getName(), new ArgumentDescription(el, desc));
    }
}
Also used : MethodParamParameter(org.develnext.jphp.genapi.parameter.MethodParamParameter) ArgumentStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken) MethodReturnParameter(org.develnext.jphp.genapi.parameter.MethodReturnParameter) DocAnnotations(org.develnext.jphp.genapi.DocAnnotations)

Example 2 with ArgumentStmtToken

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

the class ClosureValueCompiler method writePushUses.

protected void writePushUses(Collection<ArgumentStmtToken> parameters) {
    if (parameters.isEmpty()) {
        add(new InsnNode(ACONST_NULL));
        expr.stackPush(Memory.Type.REFERENCE);
        return;
    }
    expr.writePushSmallInt(parameters.size());
    add(new TypeInsnNode(ANEWARRAY, Type.getInternalName(Memory.class)));
    expr.stackPop();
    expr.stackPush(Memory.Type.REFERENCE);
    int i = 0;
    for (ArgumentStmtToken param : parameters) {
        expr.writePushDup();
        expr.writePushSmallInt(i);
        LocalVariable local = method.getLocalVariable(param.getName().getName());
        if (local == null)
            expr.writePushNull();
        else
            expr.writeVarLoad(local);
        if (!param.isReference())
            expr.writePopBoxing(true);
        add(new InsnNode(AASTORE));
        expr.stackPop();
        expr.stackPop();
        expr.stackPop();
        i++;
    }
}
Also used : MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) ArgumentStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken) LocalVariable(org.develnext.jphp.core.compiler.jvm.misc.LocalVariable) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode)

Example 3 with ArgumentStmtToken

use of org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken 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

ArgumentStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ArgumentStmtToken)3 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)1 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)1 Token (org.develnext.jphp.core.tokenizer.token.Token)1 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)1 FunctionStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.FunctionStmtToken)1 DocAnnotations (org.develnext.jphp.genapi.DocAnnotations)1 MethodParamParameter (org.develnext.jphp.genapi.parameter.MethodParamParameter)1 MethodReturnParameter (org.develnext.jphp.genapi.parameter.MethodReturnParameter)1 Test (org.junit.Test)1 InsnNode (org.objectweb.asm.tree.InsnNode)1 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)1 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)1 Context (php.runtime.env.Context)1