/* (non-Javadoc) * @see org.sapid.checker.ai.AIPlus#interpret(org.sapid.checker.ai.AIEnvironment) */ @Override public Value interpret(AIEnvironment env) { // for left String left_classname = this.left_value.getClass().getSimpleName(); if (left_classname.equals("ConcreteVariable")) { ConcreteVariable var = (ConcreteVariable) this.left_value; this.left_value = env.vars.get(var.getDefid()); } // for right String right_classname = this.right_value.getClass().getSimpleName(); if (right_classname.equals("ConcreteVariable")) { ConcreteVariable var = (ConcreteVariable) this.right_value; this.right_value = env.vars.get(var.getDefid()); } LiteralValue literal_left = (LiteralValue) left_value.getValue(env); LiteralValue literal_right = (LiteralValue) right_value.getValue(env); double left = literal_left.getLiteral(); double right = literal_right.getLiteral(); double res = left + right; return new LiteralValue(res); }
private String getString(final AST node) { switch (node.getNodeLabel()) { case ProtoLexer.IDENTIFIER: { final StringBuilder sb = new StringBuilder(node.getNodeValue()); final List<AST> children = node.getChildNodes(); if (children != null) { for (AST child : children) { sb.append('.').append(child.getNodeValue()); } } return sb.toString(); } case ProtoLexer.STRING: return ((LiteralValue.StringValue) LiteralValue.parse(node)).get(); case ProtoLexer.ML_STRING: { final String s = node.getNodeValue().trim().replace("\r\n", "\n").replace("\r", "\n"); int i = s.indexOf('\n'); int j = s.lastIndexOf('\n'); return s.substring(i + 1, j); } default: return node.getNodeValue(); } }
@Override public Node optimize(EvalContext context) { if (rhs instanceof LiteralValue) { if (((LiteralValue) rhs).getType() == ValueType.BOOLEAN) { return LiteralValue.from(!((LiteralValue) rhs).getBool()); } } return this; }
private void addElementWithError( final Compiler.Context context, final String key, final LiteralValue value) { Map.Entry<String, LiteralValue> previous = findElementByValue(value); if (previous != null) { context.error(value.getCodePosition(), "Cannot assign auto-value " + value + " to " + key); context.warning( previous.getValue().getCodePosition(), "Value " + value + " already assigned to " + previous.getKey()); return; } addElement(key, value); }