Search in sources :

Example 1 with Scope

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;
}
Also used : MacroToken(org.develnext.jphp.core.tokenizer.token.expr.value.macro.MacroToken) SemicolonToken(org.develnext.jphp.core.tokenizer.token.SemicolonToken) Token(org.develnext.jphp.core.tokenizer.token.Token) CastExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.cast.CastExprToken) BreakToken(org.develnext.jphp.core.tokenizer.token.BreakToken) ColonToken(org.develnext.jphp.core.tokenizer.token.ColonToken) UnsetCastExprToken(org.develnext.jphp.core.tokenizer.token.expr.operator.cast.UnsetCastExprToken) Scope(org.develnext.jphp.core.syntax.Scope)

Aggregations

Scope (org.develnext.jphp.core.syntax.Scope)1 BreakToken (org.develnext.jphp.core.tokenizer.token.BreakToken)1 ColonToken (org.develnext.jphp.core.tokenizer.token.ColonToken)1 SemicolonToken (org.develnext.jphp.core.tokenizer.token.SemicolonToken)1 Token (org.develnext.jphp.core.tokenizer.token.Token)1 CastExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.cast.CastExprToken)1 UnsetCastExprToken (org.develnext.jphp.core.tokenizer.token.expr.operator.cast.UnsetCastExprToken)1 MacroToken (org.develnext.jphp.core.tokenizer.token.expr.value.macro.MacroToken)1