Search in sources :

Example 1 with PrintStatement

use of org.apache.sysml.parser.PrintStatement in project incubator-systemml by apache.

the class CommonSyntacticValidator method setPrintStatement.

// -----------------------------------------------------------------
// Helper Functions for exit*FunctionCall*AssignmentStatement
// -----------------------------------------------------------------
protected void setPrintStatement(ParserRuleContext ctx, String functionName, ArrayList<ParameterExpression> paramExpression, StatementInfo thisinfo) {
    if (DMLScript.VALIDATOR_IGNORE_ISSUES == true) {
        // create dummy print statement
        try {
            int line = ctx.start.getLine();
            int col = ctx.start.getCharPositionInLine();
            ArrayList<Expression> expList = new ArrayList<Expression>();
            thisinfo.stmt = new PrintStatement(functionName, expList, line, col, line, col);
            setFileLineColumn(thisinfo.stmt, ctx);
        } catch (LanguageException e) {
            e.printStackTrace();
        }
        return;
    }
    int numParams = paramExpression.size();
    if (numParams == 0) {
        notifyErrorListeners(functionName + "() must have more than 0 parameters", ctx.start);
        return;
    } else if (numParams == 1) {
        Expression expr = paramExpression.get(0).getExpr();
        if (expr == null) {
            notifyErrorListeners("cannot process " + functionName + "() function", ctx.start);
            return;
        }
        try {
            int line = ctx.start.getLine();
            int col = ctx.start.getCharPositionInLine();
            ArrayList<Expression> expList = new ArrayList<Expression>();
            expList.add(expr);
            thisinfo.stmt = new PrintStatement(functionName, expList, line, col, line, col);
            setFileLineColumn(thisinfo.stmt, ctx);
        } catch (LanguageException e) {
            notifyErrorListeners("cannot process " + functionName + "() function", ctx.start);
            return;
        }
    } else if (numParams > 1) {
        if ("stop".equals(functionName)) {
            notifyErrorListeners("stop() function cannot have more than 1 parameter", ctx.start);
            return;
        }
        Expression firstExp = paramExpression.get(0).getExpr();
        if (firstExp == null) {
            notifyErrorListeners("cannot process " + functionName + "() function", ctx.start);
            return;
        }
        if (!(firstExp instanceof StringIdentifier)) {
            notifyErrorListeners("printf-style functionality requires first print parameter to be a string", ctx.start);
            return;
        }
        try {
            int line = ctx.start.getLine();
            int col = ctx.start.getCharPositionInLine();
            List<Expression> expressions = new ArrayList<Expression>();
            for (ParameterExpression pe : paramExpression) {
                Expression expression = pe.getExpr();
                expressions.add(expression);
            }
            thisinfo.stmt = new PrintStatement(functionName, expressions, line, col, line, col);
            setFileLineColumn(thisinfo.stmt, ctx);
        } catch (LanguageException e) {
            notifyErrorListeners("cannot process " + functionName + "() function", ctx.start);
            return;
        }
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) RelationalExpression(org.apache.sysml.parser.RelationalExpression) BooleanExpression(org.apache.sysml.parser.BooleanExpression) ParameterizedBuiltinFunctionExpression(org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression) BuiltinFunctionExpression(org.apache.sysml.parser.BuiltinFunctionExpression) BinaryExpression(org.apache.sysml.parser.BinaryExpression) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) DataExpression(org.apache.sysml.parser.DataExpression) StringIdentifier(org.apache.sysml.parser.StringIdentifier) ParameterExpression(org.apache.sysml.parser.ParameterExpression) ArrayList(java.util.ArrayList) PrintStatement(org.apache.sysml.parser.PrintStatement)

Aggregations

ArrayList (java.util.ArrayList)1 BinaryExpression (org.apache.sysml.parser.BinaryExpression)1 BooleanExpression (org.apache.sysml.parser.BooleanExpression)1 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)1 DataExpression (org.apache.sysml.parser.DataExpression)1 Expression (org.apache.sysml.parser.Expression)1 LanguageException (org.apache.sysml.parser.LanguageException)1 ParameterExpression (org.apache.sysml.parser.ParameterExpression)1 ParameterizedBuiltinFunctionExpression (org.apache.sysml.parser.ParameterizedBuiltinFunctionExpression)1 PrintStatement (org.apache.sysml.parser.PrintStatement)1 RelationalExpression (org.apache.sysml.parser.RelationalExpression)1 StringIdentifier (org.apache.sysml.parser.StringIdentifier)1