Search in sources :

Example 6 with DataMember

use of lucee.transformer.expression.var.DataMember in project Lucee by lucee.

the class ASMUtil method hasOnlyDataMembers.

public static boolean hasOnlyDataMembers(Variable var) {
    Iterator<Member> it = var.getMembers().iterator();
    Member m;
    while (it.hasNext()) {
        m = it.next();
        if (!(m instanceof DataMember))
            return false;
    }
    return true;
}
Also used : DataMember(lucee.transformer.expression.var.DataMember) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member)

Example 7 with DataMember

use of lucee.transformer.expression.var.DataMember in project Lucee by lucee.

the class ExpressionInvoker method _writeOut.

@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    Type rtn = Types.OBJECT;
    int count = members.size();
    for (int i = 0; i < count; i++) {
        adapter.loadArg(0);
    }
    expr.writeOut(bc, Expression.MODE_REF);
    for (int i = 0; i < count; i++) {
        Member member = members.get(i);
        // Data Member
        if (member instanceof DataMember) {
            ((DataMember) member).getName().writeOut(bc, MODE_REF);
            adapter.invokeVirtual(Types.PAGE_CONTEXT, ((i + 1) == count) ? GET : GET_COLLECTION);
            rtn = Types.OBJECT;
        } else // UDF
        if (member instanceof UDF) {
            UDF udf = (UDF) member;
            udf.getName().writeOut(bc, MODE_REF);
            ExpressionUtil.writeOutExpressionArray(bc, Types.OBJECT, udf.getArguments());
            adapter.invokeVirtual(Types.PAGE_CONTEXT, udf.hasNamedArgs() ? GET_FUNCTION_WITH_NAMED_ARGS : GET_FUNCTION);
            rtn = Types.OBJECT;
        }
    }
    return rtn;
}
Also used : Type(org.objectweb.asm.Type) UDF(lucee.transformer.bytecode.expression.var.UDF) DataMember(lucee.transformer.expression.var.DataMember) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member)

Example 8 with DataMember

use of lucee.transformer.expression.var.DataMember in project Lucee by lucee.

the class VT method _writeOutCallerUtil.

private Type _writeOutCallerUtil(BytecodeContext bc, int mode) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    final int count = countFM + countDM;
    // count 0
    if (count == 0)
        return _writeOutEmpty(bc);
    // pc
    adapter.loadArg(0);
    // collection
    RefInteger startIndex = new RefIntegerImpl();
    _writeOutFirst(bc, (members.get(0)), mode, count == 1, true, defaultValue, startIndex);
    // keys
    Iterator<Member> it = members.iterator();
    ArrayVisitor av = new ArrayVisitor();
    av.visitBegin(adapter, Types.COLLECTION_KEY, countDM - startIndex.toInt());
    int index = 0, i = 0;
    while (it.hasNext()) {
        DataMember member = (DataMember) it.next();
        if (i++ < startIndex.toInt())
            continue;
        av.visitBeginItem(adapter, index++);
        getFactory().registerKey(bc, member.getName(), false);
        av.visitEndItem(bc.getAdapter());
    }
    av.visitEnd();
    // defaultValue
    defaultValue.writeOut(bc, MODE_REF);
    bc.getAdapter().invokeStatic(Types.CALLER_UTIL, CALLER_UTIL_GET);
    return Types.OBJECT;
}
Also used : RefInteger(lucee.commons.lang.types.RefInteger) DataMember(lucee.transformer.expression.var.DataMember) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) ArrayVisitor(lucee.transformer.bytecode.visitor.ArrayVisitor) RefIntegerImpl(lucee.commons.lang.types.RefIntegerImpl) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member)

Example 9 with DataMember

use of lucee.transformer.expression.var.DataMember in project Lucee by lucee.

the class VariableString method variableToStringArray.

public static String[] variableToStringArray(Variable var, boolean rawIfPossible) throws TransformerException {
    List<Member> members = var.getMembers();
    List<String> arr = new ArrayList<String>();
    if (var.getScope() != Scope.SCOPE_UNDEFINED)
        arr.add(ScopeFactory.toStringScope(var.getScope(), "undefined"));
    Iterator<Member> it = members.iterator();
    DataMember dm;
    Expression n;
    while (it.hasNext()) {
        Object o = it.next();
        if (!(o instanceof DataMember))
            throw new TransformerException("can't translate Variable to a String", var.getStart());
        dm = (DataMember) o;
        n = dm.getName();
        if (n instanceof Literal) {
            if (rawIfPossible && n instanceof Identifier) {
                arr.add(((Identifier) n).getRaw());
            } else {
                arr.add(((Literal) n).getString());
            }
        } else
            throw new TransformerException("argument name must be a constant value", var.getStart());
    }
    return arr.toArray(new String[arr.size()]);
}
Also used : Identifier(lucee.transformer.bytecode.literal.Identifier) Expression(lucee.transformer.expression.Expression) Literal(lucee.transformer.expression.literal.Literal) ArrayList(java.util.ArrayList) DataMember(lucee.transformer.expression.var.DataMember) ExprString(lucee.transformer.expression.ExprString) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member) TransformerException(lucee.transformer.TransformerException)

Aggregations

DataMember (lucee.transformer.expression.var.DataMember)9 Member (lucee.transformer.expression.var.Member)9 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)6 TransformerException (lucee.transformer.TransformerException)3 ArrayVisitor (lucee.transformer.bytecode.visitor.ArrayVisitor)3 ExprString (lucee.transformer.expression.ExprString)3 Type (org.objectweb.asm.Type)3 ArrayList (java.util.ArrayList)2 Expression (lucee.transformer.expression.Expression)2 LitString (lucee.transformer.expression.literal.LitString)2 Literal (lucee.transformer.expression.literal.Literal)2 RefInteger (lucee.commons.lang.types.RefInteger)1 RefIntegerImpl (lucee.commons.lang.types.RefIntegerImpl)1 CastString (lucee.transformer.bytecode.cast.CastString)1 Argument (lucee.transformer.bytecode.expression.var.Argument)1 FunctionMember (lucee.transformer.bytecode.expression.var.FunctionMember)1 NamedArgument (lucee.transformer.bytecode.expression.var.NamedArgument)1 UDF (lucee.transformer.bytecode.expression.var.UDF)1 Identifier (lucee.transformer.bytecode.literal.Identifier)1 OpVariable (lucee.transformer.bytecode.op.OpVariable)1