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));
}
}
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++;
}
}
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());
}
Aggregations