use of org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken in project jphp by jphp-compiler.
the class ClosureStmtCompiler method compile.
@Override
public ClosureEntity compile() {
ClosureEntity entity = new ClosureEntity(getCompiler().getContext());
entity.setReturnReference(statement.getFunction().isReturnReference());
entity.setInternalName(compiler.getModule().getInternalName() + "_closure" + statement.getId());
entity.setId(statement.getId());
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
ClassStmtToken classStmtToken = new ClassStmtToken(statement.getMeta());
classStmtToken.setNamespace(NamespaceStmtToken.getDefault());
classStmtToken.setName(NameToken.valueOf(entity.getInternalName()));
classStmtToken.setExtend(ExtendsStmtToken.valueOf(Closure.class.getSimpleName()));
MethodStmtToken methodToken = new MethodStmtToken(statement.getFunction());
methodToken.setClazz(classStmtToken);
methodToken.setReturnReference(entity.isReturnReference());
methodToken.setModifier(Modifier.PUBLIC);
methodToken.setName(NameToken.valueOf("__invoke"));
classStmtToken.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(this.compiler, classStmtToken);
classStmtCompiler.setSystem(true);
classStmtCompiler.setInterfaceCheck(false);
classStmtCompiler.setClassContext(statement.getOwnerClass());
classStmtCompiler.setFunctionName(null);
ClassEntity clazzEntity = classStmtCompiler.compile();
MethodEntity __invoke = clazzEntity.findMethod("__invoke");
entity.getMethods().putAll(clazzEntity.getMethods());
if (clazzEntity.getParent() != null)
entity.setParent(clazzEntity.getParent());
entity.setData(clazzEntity.getData());
entity.setParameters(__invoke.getParameters());
entity.doneDeclare();
entity.setGeneratorEntity(__invoke.getGeneratorEntity());
return entity;
}
use of org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken in project jphp by jphp-compiler.
the class FunctionStmtCompiler method compile.
@Override
public FunctionEntity compile() {
//
ModuleEntity module = compiler.getModule();
FunctionEntity entity = new FunctionEntity(compiler.getContext());
entity.setModule(module);
entity.setName(statement.getFulledName());
entity.setReturnReference(statement.isReturnReference());
entity.setInternalName(compiler.getModule().getInternalName() + "_func" + statement.getId());
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
if (statement.getDocComment() != null)
entity.setDocComment(new DocumentComment(statement.getDocComment().getComment()));
NamespaceStmtToken namespace = NamespaceStmtToken.getDefault();
ClassStmtToken token = new ClassStmtToken(statement.getMeta());
token.setFinal(true);
token.setNamespace(namespace);
token.setName(new NameToken(TokenMeta.of(entity.getInternalName())));
MethodStmtToken methodToken = new MethodStmtToken(statement);
methodToken.setClazz(token);
methodToken.setFinal(true);
methodToken.setStatic(true);
methodToken.setReturnReference(entity.isReturnReference());
methodToken.setModifier(Modifier.PUBLIC);
methodToken.setName(new NameToken(TokenMeta.of("__invoke")));
token.setMethods(Arrays.asList(methodToken));
ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(compiler, token);
classStmtCompiler.setSystem(true);
classStmtCompiler.setFunctionName(entity.getName());
ClassEntity clazzEntity = classStmtCompiler.compile();
entity.setData(clazzEntity.getData());
MethodEntity methodEntity = clazzEntity.findMethod("__invoke");
entity.setParameters(methodEntity.getParameters());
entity.setEmpty(methodEntity.isEmpty());
entity.setUsesStackTrace(methodEntity.isUsesStackTrace());
entity.setImmutable(methodEntity.isImmutable());
entity.setResult(methodEntity.getResult());
entity.setGeneratorEntity(methodEntity.getGeneratorEntity());
return entity;
}
use of org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken in project jphp by jphp-compiler.
the class ClassStmtCompiler method compile.
@Override
public ClassEntity compile() {
entity = new ClassEntity(compiler.getContext());
entity.setId(compiler.getScope().nextClassIndex());
entity.setFinal(statement.isFinal());
entity.setAbstract(statement.isAbstract());
entity.setName(statement.getFulledName());
if (statement.getDocComment() != null)
entity.setDocComment(new DocumentComment(statement.getDocComment().getComment()));
entity.setTrace(statement.toTraceInfo(compiler.getContext()));
entity.setType(statement.getClassType());
List<ClassEntity> traits = fetchTraits();
for (ClassEntity e : traits) entity.addTrait(e);
checkAliasAndReplacementsTraits();
if (statement.getExtend() != null) {
ClassEntity parent = fetchClass(statement.getExtend().getName().getName());
if (parent == null)
compiler.getEnvironment().error(statement.getExtend().toTraceInfo(compiler.getContext()), Messages.ERR_CLASS_NOT_FOUND.fetch(statement.getExtend().getName().toName()));
ClassEntity.ExtendsResult result = entity.setParent(parent, false);
if (isInterfaceCheck) {
result.check(compiler.getEnvironment());
}
}
if (!isSystem) {
if (entity.isUseJavaLikeNames()) {
entity.setInternalName(entity.getName().replace('\\', '/'));
} else {
entity.setInternalName(compiler.getModule().getInternalName() + "_class" + compiler.getModule().getClasses().size());
}
}
if (compiler.getModule().findClass(entity.getLowerName()) != null || compiler.getEnvironment().isLoadedClass(entity.getLowerName())) {
throw new FatalException(Messages.ERR_CANNOT_REDECLARE_CLASS.fetch(entity.getName()), statement.getName().toTraceInfo(compiler.getContext()));
}
if (!statement.isInterface()) {
node.access = ACC_SUPER + ACC_PUBLIC;
node.name = !isSystem ? /*&& !statement.isTrait()*/
entity.getCompiledInternalName() : statement.getFulledName(Constants.NAME_DELIMITER);
node.superName = entity.getParent() == null ? Type.getInternalName(BaseObject.class) : entity.getParent().getInternalName();
node.sourceFile = compiler.getSourceFile();
/*if (!isSystem) {
AnnotationNode annotationNode = new AnnotationNode(Type.getInternalName(Reflection.Name.class));
annotationNode.values = Arrays.asList("value", entity.getName());
node.visibleAnnotations.add(annotationNode);
} */
writeSystemInfo();
writeConstructor();
writeDefaultConstructors();
}
// constants
if (statement.getConstants() != null)
for (ConstStmtToken constant : statement.getConstants()) {
writeConstant(constant);
}
if (statement.getMethods() != null) {
for (MethodStmtToken method : statement.getMethods()) {
ClassEntity.SignatureResult result = entity.addMethod(compiler.compileMethod(this, method, external, generatorEntity), null);
result.check(compiler.getEnvironment());
}
}
writeTraits(traits);
ClassEntity.SignatureResult result = entity.updateParentMethods();
if (isInterfaceCheck) {
result.check(compiler.getEnvironment());
}
writeImplements();
entity.doneDeclare();
if (!statement.isInterface()) {
writeDestructor();
if (entity.getType() != ClassEntity.Type.INTERFACE) {
writeInitEnvironment();
}
writeInitStatic();
cw = new JPHPClassWriter(entity.isTrait());
node.accept(cw);
entity.setData(cw.toByteArray());
}
return entity;
}
use of org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken in project jphp by jphp-compiler.
the class ClassDescription method parse.
@Override
protected void parse() {
methods = new LinkedHashMap<String, MethodDescription>();
for (MethodStmtToken el : token.getMethods()) {
methods.put(el.getName().getName().toLowerCase(), new MethodDescription(el));
}
properties = new LinkedHashMap<String, PropertyDescription>();
for (ClassVarStmtToken el : token.getProperties()) {
properties.put(el.getVariable().getName(), new PropertyDescription(el));
}
constants = new LinkedHashMap<String, ConstantDescription>();
for (ConstStmtToken el : token.getConstants()) {
constants.put(el.items.get(0).getFulledName(), new ConstantDescription(el));
}
if (token.getDocComment() != null) {
DocAnnotations annotations = new DocAnnotations(token.getDocComment().getComment());
description = annotations.getDescription();
}
}
Aggregations