Search in sources :

Example 1 with DataIdentifierContext

use of org.apache.sysml.parser.pydml.PydmlParser.DataIdentifierContext in project incubator-systemml by apache.

the class PydmlSyntacticValidator 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;
    }
    // No need to support dot() function since it will never return multi-assignment function
    FunctionCallIdentifier functCall = new FunctionCallIdentifier(paramExpression);
    functCall.setFunctionName(functionName);
    functCall.setFunctionNamespace(namespace);
    final ArrayList<DataIdentifier> targetList = new ArrayList<>();
    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)) {
        Expression e = buildForBuiltInFunction(ctx, functionName, paramExpression);
        if (e != null) {
            setMultiAssignmentStatement(targetList, e, ctx, ctx.info);
            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 : FunctionCallIdentifier(org.apache.sysml.parser.FunctionCallIdentifier) DataIdentifier(org.apache.sysml.parser.DataIdentifier) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) ArrayList(java.util.ArrayList) DataIdentifierContext(org.apache.sysml.parser.pydml.PydmlParser.DataIdentifierContext)

Example 2 with DataIdentifierContext

use of org.apache.sysml.parser.pydml.PydmlParser.DataIdentifierContext in project systemml by apache.

the class PydmlSyntacticValidator 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;
    }
    // No need to support dot() function since it will never return multi-assignment function
    FunctionCallIdentifier functCall = new FunctionCallIdentifier(paramExpression);
    functCall.setFunctionName(functionName);
    functCall.setFunctionNamespace(namespace);
    final ArrayList<DataIdentifier> targetList = new ArrayList<>();
    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)) {
        Expression e = buildForBuiltInFunction(ctx, functionName, paramExpression);
        if (e != null) {
            setMultiAssignmentStatement(targetList, e, ctx, ctx.info);
            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 : FunctionCallIdentifier(org.apache.sysml.parser.FunctionCallIdentifier) DataIdentifier(org.apache.sysml.parser.DataIdentifier) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) ArrayList(java.util.ArrayList) DataIdentifierContext(org.apache.sysml.parser.pydml.PydmlParser.DataIdentifierContext)

Aggregations

ArrayList (java.util.ArrayList)2 BinaryExpression (org.apache.sysml.parser.BinaryExpression)2 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)2 DataIdentifier (org.apache.sysml.parser.DataIdentifier)2 Expression (org.apache.sysml.parser.Expression)2 FunctionCallIdentifier (org.apache.sysml.parser.FunctionCallIdentifier)2 ParameterExpression (org.apache.sysml.parser.ParameterExpression)2 DataIdentifierContext (org.apache.sysml.parser.pydml.PydmlParser.DataIdentifierContext)2