use of org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken in project jphp by jphp-compiler.
the class FunctionGenerator method processArgument.
@SuppressWarnings("unchecked")
protected ArgumentStmtToken processArgument(ListIterator<Token> iterator) {
boolean isReference = false;
boolean isVariadic = false;
VariableExprToken variable = null;
ExprStmtToken value = null;
Token next = nextToken(iterator);
if (next instanceof CommaToken || isClosedBrace(next, BraceExprToken.Kind.SIMPLE))
return null;
NameToken hintTypeClass = null;
HintType hintType = null;
if (next instanceof SelfExprToken) {
if (analyzer.getClazz() == null) {
unexpectedToken(next);
}
next = analyzer.getClazz().getName();
}
if (next instanceof NameToken) {
String word = ((NameToken) next).getName().toLowerCase();
if (scalarTypeHints.contains(word))
hintType = HintType.of(word);
else {
hintType = jphp_scalarTypeHints.contains(word) ? null : HintType.of(word);
if (hintType == null)
hintTypeClass = analyzer.getRealName((NameToken) next);
}
next = nextToken(iterator);
}
if (next instanceof AmpersandRefToken) {
isReference = true;
next = nextToken(iterator);
}
if (next instanceof ArgumentUnpackExprToken) {
isVariadic = true;
next = nextToken(iterator);
}
if (next instanceof VariableExprToken) {
variable = (VariableExprToken) next;
} else
unexpectedToken(next);
next = nextToken(iterator);
if (next instanceof AssignExprToken) {
if (isVariadic) {
unexpectedToken(next);
}
value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, true, BraceExprToken.Kind.SIMPLE);
} else {
if (next instanceof CommaToken || isClosedBrace(next, BraceExprToken.Kind.SIMPLE)) {
if (next instanceof BraceExprToken) {
iterator.previous();
} else {
if (isVariadic) {
unexpectedToken(next);
}
}
} else
unexpectedToken(next);
}
ArgumentStmtToken argument = new ArgumentStmtToken(variable.getMeta());
argument.setName(variable);
argument.setHintType(hintType);
argument.setHintTypeClass(hintTypeClass);
argument.setReference(isReference);
argument.setVariadic(isVariadic);
argument.setValue(value);
if (argument.isReference() && argument.getValue() != null)
analyzer.getFunction().variable(argument.getName()).setUsed(true);
return argument;
}
use of org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken in project jphp by jphp-compiler.
the class ClassGenerator method processProperty.
protected List<ClassVarStmtToken> processProperty(ClassStmtToken clazz, VariableExprToken current, List<Token> modifiers, ListIterator<Token> iterator) {
Token next = current;
Token prev = null;
Set<VariableExprToken> variables = new LinkedHashSet<VariableExprToken>();
List<ExprStmtToken> initValues = new ArrayList<>();
ExprStmtToken initValue = null;
List<ClassVarStmtToken> result = new ArrayList<ClassVarStmtToken>();
Modifier modifier = Modifier.PUBLIC;
boolean isStatic = false;
for (Token token : modifiers) {
if (token instanceof PrivateStmtToken)
modifier = Modifier.PRIVATE;
else if (token instanceof ProtectedStmtToken)
modifier = Modifier.PROTECTED;
else if (token instanceof StaticExprToken)
isStatic = true;
}
do {
if (next instanceof VariableExprToken) {
if (!variables.add((VariableExprToken) next)) {
throw new ParseException(Messages.ERR_IDENTIFIER_X_ALREADY_USED.fetch(next.getWord()), next.toTraceInfo(analyzer.getContext()));
}
initValues.add(null);
} else if (next instanceof CommaToken) {
if (!(prev instanceof VariableExprToken))
unexpectedToken(next);
} else if (next instanceof AssignExprToken) {
if (!(prev instanceof VariableExprToken))
unexpectedToken(next);
initValue = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, Separator.COMMA_OR_SEMICOLON, null);
initValues.set(initValues.size() - 1, initValue);
if (iterator.hasPrevious() && isBreak(iterator.previous())) {
iterator.next();
break;
}
if (iterator.hasNext()) {
iterator.next();
}
//break;
} else if (next instanceof SemicolonToken) {
if (!(prev instanceof VariableExprToken))
unexpectedToken(next);
break;
}
prev = next;
next = nextToken(iterator);
} while (true);
int i = 0;
for (VariableExprToken variable : variables) {
ClassVarStmtToken classVar = new ClassVarStmtToken(variable.getMeta());
classVar.setModifier(modifier);
classVar.setStatic(isStatic);
classVar.setValue(initValues.get(i));
classVar.setVariable(variable);
classVar.setClazz(clazz);
result.add(classVar);
i++;
}
return result;
}
use of org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken in project jphp by jphp-compiler.
the class ConstGenerator method getToken.
/*@SuppressWarnings("unchecked")
protected void processBody(ConstStmtToken result, ListIterator<Token> iterator){
Token current = nextToken(iterator);
if (!(current instanceof AssignExprToken))
unexpectedToken(current, "=");
ExprStmtToken value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator);
if (value == null)
unexpectedToken(nextToken(iterator));
result.setValue(value);
}*/
@Override
@SuppressWarnings("unchecked")
public ConstStmtToken getToken(Token current, ListIterator<Token> iterator) {
if (current instanceof ConstStmtToken) {
ConstStmtToken result = (ConstStmtToken) current;
Token prev = null;
if (analyzer.getClazz() == null)
result.setNamespace(analyzer.getNamespace());
while (true) {
Token next = analyzer.getClazz() == null ? nextToken(iterator) : nextTokenSensitive(iterator, ClassStmtToken.class);
if (next instanceof NameToken) {
if (next instanceof FulledNameToken && !((FulledNameToken) next).isProcessed(NamespaceUseStmtToken.UseType.CONSTANT))
unexpectedToken(next, TokenType.T_STRING);
Token token = nextToken(iterator);
if (!(token instanceof AssignExprToken))
unexpectedToken(token, "=");
ExprStmtToken value = analyzer.generator(SimpleExprGenerator.class).getToken(nextToken(iterator), iterator, Separator.COMMA_OR_SEMICOLON, null);
if (!isBreak(iterator.previous())) {
iterator.next();
}
if (value == null)
unexpectedToken(iterator.previous());
result.add((NameToken) next, value);
} else if (next instanceof CommaToken) {
if (prev instanceof CommaToken)
unexpectedToken(next);
prev = next;
} else if (isBreak(next)) {
break;
} else
unexpectedToken(next, TokenType.T_STRING);
}
return result;
}
return null;
}
Aggregations