/*******************************************************************************
 * Copyright (c) 2015-2017 ONERA and IRT AESE (IRT Saint Exupéry).
 * Ce logiciel est la propriété de l’ONERA (the French Aerospace Lab) et de
 * l'IRT AESE (IRT Saint Exupéry).
 * Tous droits réservés.
 *
 * Ce programme et les éléments qui l'accompagnent sont mis à disposition
 * aux conditions définies par le contrat de licence logiciel CeCILL-C soumise
 * au droit français et respectant les principes de diffusion des logiciels libres.
 * Vous pouvez utiliser, modifier et/ou redistribuer ce programme
 * sous les conditions de la licence CeCILL-C (http://www.cecill.info).

 * This software is property of ONERA (the French Aerospace Lab) and of
 * the IRT AESE (IRT Saint Exupéry).
 * All rights reserved.
 *
 * This program and the accompanying materials are made available under
 * the terms of the CeCILL-C license under French law and
 * abiding by the rules of distribution of free software.
 * You can  use, modify and/ or redistribute the software under the terms of
 * the CeCILL-C license (http://www.cecill.info).
 *
 * Contributeurs/contributors:
 *     Guillaume Infantes (ONERA - Centre de Toulouse) - initial API and implementation
 *     Alexandre Albore (IRT Saint-Exupéry) - Altarica/Fiacre translation
 *
 *******************************************************************************/

#include "ExpressionIfThenElse.hh"


using namespace epoch::altarica;


std::string ExpressionIfThenElse::toString() const {
    std::string s;
    s+= "if " + cond_->toString() + " then " + then_->toString();
    if (else_ != NULL)
	s+= " else " + else_->toString();
    return s;
}

/// Example :  t := if r|q then 2 else 5
///          p -> 5
/// ==> if ( r|q ) then t := 2
///      else t := 5
std::string ExpressionIfThenElse::toFiacre(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am, std::string head) const {
	    std::string s;

    	s+= "if " + (cond_)->toString(n, f, am) + " then " + head + then_->toString(n, f, am);

    if (else_ != NULL)
    	s+= "\n\telse  " + head + else_->toString(n, f, am);

    s+= " end";
    return s;
}


std::string ExpressionIfThenElse::toString(const Node *n, const AltaricaModel& am) const {
    std::string s;
    s+= "if " + cond_->toString(n, am) + " then " + then_->toString(n, am);
    if (else_ != NULL)
	s+= " else "  + else_->toString(n, am);
    return s;
}


std::string ExpressionIfThenElse::toString(const Node *n, const std::pair<std::string,std::string> *f, const AltaricaModel& am) const {
    std::string s;
    s = "if "+ cond_->toString(n, f, am)  + " then " + then_->toString(n, f, am);
    if (else_ != NULL)
    	s+=  " else " + else_->toString(n, f, am);
    return s;
}

