use of org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken in project jphp by jphp-compiler.
the class ExpressionStmtCompiler method writePushStaticMethod.
Memory writePushStaticMethod(CallExprToken function, boolean returnValue, boolean writeOpcode, PushCallStatistic statistic) {
StaticAccessExprToken access = (StaticAccessExprToken) function.getName();
if (!writeOpcode)
return null;
writeLineNumber(function);
if (writePushFastStaticMethod(function, returnValue))
return null;
writePushEnv();
writePushTraceInfo(function.getName());
String methodName = null;
ValueExprToken clazz = access.getClazz();
if ((clazz instanceof NameToken || (clazz instanceof SelfExprToken && !method.clazz.entity.isTrait())) && access.getField() instanceof NameToken) {
String className;
if (clazz instanceof SelfExprToken)
className = getMacros(clazz).toString();
else
className = ((NameToken) clazz).getName();
writePushString(className.toLowerCase());
methodName = ((NameToken) access.getField()).getName();
writePushString(methodName.toLowerCase());
writePushString(className);
writePushString(methodName);
writePushParameters(function.getParameters());
if (method.clazz.statement.isTrait()) {
writePushConstNull();
writePushConstInt(0);
} else {
int cacheIndex = method.clazz.getAndIncCallMethCount();
writeGetStatic("$CALL_METH_CACHE", MethodCallCache.class);
writePushConstInt(cacheIndex);
}
writeSysStaticCall(InvokeHelper.class, "callStatic", Memory.class, Environment.class, TraceInfo.class, // lower sign name
String.class, // lower sign name
String.class, // origin names
String.class, // origin names
String.class, Memory[].class, MethodCallCache.class, Integer.TYPE);
} else {
if (clazz instanceof NameToken) {
writePushString(((NameToken) clazz).getName());
writePushDupLowerCase();
} else if (clazz instanceof SelfExprToken) {
writePushSelf(true);
} else if (clazz instanceof StaticExprToken) {
writePushStatic();
writePushDupLowerCase();
} else {
writePush(clazz, true, false);
writePopString();
writePushDupLowerCase();
}
if (access.getField() != null) {
ValueExprToken field = access.getField();
if (field instanceof NameToken) {
writePushString(((NameToken) field).getName());
writePushString(((NameToken) field).getName().toLowerCase());
} else if (field instanceof ClassExprToken) {
unexpectedToken(field);
} else {
writePush(access.getField(), true, false);
writePopString();
writePushDupLowerCase();
}
} else {
writeExpression(access.getFieldExpr(), true, false);
writePopString();
writePushDupLowerCase();
}
writePushParameters(function.getParameters());
if (clazz instanceof StaticExprToken || method.clazz.statement.isTrait() || clazz instanceof VariableExprToken) {
writePushConstNull();
writePushConstInt(0);
} else {
int cacheIndex = method.clazz.getAndIncCallMethCount();
writeGetStatic("$CALL_METH_CACHE", MethodCallCache.class);
writePushConstInt(cacheIndex);
}
writeSysStaticCall(InvokeHelper.class, "callStaticDynamic", Memory.class, Environment.class, TraceInfo.class, String.class, String.class, String.class, String.class, Memory[].class, MethodCallCache.class, Integer.TYPE);
}
if (statistic != null)
statistic.returnType = StackItem.Type.REFERENCE;
return null;
}
use of org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken in project jphp by jphp-compiler.
the class StaticAccessValueCompiler method write.
@Override
public void write(StaticAccessExprToken token, boolean returnValue) {
boolean isConstant = token.getField() instanceof NameToken;
if (token.getField() instanceof ClassExprToken) {
if (token.getClazz() instanceof ParentExprToken) {
expr.writePushParent(token.getClazz());
} else if (token.getClazz() instanceof StaticExprToken) {
expr.writePushStatic();
} else if (token.getClazz() instanceof SelfExprToken) {
expr.writePushSelf(false);
} else
expr.unexpectedToken(token);
} else {
ValueExprToken clazz = token.getClazz();
if (clazz instanceof ParentExprToken) {
expr.writePushParent(clazz);
} else if (clazz instanceof NameToken) {
expr.writePushConstString(((NameToken) clazz).getName());
expr.writePushConstString(((NameToken) clazz).getName().toLowerCase());
} else {
if (clazz instanceof StaticExprToken) {
expr.writePushStatic();
} else {
if (clazz != null) {
expr.writePush(clazz, true, false);
} else {
// it static access operator. skip.
}
}
expr.writePopString();
expr.writePushDupLowerCase();
}
if (isConstant) {
expr.writePushConstString(((NameToken) token.getField()).getName());
expr.writePushEnv();
expr.writePushTraceInfo(token);
int cacheIndex = method.clazz.getAndIncCallConstCount();
expr.writeGetStatic("$CALL_CONST_CACHE", ConstantCallCache.class);
expr.writePushConstInt(cacheIndex);
expr.writeSysStaticCall(ObjectInvokeHelper.class, "getConstant", Memory.class, String.class, String.class, String.class, Environment.class, TraceInfo.class, ConstantCallCache.class, Integer.TYPE);
expr.setStackPeekAsImmutable();
} else {
if (token.getFieldExpr() != null) {
expr.writeExpression(token.getFieldExpr(), true, false);
expr.writePopString();
} else {
if (!(token.getField() instanceof VariableExprToken))
expr.unexpectedToken(token.getField());
expr.writePushConstString(((VariableExprToken) token.getField()).getName());
}
expr.writePushEnv();
expr.writePushTraceInfo(token);
String name = "get";
if (token instanceof StaticAccessUnsetExprToken)
name = "unset";
else if (token instanceof StaticAccessIssetExprToken)
name = "isset";
if (token.getFieldExpr() == null && token.getField() instanceof NameToken) {
expr.writeGetStatic("$CALL_PROP_CACHE", PropertyCallCache.class);
expr.writePushConstInt(method.clazz.getAndIncCallPropCount());
} else {
expr.writePushConstNull();
expr.writePushConstInt(0);
}
expr.writeSysStaticCall(ObjectInvokeHelper.class, name + "StaticProperty", Memory.class, String.class, String.class, String.class, Environment.class, TraceInfo.class, PropertyCallCache.class, int.class);
}
}
if (!returnValue)
expr.writePopAll(1);
}
Aggregations