generate method
dynamic
generate([
- dynamic builder,
- dynamic output
Implementation
generate([builder, output]) {
var op = this.op;
var aNode = this.aNode;
var bNode = this.bNode;
var type = this.getNodeType(builder, output);
var typeA = null;
var typeB = null;
if (type != 'void') {
typeA = aNode.getNodeType(builder);
typeB = bNode.getNodeType(builder);
if (op == '=') {
typeB = typeA;
} else if (builder.isMatrix(typeA) && builder.isVector(typeB)) {
// matrix x vector
typeB = builder.getVectorFromMatrix(typeA);
} else if (builder.isVector(typeA) && builder.isMatrix(typeB)) {
// vector x matrix
typeA = builder.getVectorFromMatrix(typeB);
} else {
// anytype x anytype
typeA = typeB = type;
}
} else {
typeA = typeB = type;
}
var a = aNode.build(builder, typeA);
var b = bNode.build(builder, typeB);
var outputLength = builder.getTypeLength(output);
if (output != 'void') {
if (op == '=') {
builder.addFlowCode("${a} ${this.op} ${b}");
return a;
} else if (op == '>' && outputLength > 1) {
return "${builder.getMethod('greaterThan')}( ${a}, ${b} )";
} else if (op == '<=' && outputLength > 1) {
return "${builder.getMethod('lessThanEqual')}( ${a}, ${b} )";
} else {
return "( ${a} ${this.op} ${b} )";
}
} else if (typeA != 'void') {
return "${a} ${this.op} ${b}";
}
}