use of org.develnext.jphp.core.syntax.ExpressionInfo in project jphp by jphp-compiler.
the class SimpleExprGenerator method processSimpleToken.
protected Token processSimpleToken(Token current, Token previous, Token next, ListIterator<Token> iterator, BraceExprToken.Kind closedBraceKind, int braceOpened, Separator separator) {
if (current instanceof DynamicAccessExprToken) {
return processDynamicAccess(current, next, iterator, closedBraceKind, braceOpened);
}
if (current instanceof OperatorExprToken) {
isRef = false;
if (current instanceof InstanceofExprToken && next instanceof NameToken) {
if (previous instanceof VariableExprToken) {
analyzer.getScope().typeInfoOf(previous).addType(analyzer.getRealName((NameToken) next, NamespaceUseStmtToken.UseType.CLASS).getName());
}
}
}
if (current instanceof NameToken && next instanceof StringExprToken) {
// binary string
if (((NameToken) current).getName().equalsIgnoreCase("b")) {
((StringExprToken) next).setBinary(true);
iterator.next();
return processString((StringExprToken) next);
}
}
if (current instanceof YieldExprToken) {
return processYield(current, next, iterator, separator, closedBraceKind);
}
if (current instanceof ImportExprToken) {
return processImport(current, next, iterator, closedBraceKind, braceOpened);
}
if (current instanceof PrintNameToken) {
return processPrint(current, next, iterator, closedBraceKind, braceOpened);
}
if (current instanceof NewExprToken) {
return processNew(current, closedBraceKind, braceOpened, iterator);
}
if (current instanceof DollarExprToken) {
return processVarVar(current, next, iterator);
}
if (current instanceof VariableExprToken) {
VariableExprToken variable = (VariableExprToken) current;
analyzer.getScope().addVariable(variable);
FunctionStmtToken function = analyzer.getFunction();
if (function != null) {
function.setVarsExists(true);
function.variable((VariableExprToken) current).setUsed(true);
}
}
// Если переменная меняется, значит она нестабильна и не может быть заменена на костантное значение.
if ((current instanceof AssignOperatorExprToken || current instanceof IncExprToken || current instanceof DecExprToken) && previous instanceof VariableExprToken) {
if (analyzer.getFunction() != null) {
analyzer.getFunction().variable((VariableExprToken) previous).setUnstable(true);
}
}
if (current instanceof AssignExprToken && previous instanceof VariableExprToken && next instanceof VariableExprToken) {
ExpressionInfo info = analyzer.getScope().typeInfoOf(next);
analyzer.getScope().typeInfoOf(previous).addTypes(info.getTypes());
}
if (current instanceof ValueIfElseToken) {
return processValueIfElse((ValueIfElseToken) current, next, iterator, closedBraceKind, braceOpened, separator);
}
// &
if (current instanceof AmpersandRefToken) {
/*if (previous == null)
unexpectedToken(current);*/
isRef = true;
if (next instanceof VariableExprToken)
if (analyzer.getFunction() != null) {
analyzer.getFunction().variable((VariableExprToken) next).setReference(true).setMutable(true);
}
if (previous instanceof AssignExprToken || previous instanceof KeyValueExprToken || (canStartByReference && previous == null)) {
if (previous instanceof AssignExprToken)
((AssignExprToken) previous).setAsReference(true);
iterator.previous();
// =
Token token = iterator.previous();
if (iterator.hasPrevious()) {
token = iterator.previous();
if (token instanceof VariableExprToken && analyzer.getFunction() != null) {
analyzer.getFunction().variable((VariableExprToken) token).setReference(true).setMutable(true);
// analyzer.getFunction().getUnstableLocal().add((VariableExprToken)token); TODO: check is needed?
}
iterator.next();
}
iterator.next();
iterator.next();
if (!(next instanceof ValueExprToken))
unexpectedToken(token);
} else {
return new AndExprToken(current.getMeta());
}
return current;
}
// &$var, &$obj->prop['x'], &class::$prop, &$arr['x'], &call()->x;
if (previous instanceof AmpersandRefToken) {
if (current instanceof VariableExprToken)
if (analyzer.getFunction() != null)
analyzer.getFunction().variable((VariableExprToken) current).setReference(true);
}
if ((current instanceof MinusExprToken || current instanceof PlusExprToken) && (next instanceof IntegerExprToken || next instanceof DoubleExprToken)) {
if (!(previous instanceof ValueExprToken || previous instanceof ArrayGetExprToken || previous instanceof DynamicAccessExprToken || isClosedBrace(previous, SIMPLE))) {
iterator.next();
// if it minus
if (current instanceof MinusExprToken) {
if (next instanceof IntegerExprToken) {
return new IntegerExprToken(TokenMeta.of(current, next));
} else if (next instanceof DoubleExprToken) {
return new DoubleExprToken(TokenMeta.of(current, next));
}
}
// if it plus nothing
return next;
}
}
if (current instanceof MinusExprToken) {
if (!(previous instanceof ValueExprToken || previous instanceof ArrayGetExprToken || previous instanceof DynamicAccessExprToken || isClosedBrace(previous))) {
return new UnarMinusExprToken(current.getMeta());
}
}
if (current instanceof LogicOperatorExprToken) {
if (next == null)
unexpectedToken(current);
final LogicOperatorExprToken logic = (LogicOperatorExprToken) current;
ExprStmtToken result = analyzer.generator(SimpleExprGenerator.class).getNextExpression(nextToken(iterator), iterator, separator, braceOpened > 0 ? SIMPLE : closedBraceKind);
logic.setRightValue(result);
return logic;
}
if (next instanceof StaticAccessExprToken) {
return processStaticAccess(next, current, iterator);
}
if (current instanceof StaticAccessExprToken) {
return processStaticAccess(current, null, iterator);
}
if (current instanceof StringExprToken) {
return processString((StringExprToken) current);
}
if (current instanceof NameToken) {
if (previous instanceof InstanceofExprToken) {
return analyzer.getRealName((NameToken) current, NamespaceUseStmtToken.UseType.CLASS);
} else {
return analyzer.getRealName((NameToken) current, NamespaceUseStmtToken.UseType.CONSTANT);
}
}
if (current instanceof MacroToken) {
return null;
}
if (current instanceof OperatorExprToken) {
return null;
}
if (current.isNamedToken()) {
return makeSensitive(current);
}
return null;
}
Aggregations