/*
 *  JavaSMT is an API wrapper for a collection of SMT solvers.
 *  This file is part of JavaSMT.
 *
 *  Copyright (C) 2007-2015  Dirk Beyer
 *  All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.sosy_lab.java_smt.solvers.cvc4;

import edu.nyu.acsys.CVC4.Expr;
import edu.nyu.acsys.CVC4.ExprManager;
import edu.nyu.acsys.CVC4.Type;
import org.sosy_lab.common.Appender;
import org.sosy_lab.java_smt.api.BooleanFormula;
import org.sosy_lab.java_smt.api.Formula;
import org.sosy_lab.java_smt.basicimpl.AbstractFormulaManager;
import org.sosy_lab.java_smt.basicimpl.FormulaCreator;

class CVC4FormulaManager extends AbstractFormulaManager<Expr, Type, ExprManager, Expr> {

  CVC4FormulaManager(
      FormulaCreator<Expr, Type, ExprManager, Expr> pFormulaCreator,
      CVC4UFManager pFfmgr,
      CVC4BooleanFormulaManager pBfmgr,
      CVC4IntegerFormulaManager pIfmgr,
      CVC4RationalFormulaManager pRfmgr,
      CVC4ArrayFormulaManager pAfmgr) {
    super(pFormulaCreator, pFfmgr, pBfmgr, pIfmgr, pRfmgr, null, null, null, pAfmgr);
  }

  static Expr getCVC4Expr(Formula pT) {
    if (pT instanceof CVC4Formula) {
      return ((CVC4Formula) pT).getTerm();
    }
    throw new IllegalArgumentException(
        "Cannot get the formula info of type " + pT.getClass().getSimpleName() + " in the Solver!");
  }

  BooleanFormula encapsulateBooleanFormula(Expr t) {
    return getFormulaCreator().encapsulateBoolean(t);
  }

  @Override
  public BooleanFormula parse(String pS) throws IllegalArgumentException {
    throw new UnsupportedOperationException();
  }

  @Override
  public Appender dumpFormula(Expr pT) {
    throw new UnsupportedOperationException();
  }
}

@@ -777,16 +777,56 @@
 .cvc4;%0A%0A
+import com.google.common.base.Splitter;%0A
 import e
@@ -849,16 +849,16 @@
 4.Expr;%0A
-
 import e
@@ -920,16 +920,44 @@
 4.Type;%0A
+import java.io.IOException;%0A
 import o
@@ -981,24 +981,62 @@
 n.Appender;%0A
+import org.sosy_lab.common.Appenders;%0A
 import org.s
@@ -1106,32 +1106,78 @@
 mt.api.Formula;%0A
+import org.sosy_lab.java_smt.api.FormulaType;%0A
 import org.sosy_
@@ -2310,26 +2310,25 @@
 la(Expr 
-pT
+f
 ) %7B%0A    
 throw ne
@@ -2323,49 +2323,802 @@
     
-throw new UnsupportedOperationException()
+assert getFormulaCreator().getFormulaType(f) == FormulaType.BooleanType%0A        : %22Only BooleanFormulas may be dumped%22;%0A%0A    // Lazy invocation of msat_to_smtlib2 wrapped in an Appender.%0A    return new Appenders.AbstractAppender() %7B%0A      @Override%0A      public void appendTo(Appendable out) throws IOException %7B%0A        String cvc4String = f.toString();%0A        // Adjust line breaks: assert needs to be on last line, so we remove all following breaks.%0A        boolean needsLinebreak = true;%0A        for (String part : Splitter.on('%5Cn').split(cvc4String)) %7B%0A          out.append(part);%0A          if (needsLinebreak && part.startsWith(%22(assert%22)) %7B%0A            needsLinebreak = false;%0A          %7D%0A          if (needsLinebreak) %7B%0A            out.append('%5Cn');%0A          %7D%0A        %7D%0A      %7D%0A    %7D
 ;%0A  

Implement missing method in CVC4FormulaManager