Search in sources :

Example 11 with ValueExprToken

use of org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken in project jphp by jphp-compiler.

the class StringBuilderValueCompiler method writeBuilder.

public void writeBuilder(List<Token> tokens, boolean binary) {
    expr.writePushNewObject(StringBuilder.class);
    for (Token el : tokens) {
        //writePushDup();
        if (el instanceof ValueExprToken) {
            expr.writePush((ValueExprToken) el, true, false);
        } else if (el instanceof ExprStmtToken) {
            //unexpectedToken(el);
            expr.writeExpression((ExprStmtToken) el, true, false, true);
        } else
            expr.unexpectedToken(el);
        StackItem.Type peek = expr.stackPeek().type;
        if (!peek.isConstant()) {
            expr.writeSysDynamicCall(StringBuilder.class, "append", StringBuilder.class, Object.class);
        } else
            expr.writeSysDynamicCall(StringBuilder.class, "append", StringBuilder.class, peek.toClass());
    }
    expr.writeSysDynamicCall(StringBuilder.class, "toString", String.class);
    if (binary) {
        expr.writeSysStaticCall(BinaryMemory.class, "valueOf", Memory.class, String.class);
    }
}
Also used : StackItem(org.develnext.jphp.core.compiler.common.misc.StackItem) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken) ExprStmtToken(org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken) Token(org.develnext.jphp.core.tokenizer.token.Token) StringBuilderExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StringBuilderExprToken) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)

Example 12 with ValueExprToken

use of org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken in project jphp by jphp-compiler.

the class ExpressionStmtCompiler method writeArrayGet.

void writeArrayGet(ArrayGetExprToken operator, boolean returnValue) {
    StackItem o = stackPeek();
    ValueExprToken L = null;
    if (o.getToken() != null) {
        stackPop();
        writePush(L = o.getToken(), true, false);
        writePopBoxing();
    }
    String methodName = operator instanceof ArrayGetRefExprToken ? "refOfIndex" : "valueOfIndex";
    boolean isShortcut = operator instanceof ArrayGetRefExprToken && ((ArrayGetRefExprToken) operator).isShortcut();
    int i = 0;
    int size = operator.getParameters().size();
    int traceIndex = createTraceInfo(operator);
    for (ExprStmtToken param : operator.getParameters()) {
        // push dup trace
        writePushTraceInfo(traceIndex);
        writeExpression(param, true, false);
        if (operator instanceof ArrayGetUnsetExprToken && i == size - 1) {
            writePopBoxing();
            writeSysDynamicCall(Memory.class, "unsetOfIndex", void.class, TraceInfo.class, stackPeek().type.toClass());
            if (returnValue)
                writePushNull();
        } else if (operator instanceof ArrayGetIssetExprToken && i == size - 1) {
            writePopBoxing();
            writeSysDynamicCall(Memory.class, "issetOfIndex", Memory.class, TraceInfo.class, stackPeek().type.toClass());
        } else if (operator instanceof ArrayGetEmptyExprToken && i == size - 1) {
            writePopBoxing();
            writeSysDynamicCall(Memory.class, "emptyOfIndex", Memory.class, TraceInfo.class, stackPeek().type.toClass());
        } else {
            // TODO: Remove.
            // PHP CMP: $hack = &$arr[0];
            // boolean isMemory = stackPeek().type.toClass() == Memory.class;
            //if (isMemory)
            /*if (compiler.isPhpMode()){
                    if (i == size - 1 && isShortcut){
                        writePopBoxing();
                        writeSysDynamicCall(Memory.class, methodName + "AsShortcut", Memory.class, TraceInfo.class, Memory.class);
                        continue;
                    }
                }*/
            writeSysDynamicCall(Memory.class, methodName, Memory.class, TraceInfo.class, stackPeek().type.toClass());
            i++;
        }
    }
}
Also used : StackItem(org.develnext.jphp.core.compiler.common.misc.StackItem) UndefinedMemory(php.runtime.memory.helper.UndefinedMemory) Memory(php.runtime.Memory) TraceInfo(php.runtime.env.TraceInfo) ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)

Aggregations

ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)12 Memory (php.runtime.Memory)8 UndefinedMemory (php.runtime.memory.helper.UndefinedMemory)6 StackItem (org.develnext.jphp.core.compiler.common.misc.StackItem)5 Token (org.develnext.jphp.core.tokenizer.token.Token)5 ClassExprToken (org.develnext.jphp.core.tokenizer.token.expr.ClassExprToken)5 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)4 OperatorExprToken (org.develnext.jphp.core.tokenizer.token.expr.OperatorExprToken)4 OpenEchoTagToken (org.develnext.jphp.core.tokenizer.token.OpenEchoTagToken)3 ExprStmtToken (org.develnext.jphp.core.tokenizer.token.stmt.ExprStmtToken)3 Environment (php.runtime.env.Environment)3 GetVarExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.GetVarExprToken)2 VariableExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.VariableExprToken)2 TraceInfo (php.runtime.env.TraceInfo)2 CriticalException (php.runtime.exceptions.CriticalException)2 CompileClass (php.runtime.ext.support.compile.CompileClass)2 BraceExprToken (org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken)1 ExprToken (org.develnext.jphp.core.tokenizer.token.expr.ExprToken)1 CallExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.CallExprToken)1 StringBuilderExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StringBuilderExprToken)1