Search in sources :

Example 1 with FunctionArgument

use of com.googlecode.aviator.runtime.FunctionArgument in project aviatorscript by killme2008.

the class InterpretCodeGenerator method onMethodInvoke.

@Override
public void onMethodInvoke(final Token<?> lookhead) {
    final MethodMetaData methodMetaData = this.methodMetaDataStack.pop();
    @SuppressWarnings("unchecked") final List<FunctionArgument> params = lookhead != null ? (List<FunctionArgument>) lookhead.getMeta(Constants.PARAMS_META, Collections.EMPTY_LIST) : Collections.<FunctionArgument>emptyList();
    if (this.instance.getOptionValue(Options.CAPTURE_FUNCTION_ARGS).bool) {
        int funcId = getNextFuncInvocationId();
        getFuncsArgs().put(funcId, Collections.unmodifiableList(params));
        methodMetaData.funcId = funcId;
    }
    emit(new SendIR(methodMetaData.methodName, methodMetaData.parameterCount, methodMetaData.token.getMeta(Constants.UNPACK_ARGS, false), methodMetaData.funcId, new SourceInfo(this.sourceFile, methodMetaData.token.getLineNo())));
}
Also used : SendIR(com.googlecode.aviator.code.interpreter.ir.SendIR) SourceInfo(com.googlecode.aviator.code.interpreter.ir.SourceInfo) MethodMetaData(com.googlecode.aviator.code.asm.ASMCodeGenerator.MethodMetaData) FunctionArgument(com.googlecode.aviator.runtime.FunctionArgument)

Example 2 with FunctionArgument

use of com.googlecode.aviator.runtime.FunctionArgument in project aviatorscript by killme2008.

the class ExpressionParser method method.

private void method(final Token<?> methodName) {
    if (expectChar('(')) {
        this.scope.enterParen();
        checkVariableName(methodName);
        checkFunctionName(methodName, false);
        getCodeGeneratorWithTimes().onMethodName(methodName);
        move(true);
        int paramIndex = 0;
        List<FunctionArgument> params = null;
        boolean unpackArguments = false;
        if (this.captureFuncArgs) {
            params = new ArrayList<>();
        }
        int lastTokenIndex = getLookheadStartIndex();
        if (!expectChar(')')) {
            boolean isPackArgs = false;
            if (expectChar('*')) {
                move(true);
                if (expectChar('*') || expectChar(',')) {
                    // binary operation as argument
                    back();
                } else {
                    unpackArguments = true;
                    withMetaBegin();
                    isPackArgs = true;
                }
            }
            ternary();
            if (isPackArgs) {
                withMetaEnd(Constants.UNPACK_ARGS, true);
            }
            getCodeGeneratorWithTimes().onMethodParameter(this.lookhead);
            if (this.captureFuncArgs) {
                params.add(new FunctionArgument(paramIndex++, getParamExp(lastTokenIndex)));
            }
            while (expectChar(',')) {
                move(true);
                isPackArgs = false;
                lastTokenIndex = getLookheadStartIndex();
                if (expectChar('*')) {
                    move(true);
                    if (expectChar('*') || expectChar(',')) {
                        // binary operation as argument
                        back();
                    } else {
                        unpackArguments = true;
                        withMetaBegin();
                        isPackArgs = true;
                    }
                }
                if (!ternary()) {
                    reportSyntaxError("invalid argument");
                }
                if (isPackArgs) {
                    withMetaEnd(Constants.UNPACK_ARGS, true);
                }
                getCodeGeneratorWithTimes().onMethodParameter(this.lookhead);
                if (this.captureFuncArgs) {
                    params.add(new FunctionArgument(paramIndex++, getParamExp(lastTokenIndex)));
                }
            }
        }
        if (unpackArguments) {
            methodName.withMeta(Constants.UNPACK_ARGS, true);
        }
        if (expectChar(')')) {
            getCodeGeneratorWithTimes().onMethodInvoke(currentToken().withMeta(Constants.PARAMS_META, params));
            move(true);
            this.scope.leaveParen();
        }
    }
}
Also used : FunctionArgument(com.googlecode.aviator.runtime.FunctionArgument)

Aggregations

FunctionArgument (com.googlecode.aviator.runtime.FunctionArgument)2 MethodMetaData (com.googlecode.aviator.code.asm.ASMCodeGenerator.MethodMetaData)1 SendIR (com.googlecode.aviator.code.interpreter.ir.SendIR)1 SourceInfo (com.googlecode.aviator.code.interpreter.ir.SourceInfo)1