Search in sources :

Example 6 with StatementContext

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

the class DmlSyntacticValidator method exitInternalFunctionDefExpression.

// -----------------------------------------------------------------
// Internal & External Functions Definitions
// -----------------------------------------------------------------
@Override
public void exitInternalFunctionDefExpression(InternalFunctionDefExpressionContext ctx) {
    FunctionStatement functionStmt = new FunctionStatement();
    ArrayList<DataIdentifier> functionInputs = getFunctionParameters(ctx.inputParams);
    functionStmt.setInputParams(functionInputs);
    // set function outputs
    ArrayList<DataIdentifier> functionOutputs = getFunctionParameters(ctx.outputParams);
    functionStmt.setOutputParams(functionOutputs);
    // set function name
    functionStmt.setName(ctx.name.getText());
    if (ctx.body.size() > 0) {
        // handle function body
        // Create arraylist of one statement block
        ArrayList<StatementBlock> body = new ArrayList<>();
        for (StatementContext stmtCtx : ctx.body) {
            body.add(getStatementBlock(stmtCtx.info.stmt));
        }
        functionStmt.setBody(body);
        functionStmt.mergeStatementBlocks();
    } else {
        notifyErrorListeners("functions with no statements are not allowed", ctx.start);
        return;
    }
    ctx.info.stmt = functionStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
    ctx.info.functionName = ctx.name.getText();
}
Also used : ExternalFunctionStatement(org.apache.sysml.parser.ExternalFunctionStatement) FunctionStatement(org.apache.sysml.parser.FunctionStatement) DataIdentifier(org.apache.sysml.parser.DataIdentifier) ArrayList(java.util.ArrayList) StatementBlock(org.apache.sysml.parser.StatementBlock) ImportStatementContext(org.apache.sysml.parser.dml.DmlParser.ImportStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.IfdefAssignmentStatementContext) FunctionStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionStatementContext) AccumulatorAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.AccumulatorAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.dml.DmlParser.ForStatementContext) AssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.AssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.dml.DmlParser.IfStatementContext) PathStatementContext(org.apache.sysml.parser.dml.DmlParser.PathStatementContext) WhileStatementContext(org.apache.sysml.parser.dml.DmlParser.WhileStatementContext) ParForStatementContext(org.apache.sysml.parser.dml.DmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionCallAssignmentStatementContext) StatementContext(org.apache.sysml.parser.dml.DmlParser.StatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.dml.DmlParser.FunctionCallMultiAssignmentStatementContext)

Aggregations

FunctionStatementContext (org.apache.sysml.parser.dml.DmlParser.FunctionStatementContext)6 StatementContext (org.apache.sysml.parser.dml.DmlParser.StatementContext)6 AccumulatorAssignmentStatementContext (org.apache.sysml.parser.dml.DmlParser.AccumulatorAssignmentStatementContext)5 AssignmentStatementContext (org.apache.sysml.parser.dml.DmlParser.AssignmentStatementContext)5 ForStatementContext (org.apache.sysml.parser.dml.DmlParser.ForStatementContext)5 FunctionCallAssignmentStatementContext (org.apache.sysml.parser.dml.DmlParser.FunctionCallAssignmentStatementContext)5 FunctionCallMultiAssignmentStatementContext (org.apache.sysml.parser.dml.DmlParser.FunctionCallMultiAssignmentStatementContext)5 IfStatementContext (org.apache.sysml.parser.dml.DmlParser.IfStatementContext)5 IfdefAssignmentStatementContext (org.apache.sysml.parser.dml.DmlParser.IfdefAssignmentStatementContext)5 ImportStatementContext (org.apache.sysml.parser.dml.DmlParser.ImportStatementContext)5 ParForStatementContext (org.apache.sysml.parser.dml.DmlParser.ParForStatementContext)5 PathStatementContext (org.apache.sysml.parser.dml.DmlParser.PathStatementContext)5 WhileStatementContext (org.apache.sysml.parser.dml.DmlParser.WhileStatementContext)5 DataIdentifier (org.apache.sysml.parser.DataIdentifier)3 ConditionalPredicate (org.apache.sysml.parser.ConditionalPredicate)2 Expression (org.apache.sysml.parser.Expression)2 IterablePredicate (org.apache.sysml.parser.IterablePredicate)2 ParForStatement (org.apache.sysml.parser.ParForStatement)2 ParameterExpression (org.apache.sysml.parser.ParameterExpression)2 ArrayList (java.util.ArrayList)1