Search in sources :

Example 41 with DataIdentifier

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

the class DmlSyntacticValidator method exitIfdefAssignmentStatement.

@Override
public void exitIfdefAssignmentStatement(IfdefAssignmentStatementContext ctx) {
    if (!ctx.commandLineParam.getText().startsWith("$")) {
        notifyErrorListeners("the first argument of ifdef function should be a commandline argument parameter (which starts with $)", ctx.commandLineParam.start);
        return;
    }
    if (ctx.targetList == null) {
        notifyErrorListeners("ifdef assignment needs an lvalue ", ctx.start);
        return;
    }
    String targetListText = ctx.targetList.getText();
    if (targetListText.startsWith("$")) {
        notifyErrorListeners("lhs of ifdef function cannot be a commandline parameters. Use local variable instead", ctx.start);
        return;
    }
    DataIdentifier target = null;
    if (ctx.targetList.dataInfo.expr instanceof DataIdentifier) {
        target = (DataIdentifier) ctx.targetList.dataInfo.expr;
        Expression source = null;
        if (ctx.commandLineParam.dataInfo.expr != null) {
            // Since commandline parameter is set
            // The check of following is done in fillExpressionInfoCommandLineParameters:
            // Command line param cannot be empty string
            // If you want to pass space, please quote it
            source = ctx.commandLineParam.dataInfo.expr;
        } else {
            source = ctx.source.info.expr;
        }
        try {
            ctx.info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
        } catch (LanguageException e) {
            notifyErrorListeners("invalid assignment for ifdef function", ctx.targetList.start);
            return;
        }
    } else {
        notifyErrorListeners("incorrect lvalue in ifdef function ", ctx.targetList.start);
        return;
    }
}
Also used : LanguageException(org.apache.sysml.parser.LanguageException) DataIdentifier(org.apache.sysml.parser.DataIdentifier) Expression(org.apache.sysml.parser.Expression) ParameterExpression(org.apache.sysml.parser.ParameterExpression) AssignmentStatement(org.apache.sysml.parser.AssignmentStatement)

Example 42 with DataIdentifier

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

the class PydmlSyntacticValidator method exitSimpleDataIdentifierExpression.

@Override
public void exitSimpleDataIdentifierExpression(SimpleDataIdentifierExpressionContext ctx) {
    // This is either a function, or variable with namespace
    // By default, it assigns to a data type
    ctx.dataInfo.expr = new DataIdentifier(ctx.getText());
    setFileLineColumn(ctx.dataInfo.expr, ctx);
}
Also used : DataIdentifier(org.apache.sysml.parser.DataIdentifier)

Example 43 with DataIdentifier

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

the class PydmlSyntacticValidator method exitForStatement.

@Override
public void exitForStatement(ForStatementContext ctx) {
    ForStatement forStmt = new ForStatement();
    DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
    HashMap<String, String> parForParamValues = null;
    // 1/-1
    Expression incrementExpr = null;
    if (ctx.iterPred.info.increment != null) {
        incrementExpr = ctx.iterPred.info.increment;
    }
    IterablePredicate predicate = new IterablePredicate(ctx, iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to, incrementExpr, parForParamValues, currentFile);
    forStmt.setPredicate(predicate);
    if (ctx.body.size() > 0) {
        for (StatementContext stmtCtx : ctx.body) {
            forStmt.addStatementBlock(getStatementBlock(stmtCtx.info.stmt));
        }
        forStmt.mergeStatementBlocks();
    }
    ctx.info.stmt = forStmt;
    setFileLineColumn(ctx.info.stmt, ctx);
}
Also used : 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) IterablePredicate(org.apache.sysml.parser.IterablePredicate) ParForStatement(org.apache.sysml.parser.ParForStatement) ForStatement(org.apache.sysml.parser.ForStatement) 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 44 with DataIdentifier

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

the class PydmlSyntacticValidator method exitInternalFunctionDefExpression.

@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) 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 45 with DataIdentifier

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

the class ProgramConverter method createDeepCopyFunctionProgramBlock.

public static FunctionProgramBlock createDeepCopyFunctionProgramBlock(FunctionProgramBlock fpb, HashSet<String> fnStack, HashSet<String> fnCreated) {
    if (fpb == null)
        throw new DMLRuntimeException("Unable to create a deep copy of a non-existing FunctionProgramBlock.");
    // create deep copy
    FunctionProgramBlock copy = null;
    ArrayList<DataIdentifier> tmp1 = new ArrayList<>();
    ArrayList<DataIdentifier> tmp2 = new ArrayList<>();
    if (fpb.getInputParams() != null)
        tmp1.addAll(fpb.getInputParams());
    if (fpb.getOutputParams() != null)
        tmp2.addAll(fpb.getOutputParams());
    copy = new FunctionProgramBlock(fpb.getProgram(), tmp1, tmp2);
    copy.setChildBlocks(rcreateDeepCopyProgramBlocks(fpb.getChildBlocks(), 0, -1, fnStack, fnCreated, true, fpb.isRecompileOnce()));
    copy.setStatementBlock(fpb.getStatementBlock());
    copy.setRecompileOnce(fpb.isRecompileOnce());
    return copy;
}
Also used : FunctionProgramBlock(org.apache.sysml.runtime.controlprogram.FunctionProgramBlock) ExternalFunctionProgramBlock(org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock) DataIdentifier(org.apache.sysml.parser.DataIdentifier) ArrayList(java.util.ArrayList) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

DataIdentifier (org.apache.sysml.parser.DataIdentifier)56 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)13 ParameterExpression (org.apache.sysml.parser.ParameterExpression)13 Hop (org.apache.sysml.hops.Hop)12 Expression (org.apache.sysml.parser.Expression)12 LiteralOp (org.apache.sysml.hops.LiteralOp)10 BinaryExpression (org.apache.sysml.parser.BinaryExpression)8 BuiltinFunctionExpression (org.apache.sysml.parser.BuiltinFunctionExpression)8 Data (org.apache.sysml.runtime.instructions.cp.Data)7 DataGenOp (org.apache.sysml.hops.DataGenOp)6 DataOp (org.apache.sysml.hops.DataOp)6 StatementBlock (org.apache.sysml.parser.StatementBlock)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)6 HopsException (org.apache.sysml.hops.HopsException)4 DataType (org.apache.sysml.parser.Expression.DataType)4 ExternalFunctionStatement (org.apache.sysml.parser.ExternalFunctionStatement)4 IterablePredicate (org.apache.sysml.parser.IterablePredicate)4 LanguageException (org.apache.sysml.parser.LanguageException)4 ParForStatement (org.apache.sysml.parser.ParForStatement)4