Česky
Kamil Dudka

Flex/Bison based compiler and interpreter written in C++ (using Boost)

File detail

Name:DownloadvypIO.h [Download]
Location: vyp08 > vyp08-1.0pre1 > src
Size:4.4 KB
Last modification:2009-07-04 19:51

Source code

/*
 * Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
 *
 * This file is part of vyp08 (compiler and interpreter of VYP08 language).
 *
 * vyp08 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * vyp08 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with vyp08.  If not, see <http://www.gnu.org/licenses/>.
 */
 
#ifndef VYPIO_H
#define VYPIO_H
 
#include "config.h"
#include "scanner.h"
 
#ifndef BUILDING_DOX
#   include <iostream>
#   include <string>
#endif
 
/**
 * @brief Set of common stuff to work with streams.
 * (colored console output, etc.)
 */
namespace StreamDecorator {
    /// Console ouput colors enumeration. Zero means default color.
    enum EColor {
        C_NO_COLOR = 0,
        C_BLUE,
        C_GREEN,
        C_CYAN,
        C_RED,
        C_PURPLE,
        C_BROWN,
        C_LIGHT_GRAY,
        C_DARK_GRAY,
        C_LIGHT_BLUE,
        C_LIGHT_GREEN,
        C_LIGHT_CYAN,
        C_LIGHT_RED,
        C_LIGHT_PURPLE,
        C_YELLOW,
        C_WHITE
    };
 
    /**
     * @attention Global variable is used inside this class.
     * @brief Console output color manipulator
     */
    class Color {
        public:
            /**
             * @param color Desired color of console output. If omitted, default
             * color is assumed.
             */
            Color(EColor color = C_NO_COLOR);
            Color(const Color &);
            ~Color();
            /**
             * @attention Global variable is used inside this class.
             * @brief Enable/disable color ouput @b glaobally.
             */
            static void enable(bool);
            /**
             * @return Returns true if color output is @b gloablly enabled.
             */
            static bool isEnabled();
        private:
            Color& operator= (const Color &);
            static bool useColors;
            struct Private;
            Private *d;
            friend std::ostream& operator<< (std::ostream &, const Color &);
    };
    /// This behaves as standard stream manipulators.
    std::ostream& operator<< (std::ostream &, const Color &);
 
    /// error types enumeration
    enum EError {
        E_NO_ERROR = 0,                                 ///< should be not used
        E_ERROR,                                        ///< error
        E_WARNING,                                      ///< warning
        E_NOTE,                                         ///< some extra info
    };
 
    /// streamable error object
    class Error {
        public:
            /// constructor used mostly in lower layers of compiler
            Error(
                EError          type,                   ///< error type
                std::string     file,                   ///< input file causing the error
                std::string     msg,                    ///< error message
                int             lineno = 0,             ///< line number (0 means not used)
                std::string     category = std::string(),   ///< error category, e.g. lexical, ...
                Token           token = Token());       ///< input token causing the error
 
            /// constructor used mostly in higher layers of compiler
            Error(
                EError          type,                   ///< error type
                std::string     file,                   ///< input file causing the error
                std::string     msg,                    ///< error message,
                Token           token,                  ///< input token causing the error
                bool            internal = false);      ///< true for internal (compiler) error/warning
            ~Error();
        private:
            Color& operator= (const Color &);
            struct Private;
            Private *d;
            friend std::ostream& operator<< (std::ostream &, const Error &);
    };
    /// print error to stream (no new lines)
    std::ostream& operator<< (std::ostream &, const Error &);
 
} // namespace StreamDecorator
 
#endif /* VYPIO_H */