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;
}
}
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);
}
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);
}
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();
}
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;
}
Aggregations