substitute<A extends Expr> method

A substitute<A extends Expr>(
  1. A ast,
  2. Map<Expr, Expr> substitutions
)

Substitutes expressions in expr where the keys of substitutions are replaced with their corresponding values.

Implementation

A substitute<A extends Expr>(A ast, Map<Expr, Expr> substitutions) {
  final fromPtr = calloc<Z3_ast>(substitutions.length);
  final toPtr = calloc<Z3_ast>(substitutions.length);
  try {
    for (var i = 0; i < substitutions.length; i++) {
      final entry = substitutions.entries.elementAt(i);
      fromPtr[i] = _createAST(entry.key);
      toPtr[i] = _createAST(entry.value);
    }
    final result = _z3.substitute(
      _createAST(ast),
      substitutions.length,
      fromPtr,
      toPtr,
    );
    return _getAST(result) as A;
  } finally {
    malloc.free(fromPtr);
    malloc.free(toPtr);
  }
}