LCOV - code coverage report
Current view: top level - include/as2js - message.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 5 100.0 %
Date: 2014-11-22 Functions: 8 10 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #ifndef AS2JS_MESSAGE_H
       2             : #define AS2JS_MESSAGE_H
       3             : /* message.h -- written by Alexis WILKE for Made to Order Software Corp. (c) 2005-2014 */
       4             : 
       5             : /*
       6             : 
       7             : Copyright (c) 2005-2014 Made to Order Software Corp.
       8             : 
       9             : http://snapwebsites.org/project/as2js
      10             : 
      11             : Permission is hereby granted, free of charge, to any
      12             : person obtaining a copy of this software and
      13             : associated documentation files (the "Software"), to
      14             : deal in the Software without restriction, including
      15             : without limitation the rights to use, copy, modify,
      16             : merge, publish, distribute, sublicense, and/or sell
      17             : copies of the Software, and to permit persons to whom
      18             : the Software is furnished to do so, subject to the
      19             : following conditions:
      20             : 
      21             : The above copyright notice and this permission notice
      22             : shall be included in all copies or substantial
      23             : portions of the Software.
      24             : 
      25             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
      26             : ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
      27             : LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      28             : FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
      29             : EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      30             : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      31             : WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      32             : ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      33             : SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      34             : SOFTWARE.
      35             : 
      36             : */
      37             : 
      38             : #include    "position.h"
      39             : #include    "int64.h"
      40             : #include    "float64.h"
      41             : 
      42             : #include    <controlled_vars/controlled_vars_need_init.h>
      43             : 
      44             : #include    <sstream>
      45             : 
      46             : 
      47             : namespace as2js
      48             : {
      49             : 
      50             : 
      51             : enum class message_level_t
      52             : {
      53             :     MESSAGE_LEVEL_OFF,
      54             :     MESSAGE_LEVEL_FATAL,
      55             :     MESSAGE_LEVEL_ERROR,
      56             :     MESSAGE_LEVEL_WARNING,
      57             :     MESSAGE_LEVEL_INFO,
      58             :     MESSAGE_LEVEL_DEBUG,
      59             :     MESSAGE_LEVEL_TRACE
      60             : };
      61             : 
      62             : 
      63             : enum class err_code_t
      64             : {
      65             :     AS_ERR_NONE = 0,
      66             : 
      67             :     AS_ERR_ABSTRACT,
      68             :     AS_ERR_BAD_NUMERIC_TYPE,
      69             :     AS_ERR_BAD_PRAGMA,
      70             :     AS_ERR_CANNOT_COMPILE,
      71             :     AS_ERR_CANNOT_MATCH,
      72             :     AS_ERR_CANNOT_OVERLOAD,
      73             :     AS_ERR_CANNOT_OVERWRITE_CONST,
      74             :     AS_ERR_CASE_LABEL,
      75             :     AS_ERR_COLON_EXPECTED,
      76             :     AS_ERR_COMMA_EXPECTED,
      77             :     AS_ERR_CURVLY_BRACKETS_EXPECTED,
      78             :     AS_ERR_DEFAULT_LABEL,
      79             :     AS_ERR_DIVIDE_BY_ZERO,
      80             :     AS_ERR_DUPLICATES,
      81             :     AS_ERR_DYNAMIC,
      82             :     AS_ERR_EXPRESSION_EXPECTED,
      83             :     AS_ERR_FINAL,
      84             :     AS_ERR_IMPROPER_STATEMENT,
      85             :     AS_ERR_INACCESSIBLE_STATEMENT,
      86             :     AS_ERR_INCOMPATIBLE,
      87             :     AS_ERR_INCOMPATIBLE_PRAGMA_ARGUMENT,
      88             :     AS_ERR_INSTALLATION,
      89             :     AS_ERR_INSTANCE_EXPECTED,
      90             :     AS_ERR_INTERNAL_ERROR,
      91             :     AS_ERR_NATIVE,
      92             :     AS_ERR_INVALID_ARRAY_FUNCTION,
      93             :     AS_ERR_INVALID_ATTRIBUTES,
      94             :     AS_ERR_INVALID_CATCH,
      95             :     AS_ERR_INVALID_CLASS,
      96             :     AS_ERR_INVALID_CONDITIONAL,
      97             :     AS_ERR_INVALID_DEFINITION,
      98             :     AS_ERR_INVALID_DO,
      99             :     AS_ERR_INVALID_ENUM,
     100             :     AS_ERR_INVALID_EXPRESSION,
     101             :     AS_ERR_INVALID_FIELD,
     102             :     AS_ERR_INVALID_FIELD_NAME,
     103             :     AS_ERR_INVALID_FRAME,
     104             :     AS_ERR_INVALID_FUNCTION,
     105             :     AS_ERR_INVALID_GOTO,
     106             :     AS_ERR_INVALID_IMPORT,
     107             :     AS_ERR_INVALID_INPUT_STREAM,
     108             :     AS_ERR_INVALID_KEYWORD,
     109             :     AS_ERR_INVALID_LABEL,
     110             :     AS_ERR_INVALID_NAMESPACE,
     111             :     AS_ERR_INVALID_NODE,
     112             :     AS_ERR_INVALID_NUMBER,
     113             :     AS_ERR_INVALID_OPERATOR,
     114             :     AS_ERR_INVALID_PACKAGE_NAME,
     115             :     AS_ERR_INVALID_PARAMETERS,
     116             :     AS_ERR_INVALID_REST,
     117             :     AS_ERR_INVALID_RETURN_TYPE,
     118             :     AS_ERR_INVALID_SCOPE,
     119             :     AS_ERR_INVALID_TRY,
     120             :     AS_ERR_INVALID_TYPE,
     121             :     AS_ERR_INVALID_UNICODE_ESCAPE_SEQUENCE,
     122             :     AS_ERR_INVALID_VARIABLE,
     123             :     AS_ERR_IO_ERROR,
     124             :     AS_ERR_LABEL_NOT_FOUND,
     125             :     AS_ERR_LOOPING_REFERENCE,
     126             :     AS_ERR_MISMATCH_FUNC_VAR,
     127             :     AS_ERR_MISSSING_VARIABLE_NAME,
     128             :     AS_ERR_NEED_CONST,
     129             :     AS_ERR_NOT_ALLOWED,
     130             :     AS_ERR_NOT_ALLOWED_IN_STRICT_MODE,
     131             :     AS_ERR_NOT_FOUND,
     132             :     AS_ERR_NOT_SUPPORTED,
     133             :     AS_ERR_OBJECT_MEMBER_DEFINED_TWICE,
     134             :     AS_ERR_PARENTHESIS_EXPECTED,
     135             :     AS_ERR_PRAGMA_FAILED,
     136             :     AS_ERR_SEMICOLON_EXPECTED,
     137             :     AS_ERR_SQUARE_BRACKETS_EXPECTED,
     138             :     AS_ERR_STRING_EXPECTED,
     139             :     AS_ERR_STATIC,
     140             :     AS_ERR_TYPE_NOT_LINKED,
     141             :     AS_ERR_UNKNOWN_ESCAPE_SEQUENCE,
     142             :     AS_ERR_UNKNOWN_OPERATOR,
     143             :     AS_ERR_UNTERMINATED_STRING,
     144             :     AS_ERR_UNEXPECTED_EOF,
     145             :     AS_ERR_UNEXPECTED_PUNCTUATION,
     146             :     AS_ERR_UNEXPECTED_TOKEN,
     147             :     AS_ERR_UNEXPECTED_DATABASE,
     148             :     AS_ERR_UNEXPECTED_RC,
     149             : 
     150             :     AS_ERR_max
     151             : };
     152             : 
     153             : 
     154     2989071 : class MessageCallback
     155             : {
     156             : public:
     157     2989070 :     virtual             ~MessageCallback() {}
     158             : 
     159             :     virtual void        output(message_level_t message_level, err_code_t error_code, Position const& pos, std::string const& message) = 0;
     160             : };
     161             : 
     162             : 
     163             : // Note: avoid copies because with such you'd get the Message two or more times
     164             : class Message : public std::stringstream
     165             : {
     166             : public:
     167             :                         Message(message_level_t message_level, err_code_t error_code, Position const& pos);
     168             :                         Message(message_level_t message_level, err_code_t error_code);
     169             :                         Message(Message const& rhs) = delete;
     170             :                         ~Message();
     171             : 
     172             :     Message&            operator = (Message const& rhs) = delete;
     173             : 
     174             :     template<typename T>
     175     3342310 :     Message&            operator << (T const& data)
     176             :                         {
     177     3342310 :                             static_cast<std::stringstream&>(*this) << data;
     178     3342310 :                             return *this;
     179             :                         }
     180             : 
     181             :     // internal types; you can add your own types with
     182             :     // Message& operator << (Message& os, <my-type>);
     183             :     Message&            operator << (char const *s);
     184             :     Message&            operator << (wchar_t const *s);
     185             :     Message&            operator << (std::string const& s);
     186             :     Message&            operator << (std::wstring const& s);
     187             :     Message&            operator << (String const& s);
     188             :     Message&            operator << (char const v);
     189             :     Message&            operator << (signed char const v);
     190             :     Message&            operator << (unsigned char const v);
     191             :     Message&            operator << (signed short const v);
     192             :     Message&            operator << (unsigned short const v);
     193             :     Message&            operator << (signed int const v);
     194             :     Message&            operator << (unsigned int const v);
     195             :     Message&            operator << (signed long const v);
     196             :     Message&            operator << (unsigned long const v);
     197             :     Message&            operator << (signed long long const v);
     198             :     Message&            operator << (unsigned long long const v);
     199             :     Message&            operator << (Int64 const v);
     200             :     Message&            operator << (float const v);
     201             :     Message&            operator << (double const v);
     202             :     Message&            operator << (Float64 const v);
     203             :     Message&            operator << (bool const v);
     204             : 
     205             :     static void         set_message_callback(MessageCallback *callback);
     206             :     static void         set_message_level(message_level_t min_level);
     207             :     static int          warning_count();
     208             :     static int          error_count();
     209             : 
     210             : private:
     211             :     controlled_vars::need_init<message_level_t> f_message_level;
     212             :     controlled_vars::need_init<err_code_t>      f_error_code;
     213             :     Position                                    f_position;
     214             : };
     215             : 
     216             : 
     217             : 
     218             : }
     219             : // namespace as2js
     220             : #endif
     221             : //#ifndef AS2JS_MESSAGE_H
     222             : 
     223             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.10