use of php.runtime.reflection.ParameterEntity in project jphp by jphp-compiler.
the class ReflectionFunction method getParameters.
@Override
@Signature
public Memory getParameters(Environment env, Memory... args) {
if (cachedParameters != null)
return cachedParameters;
if (functionEntity instanceof CompileFunctionEntity)
exception(env, "Cannot get parameters for internal function %s()", functionEntity.getName());
ParameterEntity[] parameters = closureEntity == null ? functionEntity.getParameters() : closureEntity.parameters;
ClassEntity entity = env.fetchClass("ReflectionParameter");
ArrayMemory result = new ArrayMemory();
int i = 0;
for (ParameterEntity param : parameters) {
ReflectionParameter e = new ReflectionParameter(env, entity);
e.setEntity(param);
e.setFunctionEntity(functionEntity);
e.setPosition(i);
i++;
result.add(new ObjectMemory(e));
}
return cachedParameters = result;
}
use of php.runtime.reflection.ParameterEntity in project jphp by jphp-compiler.
the class ReflectionMethod method getParameters.
@Override
@Signature
public Memory getParameters(Environment env, Memory... args) {
if (cachedParameters != null)
return cachedParameters;
ParameterEntity[] parameters = methodEntity.getParameters(Integer.MAX_VALUE);
ClassEntity entity = env.fetchClass("ReflectionParameter");
ArrayMemory result = new ArrayMemory();
int i = 0;
for (ParameterEntity param : parameters) {
ReflectionParameter e = new ReflectionParameter(env, entity);
e.setEntity(param);
e.setFunctionEntity(methodEntity);
e.setPosition(i);
i++;
result.add(new ObjectMemory(e));
}
return cachedParameters = result;
}
use of php.runtime.reflection.ParameterEntity in project jphp by jphp-compiler.
the class WrapInvoker method getDescription.
@Signature
public Memory getDescription(Environment env, Memory... args) {
StringBuilderMemory sb = new StringBuilderMemory();
sb.append(invoker.getName());
sb.append("(");
int i = 0;
if (invoker.getParameters() == null) {
sb.append("<internal>");
} else
for (ParameterEntity param : invoker.getParameters()) {
if (i != 0)
sb.append(", ");
sb.append(param.getSignatureString());
i++;
}
sb.append(")");
return sb;
}
use of php.runtime.reflection.ParameterEntity in project jphp by jphp-compiler.
the class InvokeArgumentHelper method checkType.
public static void checkType(Environment env, TraceInfo trace, MethodEntity methodEntity, Memory... args) {
if (args == null) {
return;
}
ParameterEntity[] parameters = methodEntity.getParameters(args.length);
int i = 0;
for (Memory arg : args) {
if (i > parameters.length - 1) {
break;
}
if (!parameters[i].checkTypeHinting(env, arg)) {
invalidType(env, trace, parameters[i], i + 1, arg, methodEntity.getClazzName(), methodEntity.getName());
}
i++;
}
}
use of php.runtime.reflection.ParameterEntity in project jphp by jphp-compiler.
the class InvokeArgumentHelper method unpackArgs.
public static Memory[] unpackArgs(Environment env, TraceInfo trace, Memory[] passed, ParameterEntity[] parameters) {
List<Memory> varPassed = null;
if (passed == null) {
return null;
}
int cnt = 0, paramCnt = 0;
ParameterEntity parameterEntity = null;
boolean variadicMemoryExists = false;
for (Memory arg : passed) {
if (arg instanceof VariadicMemory) {
variadicMemoryExists = true;
if (varPassed == null) {
varPassed = new ArrayList<Memory>();
for (int i = 0; i < cnt; i++) {
varPassed.add(passed[i]);
}
}
boolean isGenerator = arg.instanceOf(Generator.class);
ForeachIterator foreachIterator = arg.getNewIterator(env, !isGenerator, false);
if (foreachIterator == null || (!isGenerator && !arg.isTraversable())) {
env.warning(trace, INVALID_TYPE_MESSAGE);
} else {
boolean isRef;
while (foreachIterator.next()) {
if (parameters != null) {
if (parameterEntity == null || !parameterEntity.isVariadic()) {
parameterEntity = paramCnt < parameters.length ? parameters[paramCnt] : null;
}
}
isRef = parameterEntity != null && parameterEntity.isReference();
Memory value = foreachIterator.getValue();
varPassed.add(isRef ? value : value.toImmutable());
paramCnt++;
if (parameterEntity != null && !parameterEntity.isVariadic()) {
parameterEntity = null;
}
}
}
} else {
if (variadicMemoryExists) {
env.error(trace, "Cannot use positional argument after argument unpacking");
}
if (varPassed != null) {
varPassed.add(arg);
}
paramCnt++;
}
cnt++;
}
if (varPassed != null) {
passed = varPassed.toArray(new Memory[varPassed.size()]);
}
return passed;
}
Aggregations