use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class SPLFunctions method class_implements.
public static Memory class_implements(Environment env, TraceInfo trace, Memory object, boolean autoLoad) {
ClassEntity entity;
if (object.isObject()) {
entity = object.toValue(ObjectMemory.class).getReflection();
} else {
entity = env.fetchClass(object.toString(), autoLoad);
}
if (entity == null) {
env.warning(trace, "class_implements(): Class %s does not exist and could not be loaded", object.toString());
return Memory.FALSE;
}
ArrayMemory result = new ArrayMemory();
do {
for (ClassEntity el : entity.getInterfaces().values()) {
result.refOfIndex(el.getName()).assign(el.getName());
}
entity = entity.getParent();
if (entity == null)
break;
} while (true);
return result.toConstant();
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class ReflectionFunction method invokeArgs.
@Signature(@Arg(value = "args", type = HintType.ARRAY))
public Memory invokeArgs(Environment env, Memory... args) throws Throwable {
ArrayMemory value = args[0].toValue(ArrayMemory.class);
Memory[] passed = value.values();
return invoke(env, passed);
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class InvokeArgumentHelper method makeArguments.
public static Memory[] makeArguments(Environment env, Memory[] args, ParameterEntity[] parameters, String originClassName, String originMethodName, TraceInfo trace) {
if (parameters == null)
return args;
args = unpackArgs(env, trace, args, parameters);
Memory[] passed = args;
if ((args == null && parameters.length > 0) || (args != null && args.length < parameters.length)) {
passed = new Memory[parameters.length];
if (args != null && args.length > 0) {
System.arraycopy(args, 0, passed, 0, args.length);
}
}
int i = 0;
if (passed != null) {
boolean variadicMemoryExists = false;
for (ParameterEntity param : parameters) {
Memory arg = passed[i];
if (param.isVariadic()) {
ArrayMemory variadicArgs = new ArrayMemory();
int _i = i;
while (arg != null) {
if (arg instanceof VariadicMemory) {
variadicMemoryExists = true;
ForeachIterator iterator = arg.getNewIterator(env, param.isReference(), false);
if (iterator == null) {
env.warning(trace, INVALID_TYPE_MESSAGE);
} else {
makeVariadic(iterator, variadicArgs, param, env, trace, _i, originClassName, originMethodName);
}
} else {
if (variadicMemoryExists) {
env.error(trace, "Cannot use positional argument after argument unpacking");
}
if (!param.checkTypeHinting(env, arg)) {
invalidType(env, trace, param, _i + 1, arg, originClassName, originMethodName);
}
variadicArgs.add(makeValue(param, arg, env, trace));
}
i++;
if (i < passed.length) {
arg = passed[i];
} else {
break;
}
}
passed[_i] = variadicArgs;
break;
}
if (arg == null) {
Memory def = param.getDefaultValue();
if (def != null) {
if (!param.isReference()) {
passed[i] = param.isMutable() ? def.toImmutable(env, trace) : def;
} else {
passed[i] = new ReferenceMemory(param.isMutable() ? def.toImmutable(env, trace) : def);
}
} else {
if (param.getTypeClass() != null) {
invalidType(env, trace, param, i + 1, null, originClassName, originMethodName);
}
env.error(trace, ErrorType.E_ERROR, Messages.ERR_MISSING_ARGUMENT, (i + 1) + " ($" + param.getName() + ")", originMethodName == null ? originClassName : originClassName + "::" + originMethodName);
passed[i] = param.isReference() ? new ReferenceMemory() : Memory.NULL;
}
} else {
if (param.isReference()) {
if (!arg.isReference() && !arg.isObject()) {
env.error(trace, ErrorType.E_ERROR, "Only variables can be passed by reference");
passed[i] = new ReferenceMemory(arg);
}
} else {
passed[i] = param.isMutable() ? arg.toImmutable() : arg.toValue();
}
}
if (!param.checkTypeHinting(env, passed[i])) {
invalidType(env, trace, param, i + 1, passed[i], originClassName, originMethodName);
}
i++;
}
if (!variadicMemoryExists) {
for (int j = parameters.length; j < passed.length; j++) {
passed[j] = passed[j].toImmutable();
}
}
}
return passed;
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class InvokeArgumentHelper method makeVariadic.
public static void makeVariadic(ForeachIterator iterator, ArrayMemory variadicArray, ParameterEntity param, Environment env, TraceInfo trace, int index, String originClassName, String originMethodName) {
while (iterator.next()) {
Memory arg = iterator.getValue();
if (!param.checkTypeHinting(env, arg)) {
invalidType(env, trace, param, index + 1, arg, originClassName, originMethodName);
}
variadicArray.add(makeValue(param, iterator.getValue(), env, trace));
}
}
use of php.runtime.memory.ArrayMemory in project jphp by jphp-compiler.
the class WrapLocale method __debugInfo.
@Signature
public Memory __debugInfo(Environment env, Memory... args) {
ArrayMemory r = new ArrayMemory();
r.refOfIndex("*language").assign(locale.getLanguage());
r.refOfIndex("*country").assign(locale.getCountry());
r.refOfIndex("*variant").assign(locale.getVariant());
return r.toConstant();
}
Aggregations