Search in sources :

Example 1 with CompileConstant

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

the class Environment method findConstant.

public Memory findConstant(String name, String nameLower) {
    ConstantEntity entity = constantMap.get(nameLower);
    if (entity != null) {
        if (!entity.caseSensitise || name.equals(entity.getName()))
            return entity.getValue();
    }
    CompileConstant constant = scope.findCompileConstant(name);
    if (constant != null)
        return constant.value;
    return null;
}
Also used : CompileConstant(php.runtime.ext.support.compile.CompileConstant)

Example 2 with CompileConstant

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

the class ExpressionStmtCompiler method writePushName.

Memory writePushName(NameToken token, boolean returnMemory, boolean writeOpcode) {
    CompileConstant constant = compiler.getScope().findCompileConstant(token.getName());
    if (constant != null) {
        if (returnMemory)
            return constant.value;
        else if (writeOpcode)
            writePushMemory(constant.value);
    } else {
        ConstantEntity constantEntity = compiler.findConstant(token.getName());
        if (constantEntity != null) {
            if (returnMemory)
                return constantEntity.getValue();
            else if (writeOpcode) {
                writePushMemory(constantEntity.getValue());
                setStackPeekAsImmutable();
            }
        } else {
            if (!writeOpcode)
                return null;
            writePushEnv();
            writePushString(token.getName());
            writePushString(token.getName().toLowerCase());
            // writePushDupLowerCase();
            writePushTraceInfo(token);
            writeSysDynamicCall(Environment.class, "__getConstant", Memory.class, String.class, String.class, TraceInfo.class);
            setStackPeekAsImmutable();
        }
    }
    return null;
}
Also used : CompileConstant(php.runtime.ext.support.compile.CompileConstant)

Example 3 with CompileConstant

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

the class CoreExtension method onRegister.

@Override
public void onRegister(CompileScope scope) {
    registerFunctions(new LangFunctions());
    registerConstants(new LangConstants());
    registerConstants(new InfoConstants());
    registerFunctions(new InfoFunctions());
    registerConstants(new MathConstants());
    registerFunctions(new MathFunctions());
    registerFunctions(new StringFunctions());
    registerConstants(new ArrayConstants());
    registerFunctions(new ArrayFunctions());
    registerConstants(new OutputConstants());
    registerFunctions(new OutputFunctions());
    // T_ERROR
    for (ErrorType el : ErrorType.values()) constants.put(el.name(), new CompileConstant(el.name(), el.value));
    registerJavaException(scope, WrapJavaExceptions.IllegalArgumentException.class, IllegalArgumentException.class);
    registerJavaException(scope, WrapJavaExceptions.IllegalStateException.class, IllegalStateException.class);
    registerJavaException(scope, WrapJavaExceptions.NumberFormatException.class, NumberFormatException.class);
    registerJavaException(scope, WrapJavaExceptions.InterruptedException.class, InterruptedException.class);
    registerClass(scope, CharUtils.class);
    registerClass(scope, StrUtils.class);
    registerClass(scope, BinUtils.class);
    registerClass(scope, NumUtils.class);
    registerClass(scope, ItemsUtils.class);
    registerClass(scope, MirrorUtils.class);
    registerClass(scope, FsUtils.class);
    registerClass(scope, OldBinUtils.class);
    registerClass(scope, OldItemsUtils.class);
    registerClass(scope, OldNumUtils.class);
    registerClass(scope, OldMirrorUtils.class);
    registerClass(scope, SharedUtils.SharedMemory.class);
    registerClass(scope, SharedUtils.SharedCollection.class);
    registerClass(scope, SharedUtils.SharedValue.class);
    registerClass(scope, SharedUtils.SharedStack.class);
    registerClass(scope, SharedUtils.SharedQueue.class);
    registerClass(scope, SharedUtils.SharedMap.class);
    registerClass(scope, SharedUtils.class);
    registerClass(scope, WrapPackageLoader.class);
    registerClass(scope, WrapClassLoader.class);
    registerClass(scope, WrapClassLoader.WrapLauncherClassLoader.class);
    registerClass(scope, WrapLocale.class);
    registerClass(scope, WrapScanner.class);
    registerClass(scope, WrapFlow.class);
    registerClass(scope, WrapConfiguration.class);
    registerClass(scope, WrapRegex.class);
    registerJavaExceptionForContext(scope, WrapRegex.RegexException.class, WrapRegex.class);
    registerClass(scope, WrapTimeZone.class);
    registerClass(scope, WrapTimeFormat.class);
    registerClass(scope, WrapTime.class);
    registerClass(scope, WrapInvoker.class);
    registerClass(scope, WrapModule.class);
    registerClass(scope, WrapPackage.class);
    registerWrapperClass(scope, SourceMap.class, WrapSourceMap.class);
    registerClass(scope, WrapEnvironment.class);
    registerClass(scope, WrapEnvironmentVariables.class);
    registerClass(scope, WrapThreadGroup.class);
    registerClass(scope, WrapThread.class);
    registerClass(scope, WrapSystem.class);
    registerClass(scope, Reflector.class);
    registerClass(scope, Reflection.class);
    registerClass(scope, ReflectionException.class);
    registerClass(scope, ReflectionExtension.class);
    registerClass(scope, ReflectionFunctionAbstract.class);
    registerClass(scope, ReflectionFunction.class);
    registerClass(scope, ReflectionParameter.class);
    registerClass(scope, ReflectionProperty.class);
    registerClass(scope, ReflectionMethod.class);
    registerClass(scope, ReflectionClass.class);
    registerClass(scope, ReflectionObject.class);
    registerClass(scope, WrapJavaExceptions.NotImplementedException.class);
    // stream
    registerJavaException(scope, WrapIOException.class, IOException.class);
    registerClass(scope, FileObject.class);
    registerClass(scope, Stream.class);
    registerClass(scope, FileStream.class);
    registerClass(scope, MiscStream.class);
    registerClass(scope, MemoryMiscStream.class);
    registerClass(scope, ResourceStream.class);
    // net
    registerClass(scope, WrapSocket.class);
    registerClass(scope, WrapServerSocket.class);
    registerJavaException(scope, WrapSocketException.class, SocketException.class);
    registerClass(scope, WrapThreadPool.class);
    registerClass(scope, WrapFuture.class);
    registerJavaException(scope, WrapJavaExceptions.TimeoutException.class, TimeoutException.class);
    registerClass(scope, WrapProcessor.class);
    registerClass(scope, WrapProcessor.ProcessorException.class);
    registerClass(scope, WrapProcess.class);
}
Also used : CompileConstant(php.runtime.ext.support.compile.CompileConstant) ErrorType(php.runtime.exceptions.support.ErrorType) WrapProcessor(php.runtime.ext.core.classes.format.WrapProcessor)

Example 4 with CompileConstant

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

the class InfoFunctions method get_defined_constants.

public static Memory get_defined_constants(Environment env, boolean capitalize) {
    Set<String> exists = new HashSet<String>();
    ArrayMemory result = new ArrayMemory();
    for (String ext : env.scope.getExtensions()) {
        Extension extension = env.scope.getExtension(ext);
        ArrayMemory item = result;
        if (capitalize)
            item = (ArrayMemory) result.refOfIndex(ext).assign(new ArrayMemory());
        for (CompileConstant constant : extension.getConstants().values()) {
            item.put(constant.name, constant.value);
            exists.add(constant.name);
        }
    }
    ArrayMemory item = result;
    if (capitalize)
        item = (ArrayMemory) result.refOfIndex("user").assign(new ArrayMemory());
    for (ConstantEntity constant : env.scope.getConstants()) {
        if (!exists.contains(constant.getName()))
            item.put(constant.getName(), constant.getValue());
    }
    for (ConstantEntity constant : env.getConstants().values()) {
        if (!exists.contains(constant.getName()))
            item.put(constant.getName(), constant.getValue());
    }
    return result;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Extension(php.runtime.ext.support.Extension) CompileConstant(php.runtime.ext.support.compile.CompileConstant) ConstantEntity(php.runtime.reflection.ConstantEntity) HashSet(java.util.HashSet)

Aggregations

CompileConstant (php.runtime.ext.support.compile.CompileConstant)4 HashSet (java.util.HashSet)1 ErrorType (php.runtime.exceptions.support.ErrorType)1 WrapProcessor (php.runtime.ext.core.classes.format.WrapProcessor)1 Extension (php.runtime.ext.support.Extension)1 ArrayMemory (php.runtime.memory.ArrayMemory)1 ConstantEntity (php.runtime.reflection.ConstantEntity)1