Search in sources :

Example 11 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class ReflectionProperty method __construct.

@Signature({ @Arg("class"), @Arg("name") })
public Memory __construct(Environment env, Memory... args) {
    ClassEntity classEntity;
    Memory arg = args[0];
    if (arg.isObject()) {
        classEntity = arg.toValue(ObjectMemory.class).getReflection();
    } else
        classEntity = env.fetchClass(arg.toString());
    if (classEntity == null) {
        exception(env, Messages.ERR_CLASS_NOT_FOUND.fetch(arg));
        return Memory.NULL;
    }
    String prop = args[1].toString();
    PropertyEntity entity = classEntity.findProperty(prop);
    if (entity == null)
        entity = classEntity.findStaticProperty(prop);
    if (entity == null) {
        exception(env, Messages.ERR_UNDEFINED_PROPERTY.fetch(classEntity.getName(), prop));
        return Memory.NULL;
    }
    setEntity(entity);
    return Memory.NULL;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) Memory(php.runtime.Memory) LongMemory(php.runtime.memory.LongMemory) StringMemory(php.runtime.memory.StringMemory) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 12 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class ReflectionClass method getMethods.

@Signature(@Arg(value = "filter", optional = @Optional("NULL")))
public Memory getMethods(Environment env, Memory... args) {
    int mod = args[0].isNull() ? -1 : args[0].toInteger();
    ArrayMemory result = new ArrayMemory();
    ClassEntity classEntity = env.fetchClass("ReflectionMethod");
    for (MethodEntity e : entity.getMethods().values()) {
        if (checkModifiers(e, mod)) {
            ReflectionMethod method = new ReflectionMethod(env, classEntity);
            method.setEntity(e);
            result.add(new ObjectMemory(method));
        }
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory) MethodEntity(php.runtime.reflection.MethodEntity)

Example 13 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class ReflectionClass method getParentClass.

@Signature
public Memory getParentClass(Environment env, Memory... args) {
    if (entity.getParent() == null)
        return Memory.NULL;
    ClassEntity classEntity = env.fetchClass("ReflectionClass");
    ReflectionClass result = new ReflectionClass(env, classEntity);
    result.setEntity(entity.getParent());
    return new ObjectMemory(result);
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 14 with ClassEntity

use of php.runtime.reflection.ClassEntity 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;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) MethodEntity(php.runtime.reflection.MethodEntity) ClassStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ClassStmtToken) MethodStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.MethodStmtToken)

Example 15 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class GeneratorStmtCompiler method compile.

@Override
public GeneratorEntity compile() {
    GeneratorEntity entity = new GeneratorEntity(getCompiler().getContext());
    entity.setReturnReference(statement.isReturnReference());
    entity.setInternalName(compiler.getModule().getInternalName() + "_generator" + statement.getId());
    entity.setId(statement.getGeneratorId());
    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(Generator.class.getSimpleName()));
    MethodStmtToken methodToken = new MethodStmtToken(statement);
    methodToken.setClazz(classStmtToken);
    methodToken.setGenerator(false);
    methodToken.setReturnReference(false);
    methodToken.setModifier(Modifier.PROTECTED);
    methodToken.setName(NameToken.valueOf("_run"));
    methodToken.setUses(statement.getArguments());
    methodToken.setArguments(Collections.<ArgumentStmtToken>emptyList());
    classStmtToken.setMethods(Arrays.asList(methodToken));
    ClassStmtCompiler classStmtCompiler = new ClassStmtCompiler(this.compiler, classStmtToken);
    classStmtCompiler.setSystem(true);
    classStmtCompiler.setInterfaceCheck(false);
    classStmtCompiler.setGeneratorEntity(entity);
    classStmtCompiler.setFunctionName(statement.getFulledName());
    ClassEntity clazzEntity = classStmtCompiler.compile();
    entity.getMethods().putAll(clazzEntity.getMethods());
    if (clazzEntity.getParent() != null)
        entity.setParent(clazzEntity.getParent());
    entity.setData(clazzEntity.getData());
    entity.doneDeclare();
    return entity;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) GeneratorEntity(php.runtime.reflection.helper.GeneratorEntity)

Aggregations

ClassEntity (php.runtime.reflection.ClassEntity)54 ObjectMemory (php.runtime.memory.ObjectMemory)21 Memory (php.runtime.Memory)14 ArrayMemory (php.runtime.memory.ArrayMemory)14 PropertyEntity (php.runtime.reflection.PropertyEntity)10 MethodEntity (php.runtime.reflection.MethodEntity)9 StringMemory (php.runtime.memory.StringMemory)8 ConstantEntity (php.runtime.reflection.ConstantEntity)5 FunctionEntity (php.runtime.reflection.FunctionEntity)5 CriticalException (php.runtime.exceptions.CriticalException)4 Closure (php.runtime.lang.Closure)4 IObject (php.runtime.lang.IObject)4 ReferenceMemory (php.runtime.memory.ReferenceMemory)4 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)4 GeneratorEntity (php.runtime.reflection.helper.GeneratorEntity)4 ForeachIterator (php.runtime.lang.ForeachIterator)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2