Search in sources :

Example 1 with AssignExprToken

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;
}
Also used : CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) HintType(php.runtime.common.HintType) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) ArgumentUnpackExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) AmpersandRefToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) ArgumentUnpackExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken) AmpersandRefToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken)

Example 2 with AssignExprToken

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;
}
Also used : CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) CommentToken(org.develnext.jphp.core.tokenizer.token.CommentToken) BraceExprToken(org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) ParseException(php.runtime.exceptions.ParseException) Modifier(php.runtime.common.Modifier)

Example 3 with AssignExprToken

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;
}
Also used : CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) SimpleExprGenerator(org.develnext.jphp.core.syntax.generators.manually.SimpleExprGenerator) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken) Token(org.develnext.jphp.core.tokenizer.token.Token) AssignExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken) ClassExprToken(org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken) ImportExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.ImportExprToken) OperatorExprToken(org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken) CommaToken(org.develnext.jphp.core.tokenizer.token.expr.CommaToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken) FulledNameToken(org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)

Aggregations

Token (org.develnext.jphp.core.tokenizer.token.Token)3 CommaToken (org.develnext.jphp.core.tokenizer.token.expr.CommaToken)3 AssignExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AssignExprToken)3 CommentToken (org.develnext.jphp.core.tokenizer.token.CommentToken)2 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)2 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)2 SimpleExprGenerator (org.develnext.jphp.core.syntax.generators.manually.SimpleExprGenerator)1 ClassExprToken (org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken)1 OperatorExprToken (org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken)1 ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)1 AmpersandRefToken (org.develnext.jphp.core.tokenizer.token.expr.operator.AmpersandRefToken)1 ArgumentUnpackExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.ArgumentUnpackExprToken)1 FulledNameToken (org.develnext.jphp.core.tokenizer.token.expr.value.FulledNameToken)1 ImportExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.ImportExprToken)1 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)1 HintType (php.runtime.common.HintType)1 Modifier (php.runtime.common.Modifier)1 ParseException (php.runtime.exceptions.ParseException)1