use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class SimpleExprGenerator method processUnset.
protected UnsetExprToken processUnset(Token previous, Token current, ListIterator<Token> iterator) {
Token next = nextTokenAndPrev(iterator);
if (!isOpenedBrace(next, SIMPLE))
unexpectedToken(next, "(");
CallExprToken call = processCall(current, nextToken(iterator), iterator);
for (ExprStmtToken param : call.getParameters()) {
List<Token> tokens = param.getTokens();
Token last = tokens.get(tokens.size() - 1);
Token newToken = null;
if (param.getSingle() instanceof StaticAccessExprToken && ((StaticAccessExprToken) param.getSingle()).isGetStaticField()) {
// allow class::$var
} else if (!(param.getSingle() instanceof VariableValueExprToken))
unexpectedToken(param);
if (last instanceof VariableExprToken || last instanceof GetVarExprToken) {
newToken = last;
// nop
} else if (last instanceof ArrayGetExprToken) {
ArrayGetUnsetExprToken el = new ArrayGetUnsetExprToken(last.getMeta());
el.setParameters(((ArrayGetExprToken) last).getParameters());
newToken = el;
} else if (last instanceof DynamicAccessExprToken) {
newToken = new DynamicAccessUnsetExprToken((DynamicAccessExprToken) last);
} else if (last instanceof StaticAccessExprToken) {
newToken = new StaticAccessUnsetExprToken((StaticAccessExprToken) last);
} else
unexpectedToken(last);
tokens.set(tokens.size() - 1, newToken);
param.updateAsmExpr(analyzer.getEnvironment(), analyzer.getContext());
}
UnsetExprToken result = (UnsetExprToken) current;
result.setParameters(call.getParameters());
return result;
}
use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class SimpleExprGenerator method getNextExpression.
public ExprStmtToken getNextExpression(Token current, ListIterator<Token> iterator, Separator separator, BraceExprToken.Kind closedBraceKind) {
ExprStmtToken value = getToken(current, iterator, separator, closedBraceKind);
Token tk = iterator.previous();
if (!isBreak(tk) && (separator == null || !separator.is(tk))) {
iterator.next();
}
return value;
}
use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class SimpleExprGenerator method processCall.
protected CallExprToken processCall(Token previous, Token current, ListIterator<Token> iterator) {
ExprStmtToken param;
List<ExprStmtToken> parameters = new ArrayList<>();
do {
param = analyzer.generator(SimpleExprGenerator.class).getNextExpression(nextToken(iterator), iterator, Separator.COMMA, SIMPLE);
if (param != null) {
parameters.add(param);
if (param.isSingle()) {
if (param.getTokens().get(0) instanceof VariableExprToken) {
if (analyzer.getFunction() != null)
analyzer.getFunction().variable((VariableExprToken) param.getTokens().get(0)).setPassed(true);
}
}
}
Token tk = nextToken(iterator);
if (isClosedBrace(tk, SIMPLE)) {
break;
} else if (param == null && tk instanceof CommaToken) {
nextToken(iterator);
break;
}
} while (param != null);
// nextToken(iterator);
CallExprToken result = new CallExprToken(TokenMeta.of(previous, current));
if (previous instanceof ValueExprToken) {
result.setName(analyzer.getRealName((ValueExprToken) previous, NamespaceUseStmtToken.UseType.FUNCTION));
if (analyzer.getFunction() != null) {
if (result.getName() instanceof NameToken) {
String name = ((NameToken) result.getName()).getName().toLowerCase();
if (result.getName() instanceof FulledNameToken) {
name = ((FulledNameToken) result.getName()).getLastName().getName().toLowerCase();
}
if (dynamicLocalFunctions.contains(name.toLowerCase())) {
analyzer.getFunction().setDynamicLocal(true);
}
if ("get_called_class".equalsIgnoreCase(name)) {
analyzer.getScope().setStaticExists(true);
}
}
}
} else {
if (previous instanceof DynamicAccessExprToken) {
result.setName((ExprToken) previous);
} else
result.setName(null);
}
result.setParameters(parameters);
if (analyzer.getFunction() != null) {
analyzer.getFunction().setCallsExist(true);
}
return result;
}
use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class SimpleExprGenerator method processStaticAccess.
protected Token processStaticAccess(Token current, Token previous, ListIterator<Token> iterator) {
Token name = previous;
if (name != null && !isTokenClass(name, SelfExprToken.class, StaticExprToken.class, ParentExprToken.class)) {
name = makeSensitive(previous);
}
if (name == null || name instanceof NameToken || name instanceof VariableExprToken || name instanceof SelfExprToken || name instanceof StaticExprToken || name instanceof ParentExprToken) {
if (name instanceof StaticExprToken) {
analyzer.getScope().setStaticExists(true);
}
StaticAccessExprToken result = (StaticAccessExprToken) current;
ValueExprToken clazz = (ValueExprToken) name;
if (clazz instanceof NameToken) {
clazz = analyzer.getRealName((NameToken) clazz);
} else if (clazz instanceof SelfExprToken) {
if (analyzer.getClazz() == null) {
;
} else {
if (!analyzer.getClazz().isTrait()) {
clazz = new FulledNameToken(clazz.getMeta(), new ArrayList<Token>() {
{
if (analyzer.getClazz().getNamespace().getName() != null)
addAll(analyzer.getClazz().getNamespace().getName().getNames());
add(analyzer.getClazz().getName());
}
});
}
}
}
result.setClazz(clazz);
if (name != null) {
nextToken(iterator);
}
current = nextToken(iterator);
if (!isTokenClass(current, ClassStmtToken.class)) {
current = makeSensitive(current);
}
if (isOpenedBrace(current, BLOCK)) {
ExprStmtToken expr = getToken(nextToken(iterator), iterator, false, BLOCK);
result.setFieldExpr(expr);
nextAndExpected(iterator, BraceExprToken.class);
} else if (current instanceof NameToken || current instanceof VariableExprToken) {
result.setField((ValueExprToken) current);
} else if (current instanceof DollarExprToken) {
Token nm = nextToken(iterator);
if (nm instanceof VariableExprToken) {
result.setFieldExpr(new ExprStmtToken(analyzer.getEnvironment(), analyzer.getContext(), nm));
} else if (nm instanceof DollarExprToken) {
result.setFieldExpr(new ExprStmtToken(analyzer.getEnvironment(), analyzer.getContext(), processVarVar(nm, nextTokenAndPrev(iterator), iterator)));
} else if (isOpenedBrace(nm, BLOCK)) {
iterator.previous();
result.setFieldExpr(analyzer.generator(ExprGenerator.class).getInBraces(BLOCK, iterator));
} else
unexpectedToken(current);
} else if (current instanceof ClassStmtToken) {
// PHP 5.5 ::class
if (clazz instanceof ParentExprToken || clazz instanceof StaticExprToken || clazz instanceof SelfExprToken) {
if (clazz instanceof StaticExprToken) {
analyzer.getScope().setStaticExists(true);
}
result.setField(new ClassExprToken(current.getMeta()));
} else if (clazz instanceof NameToken) {
return new StringExprToken(TokenMeta.of(((NameToken) clazz).getName(), clazz), StringExprToken.Quote.SINGLE);
} else
unexpectedToken(current);
} else
unexpectedToken(current);
if (name == null) {
return new StaticAccessOperatorExprToken(result);
}
return result;
} else
unexpectedToken(name);
return null;
}
use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class TokenizerTest method testBug122.
@Test
public void testBug122() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("<<<ESC\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "<?php\n" + "ESC;\n"));
Token token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
assertEquals("\n\n\n\n\n<?php", ((StringExprToken) token).getValue());
}
Aggregations