Search in sources :

Example 1 with ClosureStmtToken

use of org.develnext.jphp.core.tokenizer.token.expr.value.ClosureStmtToken in project jphp by jphp-compiler.

the class JvmCompiler method process.

public List<ExprStmtToken> process(List<Token> tokens, NamespaceStmtToken namespace) {
    List<ExprStmtToken> externalCode = new ArrayList<ExprStmtToken>();
    // write constants
    for (ConstStmtToken constant : analyzer.getConstants()) {
        List<ConstantEntity> items = compileConstant(constant);
        for (ConstantEntity el : items) {
            if (!constants.containsKey(el.getLowerName())) {
                module.addConstant(el);
                if (scope.findUserConstant(el.getName()) != null) {
                    environment.error(el.getTrace(), ErrorType.E_ERROR, Messages.ERR_CANNOT_REDECLARE_CONSTANT, el.getName());
                }
                constants.put(el.getLowerName(), el);
            } else {
                environment.error(el.getTrace(), ErrorType.E_ERROR, Messages.ERR_CANNOT_REDECLARE_CONSTANT, el.getName());
            }
        }
    }
    // write closures
    for (ClosureStmtToken closure : analyzer.getClosures()) {
        ClosureEntity closureEntity = new ClosureStmtCompiler(this, closure).compile();
        module.addClosure(closureEntity);
    }
    for (FunctionStmtToken function : analyzer.getFunctions()) {
        if (!function.isStatic()) {
            FunctionEntity entity = compileFunction(function);
            entity.setStatic(function.isStatic());
            module.addFunction(entity);
        }
    }
    for (Token token : tokens) {
        if (token instanceof NamespaceStmtToken) {
            setNamespace((NamespaceStmtToken) token);
        }
        if (token instanceof DeclareStmtToken) {
            declareStmtTokens.add((DeclareStmtToken) token);
        }
        if (token instanceof ClassStmtToken) {
            ClassStmtCompiler cmp = new ClassStmtCompiler(this, (ClassStmtToken) token);
            ClassEntity entity = cmp.compile();
            entity.setStatic(true);
            module.addClass(entity);
            if (cmp.isInitDynamicExists()) {
                externalCode.add(new ExprStmtToken(getEnvironment(), getContext(), new ClassInitEnvironment((ClassStmtToken) token, entity)));
            }
        } else if (token instanceof FunctionStmtToken) {
            FunctionEntity entity = compileFunction((FunctionStmtToken) token);
            entity.setStatic(true);
            module.addFunction(entity);
            functions.put(entity.getLowerName(), entity);
        } else if (token instanceof ExprStmtToken) {
            externalCode.add((ExprStmtToken) token);
        } else
            externalCode.add(new ExprStmtToken(getEnvironment(), getContext(), token));
    }
    return externalCode;
}
Also used : Token(org.develnext.jphp.core.tokenizer.token.Token) YieldExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.YieldExprToken) NameToken(org.develnext.jphp.core.tokenizer.token.expr.value.NameToken) ClosureStmtToken(org.develnext.jphp.core.tokenizer.token.expr.value.ClosureStmtToken) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) ClosureStmtToken(org.develnext.jphp.core.tokenizer.token.expr.value.ClosureStmtToken)

Aggregations

Token (org.develnext.jphp.core.tokenizer.token.Token)1 ClosureStmtToken (org.develnext.jphp.core.tokenizer.token.expr.value.ClosureStmtToken)1 NameToken (org.develnext.jphp.core.tokenizer.token.expr.value.NameToken)1 YieldExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.YieldExprToken)1 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)1