use of org.develnext.jphp.core.syntax.Scope in project jphp by jphp-compiler.
the class SimpleExprGenerator method processNew.
protected Token processNew(Token current, BraceExprToken.Kind closedBrace, int braceOpened, ListIterator<Token> iterator) {
NewExprToken result = (NewExprToken) current;
Token next = nextToken(iterator);
if (!isTokenClass(next, StaticExprToken.class, ParentExprToken.class, SelfExprToken.class)) {
next = makeSensitive(next);
}
if (next instanceof NameToken) {
FulledNameToken nameToken = analyzer.getRealName((NameToken) next);
result.setName(nameToken);
iterator.previous();
iterator.previous();
if (iterator.hasPrevious()) {
Token previous = iterator.previous();
if (previous instanceof AssignExprToken) {
if (iterator.hasPrevious()) {
previous = iterator.previous();
if (previous instanceof VariableExprToken) {
analyzer.getScope().typeInfoOf(previous).addType(nameToken.getName());
}
iterator.next();
}
}
iterator.next();
}
iterator.next();
iterator.next();
} else if (next instanceof VariableExprToken) {
result.setName(processNewExpr(next, closedBrace, braceOpened, iterator, true));
} else if (next instanceof StaticExprToken) {
Scope scope = analyzer.getScope();
scope.setStaticExists(true);
result.setName((StaticExprToken) next);
} else if (next instanceof SelfExprToken) {
if (analyzer.getClazz() == null) {
result.setName((SelfExprToken) next);
} else {
if (analyzer.getClazz().isTrait()) {
result.setName((SelfExprToken) next);
} else {
result.setName(new FulledNameToken(next.getMeta(), new ArrayList<Token>() {
{
if (analyzer.getClazz().getNamespace().getName() != null)
addAll(analyzer.getClazz().getNamespace().getName().getNames());
add(analyzer.getClazz().getName());
}
}));
}
}
} else
unexpectedToken(next);
next = nextToken(iterator);
if (isOpenedBrace(next, BraceExprToken.Kind.SIMPLE)) {
ExprStmtToken param;
List<ExprStmtToken> parameters = new ArrayList<ExprStmtToken>();
do {
param = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, true, BraceExprToken.Kind.SIMPLE);
if (param != null)
parameters.add(param);
} while (param != null);
nextToken(iterator);
result.setParameters(parameters);
} else {
result.setParameters(new ArrayList<ExprStmtToken>());
iterator.previous();
}
if (analyzer.getFunction() != null) {
analyzer.getFunction().setCallsExist(true);
}
return result;
}
Aggregations