/*
 *  Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * either version 2, or (at your option) any later version of the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef _OPENCTL_MODULE_H_
#define _OPENCTL_MODULE_H_

#include <list>
#include <vector>

#include <GTLCore/Macros.h>
#include <GTLCore/String.h>
#include <OpenCTL/Export.h>

namespace GTLCore {
  class CompilationMessages;
  class Function;
  class ModuleData;
  class Type;
  class Parameter;
  class TypesManager;
}

namespace OpenCTL {
  /**
   * A Module represents a CTL program or module.
   * @ingroup OpenCTL
   */
  class OPENCTL_EXPORT Module {
      GTL_NO_COPY(Module);
    public:
      Module();
      ~Module();
      /**
       * @return the name of the module (usually the name of the file without the .ctl
       *         extension, and without the path)
       */
      GTLCore::String name() const;
      /**
       * @return the namespace used for this module
       */
      GTLCore::String nameSpace() const;
      /**
       * Set the code source of the module.
       */
      void setSource(const GTLCore::String& name, const GTLCore::String& source);
      /**
       * Load the module from the given file name.
       */
      void loadFromFile(const GTLCore::String& fileName);
      /**
       * @param name the name of the function
       * @return the functions with the given name
       */
      std::list<const GTLCore::Function*> functions(const GTLCore::String& name) const;
      /**
       * @return the function corresponding to the list of types given in argument
       */
      const GTLCore::Function* function(const GTLCore::String& name, std::vector<GTLCore::Parameter>& arguments) const;
      /**
       * Start the compilation of the module.
       */
      void compile();
      /**
       * @return true if the module was successfully compiled.
       */
      bool isCompiled() const;
      /**
       * @return a string with the content of the compilation error.
       */
      GTLCore::CompilationMessages compilationMessages() const;
      /**
       * @return the list of functions available in this module.
       */
      std::list<GTLCore::Function*> functions();
      /**
       * @return a pointer to the internal Data of this module (the class Module::Data
       *         is not part of the public API and therefoare there is no reason
       *         to use this function).
       */
      const GTLCore::ModuleData* data() const;
      /**
       * @return the type manager with the types defines and use by this module (this 
       *         includes type that are defined by imported modules)
       */
      const GTLCore::TypesManager* typesManager() const;
    public:
      /**
       * @return the assembly source code, mostly useful for testing purpose
       */
      GTLCore::String asmSourceCode() const;
    private:
      struct Private;
      Private* const d;
  };

}

#endif
