use of org.develnext.jphp.core.tokenizer.token.stmt.ConstStmtToken.Item in project jphp by jphp-compiler.
the class JvmCompiler method compile.
@Override
public ModuleEntity compile(boolean autoRegister) {
module.setInternalName("$php_module_m" + UUID.randomUUID().toString().replace("-", ""));
List<ExprStmtToken> externalCode = process(tokens, NamespaceStmtToken.getDefault());
for (DeclareStmtToken declare : declareStmtTokens) {
String name = declare.getName().getName();
ExpressionStmtCompiler expressionStmtCompiler = new ExpressionStmtCompiler(this);
Memory value = expressionStmtCompiler.tryCalculateExpression(declare.getValue());
switch(name.toLowerCase()) {
case "strict_types":
module.setStrictTypes(value.toBoolean());
break;
default:
environment.error(declare.getValue().getMeta().toTraceInfo(context), ErrorType.E_ERROR, Messages.ERR_INVALID_DECLARE_CONSTANT, name);
}
}
NamespaceStmtToken namespace = NamespaceStmtToken.getDefault();
ClassStmtToken token = new ClassStmtToken(TokenMeta.of(module.getName()));
token.setFinal(true);
token.setName(new NameToken(TokenMeta.of(module.getInternalName())));
token.setNamespace(namespace);
MethodStmtToken methodToken = new MethodStmtToken(token.getMeta());
methodToken.setFinal(true);
methodToken.setClazz(token);
methodToken.setModifier(Modifier.PUBLIC);
methodToken.setStatic(true);
methodToken.setDynamicLocal(true);
methodToken.setName((NameToken) Token.of("__include"));
methodToken.setArguments(new ArrayList<>());
methodToken.setLocal(analyzer.getScope().getVariables());
methodToken.setLabels(analyzer.getScope().getLabels());
for (Item dynamicConstant : dynamicConstants) {
CallExprToken callExprToken = new CallExprToken(token.getMeta());
callExprToken.setName(NameToken.valueOf("define"));
callExprToken.setParameters(Arrays.asList(new ExprStmtToken(environment, context, new StringExprToken(TokenMeta.of(dynamicConstant.getFulledName()), Quote.SINGLE)), dynamicConstant.value));
externalCode.add(0, new ExprStmtToken(getEnvironment(), context, callExprToken));
}
methodToken.setBody(BodyStmtToken.of(externalCode));
token.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(this, token);
classStmtCompiler.setExternal(true);
classStmtCompiler.setSystem(true);
module.setData(classStmtCompiler.compile().getData());
if (autoRegister)
scope.addUserModule(module);
return module;
}