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())));
}
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();
}
}
}
Aggregations