@Override public ResultValue<Integer> eval(AutomatonExpressionArguments pArgs) { if (TRANSITION_VARS_PATTERN.matcher(varId).matches()) { // $1 AutomatonTransitionVariables // no exception here (would have come in the constructor) int key = Integer.parseInt(varId.substring(1)); String val = pArgs.getTransitionVariable(key); if (val == null) { pArgs .getLogger() .log(Level.WARNING, "could not find the transition variable $" + key + "."); return new ResultValue<>( "could not find the transition variable $" + key + ".", "AutomatonIntExpr.VarAccess"); } try { int value = Integer.parseInt(val); return new ResultValue<>(Integer.valueOf(value)); } catch (NumberFormatException e) { pArgs .getLogger() .log( Level.WARNING, "could not parse the contents of transition variable $" + key + "=\"" + val + "\"."); return new ResultValue<>( "could not parse the contents of transition variable $" + key + "=\"" + val + "\".", "AutomatonIntExpr.VarAccess"); } } else if (varId.equals("$line")) { // $line line number in sourcecode return new ResultValue<>(Integer.valueOf(pArgs.getCfaEdge().getLineNumber())); } else { AutomatonVariable variable = pArgs.getAutomatonVariables().get(varId); if (variable != null) { return new ResultValue<>(Integer.valueOf(variable.getValue())); } else { pArgs .getLogger() .log(Level.WARNING, "could not find the automaton variable " + varId + "."); return new ResultValue<>( "could not find the automaton variable " + varId + ".", "AutomatonIntExpr.VarAccess"); } } }
@Override public ResultValue<Integer> eval(AutomatonExpressionArguments pArgs) { // replace transition variables String modifiedQueryString = pArgs.replaceVariables(queryString); if (modifiedQueryString == null) { return new ResultValue<>( "Failed to modify queryString \"" + queryString + "\"", "AutomatonIntExpr.CPAQuery"); } for (AbstractState ae : pArgs.getAbstractStates()) { if (ae instanceof AbstractQueryableState) { AbstractQueryableState aqe = (AbstractQueryableState) ae; if (aqe.getCPAName().equals(cpaName)) { try { Object result = aqe.evaluateProperty(modifiedQueryString); if (result instanceof NumericValue) { result = ((NumericValue) result).getNumber(); } if (result instanceof Integer) { String message = "CPA-Check succeeded: ModifiedCheckString: \"" + modifiedQueryString + "\" CPAElement: (" + aqe.getCPAName() + ") \"" + aqe.toString() + "\""; pArgs.getLogger().log(Level.FINER, message); return new ResultValue<>((Integer) result); } else if (result instanceof Long) { String message = "CPA-Check succeeded: ModifiedCheckString: \"" + modifiedQueryString + "\" CPAElement: (" + aqe.getCPAName() + ") \"" + aqe.toString() + "\""; pArgs.getLogger().log(Level.FINER, message); return new ResultValue<>(((Long) result).intValue()); } else { pArgs .getLogger() .log( Level.WARNING, "Automaton got a non-Numeric value during Query of the " + cpaName + " CPA on Edge " + pArgs.getCfaEdge().getDescription() + "."); return new ResultValue<>( "Automaton got a non-Numeric value during Query of the " + cpaName + " CPA on Edge " + pArgs.getCfaEdge().getDescription() + ".", "AutomatonIntExpr.CPAQuery"); } } catch (InvalidQueryException e) { pArgs .getLogger() .logException( Level.WARNING, e, "Automaton encountered an Exception during Query of the " + cpaName + " CPA on Edge " + pArgs.getCfaEdge().getDescription() + "."); return new ResultValue<>( "Automaton encountered an Exception during Query of the " + cpaName + " CPA on Edge " + pArgs.getCfaEdge().getDescription() + ".", "AutomatonIntExpr.CPAQuery"); } } } } pArgs .getLogger() .log( Level.WARNING, "Did not find the CPA to be queried " + cpaName + " CPA on Edge " + pArgs.getCfaEdge().getDescription() + "."); return new ResultValue<>( "Did not find the CPA to be queried " + cpaName + " CPA on Edge " + pArgs.getCfaEdge().getDescription() + ".", "AutomatonIntExpr.CPAQuery"); }