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;
}
Aggregations