use of org.cytoscape.equations.CodeAndSourceLocation in project cytoscape-impl by cytoscape.
the class SConvNode method genCode.
public void genCode(final Stack<CodeAndSourceLocation> codeStack) {
convertee.genCode(codeStack);
final Class type = convertee.getType();
if (type == Double.class)
codeStack.push(new CodeAndSourceLocation(Instruction.SCONVF, getSourceLocation()));
else if (type == Long.class)
codeStack.push(new CodeAndSourceLocation(Instruction.SCONVI, getSourceLocation()));
else if (type == Boolean.class)
codeStack.push(new CodeAndSourceLocation(Instruction.SCONVB, getSourceLocation()));
else
throw new IllegalStateException("unknown type: " + type + ".");
}
use of org.cytoscape.equations.CodeAndSourceLocation in project cytoscape-impl by cytoscape.
the class BinOpNode method genCode.
public void genCode(final Stack<CodeAndSourceLocation> codeStack) {
rhs.genCode(codeStack);
lhs.genCode(codeStack);
switch(operator) {
case CARET:
codeStack.push(new CodeAndSourceLocation(Instruction.FPOW, getSourceLocation()));
break;
case PLUS:
codeStack.push(new CodeAndSourceLocation(Instruction.FADD, getSourceLocation()));
break;
case MINUS:
codeStack.push(new CodeAndSourceLocation(Instruction.FSUB, getSourceLocation()));
break;
case DIV:
codeStack.push(new CodeAndSourceLocation(Instruction.FDIV, getSourceLocation()));
break;
case MUL:
codeStack.push(new CodeAndSourceLocation(Instruction.FMUL, getSourceLocation()));
break;
case EQUAL:
codeStack.push(new CodeAndSourceLocation(determineOpCode(Instruction.BEQLF, Instruction.BEQLS, Instruction.BEQLB), getSourceLocation()));
break;
case NOT_EQUAL:
codeStack.push(new CodeAndSourceLocation(determineOpCode(Instruction.BNEQLF, Instruction.BNEQLS, Instruction.BNEQLB), getSourceLocation()));
break;
case GREATER_THAN:
codeStack.push(new CodeAndSourceLocation(determineOpCode(Instruction.BGTF, Instruction.BGTS, Instruction.BGTB), getSourceLocation()));
break;
case LESS_THAN:
codeStack.push(new CodeAndSourceLocation(determineOpCode(Instruction.BLTF, Instruction.BLTS, Instruction.BLTB), getSourceLocation()));
break;
case GREATER_OR_EQUAL:
codeStack.push(new CodeAndSourceLocation(determineOpCode(Instruction.BGTEF, Instruction.BGTES, Instruction.BGTEB), getSourceLocation()));
break;
case LESS_OR_EQUAL:
codeStack.push(new CodeAndSourceLocation(determineOpCode(Instruction.BLTEF, Instruction.BLTES, Instruction.BLTEB), getSourceLocation()));
break;
case AMPERSAND:
codeStack.push(new CodeAndSourceLocation(Instruction.SCONCAT, getSourceLocation()));
break;
default:
throw new IllegalStateException(getSourceLocation() + ": unknown operator: " + operator + ".");
}
}
use of org.cytoscape.equations.CodeAndSourceLocation in project cytoscape-impl by cytoscape.
the class FConvNode method genCode.
public void genCode(final Stack<CodeAndSourceLocation> codeStack) {
convertee.genCode(codeStack);
final Class type = convertee.getType();
if (type == Long.class)
codeStack.push(new CodeAndSourceLocation(Instruction.FCONVI, getSourceLocation()));
else if (type == Boolean.class)
codeStack.push(new CodeAndSourceLocation(Instruction.FCONVB, getSourceLocation()));
else if (type == String.class)
codeStack.push(new CodeAndSourceLocation(Instruction.FCONVS, getSourceLocation()));
else
throw new IllegalStateException("unknown type: " + type + ".");
}
use of org.cytoscape.equations.CodeAndSourceLocation in project cytoscape-impl by cytoscape.
the class EquationCompilerImpl method compile.
public boolean compile(final String equation, final Map<String, Class<?>> variableNameToTypeMap) {
this.equation = null;
this.errorMsg = null;
if (!parser.parse(equation, variableNameToTypeMap)) {
errorMsg = parser.getErrorMsg();
return false;
}
final TreeNode parseTree = parser.getParseTree();
final Stack<CodeAndSourceLocation> codeStack = new Stack<CodeAndSourceLocation>();
try {
parseTree.genCode(codeStack);
} catch (final IllegalStateException e) {
errorMsg = e.getCause().toString();
return false;
}
final Object[] code = new Object[codeStack.size()];
final int[] sourceLocations = new int[codeStack.size()];
for (int i = code.length - 1; i >= 0; --i) {
final CodeAndSourceLocation codeAndSourceLocation = codeStack.pop();
code[i] = codeAndSourceLocation.getCode();
sourceLocations[i] = codeAndSourceLocation.getSourceLocation();
}
this.equation = new Equation(equation, parser.getVariableReferences(), parser.getDefaultVariableValues(), code, sourceLocations, parser.getType());
errorMsg = null;
return true;
}
use of org.cytoscape.equations.CodeAndSourceLocation in project cytoscape-impl by cytoscape.
the class FuncCallNode method genCode.
public void genCode(final Stack<CodeAndSourceLocation> codeStack) {
for (int i = args.length - 1; i >= 0; --i) args[i].genCode(codeStack);
codeStack.push(new CodeAndSourceLocation(args.length, -1));
codeStack.push(new CodeAndSourceLocation(func, -1));
codeStack.push(new CodeAndSourceLocation(Instruction.CALL, getSourceLocation()));
}
Aggregations