use of buildcraft.lib.expression.node.value.NodeConstantLong in project BuildCraft by BuildCraft.
the class InternalCompiler method makeExpression.
private static IExpressionNode makeExpression(String[] postfix, FunctionContext context) throws InvalidExpressionException {
NodeStack stack = new NodeStack();
for (int i = 0; i < postfix.length; i++) {
String op = postfix[i];
if (OPERATORS.contains(op) && !"?".equals(op) && !":".equals(op)) {
boolean isNegation = UNARY_NEGATION.equals(op);
int count = 2;
if (isNegation || OPERATORS_SINGLE.contains(op)) {
op = isNegation ? "-" : op;
count = 1;
}
String function = op + FUNCTION_ARGS + count;
pushFunctionNode(stack, function, context);
} else if (// NO-OP, all handled by "?"
":".equals(op))
// NO-OP, all handled by "?"
continue;
else if ("?".equals(op))
pushConditional(stack);
else if (isValidLong(op)) {
long val = parseValidLong(op);
stack.push(new NodeConstantLong(val));
} else if (isValidDouble(op)) {
stack.push(new NodeConstantDouble(Double.parseDouble(op)));
} else if (BOOLEAN_MATCHER.matcher(op).matches()) {
stack.push(NodeConstantBoolean.of(Boolean.parseBoolean(op)));
} else if (STRING_MATCHER.matcher(op).matches()) {
stack.push(new NodeConstantObject<>(String.class, op.substring(1, op.length() - 1)));
} else if (op.startsWith(FUNCTION_START)) {
// Its a function
String function = op.substring(1);
pushFunctionNode(stack, function, context);
} else {
IExpressionNode node = context == null ? null : context.getVariable(op);
if (node == null && op.contains(".")) {
int index = op.indexOf('.');
String type = op.substring(0, index);
FunctionContext ctx = getContext(type);
if (ctx != null) {
node = ctx.getVariable(op);
if (node == null) {
node = ctx.getVariable(op.substring(index + 1));
}
}
}
if (node != null) {
stack.push(node);
} else {
String vars = getValidVariablesErrorString(context);
throw new InvalidExpressionException("Unknown variable '" + op + "'" + vars);
}
}
}
IExpressionNode node = stack.pop().inline();
if (!stack.isEmpty()) {
throw new InvalidExpressionException("Tried to make an expression with too many nodes! (" + stack + ")");
}
return node;
}
use of buildcraft.lib.expression.node.value.NodeConstantLong in project BuildCraft by BuildCraft.
the class NodeConditionalLong method inline.
@Override
public INodeLong inline() {
INodeBoolean c = condition.inline();
INodeLong t = ifTrue.inline();
INodeLong f = ifFalse.inline();
if (c instanceof NodeConstantBoolean && t instanceof NodeConstantLong && f instanceof NodeConstantLong) {
return new NodeConstantLong(((NodeConstantBoolean) c).value ? ((NodeConstantLong) t).value : ((NodeConstantLong) f).value);
} else if (c != condition || t != ifTrue || f != ifFalse) {
return new NodeConditionalLong(c, t, f);
} else {
return this;
}
}
Aggregations