/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * File:   aux.h
 * Author: pgess <v.melnychenko@xreate.org>
 *
 * Created on June 26, 2016, 6:49 PM
 */

#ifndef AUX_H
#define AUX_H

#include "ast.h"
#include "transcendlayer.h"

#include <list>
#include <boost/format.hpp>

namespace xreate { namespace analysis {

/**
 * \brief Compiles Xreate expression into ASP format recognizable by an external ASP solver.
 * @param e expression
 * @return textual expression's representation in an ASP format.
 */
std::list<std::string> compile(const Expression &e);
std::list<std::string> compileNeg(const Expression &e);
std::list<std::string> multiplyLists(std::list<std::list<std::string>> &&lists);

ASTSitePacked getSite(const Expression& e, TranscendLayer* transcend);

/**
 * \brief Converts a Transcend's fact to a Xreate's expression that can be interpreted further. Supports `query` keyword.
 * @param atom Transcend's fact
 * @param schemaT Type of the resulting expression
 * @param transcend Transcend's instance
 * @return converted Transcend' fact in form of Xreate's expression
 */
Expression representTransExpression(const Gringo::Symbol& atom, ExpandedType schemaT, TranscendLayer* transcend);

/**
 * \brief Expands slave type.
 * @param t Slave type
 * @param transcend Instance of Transcend
 * @return The expanded slave type
 */
ExpandedType dereferenceSlaveType(ExpandedType t, const TranscendLayer* transcend);

TypeAnnotation collapseColumn(const std::list<Gringo::Symbol>& symbols);
std::list<Expression> generateAllInstancesInDomain2(const ExpandedType& domainT);

Expression representVecStr(const std::vector<std::string>& srcList);
Expression findAnnById(unsigned annId, const ExpandedType& annT, const std::list<Expression>& annotations);

}} //end of xreate::analysis

#endif /* AUX_H */

