Ignore:
Timestamp:
Feb 28, 2018, 4:48:22 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
446ffa3
Parents:
6a8df56
Message:

Changed warning system to prepare for toggling warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/SemanticError.cc

    r6a8df56 ra16764a6  
    2323#include "SemanticError.h"
    2424
    25 SemanticError::SemanticError( CodeLocation location, std::string error ) {
     25SemanticErrorException::SemanticErrorException( CodeLocation location, std::string error ) {
    2626        append( location, error );
    2727}
    2828
    29 void SemanticError::append( SemanticError &other ) {
     29void SemanticErrorException::append( SemanticErrorException &other ) {
    3030        errors.splice( errors.end(), other.errors );
    3131}
    3232
    33 void SemanticError::append( CodeLocation location, const std::string & msg ) {
     33void SemanticErrorException::append( CodeLocation location, const std::string & msg ) {
    3434        errors.emplace_back( location, msg );
    3535}
    3636
    37 bool SemanticError::isEmpty() const {
     37bool SemanticErrorException::isEmpty() const {
    3838        return errors.empty();
    3939}
    4040
    41 void SemanticError::print() {
     41void SemanticErrorException::print() {
    4242        using std::to_string;
    4343        for( auto err : errors ) {
    44                 std::cerr << bold() << err.location << error_str() << reset_font() << err.description << std::endl;
     44                std::cerr << ErrorHelpers::bold() << err.location << ErrorHelpers::error_str() << ErrorHelpers::reset_font() << err.description << std::endl;
    4545        }
    4646}
    4747
    48 SemanticWarning::SemanticWarning( CodeLocation location, std::string msg ) {
    49         std::cerr << bold() << location << warning_str() << reset_font() << msg << std::endl;
     48void SemanticError( CodeLocation location, std::string error ) {
     49        throw SemanticErrorException(location, error);
     50}
     51
     52void SemanticWarningImpl( CodeLocation location, std::string msg ) {
     53        std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl;
     54}
     55
     56//-----------------------------------------------------------------------------
     57// Helpers
     58namespace ErrorHelpers {
     59        const std::string & error_str() {
     60                static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: ";
     61                return str;
     62        }
     63
     64        const std::string & warning_str() {
     65                static std::string str = isatty( STDERR_FILENO ) ? "\e[95mwarning:\e[39m " : "warning: ";
     66                return str;
     67        }
     68
     69        const std::string & bold_ttycode() {
     70                static std::string str = isatty( STDERR_FILENO ) ? "\e[1m" : "";
     71                return str;
     72        }
     73
     74        const std::string & reset_font_ttycode() {
     75                static std::string str = isatty( STDERR_FILENO ) ? "\e[0m" : "";
     76                return str;
     77        }
     78
     79        std::string make_bold( const std::string & str ) {
     80                return bold_ttycode() + str + reset_font_ttycode();
     81        }
     82
     83        std::ostream & operator<<(std::ostream & os, bold) {
     84                os << bold_ttycode();
     85                return os;
     86        }
     87
     88        std::ostream & operator<<(std::ostream & os, reset_font) {
     89                os << reset_font_ttycode();
     90                return os;
     91        }
    5092}
    5193
Note: See TracChangeset for help on using the changeset viewer.