Search in sources :

Example 1 with DataIdentifierContext

use of org.apache.sysml.parser.dml.DmlParser.DataIdentifierContext in project incubator-systemml by apache.

the class DmlSyntacticValidator method exitFunctionCallMultiAssignmentStatement.

@Override
public void exitFunctionCallMultiAssignmentStatement(FunctionCallMultiAssignmentStatementContext ctx) {
    String[] names = getQualifiedNames(ctx.name.getText());
    if (names == null) {
        notifyErrorListeners("incorrect function name (only namespace.functionName allowed. Hint: If you are trying to use builtin functions, you can skip the namespace)", ctx.name);
        return;
    }
    String namespace = names[0];
    String functionName = names[1];
    ArrayList<ParameterExpression> paramExpression = getParameterExpressionList(ctx.paramExprs);
    ConvertedDMLSyntax convertedSyntax = convertToDMLSyntax(ctx, namespace, functionName, paramExpression, ctx.name);
    if (convertedSyntax == null) {
        return;
    } else {
        namespace = convertedSyntax.namespace;
        functionName = convertedSyntax.functionName;
        paramExpression = convertedSyntax.paramExpression;
    }
    FunctionCallIdentifier functCall = new FunctionCallIdentifier(paramExpression);
    functCall.setFunctionName(functionName);
    functCall.setFunctionNamespace(namespace);
    final ArrayList<DataIdentifier> targetList = new ArrayList<DataIdentifier>();
    for (DataIdentifierContext dataCtx : ctx.targetList) {
        if (dataCtx.dataInfo.expr instanceof DataIdentifier) {
            targetList.add((DataIdentifier) dataCtx.dataInfo.expr);
        } else {
            notifyErrorListeners("incorrect type for variable ", dataCtx.start);
            return;
        }
    }
    if (namespace.equals(DMLProgram.DEFAULT_NAMESPACE)) {
        final FunctionCallMultiAssignmentStatementContext fctx = ctx;
        Action f = new Action() {

            @Override
            public void execute(Expression e) {
                setMultiAssignmentStatement(targetList, e, fctx, fctx.info);
            }
        };
        boolean validBIF = buildForBuiltInFunction(ctx, functionName, paramExpression, f);
        if (validBIF)
            return;
    }
    // Override default namespace for imported non-built-in function
    String inferNamespace = (sourceNamespace != null && sourceNamespace.length() > 0 && DMLProgram.DEFAULT_NAMESPACE.equals(namespace)) ? sourceNamespace : namespace;
    functCall.setFunctionNamespace(inferNamespace);
    setMultiAssignmentStatement(targetList, functCall, ctx, ctx.info);
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionCallMultiAssignmentStatementContext) ArrayList(java.util.ArrayList) FunctionCallIdentifier(org.apache.sysml.parser.FunctionCallIdentifier) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) DataIdentifierContext(org.apache.sysml.parser.dml.DmlParser.DataIdentifierContext)

Aggregations

ArrayList (java.util.ArrayList)1 DataIdentifier (org.apache.sysml.parser.DataIdentifier)1 Expression (org.apache.sysml.parser.Expression)1 FunctionCallIdentifier (org.apache.sysml.parser.FunctionCallIdentifier)1 ParameterExpression (org.apache.sysml.parser.ParameterExpression)1 DataIdentifierContext (org.apache.sysml.parser.dml.DmlParser.DataIdentifierContext)1 FunctionCallMultiAssignmentStatementContext (org.apache.sysml.parser.dml.DmlParser.FunctionCallMultiAssignmentStatementContext)1