Search in sources :

Example 1 with CompileClass

use of php.runtime.ext.support.compile.CompileClass in project jphp by jphp-compiler.

the class ExpressionStmtCompiler method writePushFastStaticMethod.

boolean writePushFastStaticMethod(CallExprToken function, boolean returnValue) {
    StaticAccessExprToken access = (StaticAccessExprToken) function.getName();
    CompileClass compileClass = compiler.getEnvironment().scope.findCompileClass(access.getClazz().getWord());
    if (compileClass == null)
        return false;
    ClassEntity classEntity = compiler.getEnvironment().fetchClass(compileClass.getNativeClass());
    MethodEntity methodEntity = classEntity.findMethod(access.getField().getWord().toLowerCase());
    if (methodEntity != null && methodEntity.getNativeMethod() != null && methodEntity.getNativeMethod().isAnnotationPresent(Runtime.FastMethod.class)) {
        int cnt = methodEntity.getRequiredParamCount();
        if (cnt > function.getParameters().size()) {
            writeWarning(function, Messages.ERR_EXPECT_EXACTLY_PARAMS.fetch(methodEntity.getClazzName() + "::" + methodEntity.getName(), cnt, function.getParameters().size()));
            if (returnValue)
                writePushNull();
            return true;
        }
        List<Memory> additional = new ArrayList<Memory>();
        for (ParameterEntity param : methodEntity.getParameters()) {
            if (param.getDefaultValue() != null)
                additional.add(param.getDefaultValue());
            else if (!additional.isEmpty())
                throw new IllegalStateException("Arguments with default values must be located at the end");
        }
        writePushEnv();
        writePushParameters(function.getParameters(), additional.toArray(new Memory[0]));
        writeSysStaticCall(compileClass.getNativeClass(), methodEntity.getName(), Memory.class, Environment.class, Memory[].class);
        if (!returnValue)
            writePopAll(1);
        return true;
    }
    return false;
}
Also used : CompileClass(php.runtime.ext.support.compile.CompileClass) UndefinedMemory(php.runtime.memory.helper.UndefinedMemory) Memory(php.runtime.Memory)

Example 2 with CompileClass

use of php.runtime.ext.support.compile.CompileClass in project jphp by jphp-compiler.

the class CompileScope method fetchUserClass.

public ClassEntity fetchUserClass(String name, String nameLower) {
    ClassEntity entity;
    if (classEntityFetchHandler != null) {
        for (EntityFetchHandler handler : classEntityFetchHandler) {
            handler.fetch(this, name, nameLower);
        }
    }
    entity = classMap.get(nameLower);
    if (entity != null) {
        return entity;
    }
    CompileClass compileClass = compileClassMap.get(nameLower);
    if (compileClass == null)
        return null;
    entity = new ClassEntity(new ClassWrapper(compileClass.getExtension(), this, compileClass.getNativeClass()));
    entity.setId(nextClassIndex());
    synchronized (classMap) {
        classMap.put(name, entity);
    }
    return entity;
}
Also used : CompileClass(php.runtime.ext.support.compile.CompileClass) EntityFetchHandler(php.runtime.env.handler.EntityFetchHandler) ClassWrapper(php.runtime.wrap.ClassWrapper)

Example 3 with CompileClass

use of php.runtime.ext.support.compile.CompileClass in project jphp by jphp-compiler.

the class CompileScope method registerLazyClass.

public void registerLazyClass(Extension extension, Class<?> clazz) {
    CompileClass el = new CompileClass(extension, clazz);
    compileClassMap.put(el.getLowerName(), el);
}
Also used : CompileClass(php.runtime.ext.support.compile.CompileClass)

Aggregations

CompileClass (php.runtime.ext.support.compile.CompileClass)3 Memory (php.runtime.Memory)1 EntityFetchHandler (php.runtime.env.handler.EntityFetchHandler)1 UndefinedMemory (php.runtime.memory.helper.UndefinedMemory)1 ClassWrapper (php.runtime.wrap.ClassWrapper)1