Search in sources :

Example 1 with IfStatementContext

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

the class PydmlSyntacticValidator method exitIfStatement.

@Override
public void exitIfStatement(IfStatementContext ctx) {
    IfStatement ifStmt = new IfStatement();
    ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
    ifStmt.setConditionalPredicate(predicate);
    ifStmt.setCtxValuesAndFilename(ctx, currentFile);
    if (ctx.ifBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.ifBody) {
            ifStmt.addStatementBlockIfBody(getStatementBlock(stmtCtx.info.stmt));
        }
        ifStmt.mergeStatementBlocksIfBody();
    }
    IfStatement tailIfStmt = ifStmt;
    if (ctx.elifBranches.size() > 0) {
        for (ElifBranchContext elifCtx : ctx.elifBranches) {
            tailIfStmt.addStatementBlockElseBody(getStatementBlock(elifCtx.info.stmt));
            tailIfStmt = (IfStatement) elifCtx.info.stmt;
        }
    }
    if (ctx.elseBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.elseBody) {
            tailIfStmt.addStatementBlockElseBody(getStatementBlock(stmtCtx.info.stmt));
        }
        tailIfStmt.mergeStatementBlocksElseBody();
    }
    ctx.info.stmt = ifStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : ElifBranchContext(org.apache.sysml.parser.pydml.PydmlParser.ElifBranchContext) IfStatement(org.apache.sysml.parser.IfStatement) ConditionalPredicate(org.apache.sysml.parser.ConditionalPredicate) FunctionStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext) ImportStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext) AssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext) PathStatementContext(org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext) StatementContext(org.apache.sysml.parser.pydml.PydmlParser.StatementContext) ParForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext) WhileStatementContext(org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)

Example 2 with IfStatementContext

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

the class PydmlSyntacticValidator method exitIfStatement.

@Override
public void exitIfStatement(IfStatementContext ctx) {
    IfStatement ifStmt = new IfStatement();
    ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
    ifStmt.setConditionalPredicate(predicate);
    ifStmt.setCtxValuesAndFilename(ctx, currentFile);
    if (ctx.ifBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.ifBody) {
            ifStmt.addStatementBlockIfBody(getStatementBlock(stmtCtx.info.stmt));
        }
        ifStmt.mergeStatementBlocksIfBody();
    }
    IfStatement tailIfStmt = ifStmt;
    if (ctx.elifBranches.size() > 0) {
        for (ElifBranchContext elifCtx : ctx.elifBranches) {
            tailIfStmt.addStatementBlockElseBody(getStatementBlock(elifCtx.info.stmt));
            tailIfStmt = (IfStatement) elifCtx.info.stmt;
        }
    }
    if (ctx.elseBody.size() > 0) {
        for (StatementContext stmtCtx : ctx.elseBody) {
            tailIfStmt.addStatementBlockElseBody(getStatementBlock(stmtCtx.info.stmt));
        }
        tailIfStmt.mergeStatementBlocksElseBody();
    }
    ctx.info.stmt = ifStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : ElifBranchContext(org.apache.sysml.parser.pydml.PydmlParser.ElifBranchContext) IfStatement(org.apache.sysml.parser.IfStatement) ConditionalPredicate(org.apache.sysml.parser.ConditionalPredicate) FunctionStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext) ImportStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext) AssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext) PathStatementContext(org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext) FunctionCallMultiAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext) IfStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext) IfdefAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext) ForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext) StatementContext(org.apache.sysml.parser.pydml.PydmlParser.StatementContext) ParForStatementContext(org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext) FunctionCallAssignmentStatementContext(org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext) WhileStatementContext(org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)

Aggregations

ConditionalPredicate (org.apache.sysml.parser.ConditionalPredicate)2 IfStatement (org.apache.sysml.parser.IfStatement)2 AssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.AssignmentStatementContext)2 ElifBranchContext (org.apache.sysml.parser.pydml.PydmlParser.ElifBranchContext)2 ForStatementContext (org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext)2 FunctionCallAssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatementContext)2 FunctionCallMultiAssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext)2 FunctionStatementContext (org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext)2 IfStatementContext (org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext)2 IfdefAssignmentStatementContext (org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext)2 ImportStatementContext (org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext)2 ParForStatementContext (org.apache.sysml.parser.pydml.PydmlParser.ParForStatementContext)2 PathStatementContext (org.apache.sysml.parser.pydml.PydmlParser.PathStatementContext)2 StatementContext (org.apache.sysml.parser.pydml.PydmlParser.StatementContext)2 WhileStatementContext (org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext)2