Search in sources :

Example 36 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class InfoFunctions method get_defined_functions.

public static Memory get_defined_functions(Environment env) {
    ArrayMemory array = new ArrayMemory();
    ArrayMemory item = (ArrayMemory) array.refOfIndex("internal").assign(new ArrayMemory());
    for (FunctionEntity entity : env.getFunctions()) {
        if (entity.isInternal())
            item.add(new StringMemory(entity.getName()));
    }
    item = (ArrayMemory) array.refOfIndex("user").assign(new ArrayMemory());
    for (FunctionEntity entity : env.getLoadedFunctions().values()) {
        if (!entity.isInternal())
            item.add(new StringMemory(entity.getName()));
    }
    return array.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) FunctionEntity(php.runtime.reflection.FunctionEntity) StringMemory(php.runtime.memory.StringMemory)

Example 37 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class LangFunctions method property_exists.

public static Memory property_exists(Environment env, Memory clazz, String property) throws Throwable {
    ClassEntity classEntity;
    IObject object = null;
    boolean isMagic = false;
    if (clazz.isObject()) {
        ObjectMemory tmp = clazz.toValue(ObjectMemory.class);
        classEntity = tmp.getReflection();
        object = tmp.value;
    } else {
        String name = clazz.toString();
        String nameL = name.toLowerCase();
        classEntity = env.fetchClass(name, nameL, true);
        if (classEntity == null) {
            classEntity = env.fetchMagicClass(name, nameL);
            isMagic = true;
        }
    }
    if (classEntity == null) {
        return Memory.FALSE;
    }
    if (object != null) {
        ArrayMemory props = object.getProperties();
        ClassEntity context = env.getLastClassOnStack();
        PropertyEntity entity = classEntity.isInstanceOf(context) ? context.properties.get(property) : classEntity.properties.get(property);
        int accessFlags = entity == null ? 0 : entity.canAccess(env);
        if (accessFlags != 0)
            return Memory.FALSE;
        return (props != null && props.getByScalar(entity == null ? property : entity.getSpecificName()) != null) ? Memory.TRUE : Memory.FALSE;
    } else {
        PropertyEntity entity = classEntity.properties.get(property);
        if (isMagic) {
            int accessFlags = entity == null ? 0 : entity.canAccess(env);
            if (accessFlags != 0)
                return Memory.FALSE;
        }
        return entity != null ? Memory.TRUE : Memory.FALSE;
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 38 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class LangFunctions method debug_backtrace.

public static Memory debug_backtrace(Environment env, TraceInfo trace, int options, int limit) {
    boolean provideObject = (options & LangConstants.DEBUG_BACKTRACE_PROVIDE_OBJECT) == LangConstants.DEBUG_BACKTRACE_PROVIDE_OBJECT;
    boolean ignoreArgs = (options & LangConstants.DEBUG_BACKTRACE_IGNORE_ARGS) == LangConstants.DEBUG_BACKTRACE_IGNORE_ARGS;
    ArrayMemory result = new ArrayMemory();
    for (int i = 0; i < env.getCallStackTop(); i++) {
        if (limit != 0 && i >= limit)
            break;
        CallStackItem item = env.peekCall(i);
        ArrayMemory el = item.toArray(provideObject, ignoreArgs);
        result.add(el);
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) CallStackItem(php.runtime.env.CallStackItem)

Example 39 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class LangFunctions method get_class_vars.

public static Memory get_class_vars(Environment env, TraceInfo trace, Memory value) {
    ClassEntity entity;
    if (value.isString()) {
        entity = env.fetchClass(value.toString(), true);
    } else if (value.isObject()) {
        entity = value.toValue(ObjectMemory.class).getReflection();
    } else {
        env.warning(trace, "get_class_vars(): Argument 1 must be string or object, %s given", value.getRealType().toString());
        return Memory.NULL;
    }
    if (entity == null)
        return Memory.NULL;
    ClassEntity context = env.getLastClassOnStack();
    ArrayMemory result = new ArrayMemory();
    for (PropertyEntity el : entity.getProperties()) {
        if (el.canAccess(env, context) == 0)
            result.refOfIndex(el.getName()).assign(el.getDefaultValue(env));
    }
    for (PropertyEntity el : entity.getStaticProperties()) {
        if (el.canAccess(env, context) == 0)
            result.refOfIndex(el.getName()).assign(el.getDefaultValue(env));
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 40 with ArrayMemory

use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.

the class LangFunctions method error_get_last.

public static Memory error_get_last(Environment env) {
    SystemMessage err = env.getLastMessage();
    if (err == null)
        return Memory.NULL;
    ArrayMemory result = new ArrayMemory();
    result.refOfIndex("type").assign(err.getType().value);
    result.refOfIndex("message").assign(err.getMessage());
    if (err.getTrace() != null && err.getTrace().trace != null) {
        result.refOfIndex("file").assign(err.getTrace().trace.getFileName());
        result.refOfIndex("line").assign(err.getTrace().trace.getStartLine() + 1);
        result.refOfIndex("position").assign(err.getTrace().trace.getStartPosition() + 1);
    }
    return result.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) SystemMessage(php.runtime.env.message.SystemMessage)

Aggregations

ArrayMemory (php.runtime.memory.ArrayMemory)148 Memory (php.runtime.Memory)60 ForeachIterator (php.runtime.lang.ForeachIterator)41 ObjectMemory (php.runtime.memory.ObjectMemory)35 LongMemory (php.runtime.memory.LongMemory)31 StringMemory (php.runtime.memory.StringMemory)29 ReferenceMemory (php.runtime.memory.ReferenceMemory)25 KeyValueMemory (php.runtime.memory.KeyValueMemory)17 Invoker (php.runtime.invoke.Invoker)9 ClassEntity (php.runtime.reflection.ClassEntity)9 Signature (php.runtime.annotation.Reflection.Signature)6 IObject (php.runtime.lang.IObject)6 Map (java.util.Map)4 Test (org.junit.Test)4 DoubleMemory (php.runtime.memory.DoubleMemory)4 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)3 TraceInfo (php.runtime.env.TraceInfo)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ParameterEntity (php.runtime.reflection.ParameterEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2